]>
git.saurik.com Git - apple/syslog.git/blob - syslogd.tproj/klog_in.c
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #include <sys/types.h>
26 #include <sys/socket.h>
37 #define forever for(;;)
39 #define MY_ID "klog_in"
45 static char kline
[MAXLINE
+ 1];
48 klog_in_acceptmsg(int fd
)
55 while ((n
== 1) && (c
!= '\n'))
57 if (kx
< MAXLINE
) kline
[kx
++] = c
;
61 if (kx
== 0) return NULL
;
67 return asl_syslog_input_convert(kline
, n
, NULL
, 1);
73 asldebug("%s: init\n", MY_ID
);
74 if (kfd
>= 0) return kfd
;
76 kfd
= open(_PATH_KLOG
, O_RDONLY
, 0);
79 asldebug("%s: couldn't open %s: %s\n", MY_ID
, _PATH_KLOG
, strerror(errno
));
83 if (fcntl(kfd
, F_SETFL
, O_NONBLOCK
) < 0)
87 asldebug("%s: couldn't set O_NONBLOCK for fd %d (%s): %s\n", MY_ID
, kfd
, _PATH_KLOG
, strerror(errno
));
91 return aslevent_addfd(kfd
, klog_in_acceptmsg
, NULL
, NULL
);
103 if (kfd
< 0) return 1;