Bell 32V release
[unix-history] / usr / src / cmd / uucp / uulog.c
CommitLineData
291eef98
TL
1#include "uucp.h"
2#include "uucpdefs.h"
3#include <signal.h>
4#include <sys/types.h>
5#include <sys/stat.h>
6#include <sys/dir.h>
7
8int Stop = 0;
9
10/*******
11 *
12 * uulog - this program will append all update files in
13 * directory (LOGDIR) to the log file (logf) and remove the
14 * update files.
15 *
16 * options:
17 * -n - nominal time for delete of lock file
18 * -s - system name for search
19 * -u - user name for search
20 * -x - turn on debug outputs
21 *
22 * exit codes:
23 * 0 - normal
24 * 1 - lock file problems
25 *
26 */
27
28
29#define NOMTIME 3600L
30
31
32main(argc, argv)
33char *argv[];
34{
35 FILE *plogf, *lsp;
36 char filename[NAMESIZE];
37 time_t nomtime;
38 char *system, *user;
39
40 extern int onintr(), intr1();
41 char buf[BUFSIZ], u[20], s[20];
42
43 nomtime = NOMTIME;
44 system = user = NULL;
45
46
47 while (argc>1 && argv[1][0] == '-') {
48 switch (argv[1][1]) {
49 case 'd':
50 printf("-d option removed\n");
51 break;
52 case 'n':
53 nomtime = atoi(&argv[1][2]); break;
54 case 's':
55 system = &argv[1][2];
56 break;
57 case 'u':
58 user = &argv[1][2];
59 break;
60 case 'x':
61 Debug = atoi(&argv[1][2]);
62 if (Debug <= 0)
63 Debug = 1;
64 break;
65 default:
66 printf("unknown flag %s\n", argv[1]); break;
67 }
68 --argc; argv++;
69 }
70
71 DEBUG(4, "%s\n", "START");
72 chdir(LOGDIR);
73 if (ulockf(LOGLOCK, nomtime) != 0)
74 exit(0);
75 signal(SIGHUP, intr1);
76 signal(SIGINT,intr1);
77 signal(SIGQUIT, intr1);
78
79 if ((plogf = fopen(LOGFILE, "a")) == NULL) {
80 rmlock(LOGLOCK);
81 printf("can't open %s\n", LOGFILE);
82 exit(0);
83 }
84 lsp = fopen(LOGDIR, "r");
85 ASSERT(lsp != NULL, "CAN NOT OPEN %s", LOGDIR);
86 while ((gnamef(lsp, filename)) != 0) {
87 DEBUG(4, "file-%s\n", filename);
88 if (prefix(LOGPREFIX, filename)) {
89 DEBUG(4, "copy file %s\n", filename);
90 if (appendf(plogf, filename) == SUCCESS) {
91 unlink(filename);
92 }
93 }
94 }
95 fclose(lsp);
96 fclose(plogf);
97 chmod(LOGFILE, 0666);
98 rmlock(NULL);
99 if (user == NULL && system == NULL)
100 exit(0);
101 if (Stop)
102 exit(0);
103 signal(SIGHUP, onintr);
104 signal(SIGINT, onintr);
105 signal(SIGQUIT, onintr);
106
107 plogf = fopen(LOGFILE, "r");
108 ASSERT(plogf != NULL, "CAN NOT OPEN %s", LOGFILE);
109 while (fgets(buf, BUFSIZ, plogf) != NULL) {
110 sscanf(buf, "%s%s", u, s);
111 DEBUG(4, "u s %s ", u);
112 DEBUG(4, "%s ", s);
113 DEBUG(4, "%s", buf);
114 if (user != NULL && !prefix(user, u))
115 continue;
116 if (system != NULL && !prefix(system, s))
117 continue;
118 fputs(buf, stdout);
119 }
120 exit(0);
121}
122
123
124
125
126/***
127 * onintr()
128 *
129 * onintr - interrupt routine
130 * remove lock file
131 *
132 */
133
134onintr()
135{
136 rmlock(NULL);
137 exit(0);
138}
139
140
141intr1()
142{
143 signal(SIGINT, intr1);
144 signal(SIGHUP, intr1);
145 signal(SIGQUIT, intr1);
146 Stop = 1;
147 return;
148}
149
150cleanup(code)
151int code;
152{
153 exit(code);
154}
155
156
157/*******
158 * appendf(fp, entryf) append file (entryf) to fp file
159 * FILE *fp;
160 * char *entryf;
161 *
162 * return codes:
163 SUCCESS - ok
164 * FAIL - file not readable
165 */
166
167appendf(fp, entryf)
168FILE *fp;
169char *entryf;
170{
171 FILE *pentryf;
172 char ltext[513];
173
174 if ((pentryf = fopen(entryf, "r")) == NULL) {
175 /* file entryf not readable */
176 return(FAIL);
177 }
178 while (fgets(ltext, 512, pentryf)) fputs(ltext, fp);
179 fclose(pentryf);
180 return(SUCCESS);
181}