]> git.saurik.com Git - apple/syslog.git/blob - syslogd.tproj/daemon.h
syslog-148.7.tar.gz
[apple/syslog.git] / syslogd.tproj / daemon.h
1 /*
2 * Copyright (c) 2004-2011 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_msg.h>
33 #include <asl_core.h>
34 #include <asl_private.h>
35 #include <asl_store.h>
36 #include "asl_memory.h"
37 #include "asl_mini_memory.h"
38 #include <notify.h>
39 #include <notify_keys.h>
40 #include <launch.h>
41 #include <dispatch/dispatch.h>
42 #include <libkern/OSAtomic.h>
43
44 #define ADDFD_FLAGS_LOCAL 0x00000001
45
46 #define SELF_DB_NOTIFICATION "self.logger.message"
47
48 #define ASL_OPT_IGNORE "ignore"
49 #define ASL_OPT_STORE "store"
50 #define ASL_OPT_CONTROL "control"
51 #define ASL_OPT_DB_FILE "asl_db_file"
52 #define ASL_OPT_DB_MINI "asl_db_mini_memory"
53 #define ASL_OPT_DB_MEMORY "asl_db_memory"
54
55 #define _PATH_PIDFILE "/var/run/syslog.pid"
56 #define _PATH_SYSLOG_CONF "/etc/syslog.conf"
57 #define _PATH_SYSLOG_IN "/var/run/syslog"
58 #define _PATH_KLOG "/dev/klog"
59 #define _PATH_SYSLOGD_LOG "/var/log/syslogd.log"
60
61 #define DB_TYPE_FILE 0x00000001
62 #define DB_TYPE_MEMORY 0x00000002
63 #define DB_TYPE_MINI 0x00000004
64
65 #define KERN_DISASTER_LEVEL 3
66
67 #define SOURCE_UNKNOWN 0
68 #define SOURCE_INTERNAL 1
69 #define SOURCE_ASL_SOCKET 2
70 #define SOURCE_BSD_SOCKET 3
71 #define SOURCE_UDP_SOCKET 4
72 #define SOURCE_KERN 5
73 #define SOURCE_ASL_MESSAGE 6
74 #define SOURCE_LAUNCHD 7
75
76 #define SOURCE_SESSION 100 /* does not generate messages */
77
78 #define STORE_FLAGS_FILE_CACHE_SWEEP_REQUESTED 0x00000001
79
80 #define FS_TTL_SEC 31622400
81
82 typedef struct
83 {
84 const char *name;
85 int enabled;
86 int (*init)(void);
87 int (*reset)(void);
88 int (*close)(void);
89 } module_t;
90
91 struct global_s
92 {
93 OSSpinLock lock;
94 int client_count;
95 int disaster_occurred;
96 mach_port_t listen_set;
97 mach_port_t server_port;
98 mach_port_t dead_session_port;
99 launch_data_t launch_dict;
100 uint32_t store_flags;
101 time_t start_time;
102 int lockdown_session_fd;
103 int watchers_active;
104 int reset;
105 uint64_t bsd_flush_time;
106 pthread_mutex_t *db_lock;
107 pthread_cond_t work_queue_cond;
108 dispatch_queue_t work_queue;
109 dispatch_source_t mark_timer;
110 dispatch_source_t sig_hup_src;
111 asl_store_t *file_db;
112 asl_memory_t *memory_db;
113 asl_mini_memory_t *mini_db;
114 asl_mini_memory_t *disaster_db;
115 int module_count;
116 int bsd_out_enabled;
117 module_t **module;
118
119 /* parameters below are configurable as command-line args or in /etc/asl.conf */
120 int debug;
121 char *debug_file;
122 int dbtype;
123 uint32_t db_file_max;
124 uint32_t db_memory_max;
125 uint32_t db_mini_max;
126 uint32_t mps_limit;
127 uint32_t remote_delay_time;
128 uint64_t bsd_max_dup_time;
129 uint64_t mark_time;
130 time_t utmp_ttl;
131 };
132
133 extern struct global_s global;
134
135 void init_globals(void);
136
137 void config_debug(int enable, const char *path);
138 void config_data_store(int type, uint32_t file_max, uint32_t memory_max, uint32_t mini_max);
139
140 char **explode(const char *s, const char *delim);
141 void freeList(char **l);
142
143 void asl_mark(void);
144 void asl_archive(void);
145
146 void asl_client_count_increment();
147 void asl_client_count_decrement();
148
149 char *get_line_from_file(FILE *f);
150
151 int asldebug(const char *, ...);
152 int internal_log_message(const char *str);
153
154 asl_msg_t *asl_msg_from_string(const char *buf);
155 int asl_msg_cmp(asl_msg_t *a, asl_msg_t *b);
156 time_t asl_parse_time(const char *str);
157
158 int asl_check_option(aslmsg msg, const char *opt);
159
160 void send_to_direct_watchers(asl_msg_t *msg);
161
162 void launchd_callback();
163
164 int asl_syslog_faciliy_name_to_num(const char *fac);
165 const char *asl_syslog_faciliy_num_to_name(int num);
166 aslmsg asl_input_parse(const char *in, int len, char *rhost, uint32_t source);
167
168 const char *whatsmyhostname();
169 void process_message(aslmsg m, uint32_t source);
170 void asl_out_message(aslmsg msg);
171 int asl_action_file_rotate(const char *path);
172 void bsd_out_message(aslmsg msg);
173 int control_set_param(const char *s);
174
175 /* notify SPI */
176 uint32_t notify_register_plain(const char *name, int *out_token);
177
178 #endif /* __DAEMON_H__ */