|
|
1.1 root 1: /*
2: * Routine to notify a user about
3: * the completion of a transaction
4: * Usually called by some daemon (e.g.
5: * line printer daemon).
6: * Return non-zero on failure.
7: */
8:
9: #include <stdio.h>
10: #include <pwd.h>
11:
12: notify(name, msg)
13: char *name;
14: char *msg;
15: {
16: register struct passwd *pwp;
17: int pfd[2];
18: register int pid, fd;
19: int status;
20:
21: if (*name>='0' && *name<='9')
22: if ((pwp = getpwuid(atoi(name))) == NULL)
23: name = NULL; else
24: name = pwp->pw_name;
25: if (name==NULL || pipe(pfd)<0 || (pid = fork())<0)
26: return (1);
27: if (pid) {
28: close(pfd[0]);
29: write(pfd[1], msg, strlen(msg));
30: close(pfd[1]);
31: while (wait(&status) >= 0)
32: ;
33: } else {
34: close(pfd[1]);
35: dup2(pfd[0], 0);
36: close(pfd[0]);
37: for (fd=3; fd<_NFILE; fd++)
38: close(fd);
39: execlp("/bin/send", "send", "-s", name, NULL);
40: return (1);
41: }
42: return (0);
43: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.