summary refs log tree commit diff
path: root/nq.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2015-08-25 14:56:18 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2015-08-25 14:56:18 +0200
commit7063558a6e4698e59f83b5e9d31b40ab3aec713d (patch)
tree57a016ebc1c61bd401d5a3786404805360022fa2 /nq.c
parent4eb2c736f048fbecd1e6ef6865ec8447bfed9c73 (diff)
downloadnq-7063558a6e4698e59f83b5e9d31b40ab3aec713d.tar.gz
nq-7063558a6e4698e59f83b5e9d31b40ab3aec713d.tar.xz
nq-7063558a6e4698e59f83b5e9d31b40ab3aec713d.zip
nq: add quiet flag -q.
Diffstat (limited to 'nq.c')
-rw-r--r--nq.c15
1 files changed, 10 insertions, 5 deletions
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;