diff options
author | Leah Neukirchen <leah@vuxu.org> | 2021-12-15 21:36:29 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2021-12-15 21:36:29 +0100 |
commit | 6f0d1e5f44aeadc9d81b1a7a38819f7c2cb85688 (patch) | |
tree | 46fc9a04e1eb285eaadbdd5f9848fed195faaa18 | |
parent | d95eaa1dfde19dcac6f8b0aefbab2f1a9e71cb0d (diff) | |
download | nq-6f0d1e5f44aeadc9d81b1a7a38819f7c2cb85688.tar.gz nq-6f0d1e5f44aeadc9d81b1a7a38819f7c2cb85688.tar.xz nq-6f0d1e5f44aeadc9d81b1a7a38819f7c2cb85688.zip |
nq: only change u+x bit to mark running job
-rw-r--r-- | nq.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/nq.c b/nq.c index 151ce6b..985c165 100644 --- a/nq.c +++ b/nq.c @@ -107,6 +107,18 @@ write_execline(int fd, int argc, char *argv[]) } } +static void +setx(int fd, int executable) +{ + struct stat st; + fstat(fd, &st); + if (executable) + st.st_mode |= 0100; + else + st.st_mode &= ~0100; + fchmod(fd, st.st_mode); +} + int main(int argc, char *argv[]) { @@ -241,7 +253,7 @@ usage: exit(222); } - fchmod(lockfd, 0600); + setx(lockfd, 0); if (WIFEXITED(status)) { dprintf(lockfd, "\n[exited with status %d.]\n", WEXITSTATUS(status)); @@ -314,7 +326,7 @@ wait: flock(fd, LOCK_SH); /* sit it out. */ } - fchmod(fd, 0600); + setx(fd, 0); close(fd); } } else { @@ -346,7 +358,7 @@ again: if (strcmp(ent->d_name, newestlocked) > 0) strcpy(newestlocked, ent->d_name); } else { - fchmod(fd, 0600); + setx(fd, 0); } close(fd); @@ -371,7 +383,7 @@ again: /* ready to run. */ swrite(lockfd, "\n\n"); - fchmod(lockfd, 0700); + setx(lockfd, 1); close(lockfd); |