From d9bba4f16f7c6f6f4496e831bfb3137defc459fe Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Wed, 21 Sep 2011 10:42:53 +0000 Subject: [PATCH] Check for failing 'stat' and skip this loop iteration (since data in statbuf are invalid). Check whether sysconf managed to find _SC_PAGESIZE. Report at least debug warning about failing unlink (logging scheme here seems to be a different then in lvm). Duplicate terminal FDs and use similar code as is made in clvmd and cleanup warns about missing open/close tests. FIXME: Looks like we already have 3 instancies of the same code in lvm repo. --- WHATS_NEW | 1 + daemons/cmirrord/clogd.c | 19 +++++++++++++++---- daemons/cmirrord/functions.c | 17 ++++++++++++++--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index e7fd3773f..7a341360b 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.89 - ================================== + Add missing error checks for some system calls in cmirrord. Add missing log_error() to lvresize command when fsadm tool fails. Add support for DM_DEV_DIR device path into fsadm script. Support different PATH setting for fsadm script testing. diff --git a/daemons/cmirrord/clogd.c b/daemons/cmirrord/clogd.c index 887c7f4c4..32b01a63b 100644 --- a/daemons/cmirrord/clogd.c +++ b/daemons/cmirrord/clogd.c @@ -134,6 +134,12 @@ static void daemonize(void) { int pid; int status; + int devnull; + + if ((devnull = open("/dev/null", O_RDWR)) == -1) { + LOG_ERROR("Can't open /dev/null: %s", strerror(errno)); + exit(EXIT_FAILURE); + } signal(SIGTERM, &parent_exit_handler); @@ -182,10 +188,15 @@ static void daemonize(void) chdir("/"); umask(0); - close(0); close(1); close(2); - open("/dev/null", O_RDONLY); /* reopen stdin */ - open("/dev/null", O_WRONLY); /* reopen stdout */ - open("/dev/null", O_WRONLY); /* reopen stderr */ + if (close(0) || close(1) || close(2)) { + LOG_ERROR("Failed to close terminal FDs"); + exit(EXIT_FAILURE); + } + + if ((dup2(devnull, 0) < 0) || /* reopen stdin */ + (dup2(devnull, 1) < 0) || /* reopen stdout */ + (dup2(devnull, 2) < 0)) /* reopen stderr */ + exit(EXIT_FAILURE); LOG_OPEN("cmirrord", LOG_PID, LOG_DAEMON); diff --git a/daemons/cmirrord/functions.c b/daemons/cmirrord/functions.c index 161121059..192ab40ea 100644 --- a/daemons/cmirrord/functions.c +++ b/daemons/cmirrord/functions.c @@ -329,7 +329,10 @@ static int find_disk_path(char *major_minor_str, char *path_rtn, int *unlink_pat */ sprintf(path_rtn, "/dev/mapper/%s", dep->d_name); - stat(path_rtn, &statbuf); + if (stat(path_rtn, &statbuf) < 0) { + LOG_DBG("Unable to stat %s", path_rtn); + continue; + } if (S_ISBLK(statbuf.st_mode) && (major(statbuf.st_rdev) == major) && (minor(statbuf.st_rdev) == minor)) { @@ -476,7 +479,12 @@ static int _clog_ctr(char *uuid, uint64_t luid, lc->sync_count = (log_sync == NOSYNC) ? region_count : 0; if (disk_log) { - page_size = sysconf(_SC_PAGESIZE); + if ((page_size = sysconf(_SC_PAGESIZE)) < 0) { + LOG_ERROR("Unable to read pagesize: %s", + strerror(errno)); + r = errno; + goto fail; + } pages = *(lc->clean_bits) / page_size; pages += *(lc->clean_bits) % page_size ? 1 : 0; pages += 1; /* for header */ @@ -489,7 +497,10 @@ static int _clog_ctr(char *uuid, uint64_t luid, goto fail; } if (unlink_path) - unlink(disk_path); + if (unlink(disk_path) < 0) { + LOG_DBG("Warning: Unable to unlink log device, %s: %s", + disk_path, strerror(errno)); + } lc->disk_fd = r; lc->disk_size = pages * page_size; -- 2.43.5