Because they're created with m_mktemp2(), the temporary files are
already in a list to be unlink(2)'d at exit(3), thanks to atexit(3), so
don't set_done() to attempt that twice. Updates
6bc64765f.
* Temporary files
*/
static char infile[BUFSIZ];
* Temporary files
*/
static char infile[BUFSIZ];
-static int unlink_infile = 0;
-
static char outfile[BUFSIZ];
static char outfile[BUFSIZ];
-static int unlink_outfile = 0;
-
-static void unlink_done (int) NORETURN;
if (nmh_init(argv[0], 2)) { return 1; }
if (nmh_init(argv[0], 2)) { return 1; }
- set_done(unlink_done);
-
arguments = getarguments (invo_name, argc, argv, 1);
argp = arguments;
arguments = getarguments (invo_name, argc, argv, 1);
argp = arguments;
adios(NULL, "unable to create temporary file in %s",
get_temp_dir());
}
adios(NULL, "unable to create temporary file in %s",
get_temp_dir());
}
-
- /* save a copy of the name for later removal */
strncpy (infile, cp, sizeof(infile));
strncpy (infile, cp, sizeof(infile));
/* copy standard input to temporary file */
while ((n = fread(buffer, 1, sizeof(buffer), stdin)) > 0) {
/* copy standard input to temporary file */
while ((n = fread(buffer, 1, sizeof(buffer), stdin)) > 0) {
adios(NULL, "unable to create temporary file in %s", get_temp_dir());
}
strncpy(outfile, cp, sizeof(outfile));
adios(NULL, "unable to create temporary file in %s", get_temp_dir());
}
strncpy(outfile, cp, sizeof(outfile));
/* output the message */
output_message_fp (ct, fp_out, outfile);
/* output the message */
output_message_fp (ct, fp_out, outfile);
rename (buffer, compfile);
done (1);
}
rename (buffer, compfile);
done (1);
}
+ /* Remove from atexit(3) list of files to unlink. */
+ if (!(m_unlink(outfile) == -1 && errno == ENOENT)) {
+ adios(outfile, "file exists after rename:");
+ }
free_content (ct);
done (0);
return 1;
}
free_content (ct);
done (0);
return 1;
}
-
-
-static void NORETURN
-unlink_done (int status)
-{
- /*
- * Check if we need to remove stray
- * temporary files.
- */
- if (unlink_infile)
- (void) m_unlink (infile);
- if (unlink_outfile)
- (void) m_unlink (outfile);
-
- exit (status);
-}