summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-07-24 18:50:17 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-07-24 18:50:17 +0200
commit381576322800ee3afe3246fadaf74d61377951ba (patch)
tree6775633d42783e6b709ff61d20648c599b6dbef2
parent531dd7ab05c7aee56ed2cbbaee92fbbe3ae4e6eb (diff)
downloadnq-381576322800ee3afe3246fadaf74d61377951ba.tar.gz
nq-381576322800ee3afe3246fadaf74d61377951ba.tar.xz
nq-381576322800ee3afe3246fadaf74d61377951ba.zip
fq: add -n to not wait
-rw-r--r--fq.14
-rw-r--r--fq.c12
2 files changed, 13 insertions, 3 deletions
diff --git a/fq.1 b/fq.1
index 72d9c3b..219dce6 100644
--- a/fq.1
+++ b/fq.1
@@ -7,6 +7,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl a
+.Op Fl n
 .Op Fl q
 .Op Ar job\ id ...
 .Sh DESCRIPTION
@@ -27,6 +28,9 @@ The options are as follows:
 .Bl -tag -width Ds
 .It Fl a
 Output all log files, even of already finished jobs.
+.It Fl n
+Don't wait for new output.
+Can be used to look at enqueued commands.
 .It Fl q
 Only print the first line of each job output
 (i.e. the
diff --git a/fq.c b/fq.c
index b92aa56..38a9088 100644
--- a/fq.c
+++ b/fq.c
@@ -56,7 +56,7 @@ main(int argc, char *argv[])
 	off_t off, loff;
 	ssize_t rd;
 	int didsth = 0, seen_nl = 0;
-	int opt = 0, aflag = 0, qflag = 0;
+	int opt = 0, aflag = 0, nflag = 0, qflag = 1;
 	char *path;
 
 #ifdef USE_INOTIFY
@@ -65,16 +65,19 @@ main(int argc, char *argv[])
 
 	close(0);
 
-	while ((opt = getopt(argc, argv, "+aq")) != -1) {
+	while ((opt = getopt(argc, argv, "+anq")) != -1) {
 		switch (opt) {
 		case 'a':
 			aflag = 1;
 			break;
+		case 'n':
+			nflag = 1;
+			break;
 		case 'q':
 			qflag = 1;
 			break;
 		default:
-			fputs("usage: fq [-qa] [JOBID...]\n", stderr);
+			fputs("usage: fq [-anq] [JOBID...]\n", stderr);
 			exit(1);
 		}
 	}
@@ -162,6 +165,9 @@ main(int argc, char *argv[])
 				loff = off;               /* file truncated */
 
 			if (off == loff) {
+				if (nflag && islocked(fd))
+					break;
+
 				if (flock(fd, LOCK_EX | LOCK_NB) == -1 &&
 				    errno == EWOULDBLOCK) {
 #ifdef USE_INOTIFY