diff options
-rw-r--r-- | nq.1 | 9 | ||||
-rw-r--r-- | nq.c | 22 |
2 files changed, 30 insertions, 1 deletions
diff --git a/nq.1 b/nq.1 index f6905ee..ff09dc6 100644 --- a/nq.1 +++ b/nq.1 @@ -71,6 +71,7 @@ listed job ids are done. .El .Sh ENVIRONMENT .Bl -hang -width "NQDONEDIR" +.Bl -hang -width "NQFAILDIR" .It Ev NQDIR Directory where lock files/job output resides. Each @@ -93,6 +94,14 @@ to after successful execution of the job. Ignored when .Fl c is used. +.It Ev NQFAILDIR +When set, specifies a directory +.Po +must be on the same file system as +.Ev NQDIR +.Pc +where lock files/job output is moved +to after unsuccessful execution of the job. .It Ev NQJOBID The job id of the currently running job, exposed to the job itself. diff --git a/nq.c b/nq.c index 564782d..1aff8f9 100644 --- a/nq.c +++ b/nq.c @@ -123,7 +123,7 @@ int main(int argc, char *argv[]) { int64_t ms; - int dirfd = -1, donedirfd = -1, lockfd = -1; + int dirfd = -1, donedirfd = -1, faildirfd = -1, lockfd = -1; int opt = 0, cflag = 0, qflag = 0, tflag = 0, wflag = 0; int pipefd[2]; char lockfile[64], newestlocked[64]; @@ -195,6 +195,22 @@ usage: } } + char *failpath = getenv("NQFAILDIR"); + if (failpath) { + if (mkdir(failpath, 0777) < 0) { + if (errno != EEXIST) { + perror("mkdir $NQFAILDIR"); + exit(111); + } + } + + faildirfd = open(failpath, O_RDONLY | O_DIRECTORY); + if (faildirfd < 0) { + perror("dir open"); + exit(111); + } + } + if (tflag || wflag) { snprintf(lockfile, sizeof lockfile, ".,%011" PRIx64 ".%d", ms, getpid()); @@ -263,6 +279,10 @@ usage: else if (donepath) renameat(dirfd, lockfile, donedirfd, lockfile); + } + if (WEXITSTATUS(status) != 0) { + if (failpath) + renameat(dirfd, lockfile, faildirfd, lockfile); /* errors above are ignored */ } } else { |