/opensource.apple.com/source/syslog/syslog-100.0.1/syslogd.tproj/klog_in.c
C | 132 lines | 94 code | 18 blank | 20 comment | 5 complexity | cb80e9457fb6dcc4e6c51164389f3675 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-2.0, BSD-3-Clause, GPL-3.0, MPL-2.0, LGPL-2.0, LGPL-2.1, CC-BY-SA-3.0, IPL-1.0, ISC, AGPL-1.0, AGPL-3.0, JSON, Apache-2.0, 0BSD
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>klog_in.c</title>
- <style type="text/css">
- .enscript-comment { font-style: italic; color: rgb(178,34,34); }
- .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
- .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
- .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
- .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
- .enscript-string { font-weight: bold; color: rgb(188,143,143); }
- .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
- .enscript-type { font-weight: bold; color: rgb(34,139,34); }
- .enscript-highlight { text-decoration: underline; color: 0; }
- </style>
- </head>
- <body id="top">
- <h1 style="margin:8px;" id="f1">klog_in.c <span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
- <hr/>
- <div></div>
- <pre>
- <span class="enscript-comment">/*
- * Copyright (c) 2004-2008 Apple Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * <a href="http://www.opensource.apple.com/apsl/">http://www.opensource.apple.com/apsl/</a> and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */</span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><sys/types.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><sys/stat.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><sys/socket.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><sys/un.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><sys/uio.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><stdio.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><stdlib.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><string.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><fcntl.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><errno.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><unistd.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string">"daemon.h"</span>
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">forever</span> for(;;)
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">MY_ID</span> <span class="enscript-string">"klog_in"</span>
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">MAXLINE</span> 4096
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> kx = 0;
- <span class="enscript-type">static</span> <span class="enscript-type">char</span> kline[MAXLINE + 1];
- asl_msg_t *
- <span class="enscript-function-name">klog_in_acceptmsg</span>(<span class="enscript-type">int</span> fd)
- {
- <span class="enscript-type">int</span> n;
- <span class="enscript-type">char</span> c;
- n = read(fd, &c, 1);
- <span class="enscript-keyword">while</span> ((n == 1) && (c != <span class="enscript-string">'\n'</span>))
- {
- <span class="enscript-keyword">if</span> (kx < MAXLINE) kline[kx++] = c;
- n = read(fd, &c, 1);
- }
- <span class="enscript-keyword">if</span> (kx == 0) <span class="enscript-keyword">return</span> NULL;
- n = kx - 1;
- kline[kx] = <span class="enscript-string">'\0'</span>;
- kx = 0;
- <span class="enscript-keyword">return</span> asl_input_parse(kline, n, NULL, 1);
- }
- <span class="enscript-type">int</span>
- <span class="enscript-function-name">klog_in_init</span>(<span class="enscript-type">void</span>)
- {
- asldebug(<span class="enscript-string">"%s: init\n"</span>, MY_ID);
- <span class="enscript-keyword">if</span> (global.kfd >= 0) <span class="enscript-keyword">return</span> global.kfd;
- global.kfd = open(_PATH_KLOG, O_RDONLY, 0);
- <span class="enscript-keyword">if</span> (global.kfd < 0)
- {
- asldebug(<span class="enscript-string">"%s: couldn't open %s: %s\n"</span>, MY_ID, _PATH_KLOG, strerror(errno));
- <span class="enscript-keyword">return</span> -1;
- }
- <span class="enscript-keyword">if</span> (fcntl(global.kfd, F_SETFL, O_NONBLOCK) < 0)
- {
- close(global.kfd);
- global.kfd = -1;
- asldebug(<span class="enscript-string">"%s: couldn't set O_NONBLOCK for fd %d (%s): %s\n"</span>, MY_ID, global.kfd, _PATH_KLOG, strerror(errno));
- <span class="enscript-keyword">return</span> -1;
- }
- <span class="enscript-keyword">return</span> aslevent_addfd(SOURCE_KERN, global.kfd, ADDFD_FLAGS_LOCAL, klog_in_acceptmsg, NULL, NULL);
- }
- <span class="enscript-type">int</span>
- <span class="enscript-function-name">klog_in_reset</span>(<span class="enscript-type">void</span>)
- {
- <span class="enscript-keyword">return</span> 0;
- }
- <span class="enscript-type">int</span>
- <span class="enscript-function-name">klog_in_close</span>(<span class="enscript-type">void</span>)
- {
- <span class="enscript-keyword">if</span> (global.kfd < 0) <span class="enscript-keyword">return</span> 1;
- close(global.kfd);
- global.kfd = -1;
- <span class="enscript-keyword">return</span> 0;
- }
- </pre>
- <hr />
- </body></html>