diff --git a/daemons/lvmlockd/lvmlockd-dlm.c b/daemons/lvmlockd/lvmlockd-dlm.c index ce9d9acf2..52a293abb 100644 --- a/daemons/lvmlockd/lvmlockd-dlm.c +++ b/daemons/lvmlockd/lvmlockd-dlm.c @@ -226,14 +226,14 @@ static int get_local_nodeid(void) { struct dirent *de; DIR *ls_dir; - char ls_comms_path[PATH_MAX]; + char ls_comms_path[PATH_MAX] = { 0 }; + char path[PATH_MAX] = { 0 }; FILE *file; char line[LOCK_LINE_MAX]; char *str1, *str2; int rv = -1, val; - memset(ls_comms_path, 0, sizeof(ls_comms_path)); - snprintf(ls_comms_path, PATH_MAX, "%s",DLM_COMMS_PATH); + snprintf(ls_comms_path, sizeof(ls_comms_path), "%s", DLM_COMMS_PATH); if (!(ls_dir = opendir(ls_comms_path))) return -ECONNREFUSED; @@ -241,31 +241,31 @@ static int get_local_nodeid(void) while ((de = readdir(ls_dir))) { if (de->d_name[0] == '.') continue; - memset(ls_comms_path, 0, sizeof(ls_comms_path)); - snprintf(ls_comms_path, PATH_MAX, "%s/%s/local", - DLM_COMMS_PATH, de->d_name); + + snprintf(path, sizeof(path), "%s/%s/local", + DLM_COMMS_PATH, de->d_name); if (!(file = fopen(ls_comms_path, "r"))) continue; - str1 = fgets(line, LOCK_LINE_MAX, file); - fclose(file); - + str1 = fgets(line, sizeof(line), file); + if (fclose(file)) + log_sys_debug("fclose", path); if (str1) { rv = sscanf(line, "%d", &val); if ((rv == 1) && (val == 1 )) { - memset(ls_comms_path, 0, sizeof(ls_comms_path)); - snprintf(ls_comms_path, PATH_MAX, "%s/%s/nodeid", - DLM_COMMS_PATH, de->d_name); + snprintf(path, sizeof(path), "%s/%s/nodeid", + DLM_COMMS_PATH, de->d_name); - if (!(file = fopen(ls_comms_path, "r"))) + if (!(file = fopen(path, "r"))) continue; - str2 = fgets(line, LOCK_LINE_MAX, file); - fclose(file); - + str2 = fgets(line, sizeof(line), file); + if (fclose(file)) + log_sys_debug("fclose", path); if (str2) { rv = sscanf(line, "%d", &val); if (rv == 1) { - closedir(ls_dir); + if (closedir(ls_dir)) + log_sys_debug("closedir", ls_comms_path); return val; } } @@ -274,7 +274,8 @@ static int get_local_nodeid(void) } if (closedir(ls_dir)) - log_error("get_local_nodeid closedir error"); + log_sys_debug("closedir", ls_comms_path); + return rv; } diff --git a/daemons/lvmlockd/lvmlockd-internal.h b/daemons/lvmlockd/lvmlockd-internal.h index dd59b6a5d..3aede3299 100644 --- a/daemons/lvmlockd/lvmlockd-internal.h +++ b/daemons/lvmlockd/lvmlockd-internal.h @@ -363,6 +363,8 @@ void log_level(int level, const char *fmt, ...) __attribute__((format(printf, 2 #define log_debug(fmt, args...) log_level(LOG_DEBUG, fmt, ##args) #define log_error(fmt, args...) log_level(LOG_ERR, fmt, ##args) #define log_warn(fmt, args...) log_level(LOG_WARNING, fmt, ##args) +#define log_sys_debug(x, y) \ + log_debug("%s: %s failed: %s", y, x, strerror(errno)) struct lockspace *alloc_lockspace(void); int lockspaces_empty(void); diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index b19eedcc5..8a002317e 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -393,7 +393,10 @@ int get_sysfs_binary(const char *path, char *buf, size_t buf_size, int *retlen) if (fd < 0) return 0; ret = read(fd, buf, buf_size); - close(fd); + + if (close(fd)) + log_sys_debug("close", path); + if (ret <= 0) return 0; *retlen = ret; @@ -2136,6 +2139,7 @@ int setup_devices_for_online_autoactivation(struct cmd_context *cmd) static char *_get_devname_from_devno(struct cmd_context *cmd, dev_t devno) { + static const char _partitions[] = "/proc/partitions"; char path[PATH_MAX]; char devname[PATH_MAX] = { 0 }; char namebuf[NAME_LEN]; @@ -2174,7 +2178,8 @@ static char *_get_devname_from_devno(struct cmd_context *cmd, dev_t devno) } break; } - closedir(dir); + if (closedir(dir)) + log_sys_debug("closedir", path); if (devname[0]) { log_debug("Found %s for %d:%d from sys", devname, major, minor); @@ -2214,7 +2219,7 @@ static char *_get_devname_from_devno(struct cmd_context *cmd, dev_t devno) */ try_partition: - if (!(fp = fopen("/proc/partitions", "r"))) + if (!(fp = fopen(_partitions, "r"))) return NULL; while (fgets(line, sizeof(line), fp)) { @@ -2231,10 +2236,12 @@ try_partition: } break; } - fclose(fp); + + if (fclose(fp)) + log_sys_debug("fclose", _partitions); if (devname[0]) { - log_debug("Found %s for %d:%d from proc", devname, major, minor); + log_debug("Found %s for %d:%d from %s", devname, major, minor, _partitions); return _strdup(devname); } diff --git a/lib/device/dev-mpath.c b/lib/device/dev-mpath.c index e5c49efbd..8e4393a21 100644 --- a/lib/device/dev-mpath.c +++ b/lib/device/dev-mpath.c @@ -164,6 +164,7 @@ static void _read_blacklist_file(const char *path) static void _read_wwid_exclusions(void) { + static const char _mpath_conf[] = "/etc/multipath/conf.d"; char path[PATH_MAX] = { 0 }; DIR *dir; struct dirent *de; @@ -172,14 +173,15 @@ static void _read_wwid_exclusions(void) _read_blacklist_file("/etc/multipath.conf"); - if ((dir = opendir("/etc/multipath/conf.d"))) { + if ((dir = opendir(_mpath_conf))) { while ((de = readdir(dir))) { if (de->d_name[0] == '.') continue; - snprintf(path, PATH_MAX-1, "/etc/multipath/conf.d/%s", de->d_name); + snprintf(path, sizeof(path), "%s/%s", _mpath_conf, de->d_name); _read_blacklist_file(path); } - closedir(dir); + if (closedir(dir)) + log_sys_debug("closedir", _mpath_conf); } /* for each wwid in ignored_exceptions, remove it from ignored */ @@ -594,7 +596,7 @@ static int _dev_is_mpath_component_sysfs(struct cmd_context *cmd, struct device out: if (closedir(dr)) - stack; + log_sys_debug("closedir", holders_path); if (is_mpath_component) *mpath_devno = MKDEV(dm_dev_major, dm_dev_minor); @@ -778,7 +780,7 @@ const char *dev_mpath_component_wwid(struct cmd_context *cmd, struct device *dev break; } if (closedir(dr)) - stack; + log_sys_debug("closedir", slaves_path); return wwid; } diff --git a/lib/device/online.c b/lib/device/online.c index 7ceab1750..54e3bcd26 100644 --- a/lib/device/online.c +++ b/lib/device/online.c @@ -392,7 +392,7 @@ int get_pvs_lookup(struct dm_list *pvs_online, const char *vgname) int file_major = 0, file_minor = 0; FILE *fp; - if (dm_snprintf(lookup_path, sizeof(path), "%s/%s", PVS_LOOKUP_DIR, vgname) < 0) + if (dm_snprintf(lookup_path, sizeof(lookup_path), "%s/%s", PVS_LOOKUP_DIR, vgname) < 0) return_0; if (!(fp = fopen(lookup_path, "r"))) @@ -403,7 +403,6 @@ int get_pvs_lookup(struct dm_list *pvs_online, const char *vgname) if (strlen(pvid) != ID_LEN) goto_bad; - memset(path, 0, sizeof(path)); snprintf(path, sizeof(path), "%s/%s", PVS_ONLINE_DIR, pvid); file_major = 0; @@ -443,12 +442,16 @@ int get_pvs_lookup(struct dm_list *pvs_online, const char *vgname) log_debug("Found PVs online lookup %d for %s", dm_list_size(pvs_online), vgname); - fclose(fp); + if (fclose(fp)) + log_sys_debug("fclose", lookup_path); + return 1; bad: free_po_list(pvs_online); - fclose(fp); + if (fclose(fp)) + log_sys_debug("fclose", lookup_path); + return 0; } diff --git a/lib/notify/lvmnotify.c b/lib/notify/lvmnotify.c index 7ac74d755..89aa2226b 100644 --- a/lib/notify/lvmnotify.c +++ b/lib/notify/lvmnotify.c @@ -83,7 +83,9 @@ static int lvmdbusd_running(void) } } - close(fd); + if (close(fd)) + log_sys_debug("close", lockfile); + return running; }