diff options
author | Luca Berra <bluca@comedia.it> | 2010-02-28 15:42:57 +0100 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2010-03-03 11:54:47 +1100 |
commit | ed8fa52f31521b8314859f290c464f77359933a0 (patch) | |
tree | c379d25f1ef9a5f169bb6dcd6b7743ec2633eee1 /mdmon.c | |
parent | cf556303573cd8cb9140c819b1ba1102ebc9cac7 (diff) | |
download | mdadm-ed8fa52f31521b8314859f290c464f77359933a0.tar.gz mdadm-ed8fa52f31521b8314859f290c464f77359933a0.tar.xz mdadm-ed8fa52f31521b8314859f290c464f77359933a0.zip |
mdmon: check select a writable pid_dir
Check that either VAR_DIR or ALT_DIR is actually writable before
selecting it.
Signed-off-by: Luca Berra <bluca@comedia.it>
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'mdmon.c')
-rw-r--r-- | mdmon.c | 25 |
1 files changed, 12 insertions, 13 deletions
@@ -120,6 +120,9 @@ static int make_pidfile(char *devname) int fd; int n; + if (mkdir(pid_dir, 0600) < 0 && + errno != EEXIST) + return -errno; sprintf(path, "%s/%s.pid", pid_dir, devname); fd = open(path, O_RDWR|O_CREAT|O_EXCL, 0600); @@ -474,20 +477,16 @@ static int mdmon(char *devname, int devnum, int must_fork, int takeover) */ if (victim > 0) remove_pidfile(devname); - if (mkdir(VAR_RUN, 0600) >= 0 || errno == EEXIST) - pid_dir = VAR_RUN; - else if (mkdir(ALT_RUN, 0600) >= 0 || errno == EEXIST) - pid_dir = ALT_RUN; - else { - fprintf(stderr, "mdmon: Neither %s nor %s are writable\n" - " cannot create .pid or .sock files. Aborting\n", - VAR_RUN, ALT_RUN); - exit(3); - } + pid_dir = VAR_RUN; if (make_pidfile(devname) < 0) { - fprintf(stderr, "mdmon: Cannot create pid file in %s - aborting.\n", - pid_dir); - exit(3); + /* Try the alternate */ + pid_dir = ALT_RUN; + if (make_pidfile(devname) < 0) { + fprintf(stderr, "mdmon: Neither %s nor %s are writable\n" + " cannot create .pid or .sock files. Aborting\n", + VAR_RUN, ALT_RUN); + exit(3); + } } container->sock = make_control_sock(devname); |