# HG changeset patch # User viric # Date 1458923157 -3600 # Node ID 308315d0478751b5700b6141058b7b842b320d89 # Parent 79b87e385bc5d9070c7e372cd7108fffb49fa626 Fixing output file name passing and sending. diff -r 79b87e385bc5 -r 308315d04787 Changelog --- a/Changelog Fri Mar 25 16:19:23 2016 +0100 +++ b/Changelog Fri Mar 25 17:25:57 2016 +0100 @@ -11,6 +11,8 @@ Future: - Use a better system than mkstemp() for finding output files, so we can add .gz to the gzipped outputs. +v1.0: + - Respect TMPDIR for output files. v0.7.6: - Add -k (send SIGTERM to process group). Replacement for "kill -- -`ts -p`". v0.7.4: diff -r 79b87e385bc5 -r 308315d04787 execute.c --- a/execute.c Fri Mar 25 16:19:23 2016 +0100 +++ b/execute.c Fri Mar 25 17:25:57 2016 +0100 @@ -17,6 +17,7 @@ #include #include #include +#include #include "main.h" @@ -46,7 +47,7 @@ ofname = (char *) malloc(namesize); res = read(fd_read_filename, ofname, namesize); if (res != namesize) - error("Reading the the out file name"); + error("Reading the out file name"); } res = read(fd_read_filename, &starttv, sizeof(starttv)); if (res != sizeof(starttv)) @@ -151,6 +152,7 @@ char errfname[sizeof outfname + 2]; /* .e */ int namesize; int outfd; + int err; struct timeval starttv; if (command_line.store_output) @@ -162,39 +164,48 @@ if (tmpdir == NULL) tmpdir = "/tmp"; - lname = strlen(tmpdir) + strlen(outfname) + 3 /* .gz*/ + 1 /* \0 */; + lname = strlen(tmpdir) + strlen(outfname) + 1 /* \0 */; outfname_full = (char *)malloc(lname); - strncpy(outfname_full, tmpdir, lname); - strncat(outfname_full, outfname, lname); + strcpy(outfname_full, tmpdir); + strcat(outfname_full, outfname); if (command_line.gzip) { int p[2]; /* We assume that all handles are closed*/ - pipe(p); - - strncat(outfname_full, ".gz", lname); + err = pipe(p); + assert(err == 0); /* gzip output goes to the filename */ /* This will be the handle other than 0,1,2 */ + /* mkstemp doesn't admit adding ".gz" to the pattern */ outfd = mkstemp(outfname_full); /* stdout */ + assert(outfd != -1); /* Program stdout and stderr */ /* which go to pipe write handle */ - dup2(p[1], 1); + err = dup2(p[1], 1); + assert(err != -1); if (command_line.stderr_apart) { int errfd; strncpy(errfname, outfname_full, sizeof errfname); strncat(errfname, ".e", 2); errfd = open(errfname, O_CREAT | O_WRONLY | O_TRUNC, 0600); - dup2(errfd, 2); - close(errfd); + assert(err == 0); + err = dup2(errfd, 2); + assert(err == 0); + err = close(errfd); + assert(err == 0); } else - dup2(p[1], 2); - close(p[1]); + { + err = dup2(p[1], 2); + assert(err != -1); + } + err = close(p[1]); + assert(err == 0); /* run gzip. * This wants p[0] in 0, so gzip will read @@ -221,9 +232,9 @@ } /* Send the filename */ - namesize = strlen(outfname_full); + namesize = strlen(outfname_full)+1; write(fd_send_filename, (char *)&namesize, sizeof(namesize)); - write(fd_send_filename, outfname_full, sizeof(outfname)); + write(fd_send_filename, outfname_full, namesize); } /* Times */ gettimeofday(&starttv, NULL);