Fixed two bugs: POSIXLY_CORRECT=YES no more in the child's env, and a
superfluous fd passed to the child has been removed.
--- a/execute.c Mon Apr 02 17:53:58 2007 +0200
+++ b/execute.c Mon Apr 02 23:14:51 2007 +0200
@@ -79,7 +79,9 @@
/* Closing input */
pipe(p);
close(p[1]); /* closing the write handle */
- dup2(p[0], dest); /* the pipe reading goes to stdin */
+ dup2(p[0], dest); /* the pipe reading goes to dest */
+ if(p[0] != dest)
+ close(p[0]);
}
/* This will close fd_out and fd_in in the parent */
--- a/main.c Mon Apr 02 17:53:58 2007 +0200
+++ b/main.c Mon Apr 02 23:14:51 2007 +0200
@@ -20,6 +20,10 @@
struct Command_line command_line;
int server_socket;
+/* Globals for the environment of getopt */
+static char getopt_env[] = "POSIXLY_CORRECT=YES";
+static char *old_getopt_env;
+
static char version[] = "Task Spooler v0.3 - a task queue system for the unix user.\n"
"Copyright (C) 2007 Lluis Batlle i Rossell";
@@ -303,20 +307,30 @@
puts(version);
}
-static void set_my_env()
+static void set_getopt_env()
{
- static char tmp[] = "POSIXLY_CORRECT=YES";
- putenv(tmp);
+ old_getopt_env = getenv("POSIXLY_CORRECT");
+ putenv(getopt_env);
+}
+
+static void unset_getopt_env()
+{
+ if (old_getopt_env == NULL)
+ /* Wipe the string from the environment */
+ strcpy(getopt_env, "POSIXLY_CORRECT");
+ else
+ sprintf(getopt_env, "POSIXLY_CORRECT=%s", old_getopt_env);
}
int main(int argc, char **argv)
{
int errorlevel = 0;
- set_my_env();
+ set_getopt_env();
/* This is needed in a gnu system, so getopt works well */
default_command_line();
parse_opts(argc, argv);
+ unset_getopt_env();
if (command_line.need_server)
ensure_server_up();