1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 1998 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */
29*7c478bd9Sstevel@tonic-gate
30*7c478bd9Sstevel@tonic-gate #include "uucp.h"
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate static FILE *_Lf = NULL;
33*7c478bd9Sstevel@tonic-gate static FILE *_Cf = NULL;
34*7c478bd9Sstevel@tonic-gate static int _Sf = -1;
35*7c478bd9Sstevel@tonic-gate static int CurRole = MASTER; /* Uucico's current role. */
36*7c478bd9Sstevel@tonic-gate
37*7c478bd9Sstevel@tonic-gate /*
38*7c478bd9Sstevel@tonic-gate * Make log entry
39*7c478bd9Sstevel@tonic-gate * text -> ptr to text string
40*7c478bd9Sstevel@tonic-gate * status -> ptr to status string
41*7c478bd9Sstevel@tonic-gate * Returns:
42*7c478bd9Sstevel@tonic-gate * none
43*7c478bd9Sstevel@tonic-gate */
44*7c478bd9Sstevel@tonic-gate void
logent(text,status)45*7c478bd9Sstevel@tonic-gate logent(text, status)
46*7c478bd9Sstevel@tonic-gate register char *text, *status;
47*7c478bd9Sstevel@tonic-gate {
48*7c478bd9Sstevel@tonic-gate static char logfile[MAXFULLNAME];
49*7c478bd9Sstevel@tonic-gate char *prev;
50*7c478bd9Sstevel@tonic-gate
51*7c478bd9Sstevel@tonic-gate if (*Rmtname == NULLCHAR) /* ignore logging if Rmtname is not yet set */
52*7c478bd9Sstevel@tonic-gate return;
53*7c478bd9Sstevel@tonic-gate
54*7c478bd9Sstevel@tonic-gate prev = _uu_setlocale(LC_ALL, "C");
55*7c478bd9Sstevel@tonic-gate if (Nstat.t_pid == 0)
56*7c478bd9Sstevel@tonic-gate Nstat.t_pid = getpid();
57*7c478bd9Sstevel@tonic-gate
58*7c478bd9Sstevel@tonic-gate if (_Lf != NULL
59*7c478bd9Sstevel@tonic-gate && strncmp(Rmtname, BASENAME(logfile, '/'), MAXBASENAME) != 0) {
60*7c478bd9Sstevel@tonic-gate fclose(_Lf);
61*7c478bd9Sstevel@tonic-gate _Lf = NULL;
62*7c478bd9Sstevel@tonic-gate }
63*7c478bd9Sstevel@tonic-gate
64*7c478bd9Sstevel@tonic-gate if (_Lf == NULL) {
65*7c478bd9Sstevel@tonic-gate sprintf(logfile, "%s/%s", Logfile, Rmtname);
66*7c478bd9Sstevel@tonic-gate _Lf = fopen(logfile, "a");
67*7c478bd9Sstevel@tonic-gate (void) chmod(logfile, LOGFILEMODE);
68*7c478bd9Sstevel@tonic-gate if (_Lf == NULL) {
69*7c478bd9Sstevel@tonic-gate (void) _uu_resetlocale(LC_ALL, prev);
70*7c478bd9Sstevel@tonic-gate return;
71*7c478bd9Sstevel@tonic-gate }
72*7c478bd9Sstevel@tonic-gate setbuf(_Lf, CNULL);
73*7c478bd9Sstevel@tonic-gate }
74*7c478bd9Sstevel@tonic-gate (void) fseek(_Lf, 0L, 2);
75*7c478bd9Sstevel@tonic-gate (void) fprintf(_Lf, "%s %s %s ", User, Rmtname, Jobid);
76*7c478bd9Sstevel@tonic-gate (void) fprintf(_Lf, "(%s,%ld,%d) ", timeStamp(), (long) Nstat.t_pid, Seqn);
77*7c478bd9Sstevel@tonic-gate (void) fprintf(_Lf, "%s (%s)\n", status, text);
78*7c478bd9Sstevel@tonic-gate (void) _uu_resetlocale(LC_ALL, prev);
79*7c478bd9Sstevel@tonic-gate return;
80*7c478bd9Sstevel@tonic-gate }
81*7c478bd9Sstevel@tonic-gate
82*7c478bd9Sstevel@tonic-gate
83*7c478bd9Sstevel@tonic-gate /*
84*7c478bd9Sstevel@tonic-gate * Make entry for a conversation (uucico only)
85*7c478bd9Sstevel@tonic-gate * text -> pointer to message string
86*7c478bd9Sstevel@tonic-gate * Returns:
87*7c478bd9Sstevel@tonic-gate * none
88*7c478bd9Sstevel@tonic-gate */
89*7c478bd9Sstevel@tonic-gate void
usyslog(text)90*7c478bd9Sstevel@tonic-gate usyslog(text)
91*7c478bd9Sstevel@tonic-gate register char *text;
92*7c478bd9Sstevel@tonic-gate {
93*7c478bd9Sstevel@tonic-gate int sbuflen;
94*7c478bd9Sstevel@tonic-gate char sysbuf[BUFSIZ];
95*7c478bd9Sstevel@tonic-gate char *prev = _uu_setlocale(LC_ALL, "C");
96*7c478bd9Sstevel@tonic-gate
97*7c478bd9Sstevel@tonic-gate (void) sprintf(sysbuf, "%s!%s %s (%s) (%c,%ld,%d) [%s] %s\n",
98*7c478bd9Sstevel@tonic-gate Rmtname, User, CurRole == SLAVE ? "S" : "M", timeStamp(),
99*7c478bd9Sstevel@tonic-gate Pchar, (long) getpid(), Seqn, Dc, text);
100*7c478bd9Sstevel@tonic-gate sbuflen = strlen(sysbuf);
101*7c478bd9Sstevel@tonic-gate if (_Sf < 0) {
102*7c478bd9Sstevel@tonic-gate errno = 0;
103*7c478bd9Sstevel@tonic-gate _Sf = open(SYSLOG, 1);
104*7c478bd9Sstevel@tonic-gate if (errno == ENOENT) {
105*7c478bd9Sstevel@tonic-gate _Sf = creat(SYSLOG, LOGFILEMODE);
106*7c478bd9Sstevel@tonic-gate (void) chmod(SYSLOG, LOGFILEMODE);
107*7c478bd9Sstevel@tonic-gate }
108*7c478bd9Sstevel@tonic-gate if (_Sf < 0) {
109*7c478bd9Sstevel@tonic-gate (void) _uu_resetlocale(LC_ALL, prev);
110*7c478bd9Sstevel@tonic-gate return;
111*7c478bd9Sstevel@tonic-gate }
112*7c478bd9Sstevel@tonic-gate }
113*7c478bd9Sstevel@tonic-gate (void) lseek(_Sf, 0L, 2);
114*7c478bd9Sstevel@tonic-gate (void) write(_Sf, sysbuf, sbuflen);
115*7c478bd9Sstevel@tonic-gate (void) _uu_resetlocale(LC_ALL, prev);
116*7c478bd9Sstevel@tonic-gate return;
117*7c478bd9Sstevel@tonic-gate }
118*7c478bd9Sstevel@tonic-gate
119*7c478bd9Sstevel@tonic-gate /*
120*7c478bd9Sstevel@tonic-gate * Make entry for a command
121*7c478bd9Sstevel@tonic-gate * argc -> number of command arguments
122*7c478bd9Sstevel@tonic-gate * argv -> pointer array to command arguments
123*7c478bd9Sstevel@tonic-gate * Returns:
124*7c478bd9Sstevel@tonic-gate * none
125*7c478bd9Sstevel@tonic-gate */
126*7c478bd9Sstevel@tonic-gate void
commandlog(argc,argv)127*7c478bd9Sstevel@tonic-gate commandlog(argc,argv)
128*7c478bd9Sstevel@tonic-gate int argc;
129*7c478bd9Sstevel@tonic-gate char **argv;
130*7c478bd9Sstevel@tonic-gate {
131*7c478bd9Sstevel@tonic-gate int fd;
132*7c478bd9Sstevel@tonic-gate char *prev = _uu_setlocale(LC_ALL, "C");
133*7c478bd9Sstevel@tonic-gate
134*7c478bd9Sstevel@tonic-gate if (_Cf == NULL) {
135*7c478bd9Sstevel@tonic-gate errno = 0;
136*7c478bd9Sstevel@tonic-gate fd = open(CMDLOG, O_WRONLY | O_APPEND);
137*7c478bd9Sstevel@tonic-gate if (errno == ENOENT) {
138*7c478bd9Sstevel@tonic-gate fd = creat(CMDLOG, LOGFILEMODE);
139*7c478bd9Sstevel@tonic-gate (void) chmod(CMDLOG, LOGFILEMODE);
140*7c478bd9Sstevel@tonic-gate }
141*7c478bd9Sstevel@tonic-gate if (fd < 0 || (_Cf = fdopen(fd, "a")) == NULL) {
142*7c478bd9Sstevel@tonic-gate (void) _uu_resetlocale(LC_ALL, prev);
143*7c478bd9Sstevel@tonic-gate return;
144*7c478bd9Sstevel@tonic-gate }
145*7c478bd9Sstevel@tonic-gate }
146*7c478bd9Sstevel@tonic-gate (void) fprintf(_Cf, "%s (%s) ",User, timeStamp() );
147*7c478bd9Sstevel@tonic-gate while (argc-- > 0) {
148*7c478bd9Sstevel@tonic-gate (void) fprintf(_Cf, "%s%c", *argv++, (argc > 0)?' ':'\n');
149*7c478bd9Sstevel@tonic-gate }
150*7c478bd9Sstevel@tonic-gate (void) fflush(_Cf);
151*7c478bd9Sstevel@tonic-gate (void) _uu_resetlocale(LC_ALL, prev);
152*7c478bd9Sstevel@tonic-gate return;
153*7c478bd9Sstevel@tonic-gate }
154*7c478bd9Sstevel@tonic-gate
155*7c478bd9Sstevel@tonic-gate /*
156*7c478bd9Sstevel@tonic-gate * Close log files before a fork
157*7c478bd9Sstevel@tonic-gate */
158*7c478bd9Sstevel@tonic-gate void
ucloselog()159*7c478bd9Sstevel@tonic-gate ucloselog()
160*7c478bd9Sstevel@tonic-gate {
161*7c478bd9Sstevel@tonic-gate if (_Sf >= 0) {
162*7c478bd9Sstevel@tonic-gate (void) close(_Sf);
163*7c478bd9Sstevel@tonic-gate _Sf = -1;
164*7c478bd9Sstevel@tonic-gate }
165*7c478bd9Sstevel@tonic-gate if (_Lf) {
166*7c478bd9Sstevel@tonic-gate (void) fclose(_Lf);
167*7c478bd9Sstevel@tonic-gate _Lf = NULL;
168*7c478bd9Sstevel@tonic-gate }
169*7c478bd9Sstevel@tonic-gate if (_Cf) {
170*7c478bd9Sstevel@tonic-gate (void) fclose(_Cf);
171*7c478bd9Sstevel@tonic-gate _Cf = NULL;
172*7c478bd9Sstevel@tonic-gate }
173*7c478bd9Sstevel@tonic-gate return;
174*7c478bd9Sstevel@tonic-gate }
175*7c478bd9Sstevel@tonic-gate
176*7c478bd9Sstevel@tonic-gate /*
177*7c478bd9Sstevel@tonic-gate * millitick()
178*7c478bd9Sstevel@tonic-gate *
179*7c478bd9Sstevel@tonic-gate * return msec since last time called
180*7c478bd9Sstevel@tonic-gate */
181*7c478bd9Sstevel@tonic-gate #ifdef ATTSV
182*7c478bd9Sstevel@tonic-gate #include <values.h>
183*7c478bd9Sstevel@tonic-gate
184*7c478bd9Sstevel@tonic-gate time_t
millitick()185*7c478bd9Sstevel@tonic-gate millitick()
186*7c478bd9Sstevel@tonic-gate {
187*7c478bd9Sstevel@tonic-gate struct tms tbuf;
188*7c478bd9Sstevel@tonic-gate time_t now, rval;
189*7c478bd9Sstevel@tonic-gate static time_t past; /* guaranteed 0 first time called */
190*7c478bd9Sstevel@tonic-gate
191*7c478bd9Sstevel@tonic-gate if (past == 0) {
192*7c478bd9Sstevel@tonic-gate past = times(&tbuf);
193*7c478bd9Sstevel@tonic-gate rval = 0;
194*7c478bd9Sstevel@tonic-gate } else {
195*7c478bd9Sstevel@tonic-gate now = times(&tbuf);
196*7c478bd9Sstevel@tonic-gate if (now - past > MAXLONG / 1000) /* would overflow */
197*7c478bd9Sstevel@tonic-gate rval = (now - past) / HZ * 1000;
198*7c478bd9Sstevel@tonic-gate else
199*7c478bd9Sstevel@tonic-gate rval = (now - past) * 1000 / HZ;
200*7c478bd9Sstevel@tonic-gate past = now;
201*7c478bd9Sstevel@tonic-gate }
202*7c478bd9Sstevel@tonic-gate return(rval);
203*7c478bd9Sstevel@tonic-gate }
204*7c478bd9Sstevel@tonic-gate
205*7c478bd9Sstevel@tonic-gate #else /* !ATTSV */
206*7c478bd9Sstevel@tonic-gate time_t
millitick()207*7c478bd9Sstevel@tonic-gate millitick()
208*7c478bd9Sstevel@tonic-gate {
209*7c478bd9Sstevel@tonic-gate struct timeb tbuf;
210*7c478bd9Sstevel@tonic-gate static struct timeb tbuf1;
211*7c478bd9Sstevel@tonic-gate static past; /* guaranteed 0 first time called */
212*7c478bd9Sstevel@tonic-gate time_t rval;
213*7c478bd9Sstevel@tonic-gate
214*7c478bd9Sstevel@tonic-gate if (past == 0) {
215*7c478bd9Sstevel@tonic-gate past++;
216*7c478bd9Sstevel@tonic-gate rval = 0;
217*7c478bd9Sstevel@tonic-gate ftime(&tbuf1);
218*7c478bd9Sstevel@tonic-gate } else {
219*7c478bd9Sstevel@tonic-gate ftime(&tbuf);
220*7c478bd9Sstevel@tonic-gate rval = (tbuf.time - tbuf1.time) * 1000
221*7c478bd9Sstevel@tonic-gate + tbuf.millitm - tbuf1.millitm;
222*7c478bd9Sstevel@tonic-gate tbuf1 = tbuf;
223*7c478bd9Sstevel@tonic-gate }
224*7c478bd9Sstevel@tonic-gate return(rval);
225*7c478bd9Sstevel@tonic-gate }
226*7c478bd9Sstevel@tonic-gate #endif /* ATTSV */
227