4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1998 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
35 static FILE *_Lf
= NULL
;
36 static FILE *_Cf
= NULL
;
38 static int CurRole
= MASTER
; /* Uucico's current role. */
42 * text -> ptr to text string
43 * status -> ptr to status string
49 register char *text
, *status
;
51 static char logfile
[MAXFULLNAME
];
54 if (*Rmtname
== NULLCHAR
) /* ignore logging if Rmtname is not yet set */
57 prev
= _uu_setlocale(LC_ALL
, "C");
59 Nstat
.t_pid
= getpid();
62 && strncmp(Rmtname
, BASENAME(logfile
, '/'), MAXBASENAME
) != 0) {
68 sprintf(logfile
, "%s/%s", Logfile
, Rmtname
);
69 _Lf
= fopen(logfile
, "a");
70 (void) chmod(logfile
, LOGFILEMODE
);
72 (void) _uu_resetlocale(LC_ALL
, prev
);
77 (void) fseek(_Lf
, 0L, 2);
78 (void) fprintf(_Lf
, "%s %s %s ", User
, Rmtname
, Jobid
);
79 (void) fprintf(_Lf
, "(%s,%ld,%d) ", timeStamp(), (long) Nstat
.t_pid
, Seqn
);
80 (void) fprintf(_Lf
, "%s (%s)\n", status
, text
);
81 (void) _uu_resetlocale(LC_ALL
, prev
);
87 * Make entry for a conversation (uucico only)
88 * text -> pointer to message string
98 char *prev
= _uu_setlocale(LC_ALL
, "C");
100 (void) sprintf(sysbuf
, "%s!%s %s (%s) (%c,%ld,%d) [%s] %s\n",
101 Rmtname
, User
, CurRole
== SLAVE
? "S" : "M", timeStamp(),
102 Pchar
, (long) getpid(), Seqn
, Dc
, text
);
103 sbuflen
= strlen(sysbuf
);
106 _Sf
= open(SYSLOG
, 1);
107 if (errno
== ENOENT
) {
108 _Sf
= creat(SYSLOG
, LOGFILEMODE
);
109 (void) chmod(SYSLOG
, LOGFILEMODE
);
112 (void) _uu_resetlocale(LC_ALL
, prev
);
116 (void) lseek(_Sf
, 0L, 2);
117 (void) write(_Sf
, sysbuf
, sbuflen
);
118 (void) _uu_resetlocale(LC_ALL
, prev
);
123 * Make entry for a command
124 * argc -> number of command arguments
125 * argv -> pointer array to command arguments
130 commandlog(argc
,argv
)
135 char *prev
= _uu_setlocale(LC_ALL
, "C");
139 fd
= open(CMDLOG
, O_WRONLY
| O_APPEND
);
140 if (errno
== ENOENT
) {
141 fd
= creat(CMDLOG
, LOGFILEMODE
);
142 (void) chmod(CMDLOG
, LOGFILEMODE
);
144 if (fd
< 0 || (_Cf
= fdopen(fd
, "a")) == NULL
) {
145 (void) _uu_resetlocale(LC_ALL
, prev
);
149 (void) fprintf(_Cf
, "%s (%s) ",User
, timeStamp() );
151 (void) fprintf(_Cf
, "%s%c", *argv
++, (argc
> 0)?' ':'\n');
154 (void) _uu_resetlocale(LC_ALL
, prev
);
159 * Close log files before a fork
182 * return msec since last time called
192 static time_t past
; /* guaranteed 0 first time called */
199 if (now
- past
> MAXLONG
/ 1000) /* would overflow */
200 rval
= (now
- past
) / HZ
* 1000;
202 rval
= (now
- past
) * 1000 / HZ
;
213 static struct timeb tbuf1
;
214 static past
; /* guaranteed 0 first time called */
223 rval
= (tbuf
.time
- tbuf1
.time
) * 1000
224 + tbuf
.millitm
- tbuf1
.millitm
;