2 * lock - keep a lock alive while a command runs
13 void notifyf(void*, char*);
18 fprint(2, "usage: %s [-dw] lock [command [file]...]\n", argv0);
31 errstr(err, sizeof err);
32 if(strcmp(err, "interrupted") == 0)
44 int lckfd, didwstat = 0;
48 while ((lckfd = open(lock, ORDWR)) < 0 && lockwait)
51 sysfatal("can't open %s read/write: %r", lock);
52 dir = dirfstat(lckfd);
54 sysfatal("can't fstat %s: %r", lock);
55 if (!(dir->mode & DMEXCL)) {
57 sysfatal("exclusive bit does not stick for %s", lock);
59 dir->qid.type |= QTEXCL;
60 if (dirfwstat(lckfd, dir) < 0)
61 sysfatal("can't make %s exclusive access: %r", lock);
62 /* reopen for lock to be effective */
72 main(int argc, char *argv[])
74 int fd, lckfd, lckpid, cmdpid;
103 /* set up lock and process to keep it alive */
105 lckfd = openlock(lock);
111 /* keep lock alive until killed */
119 /* spawn argument command */
120 cmdpid = rfork(RFFDG|RFREND|RFPROC|RFENVG);
125 fd = create("/env/prompt", OWRITE, 0666);
127 fprint(fd, "%s%% ", lock);
131 if(cmd[0] != '/' && strncmp(cmd, "./", 2) != 0 &&
132 strncmp(cmd, "../", 3) != 0)
133 exec(smprint("/bin/%s", cmd), args);
143 postnote(PNPROC, lckpid, "die");
146 p = utfrune(w->msg, ':');
153 fprint(2, "%s: %s # status=%s\n", argv0, cmd, p);
161 fprint(2, "%s: %s: %r\n", argv0, s);
166 notifyf(void *a, char *s)
169 if(strcmp(s, "interrupt") == 0)