return NULL;
}
-static int test_pidfile(char *devname)
-{
- char path[100];
- struct stat st;
-
- sprintf(path, "/var/run/mdadm/%s.pid", devname);
- return stat(path, &st);
-}
-
int make_pidfile(char *devname, int o_excl)
{
char path[100];
return 1;
}
-pid_t devname2mdmon(char *devname)
-{
- char buf[100];
- pid_t pid = -1;
- int fd;
-
- sprintf(buf, "/var/run/mdadm/%s.pid", devname);
- fd = open(buf, O_RDONLY|O_NOATIME);
- if (fd < 0)
- return -1;
-
- if (read(fd, buf, sizeof(buf)) > 0)
- sscanf(buf, "%d\n", &pid);
- close(fd);
-
- return pid;
-}
-
static void try_kill_monitor(pid_t pid, char *devname, int sock)
{
char buf[100];
switch (fork()) {
case 0:
- victim = devname2mdmon(devname);
+ victim = mdmon_pid(devnum);
victim_sock = connect_monitor(devname);
if (chroot(switchroot) != 0) {
fprintf(stderr, "mdmon: failed to chroot to '%s': %s\n",
* the new root
*/
if (switchroot[0] == '/') {
- victim = devname2mdmon(container->devname);
+ victim = mdmon_pid(container->devnum);
victim_sock = connect_monitor(container->devname);
} else {
victim = atoi(switchroot);
}
ignore = chdir("/");
- if (victim < 0 && test_pidfile(container->devname) == 0) {
+ if (victim < 0) {
if (ping_monitor(container->devname) == 0) {
fprintf(stderr, "mdmon: %s already managed\n",
container->devname);
exit(3);
- } else if (victim < 0)
- victim = devname2mdmon(container->devname);
+ }
+ /* if there is a pid file, kill whoever is there just in case */
+ victim = mdmon_pid(container->devnum);
}
if (container->ss->load_super(container, mdfd, devname)) {
fprintf(stderr, "mdmon: Cannot load metadata for %s\n",