From owner-svn-src-projects@FreeBSD.ORG Tue Apr 26 15:11:12 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AA719106564A; Tue, 26 Apr 2011 15:11:12 +0000 (UTC) (envelope-from flz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 98FBF8FC16; Tue, 26 Apr 2011 15:11:12 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p3QFBC3Y027452; Tue, 26 Apr 2011 15:11:12 GMT (envelope-from flz@svn.freebsd.org) Received: (from flz@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p3QFBCgR027449; Tue, 26 Apr 2011 15:11:12 GMT (envelope-from flz@svn.freebsd.org) Message-Id: <201104261511.p3QFBCgR027449@svn.freebsd.org> From: Florent Thoumie Date: Tue, 26 Apr 2011 15:11:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r221067 - projects/portbuild/sources X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Apr 2011 15:11:12 -0000 Author: flz Date: Tue Apr 26 15:11:12 2011 New Revision: 221067 URL: http://svn.freebsd.org/changeset/base/221067 Log: portbuild: cleanup ptimeout.c/pnohang.c. - Make the two scripts compile without warning (fix possible bug as well). - Replace commented printf's with DPRINTF macro. Modified: projects/portbuild/sources/pnohang.c projects/portbuild/sources/ptimeout.c Modified: projects/portbuild/sources/pnohang.c ============================================================================== --- projects/portbuild/sources/pnohang.c Tue Apr 26 13:50:11 2011 (r221066) +++ projects/portbuild/sources/pnohang.c Tue Apr 26 15:11:12 2011 (r221067) @@ -1,5 +1,5 @@ -/* pnohang: executes command ($4-) with output in file ($3) - * kills command if no output with $1 seconds with message in $2 +/* pnohang: executes command ($4-) with output in file ($2) + * kills command if no output with $1 seconds with message in $3 * usage: pnohang timeout file command args ... */ @@ -11,17 +11,23 @@ #include #include #include +#include #include #include #include #include +#if defined(DEBUG) +# define DPRINTF(fmt, ...) printf(fmt, __VA_ARGS__) +#else +# define DPRINTF(fmt, ...) +#endif + int main(int argc, char *argv[]) { int timeout, status, i, result, ofd; char *command, *outfile, *message, args[MAXPATHLEN + 1]; - char logstr[BUFSIZ + 1]; pid_t pid, pid1, pid2, child; time_t now; struct stat st; @@ -46,10 +52,10 @@ main(int argc, char *argv[]) pid = getpid(); - /*printf("timeout is %d\n", timeout); - printf("outfile is %s\n", outfile); - printf("message is %s\n", message); - printf("arguments are %s", args);*/ + DPRINTF("timeout is %d\n", timeout); + DPRINTF("outfile is %s\n", outfile); + DPRINTF("message is %s\n", message); + DPRINTF("command is %s\n", args); if ((ofd = open(outfile, O_CREAT|O_TRUNC|O_WRONLY, 0600)) == -1) err(1, "open"); @@ -68,13 +74,13 @@ main(int argc, char *argv[]) /* parent */ child = wait(&status); - /*printf("exited child is %d, status is %d\n", child, status);*/ + DPRINTF("exited child is %d, status is %d\n", child, status); - if (pid1 = child) { - /*printf("killing process %d (second child)\n", pid2);*/ + if (pid1 == child) { + DPRINTF("killing process %d (second child)\n", pid2); kill(pid2, SIGTERM); } else { - /*printf("killing process %d (first child)\n", pid1);*/ + DPRINTF("killing process %d (first child)\n", pid1); kill(pid1, SIGTERM); } /* exit status in upper 8 bits, killed signal (if any) in @@ -88,8 +94,6 @@ main(int argc, char *argv[]) now = time(NULL); stat(outfile, &st); if ((now - st.st_mtime) > timeout) { - /*snprintf(logstr, BUFSIZ, "logger -t %s killing %s %s, pid %d since no output in %d seconds", argv[0], args, message, pid, timeout); - system(logstr);*/ printf("%s: killing %s (%s, pid %d and %d) since no output in %d seconds since %s", argv[0], args, message, pid1, pid, timeout, ctime(&now)); printf("ps jgx before the signal\n"); system("ps jgxww"); @@ -105,7 +109,7 @@ main(int argc, char *argv[]) } } else { /* first child */ - /*printf("executing %s\n", args);*/ + DPRINTF("executing %s\n", args); result = execvp(command, argv + 4); if (result < 0) { printf("Failed to exec %s: %s\n", args, strerror(errno)); Modified: projects/portbuild/sources/ptimeout.c ============================================================================== --- projects/portbuild/sources/ptimeout.c Tue Apr 26 13:50:11 2011 (r221066) +++ projects/portbuild/sources/ptimeout.c Tue Apr 26 15:11:12 2011 (r221067) @@ -14,6 +14,12 @@ #include #include +#if defined(DEBUG) +# define DPRINTF(fmt, ...) printf(fmt, __VA_ARGS__) +#else +# define DPRINTF(fmt, ...) +#endif + int main(int argc, char *argv[]) { @@ -36,20 +42,20 @@ main(int argc, char *argv[]) strlcat(args, " ", MAXPATHLEN - strlen(args)); } - /*printf("timeout is %d\n", timeout); - printf("arguments are %s\n", args);*/ + DPRINTF("timeout is %d\n", timeout); + DPRINTF("arguments are %s\n", args); if ((pid1 = fork()) > 0) { if ((pid2 = fork()) > 0) { /* parent */ - /*printf("child pids are %d %d\n", pid1, pid2);*/ + DPRINTF("child pids are %d %d\n", pid1, pid2); child = wait(&status); - /*printf("exited child is %d, status is %d\n", child, status);*/ - if (pid1 = child) { - /*printf("killing process %d\n", pid2);*/ + DPRINTF("exited child is %d, status is %d\n", child, status); + if (pid1 == child) { + DPRINTF("killing process %d\n", pid2); kill(pid2, SIGKILL); } else { - /*printf("killing process %d\n", pid1);*/ + DPRINTF("killing process %d\n", pid1); kill(pid1, SIGTERM); } /* exit status in upper 8 bits, killed signal (if any) @@ -66,7 +72,7 @@ main(int argc, char *argv[]) } } else { /* first child */ - /*printf("executing %s\n", args);*/ + DPRINTF("executing %s\n", args); execvp(command, argv + 2); }