4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/fcntl.h>
47 static FILE *Lfp
; /* log file */
49 static FILE *Dfp
; /* debug file */
54 * cons_printf - emit a message to the system console
59 cons_printf(const char *fmt
, ...)
61 char buf
[MAXPATHLEN
* 2]; /* enough space for msg including a path */
66 (void) vsnprintf(buf
, sizeof (buf
), fmt
, ap
);
69 if ((fd
= open("/dev/console", O_WRONLY
|O_NOCTTY
)) != -1)
70 (void) write(fd
, buf
, strlen(buf
) + 1);
75 * openlog - open log file, sets global file pointer Lfp
81 if ((Lfp
= fopen(LOGFILE
, "a+")) == NULL
) {
82 cons_printf("SAC: could not open logfile %s: %s\n",
83 LOGFILE
, strerror(errno
));
88 * lock logfile to indicate presence
90 if (lockf(fileno(Lfp
), F_LOCK
, 0) < 0) {
91 cons_printf("SAC: could not lock logfile %s:%s\n",
92 LOGFILE
, strerror(errno
));
99 * log - put a message into the log file
101 * args: msg - message to be logged
106 char *timestamp
; /* current time in readable form */
107 time_t clock
; /* current time in seconds */
108 char buf
[SIZE
]; /* scratch buffer */
111 timestamp
= ctime(&clock
);
112 *(strchr(timestamp
, '\n')) = '\0';
113 (void) snprintf(buf
, sizeof (buf
), "%s; %ld; %s\n",
114 timestamp
, getpid(), msg
);
115 (void) fprintf(Lfp
, buf
);
121 * error - put an error message into the log file and exit if indicated
123 * args: msgid - id of message to be output
124 * action - action to be taken (EXIT or not)
129 error(int msgid
, int action
)
131 if (msgid
< 0 || msgid
> N_msgs
)
133 log(Msgs
[msgid
].e_str
);
134 if (action
== EXIT
) {
135 log("*** SAC exiting ***");
136 exit(Msgs
[msgid
].e_exitcode
);
144 * opendebug - open debugging file, sets global file pointer Dfp
151 FILE *fp
; /* scratch file pointer for problems */
153 if ((Dfp
= fopen(DBGFILE
, "a+")) == NULL
) {
154 cons_printf("SAC: could not open debugfile %s: %s\n",
155 DBGFILE
, strerror(errno
));
162 * debug - put a message into debug file
164 * args: msg - message to be output
171 char *timestamp
; /* current time in readable form */
172 time_t clock
; /* current time in seconds */
173 char buf
[SIZE
]; /* scratch buffer */
176 timestamp
= ctime(&clock
);
177 *(strchr(timestamp
, '\n')) = '\0';
178 (void) sprintf(buf
, "%s; %ld; %s\n", timestamp
, getpid(), msg
);
179 (void) fprintf(Dfp
, buf
);