parse response string from dialer
[unix-history] / usr / src / usr.bin / tip / log.c
CommitLineData
05862919 1#ifndef lint
7ca7c81c 2static char sccsid[] = "@(#)log.c 4.6 (Berkeley) %G%";
05862919 3#endif
c65b7b88 4
05862919
SL
5#include "tip.h"
6
7static FILE *flog = NULL;
c65b7b88
BJ
8
9/*
10 * Log file maintenance routines
11 */
12
13logent(group, num, acu, message)
d8feebc2 14 char *group, *num, *acu, *message;
c65b7b88
BJ
15{
16 char *user, *timestamp;
17 struct passwd *pwd;
18 long t;
19
20 if (flog == NULL)
21 return;
05862919
SL
22 if (flock(fileno(flog), LOCK_EX) < 0) {
23 perror("tip: flock");
c65b7b88
BJ
24 return;
25 }
26 if ((user = getlogin()) == NOSTR)
27 if ((pwd = getpwuid(getuid())) == NOPWD)
28 user = "???";
29 else
30 user = pwd->pw_name;
31 t = time(0);
32 timestamp = ctime(&t);
33 timestamp[24] = '\0';
34 fprintf(flog, "%s (%s) <%s, %s, %s> %s\n",
35 user, timestamp, group,
36#ifdef PRISTINE
37 "",
38#else
39 num,
40#endif
41 acu, message);
42 fflush(flog);
05862919 43 (void) flock(fileno(flog), LOCK_UN);
c65b7b88
BJ
44}
45
46loginit()
47{
05862919 48
7ca7c81c 49#ifdef ACULOG
05862919
SL
50 flog = fopen(value(LOG), "a");
51 if (flog == NULL)
c65b7b88 52 fprintf(stderr, "can't open log file\r\n");
c65b7b88 53#endif
7ca7c81c 54}