Commit | Line | Data |
---|---|---|
808bd6eb N |
1 | #include "uucp.h" |
2 | #include <sys/types.h> | |
3 | #include <time.h> | |
4 | ||
5 | ||
6 | char Tmplog[MAXFULLNAME] = ""; | |
7 | FILE *Lp = NULL; | |
8 | ||
9 | /******* | |
10 | * logent(text, status) make log entry | |
11 | * char *text, *status; | |
12 | * | |
13 | * return code - none | |
14 | */ | |
15 | ||
16 | logent(text, status) | |
17 | char *text, *status; | |
18 | { | |
19 | int n; | |
20 | FILE *fp; | |
21 | if (Lp != NULL) { | |
22 | /* make entry in existing temp log file */ | |
23 | mlogent(Lp, status, text); | |
24 | return; | |
25 | } | |
26 | ||
27 | if (ulockf(LOGLOCK, 10l) == 0) { | |
28 | if ((fp = fopen(LOGFILE, "a")) == NULL) { | |
29 | rmlock(LOGLOCK); | |
30 | } | |
31 | else { | |
32 | mlogent(fp, status, text); | |
33 | fclose(fp); | |
34 | rmlock(LOGLOCK); | |
35 | return; | |
36 | } | |
37 | } | |
38 | ||
39 | /* make a temp log file */ | |
40 | for (n = 0; n < 10; n++) { | |
41 | sprintf(Tmplog, "%s/LOG.%05d.%1d", LOGDIR, getpid(), n); | |
42 | if (access(Tmplog, 0) == -1) | |
43 | break; | |
44 | } | |
45 | if ((Lp = fopen(Tmplog, "w")) == NULL) | |
46 | return; | |
47 | chmod(Tmplog, 0222); | |
48 | setbuf(Lp, NULL); | |
49 | mlogent(Lp, status, text); | |
50 | return; | |
51 | } | |
52 | ||
53 | /*** | |
54 | * mlogent(fp, status, text) - make a log entry | |
55 | */ | |
56 | ||
57 | mlogent(fp, status, text) | |
58 | char *text, *status; | |
59 | FILE *fp; | |
60 | { | |
61 | struct tm *tp; | |
62 | extern struct tm *localtime(); | |
63 | time_t clock; | |
64 | time(&clock); | |
65 | tp = localtime(&clock); | |
66 | fprintf(fp, "%s %s ", User, Rmtname); | |
67 | fprintf(fp, "(%d/%d-%d:%d) ", tp->tm_mon + 1, | |
68 | tp->tm_mday, tp->tm_hour, tp->tm_min); | |
69 | fprintf(fp, "%s (%s)\n", status, text); | |
70 | return; | |
71 | } | |
72 | ||
73 | /*** | |
74 | * logcls() close log file | |
75 | * | |
76 | * return codes: none | |
77 | */ | |
78 | ||
79 | logcls() | |
80 | { | |
81 | if (Lp != NULL) { | |
82 | fclose(Lp); | |
83 | chmod(Tmplog, 0666); | |
84 | } | |
85 | return; | |
86 | } | |
87 | ||
88 | ||
89 | /*** | |
90 | * syslog(text) make system log entry | |
91 | * char *text; | |
92 | * | |
93 | * return codes - none | |
94 | */ | |
95 | ||
96 | syslog(text) | |
97 | char *text; | |
98 | { | |
99 | struct tm *tp; | |
100 | extern struct tm *localtime(); | |
101 | time_t clock; | |
102 | FILE *fp; | |
103 | ||
104 | time(&clock); | |
105 | tp = localtime(&clock); | |
106 | fp = fopen(SYSLOG, "a"); | |
107 | if (fp == NULL) | |
108 | return; | |
109 | fprintf(fp, "%s %s ", User, Rmtname); | |
110 | fprintf(fp, "(%d/%d-%d:%d) ", tp->tm_mon + 1, | |
111 | tp->tm_mday, tp->tm_hour, tp->tm_min); | |
112 | fprintf(fp, "%s\n", text); | |
113 | fclose(fp); | |
114 | return; | |
115 | } |