tree-wide: port everything over to fflush_and_check()
Some places invoked fflush() directly with their own manual error checking, let's unify all that by using fflush_and_check(). This also unifies the general error paths of fflush()+rename() file writers.
This commit is contained in:
@@ -551,9 +551,8 @@ int bus_pcap_header(size_t snaplen, FILE *f) {
|
||||
hdr.snaplen = (uint32_t) snaplen;
|
||||
|
||||
fwrite(&hdr, 1, sizeof(hdr), f);
|
||||
fflush(f);
|
||||
|
||||
return 0;
|
||||
return fflush_and_check(f);
|
||||
}
|
||||
|
||||
int bus_message_pcap_frame(sd_bus_message *m, size_t snaplen, FILE *f) {
|
||||
@@ -598,7 +597,5 @@ int bus_message_pcap_frame(sd_bus_message *m, size_t snaplen, FILE *f) {
|
||||
snaplen -= w;
|
||||
}
|
||||
|
||||
fflush(f);
|
||||
|
||||
return 0;
|
||||
return fflush_and_check(f);
|
||||
}
|
||||
|
||||
@@ -179,10 +179,10 @@ int introspect_finish(struct introspect *i, sd_bus *bus, sd_bus_message *m, sd_b
|
||||
assert(reply);
|
||||
|
||||
fputs("</node>\n", i->f);
|
||||
fflush(i->f);
|
||||
|
||||
if (ferror(i->f))
|
||||
return -ENOMEM;
|
||||
r = fflush_and_check(i->f);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_new_method_return(m, &q);
|
||||
if (r < 0)
|
||||
@@ -204,8 +204,6 @@ void introspect_free(struct introspect *i) {
|
||||
if (i->f)
|
||||
fclose(i->f);
|
||||
|
||||
if (i->introspection)
|
||||
free(i->introspection);
|
||||
|
||||
free(i->introspection);
|
||||
zero(*i);
|
||||
}
|
||||
|
||||
@@ -914,6 +914,7 @@ char *bus_match_to_string(struct bus_match_component *components, unsigned n_com
|
||||
char *buffer = NULL;
|
||||
size_t size = 0;
|
||||
unsigned i;
|
||||
int r;
|
||||
|
||||
if (n_components <= 0)
|
||||
return strdup("");
|
||||
@@ -942,8 +943,8 @@ char *bus_match_to_string(struct bus_match_component *components, unsigned n_com
|
||||
fputc('\'', f);
|
||||
}
|
||||
|
||||
fflush(f);
|
||||
if (ferror(f))
|
||||
r = fflush_and_check(f);
|
||||
if (r < 0)
|
||||
return NULL;
|
||||
|
||||
return buffer;
|
||||
|
||||
@@ -1082,12 +1082,10 @@ int device_update_db(sd_device *device) {
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
log_error_errno(r, "failed to create %s file '%s' for '%s'", has_info ? "db" : "empty",
|
||||
path, device->devpath);
|
||||
unlink(path);
|
||||
unlink(path_tmp);
|
||||
(void) unlink(path);
|
||||
(void) unlink(path_tmp);
|
||||
|
||||
return r;
|
||||
return log_error_errno(r, "failed to create %s file '%s' for '%s'", has_info ? "db" : "empty", path, device->devpath);
|
||||
}
|
||||
|
||||
int device_delete_db(sd_device *device) {
|
||||
|
||||
Reference in New Issue
Block a user