1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00

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.
This commit is contained in:
Zdenek Kabelac 2011-09-21 10:42:53 +00:00
parent 1a82ef4386
commit a456d3c77f
3 changed files with 30 additions and 7 deletions

View File

@ -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.

View File

@ -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);

View File

@ -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;