static int open_outfile(int fnum, int cpu, int remove_file) { char buf[PATH_MAX]; time_t t; if (!outfile_name) { _err("-S is set without -o. Please file a bug report.\n"); return -1; } time(&t); if (fnum_max) { if (remove_file) { /* remove oldest file */ if (make_outfile_name(buf, PATH_MAX, fnum - fnum_max, cpu, read_backlog(cpu, fnum - fnum_max), bulkmode) < 0) return -1; remove(buf); /* don't care */ } write_backlog(cpu, fnum, t); } if (make_outfile_name(buf, PATH_MAX, fnum, cpu, t, bulkmode) < 0) return -1; out_fd[cpu] = open (buf, O_CREAT|O_TRUNC|O_WRONLY, 0666); if (out_fd[cpu] < 0) { perr("Couldn't open output file %s", buf); return -1; } if (set_clexec(out_fd[cpu]) < 0) return -1; return 0; }
static int open_oldoutfile(int fnum, int cpu, int remove_file) { char buf[PATH_MAX]; time_t t; if (outfile_name) { time(&t); if (fnum_max) { if (remove_file) { /* remove oldest file */ if (make_outfile_name(buf, PATH_MAX, fnum - fnum_max, cpu, read_backlog(cpu, fnum - fnum_max), bulkmode) < 0) return -1; remove(buf); /* don't care */ } write_backlog(cpu, fnum, t); } if (make_outfile_name(buf, PATH_MAX, fnum, cpu, t, bulkmode) < 0) return -1; } else if (bulkmode) { if (sprintf_chk(buf, "stpd_cpu%d.%d", cpu, fnum)) return -1; } else { /* stream mode */ percpu_tmpfile[cpu] = stdout; return 0; } if((percpu_tmpfile[cpu] = fopen(buf, "w+")) == NULL) { perr("Couldn't open output file %s", buf); return -1; } out_fd[cpu] = fileno(percpu_tmpfile[cpu]); if (set_clexec(out_fd[cpu]) < 0) { perr("Couldn't clear exec bit of open output file %s", buf); return -1; } return 0; }