--- loadwatch-1.0+1.1alpha1.orig/Makefile.in +++ loadwatch-1.0+1.1alpha1/Makefile.in @@ -6,6 +6,7 @@ INSTALL = @INSTALL@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ MKINSTALLDIRS= @srcdir@/mkinstalldirs +DESTDIR= CC=@CC@ LIBS=@LIBS@ @@ -20,9 +21,9 @@ $(CC) -o $@ $^ $(LIBS) install: all - $(MKINSTALLDIRS) $(bindir) - $(INSTALL_PROGRAM) loadwatch $(bindir)/loadwatch - $(INSTALL_PROGRAM) lw-ctl $(bindir)/loadwatch + $(MKINSTALLDIRS) $(DESTDIR)$(bindir) + $(INSTALL_PROGRAM) loadwatch $(DESTDIR)$(bindir)/loadwatch + $(INSTALL_PROGRAM) lw-ctl $(DESTDIR)$(bindir)/lw-ctl clean: -rm -f *.o loadwatch lw-ctl --- loadwatch-1.0+1.1alpha1.orig/loadwatch.c +++ loadwatch-1.0+1.1alpha1/loadwatch.c @@ -1,3 +1,6 @@ +/* for getpgid() */ +#define _XOPEN_SOURCE 500 + #include #include #include @@ -20,7 +23,7 @@ pid_t child; pid_t attach = -1; -pid_t children[100]; +pid_t *children; int copies = 1; #define RUNNING 1 #define STOPPED 2 @@ -35,7 +38,7 @@ now = time(0); outline = ctime(&now); - if (p = strchr(outline, '\n')) + if ((p = strchr(outline, '\n'))) *p = 0; return outline; @@ -86,7 +89,7 @@ } tbr = 0; - cmd = malloc(size); + cmd = malloc(size+1); if (cmd) { while (1) @@ -107,6 +110,7 @@ } else if (br == 0) { + cmd[tbr] = '\0'; break; } @@ -143,18 +147,26 @@ if (setpgid(0,0) == -1) { - fprintf(stderr, "%s (%s): cannot set process group (%s)\n", + fprintf(stderr, "%s (%d): cannot set process group (%s)\n", current_time(), getpid(), strerror(errno)); exit(1); } + children = (pid_t *)malloc(copies*sizeof(pid_t)); + if (children == NULL) + { + fprintf(stderr, "%s (%d): cannot allocate memory\n", + current_time(), getpid()); + exit(1); + } + for (i = 0; i < copies; i++) { if ((children[i] = fork()) == 0) { - if (execv(*argv, argv) < 0) + if (execvp(*argv, argv) < 0) { - fprintf(stderr, "%s (%s): error exec'ing command (%s)\n", + fprintf(stderr, "%s (%d): error exec'ing command (%s)\n", current_time(), getpid(), strerror(errno)); exit(1); } @@ -164,8 +176,6 @@ while (1) { pid_t status; - time_t now; - char *p; switch(status = waitpid(0, 0, 0)) { @@ -221,23 +231,17 @@ void usage() { - fprintf(stderr, "loadwatch [-d