summaryrefslogtreecommitdiffstats
path: root/mdmon.c
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2008-09-15 20:58:43 -0700
committerDan Williams <dan.j.williams@intel.com>2008-09-15 20:58:43 -0700
commit295646b3d59c7d8d8c389ff320b30e61552ba331 (patch)
tree150b20b04a0c112123e35cbca62e40ac7d525918 /mdmon.c
parent313a4a82f130e6668ba0f4550200662e168aa945 (diff)
downloadmdadm-295646b3d59c7d8d8c389ff320b30e61552ba331.tar.gz
mdadm-295646b3d59c7d8d8c389ff320b30e61552ba331.tar.xz
mdadm-295646b3d59c7d8d8c389ff320b30e61552ba331.zip
mdmon: recreate socket/pid file on SIGHUP
Allow mdmon to start while /var/run/mdadm is readonly. Later a SIGHUP can trigger mdmon to drop its pid and socket once /var/run/mdadm is writable. Of course one needs the pid to send a HUP, that can be stored in a distribution specific rw-init directory... For now, rely on a killall -HUP mdmon to get the files dumped. Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'mdmon.c')
-rw-r--r--mdmon.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/mdmon.c b/mdmon.c
index 9485757..073d769 100644
--- a/mdmon.c
+++ b/mdmon.c
@@ -80,7 +80,7 @@ static struct superswitch *find_metadata_methods(char *vers)
}
-static int make_pidfile(char *devname, int o_excl)
+int make_pidfile(char *devname, int o_excl)
{
char path[100];
char pid[10];
@@ -89,7 +89,7 @@ static int make_pidfile(char *devname, int o_excl)
fd = open(path, O_RDWR|O_CREAT|o_excl, 0600);
if (fd < 0)
- return -1;
+ return -errno;
sprintf(pid, "%d\n", getpid());
write(fd, pid, strlen(pid));
close(fd);
@@ -138,7 +138,7 @@ void remove_pidfile(char *devname)
unlink(buf);
}
-static int make_control_sock(char *devname)
+int make_control_sock(char *devname)
{
char path[100];
int sfd;
@@ -164,6 +164,12 @@ static int make_control_sock(char *devname)
return sfd;
}
+int socket_hup_requested;
+static void hup(int sig)
+{
+ socket_hup_requested = 1;
+}
+
static void wake_me(int sig)
{
@@ -245,21 +251,29 @@ int main(int argc, char *argv[])
container->devname);
exit(3);
} else {
+ int err;
+
/* cleanup the old monitor, this one is taking over */
try_kill_monitor(container->devname);
- if (make_pidfile(container->devname, 0) < 0) {
+ err = make_pidfile(container->devname, 0);
+ if (err < 0) {
fprintf(stderr, "mdmon: %s Cannot create pidfile\n",
container->devname);
- exit(3);
+ if (err == -EROFS) {
+ /* FIXME implement a mechanism to
+ * prevent duplicate monitor instances
+ */
+ fprintf(stderr,
+ "mdmon: continuing on read-only file system\n");
+ } else
+ exit(3);
}
}
}
container->sock = make_control_sock(container->devname);
- if (container->sock < 0) {
+ if (container->sock < 0)
fprintf(stderr, "mdmon: Cannot create socket in /var/run/mdadm\n");
- exit(3);
- }
container->arrays = NULL;
mdi = sysfs_read(mdfd, container->devnum,
@@ -329,15 +343,18 @@ int main(int argc, char *argv[])
*/
sigemptyset(&set);
sigaddset(&set, SIGUSR1);
+ sigaddset(&set, SIGHUP);
sigprocmask(SIG_BLOCK, &set, NULL);
act.sa_handler = wake_me;
act.sa_flags = 0;
sigaction(SIGUSR1, &act, NULL);
+ act.sa_handler = hup;
+ sigaction(SIGHUP, &act, NULL);
act.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &act, NULL);
if (clone_monitor(container) < 0) {
- fprintf(stderr, "md-manage: failed to start monitor process: %s\n",
+ fprintf(stderr, "mdmon: failed to start monitor process: %s\n",
strerror(errno));
exit(2);
}