"Can't fdopen the snapshot config file %s: %s\n",
conf_name, strerror(errno));
rc = -1;
- goto out;
+ goto out_fd;
}
while (snapshot_fgets(fp, buf, MAX_BUF_SIZE) != NULL) {
out:
if (fd >= 0) {
- if (rc < 0) {
+ if (rc < 0)
flock(fd, LOCK_UN);
- close(fd);
- } else {
+ else
si->si_conf_fd = fd;
- }
}
-
+ /* fclose() closes any associated underlying file descriptor.
+ * explicit close(fd) not required
+ */
+ fclose(fp);
+ return rc;
+out_fd:
+ close(fd);
return rc;
}
struct snapshot_target *st;
while (!list_empty(&si->si_mdts_list)) {
- st = list_entry(si->si_mdts_list.next,
- struct snapshot_target, st_list);
+ st = list_first_entry(&si->si_mdts_list,
+ struct snapshot_target, st_list);
list_del(&st->st_list);
free(st->st_host);
free(st->st_fhost);
}
while (!list_empty(&si->si_osts_list)) {
- st = list_entry(si->si_osts_list.next,
- struct snapshot_target, st_list);
+ st = list_first_entry(&si->si_osts_list,
+ struct snapshot_target, st_list);
list_del(&st->st_list);
free(st->st_host);
free(st->st_fhost);
int rc;
int foreign = 0;
- st = list_entry(si->si_osts_list.next, struct snapshot_target,
- st_list);
+ st = list_first_entry(&si->si_osts_list, struct snapshot_target,
+ st_list);
again:
rc = 0;
memset(buf, 0, sizeof(buf));
rc = scnprintf(cmd + len, size - len - 1,
"-o %s=\"%s\" ", buf, ptr);
- if (rc <= 0)
+ if (rc <= 0) {
+ pclose(fp);
return -EOVERFLOW;
+ }
len += rc;
}
goto again;
}
while (!list_empty(&list_sub_items)) {
- lsi = list_entry(list_sub_items.next,
- struct list_sub_item, lsi_list);
+ lsi = list_first_entry(&list_sub_items,
+ struct list_sub_item, lsi_list);
list_del(&lsi->lsi_list);
if (!rc) {
si->si_ssname = lsi->lsi_ssname;