|
|
1.1 root 1: #include <stdio.h>
2: #include <sys/types.h>
3: #include <sys/stat.h>
4: #include <fcntl.h>
5: #include <unistd.h>
6: #include "dist.h"
7:
8: static void
9: sendjob(char *job, int num, char *sys)
10: {
11: char busy[MAXNAME], done[MAXNAME], mesg[MAXLINE];
12: int fd, attempt;
13:
14: sprintf(busy, "%d.%s", num, BUSY);
15: sprintf(done, "%d.%s", num, DONE);
16:
17: fd = lcreat(busy, 0600);
18: if (fd < 0)
19: return;
20: dup2(fd, 2);
21: close(fd);
22:
23: /* avoid race condition */
24: if (access(done, F_OK) == 0)
25: goto out;
26:
27: fd = open(DATA, O_RDONLY);
28: if (fd < 0)
29: goto out;
30:
31: if (!chkperm(fd)) {
32: close(fd);
33: goto out;
34: }
35:
36: sprintf(mesg, "begin job %s\n", job);
37: write(1, mesg, strlen(mesg));
38:
39: if (!sendfile(fd))
40: goto err;
41:
42: if (!getline(mesg) || sscanf(mesg, "client attempt=%d\n", &attempt) != 1)
43: goto err;
44: if (!attempt)
45: goto out;
46:
47: if (!recvfile(2))
48: goto err;
49:
50: rename(busy, done);
51:
52: fd = open("/dev/null", O_WRONLY);
53: dup2(fd, 2);
54: close(fd);
55: return;
56:
57: out:
58: /* continue with the next job */
59: remove(busy);
60: return;
61:
62: err:
63: /* failure that's too hard to resynchronize */
64: eprintf("sendjob really barfed");
65: remove(busy);
66: exit(1);
67: }
68:
69: int
70: main(int argc, char *argv[])
71: {
72: prog = argv[0];
73: if (argc < 2) {
74: eprintf("usage: transmit system");
75: return 1;
76: }
77: scanq(argv[1], sendjob);
78: return 0;
79: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.