Florian Westphal <fw@xxxxxxxxx> wrote: > Jeremy Sowden <jeremy@xxxxxxxxxx> wrote: > > Instead of statting the file, and choosing the mode with which to open > > it and whether to write the PCAP header based on the result, always open > > it with mode "a" and _then_ stat it. This simplifies the flow-control > > and avoids a race between statting and opening. > > > > Signed-off-by: Jeremy Sowden <jeremy@xxxxxxxxxx> > > --- > > output/pcap/ulogd_output_PCAP.c | 42 ++++++++++++--------------------- > > 1 file changed, 15 insertions(+), 27 deletions(-) > > > > diff --git a/output/pcap/ulogd_output_PCAP.c b/output/pcap/ulogd_output_PCAP.c > > index e7798f20c8fc..220fc6dec5fe 100644 > > --- a/output/pcap/ulogd_output_PCAP.c > > +++ b/output/pcap/ulogd_output_PCAP.c > > @@ -220,33 +220,21 @@ static int append_create_outfile(struct ulogd_pluginstance *upi) > > { > > > + struct stat st_of; > > + > > + pi->of = fopen(filename, "a"); > > + if (!pi->of) { > > + ulogd_log(ULOGD_ERROR, "can't open pcap file %s: %s\n", > > + filename, > > + strerror(errno)); > > + return -EPERM; > > + } > > + if (fstat(fileno(pi->of), &st_of) == 0 && st_of.st_size == 0) { > > + if (!write_pcap_header(pi)) { > > + ulogd_log(ULOGD_ERROR, "can't write pcap header: %s\n", > > + strerror(errno)); > > + return -ENOSPC; > > LGTM, but should that fclose() before -ENOSPC? AFAICS this doesn't really matter, ulogd will exit(). SIGHUP case doesn't handle errors.