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 (c) 1990-1997 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #ident "%Z%%M% %I% %E% SMI"
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <sys/errno.h>
34 #include <sys/syslog.h>
35 #include <sys/strlog.h>
36 #include <sys/stropts.h>
44 send(s
, msg
, len
, flags
)
50 if ((a
= _send(s
, msg
, len
, flags
)) == -1) {
60 /* Added to convert socket "/dev/log" to stream "/dev/conslog" */
61 #define logname "/dev/conslog"
63 #define SVR4_ENOTSOCK 95 /* Socket operation on non-socket */
67 sendto(s
, msg
, len
, flags
, to
, tolen
)
75 static int LogDev
= -1;
76 /* check for logfile */
78 if ((a
= _sendto(s
, msg
, len
, flags
, to
, tolen
)) == -1) {
79 if (errno
== SVR4_ENOTSOCK
&&
80 strcmp(to
->sa_data
, "/dev/log") == 0) {
88 /* close socket /dev/log */
90 /* open stream /dev/conslog */
91 tfd
= open(logname
, O_WRONLY
);
94 /* insure stream has same fd as closed socket */
96 if (dup2(tfd
, s
) < 0) {
102 if (fcntl(s
, F_SETFD
, FD_CLOEXEC
) == -1)
104 if (fstat(s
, &sbuf
) != -1)
105 LogDev
= sbuf
.st_rdev
;
107 } else if (fstat(s
, &sbuf
) == -1 ||
108 LogDev
!= sbuf
.st_rdev
)
111 /* build the header */
113 /* parse <pri> from msg */
115 hdr
.mid
= 1; /* 0 for kernal */
116 /* sid, ltime, ttime, seq_no not used */
118 hdr
.pri
= strtol(msg
+ 1, &msg_p
, 10);
119 if (msg
+ 1 == msg_p
) {
120 hdr
.pri
= (LOG_USER
|LOG_INFO
);
125 hdr
.flags
= SL_CONSOLE
;
128 ctl
.maxlen
= sizeof (struct log_ctl
);
129 ctl
.len
= sizeof (struct log_ctl
);
130 ctl
.buf
= (caddr_t
)&hdr
;
131 dat
.maxlen
= MAXLINE
;
133 if (dat
.len
> MAXLINE
) {
135 msg
[MAXLINE
- 1] = '\0';
139 /* output the message to the local logger */
140 if (_putmsg(s
, &ctl
, &dat
, 0) == 0)
143 if (errno
== N_AGAIN
)
153 sendmsg(s
, msg
, flags
)
159 if ((a
= _sendmsg(s
, msg
, flags
)) == -1) {
160 if (errno
== N_AGAIN
)