diff options
author | Chris Dunlap <[email protected]> | 2014-04-08 15:31:36 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2014-04-09 13:32:54 -0700 |
commit | 6ac770b1961b9468daf0c69eae6515c608535789 (patch) | |
tree | 073446e64b68d7fc66ccc0c015fc393be60c51c4 /cmd/zed/zed_conf.c | |
parent | 7368eb621e6c94dd8fd37020568f32c120afabf9 (diff) |
Replace zed_file_create_dirs() with mkdirp()
When processing directory components starting from the root dir,
zed_file_create_dirs() contained a bug in checking the return value of
mkdir(). A typo was made, and the test for (mkdir_errno != EEXIST) was
erroneously written as (mkdir_errno == EEXIST). If some of the leading
directory components already existed, this bug would cause the routine
to exit before creating the remaining directory components.
Instead of fixing the above mkdir_errno test, this commit replaces
zed_file_create_dirs() with mkdirp(). This cleanup was already
planned, and zed_file_create_dirs() only existed because I didn't
realize mkdirp() was already in tree at the time.
Signed-off-by: Chris Dunlap <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #2248
Diffstat (limited to 'cmd/zed/zed_conf.c')
-rw-r--r-- | cmd/zed/zed_conf.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/cmd/zed/zed_conf.c b/cmd/zed/zed_conf.c index fb3e552e9..78b45e910 100644 --- a/cmd/zed/zed_conf.c +++ b/cmd/zed/zed_conf.c @@ -29,6 +29,7 @@ #include <dirent.h> #include <errno.h> #include <fcntl.h> +#include <libgen.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> @@ -435,6 +436,7 @@ int zed_conf_write_pid(struct zed_conf *zcp) { char dirbuf[PATH_MAX]; + mode_t dirmode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; int n; char *p; mode_t mask; @@ -457,10 +459,12 @@ zed_conf_write_pid(struct zed_conf *zcp) if (p) *p = '\0'; - /* FIXME: Replace with mkdirp()? (lib/libspl/mkdirp.c) */ - if (zed_file_create_dirs(dirbuf) < 0) + if ((mkdirp(dirbuf, dirmode) < 0) && (errno != EEXIST)) { + zed_log_msg(LOG_WARNING, + "Failed to create directory \"%s\": %s", + dirbuf, strerror(errno)); return (-1); - + } (void) unlink(zcp->pid_file); mask = umask(0); @@ -494,6 +498,7 @@ int zed_conf_open_state(struct zed_conf *zcp) { char dirbuf[PATH_MAX]; + mode_t dirmode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; int n; char *p; int rv; @@ -515,10 +520,12 @@ zed_conf_open_state(struct zed_conf *zcp) if (p) *p = '\0'; - /* FIXME: Replace with mkdirp()? (lib/libspl/mkdirp.c) */ - if (zed_file_create_dirs(dirbuf) < 0) + if ((mkdirp(dirbuf, dirmode) < 0) && (errno != EEXIST)) { + zed_log_msg(LOG_WARNING, + "Failed to create directory \"%s\": %s", + dirbuf, strerror(errno)); return (-1); - + } if (zcp->state_fd >= 0) { if (close(zcp->state_fd) < 0) { zed_log_msg(LOG_WARNING, |