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)
48 while ((lckfd = open(lock, ORDWR)) < 0)
51 lckfd = open(lock, ORDWR);
53 sysfatal("can't open %s read/write: %r", lock);
54 dir = dirfstat(lckfd);
56 sysfatal("can't fstat %s: %r", lock);
57 if (!(dir->mode & DMEXCL)) {
59 dir->qid.type |= QTEXCL;
60 if (dirfwstat(lckfd, dir) < 0)
61 sysfatal("can't make %s exclusive access: %r", lock);
68 main(int argc, char *argv[])
70 int fd, lckfd, lckpid, cmdpid;
99 /* set up lock and process to keep it alive */
101 lckfd = openlock(lock);
107 /* keep lock alive until killed */
115 /* spawn argument command */
116 cmdpid = rfork(RFFDG|RFREND|RFPROC|RFENVG);
121 fd = create("/env/prompt", OWRITE, 0666);
123 fprint(fd, "%s%% ", lock);
127 if(cmd[0] != '/' && strncmp(cmd, "./", 2) != 0 &&
128 strncmp(cmd, "../", 3) != 0)
129 exec(smprint("/bin/%s", cmd), args);
139 postnote(PNPROC, lckpid, "die");
142 p = utfrune(w->msg, ':');
149 fprint(2, "%s: %s # status=%s\n", argv0, cmd, p);
157 fprint(2, "%s: %s: %r\n", argv0, s);
162 notifyf(void *a, char *s)
165 if(strcmp(s, "interrupt") == 0)