2 * Copyright (c) 2004-2009 Apple 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@
28 #include <sys/types.h>
29 #include <sys/queue.h>
32 #include <asl_private.h>
33 #include <asl_store.h>
34 #include <asl_memory.h>
35 #include <asl_mini_memory.h>
38 #include <libkern/OSAtomic.h>
40 #define ADDFD_FLAGS_LOCAL 0x00000001
42 #define ASL_DB_NOTIFICATION "com.apple.system.logger.message"
43 #define SELF_DB_NOTIFICATION "self.logger.message"
45 #define ASL_KEY_READ_UID "ReadUID"
46 #define ASL_KEY_READ_GID "ReadGID"
47 #define ASL_KEY_EXPIRE_TIME "ASLExpireTime"
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 #define ASL_KEY_OPTION "ASLOption"
54 #define ASL_OPT_IGNORE "ignore"
55 #define ASL_OPT_STORE "store"
57 #define _PATH_PIDFILE "/var/run/syslog.pid"
58 #define _PATH_ASL_IN "/var/run/asl_input"
59 #define _PATH_SYSLOG_CONF "/etc/syslog.conf"
60 #define _PATH_SYSLOG_IN "/var/run/syslog"
61 #define _PATH_KLOG "/dev/klog"
62 #define _PATH_MODULE_LIB "/usr/lib/asl"
64 #define DB_TYPE_FILE 0x00000001
65 #define DB_TYPE_MEMORY 0x00000002
66 #define DB_TYPE_MINI 0x00000004
68 #define KERN_DISASTER_LEVEL 3
70 #define SOURCE_UNKNOWN 0
71 #define SOURCE_INTERNAL 1
72 #define SOURCE_ASL_SOCKET 2
73 #define SOURCE_BSD_SOCKET 3
74 #define SOURCE_UDP_SOCKET 4
76 #define SOURCE_ASL_MESSAGE 6
77 #define SOURCE_LAUNCHD 7
79 #define SOURCE_SESSION 100 /* does not generate messages */
81 #define STORE_FLAGS_FILE_CACHE_SWEEP_REQUESTED 0x00000001
84 #define RESET_CONFIG 1
85 #define RESET_NETWORK 2
91 int disaster_occurred
;
92 mach_port_t listen_set
;
93 mach_port_t server_port
;
94 mach_port_t self_port
;
95 mach_port_t dead_session_port
;
96 launch_data_t launch_dict
;
101 uint64_t bsd_flush_time
;
102 pthread_mutex_t
*db_lock
;
103 pthread_mutex_t
*work_queue_lock
;
104 pthread_cond_t work_queue_cond
;
105 asl_search_result_t
*work_queue
;
106 asl_store_t
*file_db
;
107 asl_memory_t
*memory_db
;
108 asl_mini_memory_t
*mini_db
;
109 asl_mini_memory_t
*disaster_db
;
111 /* parameters below are configurable as command-line args or in /etc/asl.conf */
116 uint32_t db_file_max
;
117 uint32_t db_memory_max
;
118 uint32_t db_mini_max
;
120 uint64_t bsd_max_dup_time
;
121 uint64_t asl_store_ping_time
;
127 extern struct global_s global
;
129 typedef asl_msg_t
*(*aslreadfn
)(int);
130 typedef char *(*aslwritefn
)(const char *, int);
131 typedef char *(*aslexceptfn
)(int);
132 typedef int (*aslsendmsgfn
)(asl_msg_t
*msg
, const char *outid
);
138 unsigned char read
:1;
139 unsigned char write
:1;
140 unsigned char except
:1;
143 aslexceptfn exceptfn
;
147 TAILQ_ENTRY(aslevent
) entries
;
157 TAILQ_ENTRY(module_list
) entries
;
160 void config_debug(int enable
, const char *path
);
161 void config_data_store(int type
, uint32_t file_max
, uint32_t memory_max
, uint32_t mini_max
);
162 void config_timers(uint64_t bsd_max_dup
, uint64_t asl_store_ping
, uint64_t utmp
, uint64_t fs
);
164 char **explode(const char *s
, const char *delim
);
165 void freeList(char **l
);
167 int aslevent_init(void);
168 int aslevent_fdsets(fd_set
*, fd_set
*, fd_set
*);
169 void aslevent_handleevent(fd_set
*, fd_set
*, fd_set
*);
171 void asl_archive(void);
173 void asl_client_count_increment();
174 void asl_client_count_decrement();
176 char *get_line_from_file(FILE *f
);
178 int asldebug(const char *, ...);
179 int asl_log_string(const char *str
);
181 char *asl_msg_to_string(asl_msg_t
*msg
, uint32_t *len
);
182 asl_msg_t
*asl_msg_from_string(const char *buf
);
183 int asl_msg_cmp(asl_msg_t
*a
, asl_msg_t
*b
);
184 time_t asl_parse_time(const char *str
);
186 int aslevent_addfd(int source
, int fd
, uint32_t flags
, aslreadfn readfn
, aslwritefn writefn
, aslexceptfn exceptfn
);
187 int aslevent_removefd(int fd
);
188 int aslevent_addmatch(asl_msg_t
*query
, char *outid
);
190 int asl_check_option(asl_msg_t
*msg
, const char *opt
);
192 int aslevent_addoutput(aslsendmsgfn
, const char *outid
);
194 void asl_enqueue_message(uint32_t source
, struct aslevent
*e
, asl_msg_t
*msg
);
195 asl_msg_t
**asl_work_dequeue(uint32_t *count
);
196 void asl_message_match_and_log(asl_msg_t
*msg
);
198 int asl_syslog_faciliy_name_to_num(const char *fac
);
199 const char *asl_syslog_faciliy_num_to_name(int num
);
200 asl_msg_t
*asl_input_parse(const char *in
, int len
, char *rhost
, int flag
);
202 void db_ping_store(void);
204 /* message refcount utilities */
205 uint32_t asl_msg_type(asl_msg_t
*m
);
206 asl_msg_t
*asl_msg_retain(asl_msg_t
*m
);
207 void asl_msg_release(asl_msg_t
*m
);
210 uint32_t notify_register_plain(const char *name
, int *out_token
);
212 #endif /* __DAEMON_H__ */