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]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
27 * Copyright (c) 1998 by Sun Microsystems, Inc.
28 * All rights reserved.
31 #pragma ident "%Z%%M% %I% %E% SMI"
39 #include <sys/types.h>
40 #include <sys/strlog.h>
41 #include "sys/types.h"
43 #include "sys/stropts.h"
44 #include "sys/strlog.h"
46 #define CTLSIZE sizeof (struct log_ctl)
49 #define LOGDEV "/dev/log"
50 #define ERRFILE "/var/adm/streams/error.xxxxx"
52 #define LOGDEFAULT "/var/adm/streams"
53 #define DIRECTORY 040000
56 static void prlog(FILE *log
, struct log_ctl
*lp
, char *dp
, int flag
);
57 static void makefile(char *name
, time_t time
);
58 static FILE *logfile(FILE *log
, struct log_ctl
*lp
);
59 static void prlog(FILE *log
, struct log_ctl
*lp
, char *dp
, int flag
);
64 makefile(char *name
, time_t time
)
69 tp
= localtime(&time
);
70 r
= &(name
[strlen(name
) - 5]);
71 (void) sprintf(r
, "%02d-%02d", (tp
->tm_mon
+1), tp
->tm_mday
);
75 logfile(FILE *log
, struct log_ctl
*lp
)
77 static time_t lasttime
= 0;
81 newtime
= lp
->ttime
- timezone
;
84 * If it is a new day make a new log file
86 if (((newtime
/NSECDAY
) != (lasttime
/NSECDAY
)) || !log
) {
90 makefile(errfile
, lp
->ttime
);
91 return (fopen(errfile
, "a+"));
100 main(int ac
, char *av
[])
104 char dbuf
[DATSIZE
]; /* must start on word boundary */
109 struct strioctl istr
;
117 ctl
.maxlen
= CTLSIZE
;
119 dat
.maxlen
= dat
.len
= DATSIZE
;
120 fd
= open(LOGDEV
, O_RDWR
);
122 fprintf(stderr
, "ERROR: unable to open %s\n", LOGDEV
);
126 logname
= LOGDEFAULT
;
127 if (stat(logname
, &stbuf
) < 0 || !(stbuf
.st_mode
& DIRECTORY
)) {
128 fprintf(stderr
, "ERROR: %s not a directory\n", logname
);
132 if (access(logname
, ACCESS
) < 0) {
133 fprintf(stderr
, "ERROR: cannot access directory %s\n",
138 istr
.ic_cmd
= I_ERRLOG
;
139 istr
.ic_timout
= istr
.ic_len
= 0;
141 if (ioctl(fd
, I_STR
, &istr
) < 0) {
142 fprintf(stderr
, "ERROR: error logger already exists\n");
148 while (getmsg(fd
, &ctl
, &dat
, &flag
) >= 0) {
150 lp
= (struct log_ctl
*)cbuf
;
151 log
= logfile(log
, lp
);
153 fprintf(stderr
, "ERROR: unable to open %s\n", errfile
);
156 prlog(log
, lp
, dbuf
, 1);
160 if (!(lp
->flags
& SL_NOTIFY
)) continue;
161 (void) sprintf(mailcmd
, "mail %s", ADMSTR
);
162 if ((pfile
= popen(mailcmd
, "w")) != NULL
) {
163 fprintf(pfile
, "Streams Error Logger message "
164 "notification:\n\n");
165 prlog(pfile
, lp
, dbuf
, 0);
166 (void) pclose(pfile
);
174 prlog(FILE *log
, struct log_ctl
*lp
, char *dp
, int flag
)
177 time_t t
= (time_t)lp
->ttime
;
182 fprintf(log
, "%06d %s %08x %s%s%s ", lp
->seq_no
, (ts
+11),
184 ((lp
->flags
& SL_FATAL
) ? "F" : "."),
185 ((lp
->flags
& SL_NOTIFY
) ? "N" : "."),
186 ((lp
->flags
& SL_TRACE
) ? "T" : "."));
187 fprintf(log
, "%d %d %s\n", lp
->mid
, lp
->sid
, dp
);
189 fprintf(log
, "%06d %s\n", lp
->seq_no
, dp
);