]> git.saurik.com Git - apple/syslog.git/blame - syslogd.tproj/daemon.h
syslog-356.200.4.tar.gz
[apple/syslog.git] / syslogd.tproj / daemon.h
CommitLineData
b16a592a 1/*
81582353 2 * Copyright (c) 2004-2012 Apple Inc. All rights reserved.
b16a592a
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
5dd30d76
A
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.
b16a592a
A
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,
5dd30d76
A
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.
b16a592a
A
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>
a83ff38a 32#include <asl_msg.h>
db78b1bd 33#include <asl_core.h>
b16a592a 34#include <asl_private.h>
57b0aad2 35#include <asl_store.h>
a83ff38a 36#include "asl_memory.h"
81582353 37#include "asl_common.h"
b16a592a 38#include <notify.h>
db78b1bd 39#include <notify_keys.h>
5dd30d76 40#include <launch.h>
db78b1bd 41#include <dispatch/dispatch.h>
c4fdb7d1 42#include <libkern/OSAtomic.h>
5dd30d76 43
81582353
A
44#include <TargetConditionals.h>
45
5dd30d76
A
46#define ADDFD_FLAGS_LOCAL 0x00000001
47
57b0aad2 48#define SELF_DB_NOTIFICATION "self.logger.message"
5dd30d76 49
c4fdb7d1
A
50#define ASL_OPT_IGNORE "ignore"
51#define ASL_OPT_STORE "store"
db78b1bd
A
52#define ASL_OPT_CONTROL "control"
53#define ASL_OPT_DB_FILE "asl_db_file"
db78b1bd 54#define ASL_OPT_DB_MEMORY "asl_db_memory"
b16a592a 55
81582353
A
56#if TARGET_IPHONE_SIMULATOR
57/* These paths are appropriately prefixed in the simulator */
58extern const char *_path_pidfile;
59extern const char *_path_syslogd_log;
60
61#define _PATH_PIDFILE _path_pidfile
62#define _PATH_SYSLOGD_LOG _path_syslogd_log
63#else
b16a592a 64#define _PATH_PIDFILE "/var/run/syslog.pid"
b16a592a
A
65#define _PATH_SYSLOG_CONF "/etc/syslog.conf"
66#define _PATH_SYSLOG_IN "/var/run/syslog"
67#define _PATH_KLOG "/dev/klog"
db78b1bd 68#define _PATH_SYSLOGD_LOG "/var/log/syslogd.log"
81582353 69#endif
b16a592a 70
f3df4c03
A
71#define NOTIFY_PATH_SERVICE "com.apple.system.notify.service.path:0x87:"
72
57b0aad2
A
73#define DB_TYPE_FILE 0x00000001
74#define DB_TYPE_MEMORY 0x00000002
57b0aad2 75
5dd30d76
A
76#define KERN_DISASTER_LEVEL 3
77
c4fdb7d1
A
78#define SOURCE_UNKNOWN 0
79#define SOURCE_INTERNAL 1
f3df4c03
A
80#define SOURCE_BSD_SOCKET 2
81#define SOURCE_UDP_SOCKET 3
82#define SOURCE_KERN 4
83#define SOURCE_ASL_MESSAGE 5
84#define SOURCE_LAUNCHD 6
c4fdb7d1
A
85
86#define SOURCE_SESSION 100 /* does not generate messages */
87
88#define STORE_FLAGS_FILE_CACHE_SWEEP_REQUESTED 0x00000001
89
db78b1bd
A
90#define FS_TTL_SEC 31622400
91
81582353
A
92#define SEC_PER_DAY 86400
93
5222c21d
A
94typedef struct sender_stats_s
95{
96 char *sender;
97 uint64_t count;
98 uint64_t size;
99 struct sender_stats_s *next;
100} sender_stats_t;
101
102typedef struct
103{
104 uint32_t mcount;
105 uint32_t shim_count;
106 uint32_t bucket_count;
107 sender_stats_t **bucket;
108} stats_table_t;
f3df4c03 109
db78b1bd
A
110typedef struct
111{
112 const char *name;
113 int enabled;
114 int (*init)(void);
115 int (*reset)(void);
116 int (*close)(void);
117} module_t;
c4fdb7d1 118
57b0aad2
A
119struct global_s
120{
c4fdb7d1
A
121 OSSpinLock lock;
122 int client_count;
57b0aad2 123 int disaster_occurred;
c4fdb7d1 124 mach_port_t listen_set;
57b0aad2 125 mach_port_t server_port;
c4fdb7d1 126 mach_port_t dead_session_port;
57b0aad2 127 launch_data_t launch_dict;
81582353
A
128 int *lockdown_session_fds;
129 int lockdown_session_count;
a83ff38a 130 int watchers_active;
c4fdb7d1 131 int reset;
81582353
A
132 pid_t pid;
133 int32_t work_queue_count;
5222c21d
A
134 /* memory_size must be aligned for OSAtomicAdd64 */
135 __attribute__((aligned(8))) int64_t memory_size;
81582353
A
136 int32_t asl_queue_count;
137 int32_t bsd_queue_count;
c4fdb7d1 138 pthread_mutex_t *db_lock;
c4fdb7d1 139 pthread_cond_t work_queue_cond;
db78b1bd
A
140 dispatch_queue_t work_queue;
141 dispatch_source_t mark_timer;
142 dispatch_source_t sig_hup_src;
57b0aad2
A
143 asl_store_t *file_db;
144 asl_memory_t *memory_db;
f3df4c03 145 asl_memory_t *disaster_db;
db78b1bd
A
146 int module_count;
147 int bsd_out_enabled;
81582353 148 int launchd_enabled;
db78b1bd 149 module_t **module;
81582353 150 asl_out_module_t *asl_out_module;
5222c21d
A
151 time_t stats_last;
152 stats_table_t *stats;
c4fdb7d1
A
153
154 /* parameters below are configurable as command-line args or in /etc/asl.conf */
c4fdb7d1
A
155 int debug;
156 char *debug_file;
5222c21d 157 char *hostname;
c4fdb7d1
A
158 int dbtype;
159 uint32_t db_file_max;
160 uint32_t db_memory_max;
f3df4c03 161 uint32_t db_memory_str_max;
c4fdb7d1 162 uint32_t mps_limit;
db78b1bd 163 uint32_t remote_delay_time;
c4fdb7d1 164 uint64_t bsd_max_dup_time;
c4fdb7d1
A
165 uint64_t mark_time;
166 time_t utmp_ttl;
5222c21d
A
167 time_t stats_interval;
168 int64_t memory_max;
57b0aad2
A
169};
170
171extern struct global_s global;
5dd30d76 172
db78b1bd 173void init_globals(void);
b16a592a 174
c4fdb7d1 175void config_debug(int enable, const char *path);
f3df4c03 176void config_data_store(int type, uint32_t file_max, uint32_t memory_max, uint32_t str_memory_max);
c4fdb7d1 177
5dd30d76
A
178void asl_mark(void);
179void asl_archive(void);
b16a592a 180
c4fdb7d1
A
181void asl_client_count_increment();
182void asl_client_count_decrement();
183
b16a592a 184int asldebug(const char *, ...);
db78b1bd 185int internal_log_message(const char *str);
b16a592a 186
a83ff38a 187void send_to_direct_watchers(asl_msg_t *msg);
c4fdb7d1 188
81582353 189#if !TARGET_IPHONE_SIMULATOR
db78b1bd 190void launchd_callback();
81582353 191#endif
db78b1bd 192
b16a592a
A
193int asl_syslog_faciliy_name_to_num(const char *fac);
194const char *asl_syslog_faciliy_num_to_name(int num);
f3df4c03 195asl_msg_t *asl_input_parse(const char *in, int len, char *rhost, uint32_t source);
5dd30d76 196
f3df4c03 197void process_message(asl_msg_t *msg, uint32_t source);
5222c21d
A
198void asl_out_message(asl_msg_t *msg, int64_t msize);
199void bsd_out_message(asl_msg_t *msg, int64_t msize);
81582353
A
200int control_set_param(const char *s, bool eval);
201int asl_action_control_set_param(const char *s);
c8dfc69e 202void asl_action_out_module_query(asl_msg_t *q, asl_msg_t *m, bool all);
5dd30d76 203
b16a592a 204/* notify SPI */
b16a592a
A
205uint32_t notify_register_plain(const char *name, int *out_token);
206
207#endif /* __DAEMON_H__ */