2 * Copyright (c) 2007-2008 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@
33 #include <sys/socket.h>
34 #include <sys/sysctl.h>
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
37 #include <mach/mach.h>
38 #include <servers/bootstrap.h>
42 #include <asl_private.h>
45 #include <asl_store.h>
48 #define MOD_CASE_FOLD 'C'
50 #define MOD_SUBSTRING 'S'
51 #define MOD_PREFIX 'A'
52 #define MOD_SUFFIX 'Z'
53 #define MOD_NUMERIC 'N'
62 #define ASL_QUERY_OP_NOT 0x1000
64 #define QUERY_FLAG_SEARCH_REVERSE 0x00000001
66 #define FACILITY_CONSOLE "com.apple.console"
70 #define SEARCH_MATCH 1
72 #define PROC_NOT_FOUND -1
73 #define PROC_NOT_UNIQUE -2
79 #define forever for(;;)
81 #define SEND_FORMAT_LEGACY 0
82 #define SEND_FORMAT_ASL 1
84 #define TIME_SEC 0x00000010
85 #define TIME_UTC 0x00000020
86 #define TIME_LCL 0x00000040
88 #define FORMAT_RAW 0x00000100
89 #define FORMAT_LEGACY 0x00000200
90 #define FORMAT_STD 0x00000400
91 #define FORMAT_XML 0x00000800
93 #define EXPORT 0x00000100
95 #define ASL_FILTER_MASK_PACEWNID 0xff
96 #define ASL_FILTER_MASK_PACEWNI 0x7f
97 #define ASL_FILTER_MASK_PACEWN 0x3f
98 #define ASL_FILTER_MASK_PACEW 0x1f
99 #define ASL_FILTER_MASK_PACE 0x0f
100 #define ASL_FILTER_MASK_PAC 0x07
102 #define FETCH_BATCH 1024
104 #define DB_SELECT_STORE 0
105 #define DB_SELECT_FILES 1
106 #define DB_SELECT_SYSLOGD 2
107 #define DB_SELECT_LEGACY 3
109 static asl_file_list_t
*db_files
= NULL
;
110 static asl_store_t
*store
= NULL
;
111 static asl_file_t
*legacy
= NULL
;
112 static uint32_t dbselect
= DB_SELECT_STORE
;
113 static asl_file_t
*export
= NULL
;
116 uint32_t notify_register_plain(const char *name
, int *out_token
);
118 extern char *asl_msg_to_string(aslmsg msg
, uint32_t *len
);
119 extern asl_msg_t
*asl_msg_from_string(const char *buf
);
120 extern char *asl_list_to_string(asl_search_result_t
*list
, uint32_t *outlen
);
121 extern asl_search_result_t
*asl_list_from_string(const char *buf
);
122 extern int asl_msg_cmp(asl_msg_t
*a
, asl_msg_t
*b
);
123 extern time_t asl_parse_time(const char *in
);
124 /* END PRIVATE API */
126 #define ASL_SERVICE_NAME "com.apple.system.logger"
127 static mach_port_t asl_server_port
= MACH_PORT_NULL
;
129 static const char *myname
= "syslog";
134 fprintf(stderr
, "usage:\n");
135 fprintf(stderr
, "%s -s [-r host] [-l level] message...\n", myname
);
136 fprintf(stderr
, " send a message\n");
137 fprintf(stderr
, "\n");
138 fprintf(stderr
, "%s -s [-r host] -k key val [key val]...\n", myname
);
139 fprintf(stderr
, " send a message with the given keys and values\n");
140 fprintf(stderr
, "\n");
141 fprintf(stderr
, "%s -c process [filter]\n", myname
);
142 fprintf(stderr
, " get (set if filter is specified) syslog filter for process (pid or name)\n");
143 fprintf(stderr
, " level may be any combination of the characters \"p a c e w n i d\"\n");
144 fprintf(stderr
, " p = Emergency (\"Panic\")\n");
145 fprintf(stderr
, " a = Alert\n");
146 fprintf(stderr
, " c = Critical\n");
147 fprintf(stderr
, " e = Error\n");
148 fprintf(stderr
, " w = Warning\n");
149 fprintf(stderr
, " n = Notice\n");
150 fprintf(stderr
, " i = Info\n");
151 fprintf(stderr
, " d = Debug\n");
152 fprintf(stderr
, " a minus sign preceeding a single letter means \"up to\" that level\n");
153 fprintf(stderr
, "\n");
154 fprintf(stderr
, "%s [-f file...] [-d path...] [-x file] [-w [N]] [-F format] [-u] [-k key [[op] val]]... [-o -k key [[op] val]] ...]...\n", myname
);
155 fprintf(stderr
, " -f read named file[s], rather than standard log message store.\n");
156 fprintf(stderr
, " -d read all file in named directory path, rather than standard log message store.\n");
157 fprintf(stderr
, " -x export to named ASL format file, rather than printing\n");
158 fprintf(stderr
, " -w watch data store (^C to quit)\n");
159 fprintf(stderr
, " prints the last N matching lines (default 10) before waiting\n");
160 fprintf(stderr
, " \"-w 0\" prints all matching lines before waiting\n");
161 fprintf(stderr
, " -F output format may be \"std\", \"raw\", \"bsd\", or \"xml\"\n");
162 fprintf(stderr
, " format may also be a string containing variables of the form\n");
163 fprintf(stderr
, " $Key or $(Key) - use the latter for non-whitespace delimited variables\n");
164 fprintf(stderr
, " -T timestamp format may be \"sec\" (seconds), \"utc\" (UTC), or \"local\" (local timezone)\n");
165 fprintf(stderr
, " -E text encoding may be \"vis\", \"safe\", or \"none\"\n");
166 fprintf(stderr
, " -u print timestamps using UTC (equivalent to \"-T utc\")\n");
167 fprintf(stderr
, " -k key/value match\n");
168 fprintf(stderr
, " if no operator or value is given, checks for the existance of the key\n");
169 fprintf(stderr
, " if no operator is given, default is \"%s\"\n", OP_EQ
);
170 fprintf(stderr
, " -C alias for \"-k Facility com.apple.console\"\n");
171 fprintf(stderr
, " -o begins a new query\n");
172 fprintf(stderr
, " queries are \'OR\'ed together\n");
173 fprintf(stderr
, "operators are zero or more modifiers followed by a comparison\n");
174 fprintf(stderr
, " %s equal\n", OP_EQ
);
175 fprintf(stderr
, " %s not equal\n", OP_NE
);
176 fprintf(stderr
, " %s greater than\n", OP_GT
);
177 fprintf(stderr
, " %s greater or equal\n", OP_GE
);
178 fprintf(stderr
, " %s less than\n", OP_LT
);
179 fprintf(stderr
, " %s less or equal\n", OP_LE
);
180 fprintf(stderr
, "optional modifiers for operators\n");
181 fprintf(stderr
, " %c case-fold\n", MOD_CASE_FOLD
);
182 fprintf(stderr
, " %c regular expression\n", MOD_REGEX
);
183 fprintf(stderr
, " %c substring\n", MOD_SUBSTRING
);
184 fprintf(stderr
, " %c prefix\n", MOD_PREFIX
);
185 fprintf(stderr
, " %c suffix\n", MOD_SUFFIX
);
186 fprintf(stderr
, " %c numeric comparison\n", MOD_NUMERIC
);
190 notify_status_string(int status
)
192 if (status
== NOTIFY_STATUS_OK
) return "OK";
193 if (status
== NOTIFY_STATUS_INVALID_NAME
) return "Process not registered";
194 if (status
== NOTIFY_STATUS_NOT_AUTHORIZED
) return "Not authorized";
195 return "Operation failed";
199 asl_level_string(int level
)
201 if (level
== ASL_LEVEL_EMERG
) return ASL_STRING_EMERG
;
202 if (level
== ASL_LEVEL_ALERT
) return ASL_STRING_ALERT
;
203 if (level
== ASL_LEVEL_CRIT
) return ASL_STRING_CRIT
;
204 if (level
== ASL_LEVEL_ERR
) return ASL_STRING_ERR
;
205 if (level
== ASL_LEVEL_WARNING
) return ASL_STRING_WARNING
;
206 if (level
== ASL_LEVEL_NOTICE
) return ASL_STRING_NOTICE
;
207 if (level
== ASL_LEVEL_INFO
) return ASL_STRING_INFO
;
208 if (level
== ASL_LEVEL_DEBUG
) return ASL_STRING_DEBUG
;
213 procinfo(char *pname
, int *pid
, int *uid
)
216 int i
, status
, nprocs
;
218 struct kinfo_proc
*procs
, *newprocs
;
225 mib
[2] = KERN_PROC_ALL
;
229 status
= sysctl(mib
, miblen
, NULL
, &size
, NULL
, 0);
233 newprocs
= reallocf(procs
, size
);
234 if (newprocs
== NULL
)
236 if (procs
!= NULL
) free(procs
);
237 return PROC_NOT_FOUND
;
241 status
= sysctl(mib
, miblen
, procs
, &size
, NULL
, 0);
242 } while ((status
== -1) && (errno
== ENOMEM
));
246 if (procs
!= NULL
) free(procs
);
247 return PROC_NOT_FOUND
;
250 if (size
% sizeof(struct kinfo_proc
) != 0)
252 if (procs
!= NULL
) free(procs
);
253 return PROC_NOT_FOUND
;
256 if (procs
== NULL
) return PROC_NOT_FOUND
;
258 nprocs
= size
/ sizeof(struct kinfo_proc
);
262 /* Search for a pid */
263 for (i
= 0; i
< nprocs
; i
++)
265 if (*pid
== procs
[i
].kp_proc
.p_pid
)
267 *uid
= procs
[i
].kp_eproc
.e_ucred
.cr_uid
;
272 return PROC_NOT_FOUND
;
275 *pid
= PROC_NOT_FOUND
;
277 for (i
= 0; i
< nprocs
; i
++)
279 if (!strcmp(procs
[i
].kp_proc
.p_comm
, pname
))
281 if (*pid
!= PROC_NOT_FOUND
)
284 return PROC_NOT_UNIQUE
;
287 *pid
= procs
[i
].kp_proc
.p_pid
;
288 *uid
= procs
[i
].kp_eproc
.e_ucred
.cr_uid
;
293 if (*pid
== PROC_NOT_FOUND
) return PROC_NOT_FOUND
;
299 rcontrol_get_string(const char *prefix
, int pid
, int *val
)
305 status
= NOTIFY_STATUS_OK
;
307 if (pid
== RC_SYSLOGD
)
309 status
= notify_register_plain(NOTIFY_SYSTEM_ASL_FILTER
, &t
);
311 else if (pid
== RC_MASTER
)
313 status
= notify_register_plain(NOTIFY_SYSTEM_MASTER
, &t
);
318 asprintf(&name
, "%s.%d", prefix
, pid
);
319 if (name
== NULL
) return NOTIFY_STATUS_FAILED
;
321 status
= notify_register_plain(name
, &t
);
325 if (status
!= NOTIFY_STATUS_OK
) return status
;
328 status
= notify_get_state(t
, &x
);
337 rcontrol_set_string(const char *prefix
, int pid
, int filter
)
343 status
= NOTIFY_STATUS_OK
;
345 if (pid
== RC_SYSLOGD
)
347 status
= notify_register_plain(NOTIFY_SYSTEM_ASL_FILTER
, &t
);
349 else if (pid
== RC_MASTER
)
351 status
= notify_register_plain(NOTIFY_SYSTEM_MASTER
, &t
);
356 asprintf(&name
, "%s.%d", prefix
, pid
);
357 if (name
== NULL
) return NOTIFY_STATUS_FAILED
;
359 status
= notify_register_plain(name
, &t
);
363 if (status
!= NOTIFY_STATUS_OK
) return status
;
366 status
= notify_set_state(t
, x
);
367 if ((pid
== RC_SYSLOGD
) && (status
== NOTIFY_STATUS_OK
)) status
= notify_post(NOTIFY_SYSTEM_ASL_FILTER
);
373 asl_string_to_filter(char *s
)
377 if (s
== NULL
) return 0;
378 if (s
[0] == '\0') return 0;
380 if ((s
[0] >= '0') && (s
[0] <= '9')) return ASL_FILTER_MASK(atoi(s
));
384 if ((s
[1] == 'P') || (s
[1] == 'p')) i
= ASL_LEVEL_EMERG
;
385 else if ((s
[1] == 'A') || (s
[1] == 'a')) i
= ASL_LEVEL_ALERT
;
386 else if ((s
[1] == 'C') || (s
[1] == 'c')) i
= ASL_LEVEL_CRIT
;
387 else if ((s
[1] == 'E') || (s
[1] == 'e')) i
= ASL_LEVEL_ERR
;
388 else if ((s
[1] == 'X') || (s
[1] == 'x')) i
= ASL_LEVEL_ERR
;
389 else if ((s
[1] == 'W') || (s
[1] == 'w')) i
= ASL_LEVEL_WARNING
;
390 else if ((s
[1] == 'N') || (s
[1] == 'n')) i
= ASL_LEVEL_NOTICE
;
391 else if ((s
[1] == 'I') || (s
[1] == 'i')) i
= ASL_LEVEL_INFO
;
392 else if ((s
[1] == 'D') || (s
[1] == 'd')) i
= ASL_LEVEL_DEBUG
;
393 else i
= atoi(s
+ 1);
394 f
= ASL_FILTER_MASK_UPTO(i
);
399 for (i
= 0; s
[i
] != '\0'; i
++)
401 if ((s
[i
] == 'P') || (s
[i
] == 'p')) f
|= ASL_FILTER_MASK_EMERG
;
402 else if ((s
[i
] == 'A') || (s
[i
] == 'a')) f
|= ASL_FILTER_MASK_ALERT
;
403 else if ((s
[i
] == 'C') || (s
[i
] == 'c')) f
|= ASL_FILTER_MASK_CRIT
;
404 else if ((s
[i
] == 'E') || (s
[i
] == 'e')) f
|= ASL_FILTER_MASK_ERR
;
405 else if ((s
[i
] == 'X') || (s
[i
] == 'x')) f
|= ASL_FILTER_MASK_ERR
;
406 else if ((s
[i
] == 'W') || (s
[i
] == 'w')) f
|= ASL_FILTER_MASK_WARNING
;
407 else if ((s
[i
] == 'N') || (s
[i
] == 'n')) f
|= ASL_FILTER_MASK_NOTICE
;
408 else if ((s
[i
] == 'I') || (s
[i
] == 'i')) f
|= ASL_FILTER_MASK_INFO
;
409 else if ((s
[i
] == 'D') || (s
[i
] == 'd')) f
|= ASL_FILTER_MASK_DEBUG
;
416 asl_filter_string(int f
)
418 static char str
[1024];
421 memset(str
, 0, sizeof(str
));
424 if ((f
== ASL_FILTER_MASK_PACEWNID
) != 0)
426 strcat(str
, "Emergency - Debug");
430 if ((f
== ASL_FILTER_MASK_PACEWNI
) != 0)
432 strcat(str
, "Emergency - Info");
436 if ((f
== ASL_FILTER_MASK_PACEWN
) != 0)
438 strcat(str
, "Emergency - Notice");
442 if ((f
== ASL_FILTER_MASK_PACEW
) != 0)
444 strcat(str
, "Emergency - Warning");
448 if ((f
== ASL_FILTER_MASK_PACE
) != 0)
450 strcat(str
, "Emergency - Error");
454 if ((f
== ASL_FILTER_MASK_PAC
) != 0)
456 strcat(str
, "Emergency - Critical");
460 if ((f
& ASL_FILTER_MASK_EMERG
) != 0)
462 strcat(str
, "Emergency");
466 if ((f
& ASL_FILTER_MASK_ALERT
) != 0)
468 if (i
> 0) strcat(str
, ", ");
469 strcat(str
, "Alert");
473 if ((f
& ASL_FILTER_MASK_CRIT
) != 0)
475 if (i
> 0) strcat(str
, ", ");
476 strcat(str
, "Critical");
480 if ((f
& ASL_FILTER_MASK_ERR
) != 0)
482 if (i
> 0) strcat(str
, ", ");
483 strcat(str
, "Error");
487 if ((f
& ASL_FILTER_MASK_WARNING
) != 0)
489 if (i
> 0) strcat(str
, ", ");
490 strcat(str
, "Warning");
494 if ((f
& ASL_FILTER_MASK_NOTICE
) != 0)
496 if (i
> 0) strcat(str
, ", ");
497 strcat(str
, "Notice");
501 if ((f
& ASL_FILTER_MASK_INFO
) != 0)
503 if (i
> 0) strcat(str
, ", ");
508 if ((f
& ASL_FILTER_MASK_DEBUG
) != 0)
510 if (i
> 0) strcat(str
, ", ");
511 strcat(str
, "Debug");
515 if (i
== 0) sprintf(str
, "Off");
521 rcontrol_get(const char *prefix
, int pid
)
531 if (pid
== RC_SYSLOGD
) name
= "ASL Data Store";
533 status
= rcontrol_get_string(NULL
, pid
, &filter
);
534 if (status
== NOTIFY_STATUS_OK
)
536 printf("%s filter mask: %s\n", name
, asl_filter_string(filter
));
540 printf("Unable to determine %s filter mask\n", name
);
544 status
= rcontrol_get_string(prefix
, pid
, &filter
);
545 if (status
== NOTIFY_STATUS_OK
)
547 printf("Process %d syslog filter mask: %s\n", pid
, asl_filter_string(filter
));
551 printf("Unable to determine syslog filter mask for pid %d\n", pid
);
556 rcontrol_set(const char *prefix
, int pid
, int filter
)
564 if (pid
== RC_SYSLOGD
) name
= "ASL Data Store";
565 status
= rcontrol_set_string(NULL
, pid
, filter
);
567 if (status
== NOTIFY_STATUS_OK
)
569 printf("Set %s syslog filter mask: %s\n", name
, asl_filter_string(filter
));
573 printf("Unable to set %s syslog filter mask: %s\n", name
, notify_status_string(status
));
577 status
= rcontrol_set_string(prefix
, pid
, filter
);
578 if (status
== NOTIFY_STATUS_OK
)
580 printf("Set process %d syslog filter mask set: %s\n", pid
, asl_filter_string(filter
));
584 printf("Unable to set syslog filter mask for pid %d: %s\n", pid
, notify_status_string(status
));
589 rsend(aslmsg msg
, char *rhost
)
598 struct sockaddr_in dst
;
600 char myname
[MAXHOSTNAMELEN
+ 1];
602 if (msg
== NULL
) return 0;
604 h
= gethostbyname(rhost
);
605 if (h
== NULL
) return -1;
607 s
= socket(AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
);
608 if (s
<= 0) return -1;
610 memset(&dst
, 0, sizeof(struct sockaddr_in
));
611 memcpy(&(dst
.sin_addr
.s_addr
), h
->h_addr_list
[0], 4);
612 dst
.sin_family
= AF_INET
;
614 dst
.sin_len
= sizeof(struct sockaddr_in
);
616 level
= ASL_LEVEL_DEBUG
;
618 val
= asl_get(msg
, ASL_KEY_LEVEL
);
619 if (val
!= NULL
) level
= atoi(val
);
621 memset(>ime
, 0, sizeof(struct tm
));
625 gmtime_r(&tick
, >ime
);
627 /* Canonical form: YYYY.MM.DD hh:mm:ss UTC */
628 asprintf(×tr
, "%d.%02d.%02d %02d:%02d:%02d UTC", gtime
.tm_year
+ 1900, gtime
.tm_mon
+ 1, gtime
.tm_mday
, gtime
.tm_hour
, gtime
.tm_min
, gtime
.tm_sec
);
632 asl_set(msg
, ASL_KEY_TIME
, timestr
);
636 if (gethostname(myname
, MAXHOSTNAMELEN
) == 0) asl_set(msg
, ASL_KEY_HOST
, myname
);
639 str
= asl_msg_to_string(msg
, &len
);
640 if (str
== NULL
) return -1;
642 asprintf(&out
, "%10u %s\n", len
+1, str
);
644 if (out
== NULL
) return -1;
646 sendto(s
, out
, len
+12, 0, (const struct sockaddr
*)&dst
, sizeof(struct sockaddr_in
));
654 rlegacy(char *msg
, int level
, char *rhost
)
661 struct sockaddr_in dst
;
663 char myname
[MAXHOSTNAMELEN
+ 1];
665 if (msg
== NULL
) return 0;
667 h
= gethostbyname(rhost
);
668 if (h
== NULL
) return -1;
670 s
= socket(AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
);
671 if (s
<= 0) return -1;
673 memset(&dst
, 0, sizeof(struct sockaddr_in
));
674 memcpy(&(dst
.sin_addr
.s_addr
), h
->h_addr_list
[0], 4);
675 dst
.sin_family
= AF_INET
;
677 dst
.sin_len
= sizeof(struct sockaddr_in
);
680 ltime
= ctime(&tick
);
683 gethostname(myname
, MAXHOSTNAMELEN
);
685 asprintf(&out
, "<%d>%s %s syslog[%d]: %s", level
, ltime
+4, myname
, getpid(), msg
);
687 sendto(s
, out
, len
, 0, (const struct sockaddr
*)&dst
, sizeof(struct sockaddr_in
));
699 if (s
== NULL
) return 0;
702 if ((s
[0] == '-') || (s
[0] == '+')) i
= 1;
704 if (s
[i
] == '\0') return 0;
706 for (; s
[i
] != '\0'; i
++)
708 if (!isdigit(s
[i
])) return 0;
715 asl_string_to_level(const char *s
)
717 if (s
== NULL
) return -1;
719 if ((s
[0] >= '0') && (s
[0] <= '7') && (s
[1] == '\0')) return atoi(s
);
721 if (!strncasecmp(s
, "em", 2)) return ASL_LEVEL_EMERG
;
722 else if (!strncasecmp(s
, "p", 1)) return ASL_LEVEL_EMERG
;
723 else if (!strncasecmp(s
, "a", 1)) return ASL_LEVEL_ALERT
;
724 else if (!strncasecmp(s
, "c", 1)) return ASL_LEVEL_CRIT
;
725 else if (!strncasecmp(s
, "er", 2)) return ASL_LEVEL_ERR
;
726 else if (!strncasecmp(s
, "x", 1)) return ASL_LEVEL_ERR
;
727 else if (!strncasecmp(s
, "w", 1)) return ASL_LEVEL_WARNING
;
728 else if (!strncasecmp(s
, "n", 1)) return ASL_LEVEL_NOTICE
;
729 else if (!strncasecmp(s
, "i", 1)) return ASL_LEVEL_INFO
;
730 else if (!strncasecmp(s
, "d", 1)) return ASL_LEVEL_DEBUG
;
736 syslog_remote_control(int argc
, char *argv
[])
738 int pid
, uid
, status
, mask
;
741 if ((argc
< 3) || (argc
> 4))
743 fprintf(stderr
, "usage:\n");
744 fprintf(stderr
, "%s -c process [mask]\n", myname
);
745 fprintf(stderr
, " get (set if mask is specified) syslog filter mask for process (pid or name)\n");
746 fprintf(stderr
, " process may be pid or process name\n");
747 fprintf(stderr
, " use \"-c 0\" to get master syslog filter mask\n");
748 fprintf(stderr
, " use \"-c 0 off\" to disable master syslog filter mask\n");
749 fprintf(stderr
, "\n");
756 status
= PROC_NOT_FOUND
;
758 if ((!strcmp(argv
[2], "syslogd")) || (!strcmp(argv
[2], "syslog")))
764 else if (_isanumber(argv
[2]) != 0)
767 status
= procinfo(NULL
, &pid
, &uid
);
771 status
= procinfo(argv
[2], &pid
, &uid
);
774 if (status
== PROC_NOT_FOUND
)
776 fprintf(stderr
, "%s: process not found\n", argv
[2]);
780 if (status
== PROC_NOT_UNIQUE
)
782 fprintf(stderr
, "%s: multiple processes found\n", argv
[2]);
783 fprintf(stderr
, "use pid to identify a process uniquely\n");
787 if (pid
== 0) pid
= RC_MASTER
;
789 prefix
= NOTIFY_PREFIX_USER
;
790 if (uid
== 0) prefix
= NOTIFY_PREFIX_SYSTEM
;
794 if ((pid
== RC_MASTER
) && (!strcasecmp(argv
[3], "off"))) mask
= 0;
795 else if ((pid
== RC_SYSLOGD
) && (!strcasecmp(argv
[3], "off"))) mask
= 0;
798 mask
= asl_string_to_filter(argv
[3]);
801 printf("unknown syslog mask: %s\n", argv
[3]);
806 rcontrol_set(prefix
, pid
, mask
);
810 rcontrol_get(prefix
, pid
);
817 syslog_send(int argc
, char *argv
[])
819 int i
, start
, kv
, len
, rfmt
, rlevel
, filter
, status
;
822 char tmp
[64], *str
, *rhost
;
826 rfmt
= SEND_FORMAT_LEGACY
;
830 for (i
= 1; i
< argc
; i
++)
832 if (!strcmp(argv
[i
], "-s")) start
= i
+1;
833 else if (!strcmp(argv
[i
], "-k"))
836 rfmt
= SEND_FORMAT_ASL
;
838 else if (!strcmp(argv
[i
], "-r"))
843 else if (!strcmp(argv
[i
], "-l"))
845 rlevel
= asl_string_to_level(argv
[++i
]);
848 fprintf(stderr
, "Unknown level: %s\n", argv
[i
]);
855 asl
= asl_open(myname
, "syslog", 0);
856 asl_set_filter(asl
, ASL_FILTER_MASK_UPTO(ASL_LEVEL_DEBUG
));
858 m
= asl_new(ASL_TYPE_MSG
);
859 asl_set(m
, ASL_KEY_SENDER
, myname
);
861 sprintf(tmp
, "%d", rlevel
);
862 asl_set(m
, ASL_KEY_LEVEL
, tmp
);
869 for (i
= start
; i
< argc
; i
++) len
+= (strlen(argv
[i
]) + 1);
870 str
= calloc(len
+ 1, 1);
871 if (str
== NULL
) return -1;
873 for (i
= start
; i
< argc
; i
++)
875 strcat(str
, argv
[i
]);
876 if ((i
+1) < argc
) strcat(str
, " ");
878 asl_set(m
, ASL_KEY_MSG
, str
);
882 for (i
= start
+ 1; i
< argc
; i
+= 2)
884 if (!strcmp(argv
[i
], "-k")) i
++;
885 asl_set(m
, argv
[i
], argv
[i
+ 1]);
886 if (!strcmp(argv
[i
], ASL_KEY_LEVEL
)) rlevel
= atoi(argv
[i
+ 1]);
893 status
= rcontrol_get_string(NULL
, RC_SYSLOGD
, &filter
);
896 fprintf(stderr
, "Warning: Can't get current syslogd ASL filter value\n");
898 else if ((ASL_FILTER_MASK(rlevel
) & filter
) == 0)
900 fprintf(stderr
, "Warning: The current syslogd ASL filter value (%s)\n", asl_filter_string(filter
));
901 fprintf(stderr
, " will exclude this message from the ASL database\n");
906 else if (rfmt
== SEND_FORMAT_ASL
)
910 else if ((rfmt
== SEND_FORMAT_LEGACY
) && (str
!= NULL
))
912 rlegacy(str
, rlevel
, rhost
);
917 if (str
!= NULL
) free(str
);
925 print_xml_header(FILE *f
)
927 if (f
== NULL
) return;
929 fprintf(f
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
930 fprintf(f
, "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n");
931 fprintf(f
, "<plist version=\"1.0\">\n");
932 fprintf(f
, "<array>\n");
936 print_xml_trailer(FILE *f
)
938 if (f
== NULL
) return;
940 fprintf(f
, "</array>\n");
941 fprintf(f
, "</plist>\n");
945 printmsg(FILE *f
, asl_msg_t
*msg
, char *fmt
, int pflags
)
949 uint32_t encode
, len
, status
;
957 status
= asl_file_save(export
, msg
, &xid
);
958 if (status
!= ASL_STATUS_OK
)
960 fprintf(stderr
, "export file write failed: %s\n", asl_core_error(status
));
961 asl_file_close(export
);
969 encode
= pflags
& 0x0000000f;
971 mf
= ASL_MSG_FMT_RAW
;
972 if (fmt
!= NULL
) mf
= (const char *)fmt
;
973 else if (pflags
& FORMAT_STD
) mf
= ASL_MSG_FMT_STD
;
974 else if (pflags
& FORMAT_LEGACY
) mf
= ASL_MSG_FMT_BSD
;
975 else if (pflags
& FORMAT_XML
) mf
= ASL_MSG_FMT_XML
;
977 tf
= ASL_TIME_FMT_SEC
;
978 if (pflags
& TIME_UTC
) tf
= ASL_TIME_FMT_UTC
;
979 if (pflags
& TIME_LCL
) tf
= ASL_TIME_FMT_LCL
;
982 str
= asl_format_message(msg
, mf
, tf
, encode
, &len
);
985 fprintf(f
, "%s", str
);
990 asl_search_result_t
*
991 store_query(asl_search_result_t
*q
, uint64_t start
, int count
, int dir
, uint64_t *last
)
994 asl_search_result_t
*res
;
998 status
= asl_store_open_read(NULL
, &store
);
999 if (status
!= 0) return NULL
;
1003 status
= asl_store_match(store
, q
, &res
, last
, start
, count
, dir
);
1004 if (status
!= 0) return NULL
;
1009 asl_search_result_t
*
1010 file_query(asl_search_result_t
*q
, uint64_t start
, int count
, int dir
, uint64_t *last
)
1013 asl_search_result_t
*res
;
1016 status
= asl_file_list_match(db_files
, q
, &res
, last
, start
, count
, dir
);
1017 if (status
!= 0) return NULL
;
1022 asl_search_result_t
*
1023 legacy_query(asl_search_result_t
*q
, uint64_t start
, int count
, int dir
, uint64_t *last
)
1026 asl_search_result_t
*res
;
1029 status
= asl_file_match(legacy
, q
, &res
, last
, start
, count
, dir
);
1030 if (status
!= 0) return NULL
;
1035 asl_search_result_t
*
1036 syslogd_query(asl_search_result_t
*q
, uint64_t start
, int count
, int dir
, uint64_t *last
)
1040 uint32_t len
, reslen
, status
;
1042 kern_return_t kstatus
;
1043 security_token_t sec
;
1044 asl_search_result_t
*l
;
1046 if (asl_server_port
== MACH_PORT_NULL
)
1048 kstatus
= bootstrap_look_up(bootstrap_port
, ASL_SERVICE_NAME
, &asl_server_port
);
1049 if (kstatus
!= KERN_SUCCESS
)
1051 fprintf(stderr
, "query failed: can't contact syslogd\n");
1057 str
= asl_list_to_string(q
, &len
);
1059 kstatus
= vm_allocate(mach_task_self(), (vm_address_t
*)&vmstr
, len
, TRUE
);
1060 if (kstatus
!= KERN_SUCCESS
)
1066 memmove(vmstr
, str
, len
);
1075 if (dir
< 0) flags
= QUERY_FLAG_SEARCH_REVERSE
;
1077 kstatus
= _asl_server_query(asl_server_port
, (caddr_t
)vmstr
, len
, start
, count
, flags
, (caddr_t
*)&res
, &reslen
, last
, (int *)&status
, &sec
);
1079 if (res
== NULL
) return NULL
;
1080 l
= asl_list_from_string(res
);
1081 vm_deallocate(mach_task_self(), (vm_address_t
)res
, reslen
);
1086 search_once(FILE *f
, char *pfmt
, int pflags
, asl_search_result_t
*ql
, uint64_t qmin
, uint64_t *cmax
, uint32_t count
, uint32_t batch
, int dir
, uint32_t tail
)
1088 asl_search_result_t
*res
;
1091 if (pflags
& FORMAT_XML
) print_xml_header(f
);
1099 if (dbselect
== DB_SELECT_STORE
) res
= store_query(ql
, qmin
, batch
, dir
, cmax
);
1100 else if (dbselect
== DB_SELECT_FILES
) res
= file_query(ql
, qmin
, batch
, dir
, cmax
);
1101 else if (dbselect
== DB_SELECT_SYSLOGD
) res
= syslogd_query(ql
, qmin
, batch
, dir
, cmax
);
1102 else if (dbselect
== DB_SELECT_LEGACY
) res
= legacy_query(ql
, qmin
, batch
, dir
, cmax
);
1104 if ((dir
>= 0) && (*cmax
> qmin
)) qmin
= *cmax
;
1105 else if ((dir
< 0) && (*cmax
< qmin
)) qmin
= *cmax
;
1113 if ((batch
> 0) && (res
->count
< batch
)) more
= 0;
1114 total
+= res
->count
;
1115 if ((count
> 0) && (total
>= count
)) more
= 0;
1120 i
= res
->count
- tail
;
1125 if ((f
!= NULL
) || (export
!= NULL
))
1127 for (; i
< res
->count
; i
++) printmsg(f
, res
->msg
[i
], pfmt
, pflags
);
1130 aslresponse_free((aslresponse
)res
);
1134 if (pflags
& FORMAT_XML
) print_xml_trailer(f
);
1142 op
= ASL_QUERY_OP_NULL
;
1144 if (o
== NULL
) return op
;
1146 for (i
= 0; o
[i
] != '\0'; i
++)
1148 if (o
[i
] == MOD_CASE_FOLD
) op
|= ASL_QUERY_OP_CASEFOLD
;
1149 else if (o
[i
] == MOD_REGEX
) op
|= ASL_QUERY_OP_REGEX
;
1150 else if (o
[i
] == MOD_NUMERIC
) op
|= ASL_QUERY_OP_NUMERIC
;
1151 else if (o
[i
] == MOD_SUBSTRING
) op
|= ASL_QUERY_OP_SUBSTRING
;
1152 else if (o
[i
] == MOD_PREFIX
) op
|= ASL_QUERY_OP_PREFIX
;
1153 else if (o
[i
] == MOD_SUFFIX
) op
|= ASL_QUERY_OP_SUFFIX
;
1155 else if (!strncasecmp(o
+i
, OP_EQ
, sizeof(OP_EQ
)))
1157 op
|= ASL_QUERY_OP_EQUAL
;
1158 i
+= (sizeof(OP_EQ
) - 2);
1160 else if (!strncasecmp(o
+i
, OP_NE
, sizeof(OP_NE
)))
1162 op
|= ASL_QUERY_OP_NOT_EQUAL
;
1163 i
+= (sizeof(OP_NE
) - 2);
1165 else if (!strncasecmp(o
+i
, OP_GT
, sizeof(OP_GT
)))
1167 op
|= ASL_QUERY_OP_GREATER
;
1168 i
+= (sizeof(OP_GT
) - 2);
1170 else if (!strncasecmp(o
+i
, OP_GE
, sizeof(OP_GE
)))
1172 op
|= ASL_QUERY_OP_GREATER_EQUAL
;
1173 i
+= (sizeof(OP_GE
) - 2);
1175 else if (!strncasecmp(o
+i
, OP_LT
, sizeof(OP_LT
)))
1177 op
|= ASL_QUERY_OP_LESS
;
1178 i
+= (sizeof(OP_LT
) - 2);
1180 else if (!strncasecmp(o
+i
, OP_LE
, sizeof(OP_LE
)))
1182 op
|= ASL_QUERY_OP_LESS_EQUAL
;
1183 i
+= (sizeof(OP_LE
) - 2);
1187 fprintf(stderr
, "invalid option: %s\n", o
);
1193 if (op
& ASL_QUERY_OP_NUMERIC
)
1195 if (op
& ASL_QUERY_OP_CASEFOLD
)
1197 fprintf(stderr
, "warning: case fold modifier has no effect with numeric comparisons\n");
1198 op
&= ~ASL_QUERY_OP_CASEFOLD
;
1201 if (op
& ASL_QUERY_OP_REGEX
)
1203 fprintf(stderr
, "warning: regex modifier has no effect with numeric comparisons\n");
1204 op
&= ~ASL_QUERY_OP_REGEX
;
1207 if (op
& ASL_QUERY_OP_SUBSTRING
)
1209 fprintf(stderr
, "warning: substring modifier has no effect with numeric comparisons\n");
1210 op
&= ~ASL_QUERY_OP_SUBSTRING
;
1213 if (op
& ASL_QUERY_OP_PREFIX
)
1215 fprintf(stderr
, "warning: prefix modifier has no effect with numeric comparisons\n");
1216 op
&= ~ASL_QUERY_OP_PREFIX
;
1219 if (op
& ASL_QUERY_OP_SUFFIX
)
1221 fprintf(stderr
, "warning: suffix modifier has no effect with numeric comparisons\n");
1222 op
&= ~ASL_QUERY_OP_SUFFIX
;
1226 if (op
& ASL_QUERY_OP_REGEX
)
1228 if (op
& ASL_QUERY_OP_SUBSTRING
)
1230 fprintf(stderr
, "warning: substring modifier has no effect with regular expression comparisons\n");
1231 op
&= ~ASL_QUERY_OP_SUBSTRING
;
1234 if (op
& ASL_QUERY_OP_PREFIX
)
1236 fprintf(stderr
, "warning: prefix modifier has no effect with regular expression comparisons\n");
1237 op
&= ~ASL_QUERY_OP_PREFIX
;
1240 if (op
& ASL_QUERY_OP_SUFFIX
)
1242 fprintf(stderr
, "warning: suffix modifier has no effect with regular expression comparisons\n");
1243 op
&= ~ASL_QUERY_OP_SUFFIX
;
1251 add_op(asl_msg_t
*q
, char *key
, char *op
, char *val
, uint32_t flags
)
1255 if (key
== NULL
) return -1;
1256 if (q
== NULL
) return -1;
1258 o
= ASL_QUERY_OP_NULL
;
1262 if (o
== ASL_QUERY_OP_NULL
) return -1;
1265 fprintf(stderr
, "no value supplied for operator %s %s\n", key
, op
);
1269 if ((o
& ASL_QUERY_OP_NUMERIC
) && (strcmp(key
, ASL_KEY_TIME
) != 0) && (_isanumber(val
) == 0))
1271 fprintf(stderr
, "non-numeric value supplied for numeric operator %s %s %s\n", key
, op
, val
);
1278 asl_set_query(q
, key
, val
, o
);
1284 add_db_file(const char *name
)
1289 if (dbselect
== DB_SELECT_LEGACY
)
1291 fprintf(stderr
, "syslog can only read one legacy format database\n");
1292 fprintf(stderr
, "can't combine legacy and non-legacy databases in a single search\n");
1296 /* shouldn't happen */
1297 if (name
== NULL
) return DB_SELECT_STORE
;
1300 status
= asl_file_open_read(name
, &s
);
1301 if (status
!= ASL_STATUS_OK
)
1303 fprintf(stderr
, "data store file %s open failed: %s \n", name
, asl_core_error(status
));
1309 fprintf(stderr
, "data store file %s open failed\n", name
);
1313 if (s
->flags
& ASL_FILE_FLAG_LEGACY_STORE
)
1315 if (db_files
!= NULL
)
1317 fprintf(stderr
, "syslog can only read a single legacy format database\n");
1318 fprintf(stderr
, "can't combine legacy and non-legacy databases in a single search\n");
1323 return DB_SELECT_LEGACY
;
1326 db_files
= asl_file_list_add(db_files
, s
);
1327 return DB_SELECT_FILES
;
1331 add_db_dir(const char *name
)
1334 struct dirent
*dent
;
1340 * Open all readable files
1345 fprintf(stderr
, "%s: %s\n", name
, strerror(errno
));
1349 while ((dent
= readdir(dp
)) != NULL
)
1351 if (dent
->d_name
[0] == '.') continue;
1354 asprintf(&path
, "%s/%s", name
, dent
->d_name
);
1357 * asl_file_open_read will fail if path is NULL,
1358 * if the file is not an ASL store file,
1359 * or if it isn't readable.
1362 status
= asl_file_open_read(path
, &s
);
1363 if (path
!= NULL
) free(path
);
1364 if ((status
!= ASL_STATUS_OK
) || (s
== NULL
)) continue;
1366 db_files
= asl_file_list_add(db_files
, s
);
1371 return DB_SELECT_FILES
;
1375 main(int argc
, char *argv
[])
1378 int i
, j
, n
, watch
, status
, pflags
, tflags
, iamroot
, user_tflag
;
1379 int notify_file
, notify_token
;
1380 asl_search_result_t
*qlist
;
1383 const char *exportname
;
1384 uint32_t flags
, tail_count
, batch
, encode
;
1385 uint64_t qmin
, cmax
;
1393 batch
= FETCH_BATCH
;
1394 pflags
= FORMAT_STD
;
1396 encode
= ASL_ENCODE_ASL
;
1400 if (getuid() == 0) iamroot
= 1;
1402 for (i
= 1; i
< argc
; i
++)
1404 if ((!strcmp(argv
[i
], "-help")) || (!strcmp(argv
[i
], "--help")))
1410 if (!strcmp(argv
[i
], "-time"))
1413 printf("%llu\n", qmin
);
1417 if (!strcmp(argv
[i
], "-s"))
1419 syslog_send(argc
, argv
);
1423 if (!strcmp(argv
[i
], "-c"))
1425 syslog_remote_control(argc
, argv
);
1430 qlist
= (asl_search_result_t
*)calloc(1, sizeof(asl_search_result_t
));
1431 if (qlist
== NULL
) exit(1);
1433 for (i
= 1; i
< argc
; i
++)
1435 if (!strcmp(argv
[i
], "-f"))
1439 for (j
= i
+ 1; j
< argc
; j
++)
1441 if (!strcmp(argv
[j
], "-"))
1443 dbselect
= DB_SELECT_SYSLOGD
;
1446 else if (argv
[j
][0] == '-')
1452 dbselect
= add_db_file(argv
[j
]);
1457 if (!strcmp(argv
[i
], "-d"))
1461 for (j
= i
+ 1; j
< argc
; j
++)
1463 if (!strcmp(argv
[j
], "store"))
1465 dbselect
= add_db_dir(PATH_ASL_STORE
);
1467 else if (!strcmp(argv
[j
], "archive"))
1469 dbselect
= add_db_dir(PATH_ASL_ARCHIVE
);
1471 else if (argv
[j
][0] == '-')
1477 dbselect
= add_db_dir(argv
[j
]);
1482 else if (!strcmp(argv
[i
], "-w"))
1486 if (((i
+ 1) < argc
) && (argv
[i
+ 1][0] != '-'))
1489 tail_count
= atoi(argv
[i
]);
1492 else if (!strcmp(argv
[i
], "-u"))
1497 else if (!strcmp(argv
[i
], "-x"))
1499 if ((i
+ 1) >= argc
)
1501 aslresponse_free(qlist
);
1506 exportname
= argv
[++i
];
1508 else if (!strcmp(argv
[i
], "-E"))
1510 if ((i
+ 1) >= argc
)
1512 aslresponse_free(qlist
);
1519 if (!strcmp(argv
[i
], "vis")) encode
= ASL_ENCODE_ASL
;
1520 else if (!strcmp(argv
[i
], "safe")) encode
= ASL_ENCODE_SAFE
;
1521 else if (!strcmp(argv
[i
], "none")) encode
= ASL_ENCODE_NONE
;
1522 else if ((argv
[i
][0] >= '0') && (argv
[i
][0] <= '9') && (argv
[i
][1] == '\0')) encode
= atoi(argv
[i
]);
1524 else if (!strcmp(argv
[i
], "-F"))
1526 if ((i
+ 1) >= argc
)
1528 aslresponse_free(qlist
);
1535 if (!strcmp(argv
[i
], "raw"))
1537 pflags
= FORMAT_RAW
;
1538 if (user_tflag
== 0) tflags
= TIME_SEC
;
1540 else if (!strcmp(argv
[i
], "std"))
1542 pflags
= FORMAT_STD
;
1544 else if (!strcmp(argv
[i
], "bsd"))
1546 pflags
= FORMAT_LEGACY
;
1548 else if (!strcmp(argv
[i
], "xml"))
1550 pflags
= FORMAT_XML
;
1558 else if (!strcmp(argv
[i
], "-T"))
1560 if ((i
+ 1) >= argc
)
1562 aslresponse_free(qlist
);
1570 if (!strcmp(argv
[i
], "sec")) tflags
= TIME_SEC
;
1571 else if (!strcmp(argv
[i
], "utc")) tflags
= TIME_UTC
;
1572 else if (!strcmp(argv
[i
], "local")) tflags
= TIME_LCL
;
1573 else if (!strcmp(argv
[i
], "lcl")) tflags
= TIME_LCL
;
1574 else tflags
= TIME_LCL
;
1576 else if (!strcmp(argv
[i
], "-o"))
1580 if (qlist
->count
== 0)
1582 qlist
->msg
= (asl_msg_t
**)calloc(1, sizeof(asl_msg_t
*));
1586 qlist
->msg
= (asl_msg_t
**)reallocf(qlist
->msg
, (qlist
->count
+ 1) * sizeof(asl_msg_t
*));
1589 if (qlist
->msg
== NULL
) exit(1);
1591 cq
= asl_new(ASL_TYPE_QUERY
);
1592 qlist
->msg
[qlist
->count
] = cq
;
1595 else if (!strcmp(argv
[i
], "-n"))
1597 flags
= ASL_QUERY_OP_NOT
;
1599 else if (!strcmp(argv
[i
], "-C"))
1601 if (qlist
->count
== 0)
1603 qlist
->msg
= (asl_msg_t
**)calloc(1, sizeof(asl_msg_t
*));
1604 if (qlist
->msg
== NULL
) exit(1);
1606 cq
= asl_new(ASL_TYPE_QUERY
);
1607 qlist
->msg
[qlist
->count
] = cq
;
1611 status
= add_op(cq
, ASL_KEY_FACILITY
, OP_EQ
, FACILITY_CONSOLE
, flags
);
1616 aslresponse_free(qlist
);
1620 else if (!strcmp(argv
[i
], "-k"))
1623 for (n
= i
; n
< argc
; n
++)
1625 if (!strcmp(argv
[n
], "-o")) break;
1626 if (!strcmp(argv
[n
], "-n")) break;
1627 if (!strcmp(argv
[n
], "-k")) break;
1630 fprintf(stderr
, "invalid sequence: -k");
1631 for (j
= i
; j
<= n
; j
++) fprintf(stderr
, " %s", argv
[j
]);
1632 fprintf(stderr
, "\n");
1645 if (qlist
->count
== 0)
1647 qlist
->msg
= (asl_msg_t
**)calloc(1, sizeof(asl_msg_t
*));
1648 if (qlist
->msg
== NULL
) exit(1);
1650 cq
= asl_new(ASL_TYPE_QUERY
);
1651 qlist
->msg
[qlist
->count
] = cq
;
1656 if (n
== 1) status
= add_op(cq
, argv
[i
], NULL
, NULL
, flags
);
1657 else if (n
== 2) status
= add_op(cq
, argv
[i
], OP_EQ
, argv
[i
+1], flags
);
1658 else status
= add_op(cq
, argv
[i
], argv
[i
+1], argv
[i
+2], flags
);
1663 aslresponse_free(qlist
);
1674 if (exportname
!= NULL
)
1678 fprintf(stderr
, "Warning: -w flag has no effect with -x export flag\n");
1682 status
= asl_file_open_write(exportname
, 0644, -1, -1, &export
);
1683 if (status
!= ASL_STATUS_OK
)
1685 aslresponse_free(qlist
);
1686 fprintf(stderr
, "export file open failed: %s\n", asl_core_error(status
));
1691 * allow the string cache to be unlimited to maximize string dup compression
1692 * preserve message IDs
1694 export
->flags
= ASL_FILE_FLAG_UNLIMITED_CACHE
| ASL_FILE_FLAG_PRESERVE_MSG_ID
;
1707 if ((dbselect
== DB_SELECT_STORE
) || (dbselect
== DB_SELECT_SYSLOGD
))
1709 status
= notify_register_file_descriptor("com.apple.system.logger.message", ¬ify_file
, 0, ¬ify_token
);
1710 if (status
!= NOTIFY_STATUS_OK
) notify_token
= -1;
1714 if ((qlist
->count
== 0) && (watch
== 1))
1717 search_once(NULL
, NULL
, 0, NULL
, qmin
, &cmax
, 1, 1, -1, 0);
1718 qmin
= (cmax
+ 1) - tail_count
;
1722 /* output should be line buffered */
1723 setlinebuf(outfile
);
1725 search_once(outfile
, pfmt
, pflags
, qlist
, qmin
, &cmax
, 0, batch
, 1, tail_count
);
1729 if (notify_token
== -1)
1734 if (cmax
> qmin
) qmin
= cmax
;
1735 search_once(outfile
, pfmt
, pflags
, qlist
, qmin
+ 1, &cmax
, 0, batch
, 1, 0);
1740 while (read(notify_file
, &i
, 4) == 4)
1742 if (cmax
> qmin
) qmin
= cmax
;
1743 search_once(outfile
, pfmt
, pflags
, qlist
, qmin
+ 1, &cmax
, 0, batch
, 1, 0);
1748 if (db_files
!= NULL
) asl_file_list_close(db_files
);
1749 if (store
!= NULL
) asl_store_close(store
);
1750 if (export
!= NULL
) asl_file_close(export
);
1752 aslresponse_free(qlist
);