1 /*-
2 * Copyright (c) 1985, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.proprietary.c%
6 */
7
8 #ifndef lint
9 static char copyright[] =
10 "@(#) Copyright (c) 1985, 1988, 1993\n\
11 The Regents of the University of California. All rights reserved.\n";
12 #endif /* not lint */
13
14 #ifndef lint
15 static char sccsid[] = "@(#)uulog.c 8.1 (Berkeley) 06/06/93";
16 #endif /* not lint */
17
18 #include "uucp.h"
19
20 struct timeb Now;
21
main(argc,argv)22 main(argc, argv)
23 char *argv[];
24 {
25 #ifndef LOGBYSITE
26 FILE *plogf;
27 char u[64], s[64];
28 #endif /* !LOGBYSITE */
29 char *sys, *user;
30 int c;
31 extern char *optarg;
32 extern int optind;
33
34 char buf[BUFSIZ];
35
36 strcpy(Progname, "uulog");
37 sys = user = NULL;
38
39 while ((c = getopt(argc, argv, "s:u:")) != EOF)
40 switch (c) {
41 case 's':
42 sys = optarg;
43 if (strlen(sys) > MAXBASENAME)
44 sys[MAXBASENAME] = '\0';
45 if (versys(&sys) != SUCCESS){
46 fprintf(stderr,"uulog: unknown system %s\n", sys);
47 sys = NULL;
48 }
49 break;
50 case 'u':
51 user = optarg;
52 break;
53 case '?':
54 default:
55 fprintf(stderr, "unknown flag %s\n", argv[optind-1]);
56 break;
57 }
58
59 if (user == NULL && sys == NULL) {
60 fprintf(stderr, "usage: uulog [-u user] [-s sys]\n");
61 exit(1);
62 }
63
64 #ifdef LOGBYSITE
65 if (chdir(SPOOL) < 0) {
66 perror(SPOOL);
67 exit(1);
68 }
69 /* this program is really obsolete, this is a rude backward compat */
70 if (user) {
71 sprintf(buf, "exec cat LOG/uu*/* | egrep '^%s '", user);
72 system(buf);
73 }
74 if (sys) {
75 sprintf(buf,"exec cat LOG/uu*/%s", sys);
76 system(buf);
77 }
78 #else !LOGBYSITE
79 plogf = fopen(LOGFILE, "r");
80 if (plogf == NULL) {
81 syslog(LOG_WARNING, "fopen(%s) failed: %m", LOGFILE);
82 cleanup(1);
83 }
84 while (fgets(buf, BUFSIZ, plogf) != NULL) {
85 sscanf(buf, "%s%s", u, s);
86 if (user != NULL && !(prefix(user, u) || prefix(u, user)))
87 continue;
88 if (sys != NULL && !(prefix(sys, s) || prefix(s, sys)))
89 continue;
90 fputs(buf, stdout);
91 fflush(stdout);
92 }
93 #endif !LOGBYSITE
94 exit(0);
95 }
96
cleanup(code)97 cleanup(code)
98 int code;
99 {
100 exit(code);
101 }
102