Adding the functionality of keeping stderr apart. For Jan Šmydke.
--- a/Changelog Tue Oct 11 19:53:31 2011 +0200
+++ b/Changelog Wed Nov 16 22:17:53 2011 +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.
+v0.7.2:
+ - Add option '-E', to keep stderr apart. It goes to "`ts -o`.e".
v0.7.1:
- Implement check of ownership of the socket. Security bugfix.
v0.7.0:
--- a/execute.c Tue Oct 11 19:53:31 2011 +0200
+++ b/execute.c Wed Nov 16 22:17:53 2011 +0100
@@ -15,6 +15,8 @@
#include <time.h>
#include <sys/times.h>
#include <sys/time.h>
+#include <sys/types.h>
+#include <fcntl.h>
#include "main.h"
@@ -146,6 +148,7 @@
static void run_child(int fd_send_filename)
{
char outfname[] = "/tmp/ts-out.XXXXXX";
+ char errfname[sizeof outfname + 2]; /* .e */
int namesize;
int outfd;
struct timeval starttv;
@@ -160,16 +163,26 @@
/* We assume that all handles are closed*/
pipe(p);
+ /* gzip output goes to the filename */
+ /* This will be the handle other than 0,1,2 */
+ outfd = mkstemp(outfname); /* stdout */
+
/* Program stdout and stderr */
/* which go to pipe write handle */
dup2(p[1], 1);
- dup2(p[1], 2);
+ if (command_line.stderr_apart)
+ {
+ int errfd;
+ strncpy(errfname, outfname, sizeof errfname);
+ strncat(errfname, ".e", 2);
+ errfd = open(errfname, O_CREAT | O_WRONLY | O_TRUNC, 0600);
+ dup2(errfd, 2);
+ close(errfd);
+ }
+ else
+ dup2(p[1], 2);
close(p[1]);
- /* gzip output goes to the filename */
- /* This will be the handle other than 0,1,2 */
- outfd = mkstemp(outfname); /* stdout */
-
/* run gzip.
* This wants p[0] in 0, so gzip will read
* from it */
@@ -180,7 +193,17 @@
/* Prepare the filename */
outfd = mkstemp(outfname); /* stdout */
dup2(outfd, 1); /* stdout */
- dup2(outfd, 2); /* stderr */
+ if (command_line.stderr_apart)
+ {
+ int errfd;
+ strncpy(errfname, outfname, sizeof errfname);
+ strncat(errfname, ".e", 2);
+ errfd = open(errfname, O_CREAT | O_WRONLY | O_TRUNC, 0600);
+ dup2(errfd, 2);
+ close(errfd);
+ }
+ else
+ dup2(outfd, 2);
close(outfd);
}
--- a/main.c Tue Oct 11 19:53:31 2011 +0200
+++ b/main.c Wed Nov 16 22:17:53 2011 +0100
@@ -43,6 +43,7 @@
command_line.depend_on = -1; /* -1 means depend on previous */
command_line.max_slots = 1;
command_line.wait_enqueuing = 1;
+ command_line.stderr_apart = 0;
}
void get_command(int index, int argc, char **argv)
@@ -82,7 +83,7 @@
/* Parse options */
while(1) {
- c = getopt(argc, argv, ":VhKgClnfmBr:t:c:o:p:w:u:s:U:i:L:dS:D:");
+ c = getopt(argc, argv, ":VhKgClnfmBEr:t:c:o:p:w:u:s:U:i:L:dS:D:");
if (c == -1)
break;
@@ -193,6 +194,9 @@
/* I picked 'B' quite at random among the letters left */
command_line.wait_enqueuing = 0;
break;
+ case 'E':
+ command_line.stderr_apart = 1;
+ break;
case ':':
switch(optopt)
{
--- a/main.h Tue Oct 11 19:53:31 2011 +0200
+++ b/main.h Wed Nov 16 22:17:53 2011 +0100
@@ -64,6 +64,7 @@
enum Request request;
int need_server;
int store_output;
+ int stderr_apart;
int should_go_background;
int should_keep_finished;
int send_output_by_mail;