| /* MAXHOSTNAMELEN is in sys/param.h */ |
| #define MAXHOSTNAMELEN 64 |
| char lockstring[MAXHOSTNAMELEN+8]; |
| main(int argc, char *argv[]) { |
| fprint(2, "usage: LOCK lockfile hostname ppid\n"); |
| exits("lock failed on usage"); |
| if ((fd=create(lockfile, OLOCK|ORDWR, 0666)) < 0) { |
| exits("lock failed on create"); |
| ssize = sprint(lockstring, "%s %s\n", argv[2], argv[3]); |
| if (write(fd, lockstring, ssize) != ssize) { |
| fprint(2, "LOCK:write(): %r\n"); |
| exits("lock failed on write to lockfile"); |
| fprint(2, "LOCK:fork(): %r\n"); |
| exits("lock failed on fork"); |
| if (statbuf->length == 0){ |
| if (write(fd, "", 0) < 0) |
| postnote(PNGROUP, ppid, "kill"); |