From 7063558a6e4698e59f83b5e9d31b40ab3aec713d Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Tue, 25 Aug 2015 14:56:18 +0200 Subject: nq: add quiet flag -q. --- README.md | 5 +++-- nq.c | 15 ++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index cc5fa41..b793bd7 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,9 @@ Enforcing job order works like this: - the lock is released by the kernel after the job terminates You enqueue (get it?) new jobs using `nq CMDLINE...`. The job id is -output and `nq` detaches immediately, running the job in the background. -STDOUT and STDERR are redirected into the log file. +output (unless suppressed using `-q`) and `nq` detaches immediately, +running the job in the background. STDOUT and STDERR are redirected +into the log file. `nq` tries hard (but does not guarantee) to ensure the log file of the currently running job has +x bit set. Thus you can use `ls -F` to get diff --git a/nq.c b/nq.c index 7401c2e..9b8b692 100644 --- a/nq.c +++ b/nq.c @@ -2,6 +2,7 @@ * nq CMD... - run CMD... in background and in order, saving output * -w ... wait for all jobs/listed jobs queued so far to finish * -t ... exit 0 if no (listed) job needs waiting + * -q quiet, do not output job id * * - requires POSIX.1-2008 and having flock(2) * - enforcing order works like this: @@ -74,7 +75,7 @@ int main(int argc, char *argv[]) { int64_t ms; - int dirfd = 0, lockfd = 0, opt = 0, tflag = 0, wflag = 0; + int dirfd = 0, lockfd = 0, opt = 0, qflag = 0, tflag = 0, wflag = 0; int pipefd[2]; char lockfile[64]; pid_t child; @@ -86,7 +87,7 @@ main(int argc, char *argv[]) gettimeofday(&started, NULL); ms = (int64_t)started.tv_sec*1000 + started.tv_usec/1000; - while ((opt = getopt(argc, argv, "+htw")) != -1) { + while ((opt = getopt(argc, argv, "+hqtw")) != -1) { switch (opt) { case 'w': wflag = 1; @@ -94,6 +95,9 @@ main(int argc, char *argv[]) case 't': tflag = 1; break; + case 'q': + qflag = 1; + break; case 'h': default: goto usage; @@ -102,7 +106,7 @@ main(int argc, char *argv[]) if (argc <= 1) { usage: - swrite(2, "usage: nq [-w ... | -t ... | CMD...]\n"); + swrite(2, "usage: nq [-q] [-w ... | -t ... | CMD...]\n"); exit(1); } @@ -157,7 +161,8 @@ usage: /* output expected lockfile name. */ snprintf(lockfile, sizeof lockfile, ",%011" PRIx64 ".%d", ms, child); - dprintf(1, "%s\n", lockfile); + if (!qflag) + dprintf(1, "%s\n", lockfile); close(0); close(1); close(2); @@ -284,7 +289,7 @@ again: setenv("NQJOBID", lockfile+1, 1); setsid(); - execvp(argv[1], argv+1); + execvp(argv[optind], argv+optind); perror("execvp"); return 222; -- cgit 1.4.1