mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Add some missing close() and fclose() return code checks.
Fix exit statuses of reporting tools (2.02.19).
This commit is contained in:
parent
232da7ecc7
commit
2e1b92e3ea
@ -1,5 +1,7 @@
|
||||
Version 2.02.20 -
|
||||
===================================
|
||||
Add some missing close() and fclose() return code checks.
|
||||
Fix exit statuses of reporting tools (2.02.19).
|
||||
Add init script for dmeventd monitoring.
|
||||
lvm.static no longer interacts with dmeventd unless explicitly asked to.
|
||||
Add field definitions to report help text.
|
||||
|
@ -473,7 +473,8 @@ static void drop_vg_locks()
|
||||
sync_unlock(vg, LCK_EXCL);
|
||||
|
||||
}
|
||||
fclose(vgs);
|
||||
if (fclose(vgs))
|
||||
DEBUGLOG("vgs fclose failed: %s\n", strerror(errno));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -523,7 +524,8 @@ static void *get_initial_state()
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(lvs);
|
||||
if (fclose(lvs))
|
||||
DEBUGLOG("lvs fclose failed: %s\n", strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -59,8 +59,6 @@
|
||||
# include <malloc.h>
|
||||
#endif
|
||||
|
||||
static FILE *_log;
|
||||
|
||||
static int _get_env_vars(struct cmd_context *cmd)
|
||||
{
|
||||
const char *e;
|
||||
@ -1114,8 +1112,4 @@ void destroy_toolcontext(struct cmd_context *cmd)
|
||||
activation_exit();
|
||||
fin_log();
|
||||
fin_syslog();
|
||||
|
||||
if (_log)
|
||||
fclose(_log);
|
||||
|
||||
}
|
||||
|
@ -435,13 +435,13 @@ int write_config_file(struct config_tree *cft, const char *file,
|
||||
log_verbose("Dumping configuration to %s", file);
|
||||
if (!argc) {
|
||||
if (!_write_config(cft->root, 0, fp, 0)) {
|
||||
log_error("Failure while writing configuration");
|
||||
log_error("Failure while writing to %s", file);
|
||||
r = 0;
|
||||
}
|
||||
} else while (argc--) {
|
||||
if ((cn = find_config_node(cft->root, *argv))) {
|
||||
if (!_write_config(cn, 1, fp, 0)) {
|
||||
log_error("Failure while writing configuration");
|
||||
log_error("Failure while writing to %s", file);
|
||||
r = 0;
|
||||
}
|
||||
} else {
|
||||
@ -451,8 +451,10 @@ int write_config_file(struct config_tree *cft, const char *file,
|
||||
argv++;
|
||||
}
|
||||
|
||||
if (fp != stdout)
|
||||
fclose(fp);
|
||||
if ((fp != stdout) && fclose(fp)) {
|
||||
log_sys_error("fclose", file);
|
||||
r = 0;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -292,11 +292,14 @@ int dev_get_sectsize(struct device *dev, uint32_t *size)
|
||||
|
||||
if (ioctl(fd, BLKSSZGET, &s) < 0) {
|
||||
log_sys_error("ioctl BLKSSZGET", name);
|
||||
close(fd);
|
||||
if (close(fd))
|
||||
log_sys_error("close", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
if (close(fd))
|
||||
log_sys_error("close", name);
|
||||
|
||||
*size = (uint32_t) s;
|
||||
|
||||
log_very_verbose("%s: sector size is %" PRIu32 " bytes", name, *size);
|
||||
|
@ -239,7 +239,10 @@ int persistent_filter_dump(struct dev_filter *f)
|
||||
/* _write_array(pf, fp, "invalid_devices", PF_BAD_DEVICE); */
|
||||
|
||||
fprintf(fp, "}\n");
|
||||
fclose(fp);
|
||||
if (fclose(fp)) {
|
||||
log_sys_error("fclose", tmp_file);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (rename(tmp_file, pf->file))
|
||||
log_error("%s: rename to %s failed: %s", tmp_file, pf->file,
|
||||
|
@ -54,7 +54,9 @@ static int _locate_sysfs_blocks(const char *proc, char *path, size_t len)
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
if (fclose(fp))
|
||||
log_sys_error("fclose", proc_mounts);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -156,7 +158,9 @@ static int _read_dev(const char *file, dev_t *result)
|
||||
}
|
||||
|
||||
r = _parse_dev(file, fp, result);
|
||||
fclose(fp);
|
||||
|
||||
if (fclose(fp))
|
||||
log_sys_error("fclose", file);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -204,7 +204,8 @@ static int _scan_proc_dev(const char *proc, const struct config_node *cn)
|
||||
if (cv->type != CFG_STRING) {
|
||||
log_error("Expecting string in devices/types "
|
||||
"in config file");
|
||||
fclose(pd);
|
||||
if (fclose(pd))
|
||||
log_sys_error("fclose", proc_devices);
|
||||
return 0;
|
||||
}
|
||||
dev_len = strlen(cv->v.str);
|
||||
@ -214,14 +215,16 @@ static int _scan_proc_dev(const char *proc, const struct config_node *cn)
|
||||
log_error("Max partition count missing for %s "
|
||||
"in devices/types in config file",
|
||||
name);
|
||||
fclose(pd);
|
||||
if (fclose(pd))
|
||||
log_sys_error("fclose", proc_devices);
|
||||
return 0;
|
||||
}
|
||||
if (!cv->v.i) {
|
||||
log_error("Zero partition count invalid for "
|
||||
"%s in devices/types in config file",
|
||||
name);
|
||||
fclose(pd);
|
||||
if (fclose(pd))
|
||||
log_sys_error("fclose", proc_devices);
|
||||
return 0;
|
||||
}
|
||||
if (dev_len <= strlen(line + i) &&
|
||||
@ -232,7 +235,10 @@ static int _scan_proc_dev(const char *proc, const struct config_node *cn)
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(pd);
|
||||
|
||||
if (fclose(pd))
|
||||
log_sys_error("fclose", proc_devices);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -249,17 +249,23 @@ int archive_vg(struct volume_group *vg,
|
||||
|
||||
if (!(fp = fdopen(fd, "w"))) {
|
||||
log_err("Couldn't create FILE object for archive.");
|
||||
close(fd);
|
||||
if (close(fd))
|
||||
log_sys_error("close", temp_file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!text_vg_export_file(vg, desc, fp)) {
|
||||
stack;
|
||||
fclose(fp);
|
||||
if (fclose(fp))
|
||||
log_sys_error("fclose", temp_file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
if (fclose(fp)) {
|
||||
log_sys_error("fclose", temp_file);
|
||||
/* Leave file behind as evidence of failure */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Now we want to rename this file to <vg>_index.vg.
|
||||
|
@ -710,7 +710,8 @@ static int _vg_write_file(struct format_instance *fid, struct volume_group *vg,
|
||||
|
||||
if (!(fp = fdopen(fd, "w"))) {
|
||||
log_sys_error("fdopen", temp_file);
|
||||
close(fd);
|
||||
if (close(fd))
|
||||
log_sys_error("fclose", temp_file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -718,13 +719,15 @@ static int _vg_write_file(struct format_instance *fid, struct volume_group *vg,
|
||||
|
||||
if (!text_vg_export_file(vg, tc->desc, fp)) {
|
||||
log_error("Failed to write metadata to %s.", temp_file);
|
||||
fclose(fp);
|
||||
if (fclose(fp))
|
||||
log_sys_error("fclose", temp_file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (fsync(fd) && (errno != EROFS) && (errno != EINVAL)) {
|
||||
log_sys_error("fsync", tc->path_edit);
|
||||
fclose(fp);
|
||||
if (fclose(fp))
|
||||
log_sys_error("fclose", tc->path_edit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -163,8 +163,8 @@ static int _lock_file(const char *file, int flags)
|
||||
log_very_verbose("Locking %s %c%c", ll->res, state,
|
||||
flags & LCK_NONBLOCK ? ' ' : 'B');
|
||||
do {
|
||||
if (ll->lf > -1)
|
||||
close(ll->lf);
|
||||
if ((ll->lf > -1) && close(ll->lf))
|
||||
log_sys_error("close", file);
|
||||
|
||||
if ((ll->lf = open(file, O_CREAT | O_APPEND | O_RDWR, 0777))
|
||||
< 0) {
|
||||
|
@ -120,7 +120,8 @@ void fin_log(void)
|
||||
}
|
||||
|
||||
if (_log_to_file) {
|
||||
fclose(_log_file);
|
||||
if (fclose(_log_file))
|
||||
fprintf(stderr, "fclose() on log file failed: %s", strerror(errno));
|
||||
_log_to_file = 0;
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,8 @@ int create_temp_name(const char *dir, char *buffer, size_t len, int *fd)
|
||||
if (!fcntl(*fd, F_SETLK, &lock))
|
||||
return 1;
|
||||
|
||||
close(*fd);
|
||||
if (close(*fd))
|
||||
log_sys_error("close", buffer);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -239,7 +240,8 @@ void sync_dir(const char *file)
|
||||
if (fsync(fd) && (errno != EROFS) && (errno != EINVAL))
|
||||
log_sys_error("fsync", dir);
|
||||
|
||||
close(fd);
|
||||
if (close(fd))
|
||||
log_sys_error("close", dir);
|
||||
|
||||
out:
|
||||
dm_free(dir);
|
||||
|
@ -1065,8 +1065,9 @@ static int _run_script(struct cmd_context *cmd, int argc, char **argv)
|
||||
char buffer[CMD_LEN];
|
||||
int ret = 0;
|
||||
int magic_number = 0;
|
||||
char *script_file = argv[0];
|
||||
|
||||
if ((script = fopen(argv[0], "r")) == NULL)
|
||||
if ((script = fopen(script_file, "r")) == NULL)
|
||||
return ENO_SUCH_CMD;
|
||||
|
||||
while (fgets(buffer, sizeof(buffer), script) != NULL) {
|
||||
@ -1099,7 +1100,9 @@ static int _run_script(struct cmd_context *cmd, int argc, char **argv)
|
||||
lvm_run_command(cmd, argc, argv);
|
||||
}
|
||||
|
||||
fclose(script);
|
||||
if (fclose(script))
|
||||
log_sys_error("fclose", script_file);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ static int _vgs_single(struct cmd_context *cmd __attribute((unused)),
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (!report_object(handle, vg, NULL, NULL, NULL, NULL));
|
||||
if (!report_object(handle, vg, NULL, NULL, NULL, NULL))
|
||||
return ECMD_FAILED;
|
||||
|
||||
check_current_backup(vg);
|
||||
@ -39,7 +39,7 @@ static int _lvs_single(struct cmd_context *cmd, struct logical_volume *lv,
|
||||
if (!arg_count(cmd, all_ARG) && !lv_is_visible(lv))
|
||||
return ECMD_PROCESSED;
|
||||
|
||||
if (!report_object(handle, lv->vg, lv, NULL, NULL, NULL));
|
||||
if (!report_object(handle, lv->vg, lv, NULL, NULL, NULL))
|
||||
return ECMD_FAILED;
|
||||
|
||||
return ECMD_PROCESSED;
|
||||
@ -48,7 +48,7 @@ static int _lvs_single(struct cmd_context *cmd, struct logical_volume *lv,
|
||||
static int _segs_single(struct cmd_context *cmd __attribute((unused)),
|
||||
struct lv_segment *seg, void *handle)
|
||||
{
|
||||
if (!report_object(handle, seg->lv->vg, seg->lv, NULL, seg, NULL));
|
||||
if (!report_object(handle, seg->lv->vg, seg->lv, NULL, seg, NULL))
|
||||
return ECMD_FAILED;
|
||||
|
||||
return ECMD_PROCESSED;
|
||||
@ -78,7 +78,7 @@ static int _pvsegs_sub_single(struct cmd_context *cmd, struct volume_group *vg,
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!report_object(handle, vg, NULL, pv, NULL, pvseg));
|
||||
if (!report_object(handle, vg, NULL, pv, NULL, pvseg))
|
||||
ret = ECMD_FAILED;
|
||||
|
||||
out:
|
||||
@ -128,7 +128,7 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
|
||||
}
|
||||
}
|
||||
|
||||
if (!report_object(handle, vg, NULL, pv, NULL, NULL));
|
||||
if (!report_object(handle, vg, NULL, pv, NULL, NULL))
|
||||
ret = ECMD_FAILED;
|
||||
|
||||
out:
|
||||
|
Loading…
Reference in New Issue
Block a user