]> git.saurik.com Git - apple/syslog.git/blob - syslogd.tproj/daemon.h
73a57328f4fd4e859a441fa0218ca6946e71a36f
[apple/syslog.git] / syslogd.tproj / daemon.h
1 /*
2 * Copyright (c) 2004-2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef __DAEMON_H__
25 #define __DAEMON_H__
26
27 #include <stdio.h>
28 #include <sys/types.h>
29 #include <sys/queue.h>
30 #include <time.h>
31 #include <asl.h>
32 #include <asl_private.h>
33 #include <asl_store.h>
34 #include <asl_memory.h>
35 #include <asl_mini_memory.h>
36 #include <notify.h>
37 #include <launch.h>
38
39 #define ADDFD_FLAGS_LOCAL 0x00000001
40
41 #define ASL_DB_NOTIFICATION "com.apple.system.logger.message"
42 #define SELF_DB_NOTIFICATION "self.logger.message"
43
44 #define ASL_KEY_READ_UID "ReadUID"
45 #define ASL_KEY_READ_GID "ReadGID"
46 #define ASL_KEY_EXPIRE_TIME "ASLExpireTime"
47 #define ASL_KEY_IGNORE "ASLIgnore"
48 #define ASL_KEY_TIME_NSEC "TimeNanoSec"
49 #define ASL_KEY_REF_PID "RefPID"
50 #define ASL_KEY_REF_PROC "RefProc"
51 #define ASL_KEY_SESSION "Session"
52
53 #define _PATH_PIDFILE "/var/run/syslog.pid"
54 #define _PATH_ASL_IN "/var/run/asl_input"
55 #define _PATH_SYSLOG_CONF "/etc/syslog.conf"
56 #define _PATH_SYSLOG_IN "/var/run/syslog"
57 #define _PATH_KLOG "/dev/klog"
58 #define _PATH_MODULE_LIB "/usr/lib/asl"
59
60 #define DB_TYPE_FILE 0x00000001
61 #define DB_TYPE_MEMORY 0x00000002
62 #define DB_TYPE_MINI 0x00000004
63
64 #define KERN_DISASTER_LEVEL 3
65
66 struct global_s
67 {
68 int asl_log_filter;
69 int restart;
70 int debug;
71 int disaster_occurred;
72 mach_port_t server_port;
73 launch_data_t launch_dict;
74 const char *debug_file;
75 int dbtype;
76 int did_store_sweep;
77 time_t start_time;
78 uint32_t db_file_max;
79 uint32_t db_memory_max;
80 uint32_t db_mini_max;
81 int kfd;
82 uint64_t bsd_flush_time;
83 uint64_t asl_store_ping_time;
84 uint64_t bsd_max_dup_time;
85 time_t utmp_ttl;
86 time_t fs_ttl;
87 asl_store_t *file_db;
88 asl_memory_t *memory_db;
89 asl_mini_memory_t *mini_db;
90 asl_mini_memory_t *disaster_db;
91 };
92
93 extern struct global_s global;
94
95 struct module_list
96 {
97 char *name;
98 void *module;
99 int (*init)(void);
100 int (*reset)(void);
101 int (*close)(void);
102 TAILQ_ENTRY(module_list) entries;
103 };
104
105 int aslevent_init(void);
106 int aslevent_fdsets(fd_set *, fd_set *, fd_set *);
107 void aslevent_handleevent(fd_set *, fd_set *, fd_set *);
108 void asl_mark(void);
109 void asl_archive(void);
110
111 char *get_line_from_file(FILE *f);
112
113 int asldebug(const char *, ...);
114 int asl_log_string(const char *str);
115
116 char *asl_msg_to_string(asl_msg_t *msg, uint32_t *len);
117 asl_msg_t *asl_msg_from_string(const char *buf);
118 int asl_msg_cmp(asl_msg_t *a, asl_msg_t *b);
119 time_t asl_parse_time(const char *str);
120
121 typedef asl_msg_t *(*aslreadfn)(int);
122 typedef char *(*aslwritefn)(const char *, int);
123 typedef char *(*aslexceptfn)(int);
124 typedef int (*aslsendmsgfn)(asl_msg_t *msg, const char *outid);
125
126 int aslevent_addfd(int fd, uint32_t flags, aslreadfn, aslwritefn, aslexceptfn);
127 int aslevent_removefd(int fd);
128 int aslevent_addmatch(asl_msg_t *query, char *outid);
129
130 int aslevent_addoutput(aslsendmsgfn, const char *outid);
131
132 int asl_syslog_faciliy_name_to_num(const char *fac);
133 const char *asl_syslog_faciliy_num_to_name(int num);
134 asl_msg_t *asl_input_parse(const char *in, int len, char *rhost, int flag);
135
136 void db_ping_store(time_t now);
137
138 /* message refcount utilities */
139 uint32_t asl_msg_type(asl_msg_t *m);
140 asl_msg_t *asl_msg_retain(asl_msg_t *m);
141 void asl_msg_release(asl_msg_t *m);
142
143 /* notify SPI */
144 uint32_t notify_register_plain(const char *name, int *out_token);
145
146 #endif /* __DAEMON_H__ */