]>
Commit | Line | Data |
---|---|---|
81582353 A |
1 | /* |
2 | * Copyright (c) 2012 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5222c21d | 5 | * |
81582353 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. | |
5222c21d | 12 | * |
81582353 A |
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. | |
5222c21d | 20 | * |
81582353 A |
21 | * @APPLE_LICENSE_HEADER_END@ |
22 | */ | |
23 | ||
24 | #ifndef __ASL_COMMON_H__ | |
25 | #define __ASL_COMMON_H__ | |
26 | ||
27 | #include <stdio.h> | |
28 | #include <xpc/xpc.h> | |
5222c21d | 29 | #include <asl_msg.h> |
81582353 A |
30 | |
31 | #define ASL_MODULE_NAME "com.apple.asl" | |
32 | #define _PATH_CRASHREPORTER "/Library/Logs/CrashReporter" | |
5222c21d A |
33 | #define _PATH_CRASHREPORTER_MOBILE_1 "/var/mobile/Library/Logs/CrashReporter" |
34 | #define _PATH_CRASHREPORTER_MOBILE_2 "/private/var/mobile/Library/Logs/CrashReporter" | |
35 | #define ASL_INTERNAL_LOGS_DIR "Logs" | |
81582353 A |
36 | |
37 | #define ASL_SERVICE_NAME "com.apple.system.logger" | |
38 | ||
39 | #define CRASH_MOVER_WILL_START_NOTIFICATION "CrashMoverWillStart" | |
40 | ||
81582353 | 41 | #define SECONDS_PER_DAY 86400 |
5222c21d | 42 | #define DEFAULT_TTL (7 * SECONDS_PER_DAY) |
81582353 A |
43 | |
44 | #define ACTION_NONE 0 | |
45 | #define ACTION_SET_PARAM 1 | |
46 | #define ACTION_OUT_DEST 2 | |
47 | #define ACTION_IGNORE 3 | |
48 | #define ACTION_SKIP 4 | |
49 | #define ACTION_CLAIM 5 | |
50 | #define ACTION_NOTIFY 6 | |
51 | #define ACTION_BROADCAST 7 | |
52 | #define ACTION_ACCESS 8 | |
f3df4c03 A |
53 | #define ACTION_SET_KEY 9 |
54 | #define ACTION_UNSET_KEY 10 | |
55 | #define ACTION_ASL_STORE 11 /* Save in main ASL Database */ | |
56 | #define ACTION_ASL_FILE 12 /* Save in an ASL format data file */ | |
57 | #define ACTION_ASL_DIR 13 /* Save in an ASL directory */ | |
58 | #define ACTION_FILE 14 /* Save in a text file */ | |
59 | #define ACTION_FORWARD 15 | |
60 | #define ACTION_CONTROL 16 | |
61 | #define ACTION_SET_FILE 17 /* = foo [File /a/b/c] */ | |
62 | #define ACTION_SET_PLIST 18 /* = foo [Plist /a/b/c] ... */ | |
63 | #define ACTION_SET_PROF 19 /* = foo [Profile abc] ... */ | |
81582353 A |
64 | |
65 | #define STYLE_SEC_PREFIX_CHAR 'T' | |
66 | ||
67 | #define MODULE_FLAG_HAS_LOGGED 0x80000000 | |
68 | #define MODULE_FLAG_CLEAR_LOGGED 0x7fffffff | |
69 | #define MODULE_FLAG_ENABLED 0x00000001 | |
70 | #define MODULE_FLAG_LOCAL 0x00000002 | |
71 | #define MODULE_FLAG_ROTATE 0x00000004 | |
72 | #define MODULE_FLAG_COALESCE 0x00000008 | |
73 | #define MODULE_FLAG_COMPRESS 0x00000010 | |
f3df4c03 A |
74 | #define MODULE_FLAG_NONSTD_DIR 0x00000020 |
75 | #define MODULE_FLAG_EXTERNAL 0x00000040 | |
76 | #define MODULE_FLAG_TRUNCATE 0x00000080 | |
5222c21d A |
77 | #define MODULE_FLAG_BASESTAMP 0x00000100 /* base file has timestamp */ |
78 | #define MODULE_FLAG_SYMLINK 0x00000200 /* link to basestamp name */ | |
79 | #define MODULE_FLAG_CRASHLOG 0x00000400 /* checkpoint on CrashMoverWillStart notification */ | |
80 | #define MODULE_FLAG_SOFT_WRITE 0x00000800 /* ignore write failures */ | |
81 | #define MODULE_FLAG_TYPE_ASL 0x00001000 /* asl format file */ | |
82 | #define MODULE_FLAG_TYPE_ASL_DIR 0x00002000 /* asl format directory */ | |
83 | #define MODULE_FLAG_STD_BSD_MSG 0x00004000 /* print format is std, bsd, or msg */ | |
84 | #define MODULE_FLAG_ACTIVITY 0x00008000 | |
85 | ||
86 | #define MODULE_NAME_STYLE_FORMAT_MASK 0xf0000000 | |
87 | #define MODULE_NAME_STYLE_FORMAT_BS 0x10000000 /* base.stamp */ | |
88 | #define MODULE_NAME_STYLE_FORMAT_BES 0x20000000 /* base.ext.stamp */ | |
89 | #define MODULE_NAME_STYLE_FORMAT_BSE 0x40000000 /* base.stamp.ext */ | |
90 | #define MODULE_NAME_STYLE_STAMP_MASK 0x000000ff | |
91 | #define MODULE_NAME_STYLE_STAMP_SEC 0x00000001 /* foo.T1332799722 (note STYLE_SEC_PREFIX_CHAR) */ | |
92 | #define MODULE_NAME_STYLE_STAMP_SEQ 0x00000002 /* foo.0 */ | |
93 | #define MODULE_NAME_STYLE_STAMP_UTC 0x00000004 /* foo.2012-04-06T13:45:00Z */ | |
94 | #define MODULE_NAME_STYLE_STAMP_UTC_B 0x00000008 /* ("basic utc") foo.20120406T134500Z */ | |
95 | #define MODULE_NAME_STYLE_STAMP_LCL 0x00000010 /* foo.2012-04-06T13:45:00-7 */ | |
96 | #define MODULE_NAME_STYLE_STAMP_LCL_B 0x00000020 /* ("basic local") foo.20120406T134500-7 */ | |
97 | ||
98 | #define STAMP_STYLE_INVALID -1 | |
99 | #define STAMP_STYLE_NULL 0 | |
100 | #define STAMP_STYLE_SEC 1 | |
101 | #define STAMP_STYLE_SEQ 2 | |
102 | #define STAMP_STYLE_ISO8601 3 | |
103 | ||
81582353 | 104 | #define CHECKPOINT_TEST 0x00000000 |
f3df4c03 A |
105 | #define CHECKPOINT_FORCE 0x00000001 |
106 | #define CHECKPOINT_CRASH 0x00000002 | |
107 | ||
108 | #define LEVEL_ALL 8 | |
81582353 A |
109 | |
110 | typedef struct | |
111 | { | |
5222c21d | 112 | char *dir; |
81582353 | 113 | char *path; |
5222c21d | 114 | char *current_name; |
81582353 | 115 | char *fmt; |
81582353 | 116 | char *rotate_dir; |
5222c21d A |
117 | char *base; |
118 | char *ext; | |
119 | const char *tfmt; | |
120 | uint32_t style_flags; | |
f3df4c03 | 121 | uint32_t pvt_flags; |
81582353 A |
122 | uint32_t flags; |
123 | uint32_t fails; | |
f3df4c03 | 124 | uint32_t ttl[9]; |
81582353 A |
125 | mode_t mode; |
126 | #if !TARGET_IPHONE_SIMULATOR | |
127 | uid_t *uid; | |
128 | uint32_t nuid; | |
129 | gid_t *gid; | |
130 | uint32_t ngid; | |
131 | #endif | |
132 | size_t file_max; | |
133 | size_t all_max; | |
134 | uint32_t refcount; | |
5222c21d | 135 | time_t timestamp; |
81582353 A |
136 | size_t size; |
137 | void *private; | |
138 | } asl_out_dst_data_t; | |
139 | ||
140 | typedef struct asl_out_rule_s | |
141 | { | |
142 | asl_msg_t *query; | |
143 | uint32_t action; | |
144 | char *options; | |
145 | asl_out_dst_data_t *dst; | |
146 | void *private; | |
147 | struct asl_out_rule_s *next; | |
148 | } asl_out_rule_t; | |
149 | ||
150 | typedef struct asl_out_module_s | |
151 | { | |
152 | char *name; | |
153 | uint32_t flags; | |
154 | asl_out_rule_t *ruleset; | |
155 | struct asl_out_module_s *next; | |
156 | } asl_out_module_t; | |
157 | ||
158 | typedef struct asl_out_file_list_s | |
159 | { | |
160 | char *name; | |
5222c21d | 161 | uint32_t stamp; |
81582353 A |
162 | time_t ftime; |
163 | uint32_t seq; | |
164 | size_t size; | |
165 | struct asl_out_file_list_s *next; | |
166 | struct asl_out_file_list_s *prev; | |
167 | } asl_out_file_list_t; | |
168 | ||
169 | char **explode(const char *s, const char *delim); | |
170 | void free_string_list(char **l); | |
171 | char *get_line_from_file(FILE *f); | |
172 | char *next_word_from_string(char **s); | |
173 | size_t asl_str_to_size(char *s); | |
174 | asl_msg_t *xpc_object_to_asl_msg(xpc_object_t xobj); | |
175 | ||
f3df4c03 | 176 | int asl_check_option(asl_msg_t *msg, const char *opt); |
81582353 A |
177 | |
178 | /* ASL OUT MODULES */ | |
179 | asl_out_module_t *asl_out_module_new(const char *name); | |
180 | void asl_out_module_free(asl_out_module_t *m); | |
181 | asl_out_module_t *asl_out_module_init(void); | |
182 | asl_out_module_t *asl_out_module_init_from_file(const char *name, FILE *f); | |
183 | asl_out_rule_t *asl_out_module_parse_line(asl_out_module_t *m, char *s); | |
184 | ||
185 | void asl_out_module_print(FILE *f, asl_out_module_t *m); | |
186 | char *asl_out_module_rule_to_string(asl_out_rule_t *r); | |
187 | ||
f3df4c03 | 188 | int asl_out_mkpath(asl_out_module_t *mlist, asl_out_rule_t *r); |
5222c21d | 189 | int asl_make_database_dir(const char *dir, char **out); |
81582353 | 190 | int asl_out_dst_checkpoint(asl_out_dst_data_t *dst, uint32_t force); |
f3df4c03 | 191 | int asl_out_dst_file_create_open(asl_out_dst_data_t *dst, char **pathp); |
81582353 A |
192 | int asl_out_dst_set_access(int fd, asl_out_dst_data_t *dst); |
193 | void asl_make_timestamp(time_t stamp, uint32_t flags, char *buf, size_t len); | |
5222c21d | 194 | void asl_dst_make_current_name(asl_out_dst_data_t *dst, uint32_t xflags, char *buf, size_t len); |
81582353 A |
195 | |
196 | asl_out_dst_data_t *asl_out_dst_data_retain(asl_out_dst_data_t *dst); | |
197 | void asl_out_dst_data_release(asl_out_dst_data_t *dst); | |
198 | ||
199 | /* rotated log files */ | |
5222c21d | 200 | asl_out_file_list_t *asl_list_log_files(const char *dir, const char *base, const char *ext, uint32_t flags, bool src); |
81582353 A |
201 | asl_out_file_list_t * asl_list_src_files(asl_out_dst_data_t *dst); |
202 | asl_out_file_list_t * asl_list_dst_files(asl_out_dst_data_t *dst); | |
203 | void asl_out_file_list_free(asl_out_file_list_t *l); | |
5222c21d | 204 | asl_out_dst_data_t *asl_out_dest_for_path(asl_out_module_t *m, const char *path); |
81582353 A |
205 | |
206 | asl_msg_t *configuration_profile_to_asl_msg(const char *ident); | |
207 | ||
f3df4c03 A |
208 | int asl_secure_chown_chmod_dir(const char *path, uid_t uid, gid_t gid, mode_t mode); |
209 | ||
81582353 | 210 | #endif /* __ASL_COMMON_H__ */ |