From 232da7ecc7a01aa3df9b12c150f6a235a0859c0f Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Thu, 25 Jan 2007 14:16:20 +0000 Subject: [PATCH] Add some missing close() and fclose() return value checks. --- WHATS_NEW_DM | 1 + daemons/dmeventd/dmeventd.c | 5 +++-- libdm/ioctl/libdm-iface.c | 13 +++++++------ tools/dmsetup.c | 17 +++++++++-------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index d0a9a05e3..9ea50ee2c 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.16 - =================================== + Add some missing close() and fclose() return value checks. Migrate dmsetup column-based output over to new libdevmapper report framework. Add descriptions to reporting field definitions. Add a dso-private variable to dmeventd dso interface. diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c index 69e8ecac6..536d6471c 100644 --- a/daemons/dmeventd/dmeventd.c +++ b/daemons/dmeventd/dmeventd.c @@ -1566,7 +1566,8 @@ static int _set_oom_adj(int val) } fprintf(fp, "%i", val); - fclose(fp); + if (fclose(fp)) + perror(OOM_ADJ_FILE ": fclose failed"); return 1; } @@ -1583,7 +1584,7 @@ static void _daemonize(void) sigemptyset(&my_sigset); if (sigprocmask(SIG_SETMASK, &my_sigset, NULL) < 0) { - fprintf(stderr, "Unable to restore signals."); + fprintf(stderr, "Unable to restore signals.\n"); exit(EXIT_FAILURE); } signal(SIGTERM, &_exit_handler); diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c index d343bc19c..0211657ac 100644 --- a/libdm/ioctl/libdm-iface.c +++ b/libdm/ioctl/libdm-iface.c @@ -149,7 +149,8 @@ static int _get_proc_number(const char *file, const char *name, if (!strcmp(name, nm)) { if (number) { *number = num; - fclose(fl); + if (fclose(fl)) + log_error("%s: fclose failed: %s", file, strerror(errno)); return 1; } dm_bit_set(_dm_bitset, num); @@ -158,7 +159,8 @@ static int _get_proc_number(const char *file, const char *name, c = fgetc(fl); } while (c != EOF && c != '\n'); } - fclose(fl); + if (fclose(fl)) + log_error("%s: fclose failed: %s", file, strerror(errno)); if (number) { log_error("%s: No entry for %s found", file, name); @@ -1322,7 +1324,7 @@ static int _process_mapper_dir(struct dm_task *dmt) dir = dm_dir(); if (!(d = opendir(dir))) { - fprintf(stderr, "opendir %s: %s", dir, strerror(errno)); + log_error("opendir %s: %s", dir, strerror(errno)); return 0; } @@ -1335,9 +1337,8 @@ static int _process_mapper_dir(struct dm_task *dmt) dm_task_run(dmt); } - if (closedir(d)) { - fprintf(stderr, "closedir %s: %s", dir, strerror(errno)); - } + if (closedir(d)) + log_error("closedir %s: %s", dir, strerror(errno)); return r; } diff --git a/tools/dmsetup.c b/tools/dmsetup.c index 1b544c79b..b2dc16c82 100644 --- a/tools/dmsetup.c +++ b/tools/dmsetup.c @@ -231,8 +231,9 @@ static int _parse_file(struct dm_task *dmt, const char *file) #else free(buffer); #endif - if (file) - fclose(fp); + if (file && fclose(fp)) + fprintf(stderr, "%s: fclose failed: %s", file, strerror(errno)); + return r; } @@ -1479,7 +1480,7 @@ static int _tree(int argc, char **argv, void *data __attribute((unused))) static int _int32_disp(struct dm_report *rh, struct dm_pool *mem __attribute((unused)), struct dm_report_field *field, const void *data, - void *private) + void *private __attribute((unused))) { const int32_t value = *(const int32_t *)data; @@ -1489,7 +1490,7 @@ static int _int32_disp(struct dm_report *rh, static int _uint32_disp(struct dm_report *rh, struct dm_pool *mem __attribute((unused)), struct dm_report_field *field, const void *data, - void *private) + void *private __attribute((unused))) { const uint32_t value = *(const int32_t *)data; @@ -1499,7 +1500,7 @@ static int _uint32_disp(struct dm_report *rh, static int _dm_name_disp(struct dm_report *rh, struct dm_pool *mem __attribute((unused)), struct dm_report_field *field, const void *data, - void *private) + void *private __attribute((unused))) { const char *name = dm_task_get_name((struct dm_task *) data); @@ -1509,7 +1510,7 @@ static int _dm_name_disp(struct dm_report *rh, static int _dm_uuid_disp(struct dm_report *rh, struct dm_pool *mem __attribute((unused)), struct dm_report_field *field, - const void *data, void *private) + const void *data, void *private __attribute((unused))) { const char *uuid = dm_task_get_uuid((struct dm_task *) data); @@ -1522,7 +1523,7 @@ static int _dm_uuid_disp(struct dm_report *rh, static int _dm_info_status_disp(struct dm_report *rh, struct dm_pool *mem __attribute((unused)), struct dm_report_field *field, const void *data, - void *private) + void *private __attribute((unused))) { char buf[5]; const char *s = buf; @@ -1607,7 +1608,7 @@ static int _report_init(struct command *c) options = _string_args[OPTIONS_ARG]; else { len = strlen(default_report_options) + - strlen(_string_args[OPTIONS_ARG]); + strlen(_string_args[OPTIONS_ARG]) + 1; if (!(options = dm_malloc(len))) { err("Failed to allocate option string."); return 0;