2 * Copyright (c) 2015 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 <asl_private.h>
31 #include <asl_store.h>
36 #include <sys/param.h>
42 #include <servers/bootstrap.h>
43 #include <bootstrap_priv.h>
44 #include <mach/mach.h>
47 #include <dispatch/dispatch.h>
49 #include <xpc/private.h>
50 #include <os/assumes.h>
51 #include <vproc_priv.h>
52 #include <libkern/OSAtomic.h>
57 extern uint32_t debug
;
59 extern dispatch_queue_t work_queue
;
61 static mach_port_t asl_server_port
;
62 static aslclient aslc
;
63 static int asl_aux_fd
= -1;
65 extern kern_return_t _asl_server_query
69 mach_msg_type_number_t requestCnt
,
74 mach_msg_type_number_t
*replyCnt
,
77 security_token_t
*token
81 keep_str(uint8_t mask
)
86 memset(str
, 0, sizeof(str
));
87 if (mask
& 0x01) str
[x
++] = '0';
88 if (mask
& 0x02) str
[x
++] = '1';
89 if (mask
& 0x04) str
[x
++] = '2';
90 if (mask
& 0x08) str
[x
++] = '3';
91 if (mask
& 0x10) str
[x
++] = '4';
92 if (mask
& 0x20) str
[x
++] = '5';
93 if (mask
& 0x40) str
[x
++] = '6';
94 if (mask
& 0x80) str
[x
++] = '7';
95 if (x
== 0) str
[x
++] = '-';
100 set_debug(int flag
, const char *str
)
104 if (str
== NULL
) x
= ASL_LEVEL_ERR
;
105 else if (((str
[0] == 'L') || (str
[0] == 'l')) && ((str
[1] >= '0') && (str
[1] <= '7')) && (str
[2] == '\0')) x
= atoi(str
+1);
106 else if ((str
[0] >= '0') && (str
[0] <= '7') && (str
[1] == '\0')) x
= ASL_LEVEL_CRIT
+ atoi(str
);
107 else x
= ASL_LEVEL_ERR
;
110 else if (x
> 7) x
= 7;
112 level
= debug
& DEBUG_LEVEL_MASK
;
113 if (x
> level
) level
= x
;
115 debug
= debug
& DEBUG_FLAG_MASK
;
121 debug_log(int level
, char *str
, ...)
126 time_t now
= time(NULL
);
127 memset(ts
, 0, sizeof(ts
));
128 strftime(ts
, sizeof(ts
), "%b %e %T", localtime(&now
));
130 if ((debug
& DEBUG_STDERR
) && (level
<= (debug
& DEBUG_LEVEL_MASK
)))
132 fprintf(stderr
, "%s: ", ts
);
134 vfprintf(stderr
, str
, v
);
138 if ((debug
& DEBUG_FILE
) && (debugfp
!= NULL
))
140 fprintf(debugfp
, "%s: ", ts
);
142 vfprintf(debugfp
, str
, v
);
146 if (debug
& DEBUG_ASL
)
152 aslc
= asl_open("aslmanager", "syslog", 0);
153 asl_msg_t
*msg
= asl_msg_new(ASL_TYPE_MSG
);
155 asl_msg_set_key_val(msg
, ASL_KEY_MSG
, "Status Report");
156 asl_msg_set_key_val(msg
, ASL_KEY_LEVEL
, ASL_STRING_NOTICE
);
157 asl_create_auxiliary_file((asl_object_t
)msg
, "Status Report", "public.text", &asl_aux_fd
);
158 asl_msg_release(msg
);
162 vasprintf(&line
, str
, v
);
167 write(asl_aux_fd
, ts
, strlen(ts
));
168 write(asl_aux_fd
, line
, strlen(line
));
178 if (asl_aux_fd
>= 0) asl_close_auxiliary_file(asl_aux_fd
);
179 if (debugfp
!= NULL
) fclose(debugfp
);
183 add_to_name_list(name_list_t
*l
, const char *name
, size_t size
, uint32_t flags
)
187 if (name
== NULL
) return l
;
189 e
= (name_list_t
*)calloc(1, sizeof(name_list_t
));
190 if (e
== NULL
) return NULL
;
192 e
->name
= strdup(name
);
202 /* list is sorted by name (i.e. primarily by timestamp) */
203 if (l
== NULL
) return e
;
205 if (strcmp(e
->name
, l
->name
) <= 0)
211 for (x
= l
; (x
->next
!= NULL
) && (strcmp(e
->name
, x
->next
->name
) > 0) ; x
= x
->next
);
219 free_name_list(name_list_t
*l
)
235 copy_compress_file(asl_out_dst_data_t
*asldst
, const char *src
, const char *dst
)
242 in
= open(src
, O_RDONLY
, 0);
243 if (in
< 0) return -1;
245 out
= open(dst
, O_WRONLY
| O_CREAT
, asldst
->mode
& 0666);
246 if (out
>= 0) out
= asl_out_dst_set_access(out
, asldst
);
253 gz
= gzdopen(out
, "w");
262 n
= read(in
, buf
, sizeof(buf
));
263 if (n
> 0) gzwrite(gz
, buf
, n
);
264 } while (n
== IOBUFSIZE
);
274 filesystem_rename(const char *src
, const char *dst
)
278 debug_log(ASL_LEVEL_NOTICE
, " rename %s ---> %s\n", src
, dst
);
281 status
= rename(src
, dst
);
282 if (status
!= 0) debug_log(ASL_LEVEL_ERR
, " FAILED status %d errno %d [%s] rename %s ---> %s\n", status
, errno
, strerror(errno
), src
, dst
);
286 filesystem_unlink(const char *path
)
290 debug_log(ASL_LEVEL_NOTICE
, " remove %s\n", path
);
293 status
= unlink(path
);
294 if (status
!= 0) debug_log(ASL_LEVEL_ERR
, " FAILED status %d errno %d [%s] unlink %s\n", status
, errno
, strerror(errno
), path
);
298 filesystem_truncate(const char *path
)
302 debug_log(ASL_LEVEL_NOTICE
, " truncate %s\n", path
);
305 status
= truncate(path
, 0);
306 if (status
!= 0) debug_log(ASL_LEVEL_ERR
, " FAILED status %d errno %d [%s] unlink %s\n", status
, errno
, strerror(errno
), path
);
310 filesystem_rmdir(const char *path
)
314 debug_log(ASL_LEVEL_NOTICE
, " remove directory %s\n", path
);
317 status
= rmdir(path
);
318 if (status
!= 0) debug_log(ASL_LEVEL_ERR
, " FAILED status %d errno %d [%s] rmdir %s\n", status
, errno
, strerror(errno
), path
);
322 * Copy ASL files by reading and writing each record.
325 copy_asl_file(const char *src
, const char *dst
, mode_t mode
)
327 asl_file_t
*fin
, *fout
;
330 if (src
== NULL
) return ASL_STATUS_INVALID_ARG
;
331 if (dst
== NULL
) return ASL_STATUS_INVALID_ARG
;
334 status
= asl_file_open_read(src
, &fin
);
335 if (status
!= ASL_STATUS_OK
) return status
;
338 status
= asl_file_open_write(dst
, mode
, -1, -1, &fout
);
339 if (status
!= ASL_STATUS_OK
)
348 return ASL_STATUS_FAILED
;
351 fout
->flags
= ASL_FILE_FLAG_PRESERVE_MSG_ID
;
353 status
= asl_file_read_set_position(fin
, ASL_FILE_POSITION_FIRST
);
354 if (status
!= ASL_STATUS_OK
)
357 asl_file_close(fout
);
358 return ASL_STATUS_READ_FAILED
;
361 while (status
== ASL_STATUS_OK
)
364 asl_msg_t
*msg
= NULL
;
366 status
= asl_file_fetch_next(fin
, &msg
);
369 status
= ASL_STATUS_OK
;
373 if (status
!= ASL_STATUS_OK
) break;
375 status
= asl_file_save(fout
, msg
, &mid
);
376 asl_msg_release(msg
);
380 asl_file_close(fout
);
386 filesystem_copy(asl_out_dst_data_t
*asldst
, const char *src
, const char *dst
, uint32_t flags
)
390 if ((src
== NULL
) || (dst
== NULL
)) return 0;
392 dot
= strrchr(src
, '.');
393 if ((dot
!= NULL
) && (!strcmp(dot
, ".gz"))) flags
&= ~MODULE_FLAG_COMPRESS
;
395 if (((flags
& MODULE_FLAG_COMPRESS
) == 0) && (!strcmp(src
, dst
))) return 0;
397 if (flags
& MODULE_FLAG_TYPE_ASL
) debug_log(ASL_LEVEL_NOTICE
, " copy asl %s ---> %s\n", src
, dst
);
398 else if (flags
& MODULE_FLAG_COMPRESS
) debug_log(ASL_LEVEL_NOTICE
, " copy compress %s ---> %s.gz\n", src
, dst
);
399 else debug_log(ASL_LEVEL_NOTICE
, " copy %s ---> %s\n", src
, dst
);
401 if (dryrun
) return 0;
403 if (flags
& MODULE_FLAG_TYPE_ASL
)
405 uint32_t status
= copy_asl_file(src
, dst
, asldst
->mode
);
408 debug_log(ASL_LEVEL_ERR
, " FAILED status %u [%s] asl copy %s ---> %s\n", status
, asl_core_error(status
), src
, dst
);
412 else if (flags
& MODULE_FLAG_COMPRESS
)
414 char gzdst
[MAXPATHLEN
];
416 snprintf(gzdst
, sizeof(gzdst
), "%s.gz", dst
);
418 int status
= copy_compress_file(asldst
, src
, gzdst
);
421 debug_log(ASL_LEVEL_ERR
, " FAILED status %d errno %d [%s] copy & compress %s ---> %s\n", status
, errno
, strerror(errno
), src
, dst
);
427 int status
= copyfile(src
, dst
, NULL
, COPYFILE_ALL
| COPYFILE_RECURSIVE
);
430 debug_log(ASL_LEVEL_ERR
, " FAILED status %d errno %d [%s] copy %s ---> %s\n", status
, errno
, strerror(errno
), src
, dst
);
439 filesystem_reset_ctime(const char *path
)
441 struct attrlist attr_list
;
444 debug_log(ASL_LEVEL_NOTICE
, " reset ctime %s\n", path
);
446 memset(&attr_list
, 0, sizeof(attr_list
));
447 attr_list
.bitmapcount
= ATTR_BIT_MAP_COUNT
;
448 attr_list
.commonattr
= ATTR_CMN_CRTIME
;
450 memset(&now
, 0, sizeof(now
));
451 now
.tv_sec
= time(NULL
);
453 return setattrlist(path
, &attr_list
, &now
, sizeof(now
), 0);
457 remove_directory(const char *path
)
464 if (dp
== NULL
) return 0;
466 while ((dent
= readdir(dp
)) != NULL
)
468 if ((!strcmp(dent
->d_name
, ".")) || (!strcmp(dent
->d_name
, ".."))) continue;
469 asprintf(&str
, "%s/%s", path
, dent
->d_name
);
472 filesystem_unlink(str
);
479 filesystem_rmdir(path
);
485 directory_size(const char *path
)
494 if (dp
== NULL
) return 0;
497 while ((dent
= readdir(dp
)) != NULL
)
499 if ((!strcmp(dent
->d_name
, ".")) || (!strcmp(dent
->d_name
, ".."))) continue;
501 memset(&sb
, 0, sizeof(struct stat
));
503 asprintf(&str
, "%s/%s", path
, dent
->d_name
);
505 if ((str
!= NULL
) && (stat(str
, &sb
) == 0) && S_ISREG(sb
.st_mode
))
517 parse_ymd_name(const char *name
)
521 int32_t tzh
, tzm
, sign
= -1;
525 if (name
== NULL
) return -1;
529 if ((*x
== 'T') || (*x
== 't'))
533 if ((created
== 0) && (*x
!= '0')) return -1;
536 if (x
== NULL
) return -1;
541 memset(&ftime
, 0, sizeof(ftime
));
543 if ((*x
< '0') || (*x
> '9')) return 1;
544 ftime
.tm_year
= 1000 * (*x
++ - '0');
546 if ((*x
< '0') || (*x
> '9')) return 1;
547 ftime
.tm_year
+= 100 * (*x
++ - '0');
549 if ((*x
< '0') || (*x
> '9')) return 1;
550 ftime
.tm_year
+= 10 * (*x
++ - '0');
552 if ((*x
< '0') || (*x
> '9')) return 1;
553 ftime
.tm_year
+= *x
++ - '0';
554 ftime
.tm_year
-= 1900;
563 if ((*x
< '0') || (*x
> '9')) return 1;
564 ftime
.tm_mon
= 10 * (*x
++ - '0');
566 if ((*x
< '0') || (*x
> '9')) return 1;
567 ftime
.tm_mon
+= *x
++ - '0';
570 if ((*x
== '-') || (*x
== '.')) x
++;
572 if ((*x
< '0') || (*x
> '9')) return 1;
573 ftime
.tm_mday
= 10 * (*x
++ - '0');
575 if ((*x
< '0') || (*x
> '9')) return 1;
576 ftime
.tm_mday
+= *x
++ - '0';
580 if ((*x
!= '.') && (*x
!= '\0')) return -1;
582 /* assume the file was created at midnight */
588 created
= mktime(&ftime
);
592 if ((*x
!= 'T') && (*x
!= 't')) return 1;
595 if ((*x
< '0') || (*x
> '9')) return 1;
596 ftime
.tm_hour
= 10 * (*x
++ - '0');
598 if ((*x
< '0') || (*x
> '9')) return 1;
599 ftime
.tm_hour
+= *x
++ - '0';
603 if ((*x
< '0') || (*x
> '9')) return 1;
604 ftime
.tm_min
= 10 * (*x
++ - '0');
606 if ((*x
< '0') || (*x
> '9')) return 1;
607 ftime
.tm_min
+= *x
++ - '0';
611 if ((*x
< '0') || (*x
> '9')) return 1;
612 ftime
.tm_sec
= 10 * (*x
++ - '0');
614 if ((*x
< '0') || (*x
> '9')) return 1;
615 ftime
.tm_sec
+= *x
++ - '0';
617 if ((*x
== 'Z') || (*x
== 'z'))
619 created
= timegm(&ftime
);
623 if ((*x
!= '+') && (*x
!= '-')) return 1;
625 if (*x
== '-') sign
= 1;
628 if ((*x
< '0') || (*x
> '9')) return 1;
629 tzh
= 10 * (*x
++ - '0');
631 if ((*x
< '0') || (*x
> '9')) tzh
/= 10;
632 else tzh
+= *x
++ - '0';
634 if (tzh
> 23) return 1;
637 if ((*x
== ':') || ((*x
>= '0') && (*x
<= '9')))
639 if (*x
!= ':') tzm
= 10 * (*x
- '0');
642 if ((*x
< '0') || (*x
> '9'))return -1;
645 if (tzm
> 59) return -1;
648 ftime
.tm_sec
+= (sign
* (tzh
* SECONDS_PER_HOUR
) + (tzm
* SECONDS_PER_MINUTE
));
650 if ((*x
!= '.') && (*x
!= '\0')) return -1;
652 created
= timegm(&ftime
);
658 * Determine the age (in seconds) of a YMD file from its name.
659 * Also determines UID and GID from ".Unnn.Gnnn" part of file name.
662 ymd_file_age(const char *name
, time_t now
, uid_t
*u
, gid_t
*g
)
669 if (name
== NULL
) return 0;
671 if (now
== 0) now
= time(NULL
);
673 memset(&ftime
, 0, sizeof(struct tm
));
675 created
= parse_ymd_name(name
);
676 if (created
< 0) return 0;
677 if (created
> now
) return 0;
678 seconds
= now
- created
;
683 p
= strchr(name
, 'U');
684 if (p
!= NULL
) *u
= atoi(p
+1);
690 p
= strchr(name
, 'G');
691 if (p
!= NULL
) *g
= atoi(p
+1);
699 aux_url_callback(const char *url
)
701 if (url
== NULL
) return;
702 if (!strncmp(url
, AUX_URL_MINE
, AUX_URL_MINE_LEN
)) filesystem_unlink(url
+ AUX_URL_PATH_OFFSET
);
706 ymd_file_filter(const char *name
, const char *path
, uint32_t keep_mask
, mode_t ymd_mode
, uid_t ymd_uid
, gid_t ymd_gid
)
708 asl_file_t
*f
= NULL
;
709 uint8_t km
= keep_mask
;
710 uint32_t status
, len
, dstcount
= 0;
711 char src
[MAXPATHLEN
];
712 char dst
[MAXPATHLEN
];
714 if (snprintf(src
, MAXPATHLEN
, "%s/%s", path
, name
) >= MAXPATHLEN
) return ASL_STATUS_FAILED
;
715 if (snprintf(dst
, MAXPATHLEN
, "%s/%s", path
, name
) >= MAXPATHLEN
) return ASL_STATUS_FAILED
;
716 len
= strlen(src
) - 3;
717 snprintf(dst
+ len
, 4, "tmp");
719 //TODO: check if src file is already filtered
720 debug_log(ASL_LEVEL_NOTICE
, " filter %s %s ---> %s\n", src
, keep_str(km
), dst
);
722 status
= ASL_STATUS_OK
;
726 status
= asl_file_open_read(name
, &f
);
727 if (status
!= ASL_STATUS_OK
) return status
;
729 status
= asl_file_filter_level(f
, dst
, keep_mask
, ymd_mode
, ymd_uid
, ymd_gid
, &dstcount
, aux_url_callback
);
733 filesystem_unlink(src
);
734 if ((status
!= ASL_STATUS_OK
) || (dstcount
== 0)) filesystem_unlink(dst
);
735 else filesystem_rename(dst
, src
);
741 process_asl_data_store(asl_out_dst_data_t
*dst
, asl_out_dst_data_t
*opts
)
743 time_t now
, midnight
, since_midnight
;
747 name_list_t
*ymd_list
, *bb_list
, *aux_list
, *bb_aux_list
, *e
;
748 size_t file_size
, store_size
;
760 if (dst
== NULL
) return 0;
761 if (dst
->path
== NULL
) return 0;
763 ttl
= dst
->ttl
[LEVEL_ALL
];
764 if ((opts
!= NULL
) && (opts
->ttl
[LEVEL_ALL
] > 0)) ttl
= opts
->ttl
[LEVEL_ALL
];
766 size_t all_max
= dst
->all_max
;
767 if ((opts
!= NULL
) && (opts
->all_max
> 0)) all_max
= opts
->all_max
;
769 debug_log(ASL_LEVEL_NOTICE
, "----------------------------------------\n");
770 debug_log(ASL_LEVEL_NOTICE
, "Processing data store %s\n", dst
->path
);
772 if (dst
->rotate_dir
!= NULL
)
775 memset(&sb
, 0, sizeof(struct stat
));
776 if (stat(dst
->rotate_dir
, &sb
) == 0)
778 /* must be a directory */
779 if (!S_ISDIR(sb
.st_mode
))
781 debug_log(ASL_LEVEL_ERR
, "aslmanager error: archive %s is not a directory", dst
->rotate_dir
);
789 /* archive doesn't exist - create it */
790 if (mkdir(dst
->rotate_dir
, 0755) != 0)
792 debug_log(ASL_LEVEL_ERR
, "aslmanager error: can't create archive %s: %s\n", dst
->rotate_dir
, strerror(errno
));
798 /* stat failed for some other reason */
799 debug_log(ASL_LEVEL_ERR
, "aslmanager error: can't stat archive %s: %s\n", dst
->rotate_dir
, strerror(errno
));
807 /* determine current time */
810 localtime_r(&now
, &t_tmp
);
816 midnight
= mktime(&t_tmp
);
817 since_midnight
= now
- midnight
;
819 dp
= opendir(dst
->path
);
820 if (dp
== NULL
) return -1;
822 /* gather a list of YMD files, AUX dirs, BB.AUX dirs, and BB files */
823 while ((dent
= readdir(dp
)) != NULL
)
825 uint32_t file_flags
= 0;
828 memset(&sb
, 0, sizeof(struct stat
));
830 if (stat(dent
->d_name
, &sb
) == 0) file_size
= sb
.st_size
;
832 dot
= strrchr(dent
->d_name
, '.');
833 if ((dot
!= NULL
) && !strcmp(dot
, ".gz")) file_flags
|= NAME_LIST_FLAG_COMPRESSED
;
835 if ((dent
->d_name
[0] >= '0') && (dent
->d_name
[0] <= '9'))
837 ymd_list
= add_to_name_list(ymd_list
, dent
->d_name
, file_size
, file_flags
);
838 store_size
+= file_size
;
840 else if (((dent
->d_name
[0] == 'T') || (dent
->d_name
[0] == 't')) && (dent
->d_name
[1] >= '0') && (dent
->d_name
[1] <= '9'))
842 ymd_list
= add_to_name_list(ymd_list
, dent
->d_name
, file_size
, file_flags
);
843 store_size
+= file_size
;
845 else if (!strncmp(dent
->d_name
, "AUX.", 4) && (dent
->d_name
[4] >= '0') && (dent
->d_name
[4] <= '9') && S_ISDIR(sb
.st_mode
))
847 file_size
= directory_size(dent
->d_name
);
848 aux_list
= add_to_name_list(aux_list
, dent
->d_name
, file_size
, file_flags
);
849 store_size
+= file_size
;
851 else if (!strncmp(dent
->d_name
, "BB.AUX.", 7) && (dent
->d_name
[7] >= '0') && (dent
->d_name
[7] <= '9') && S_ISDIR(sb
.st_mode
))
853 file_size
= directory_size(dent
->d_name
);
854 bb_aux_list
= add_to_name_list(bb_aux_list
, dent
->d_name
, file_size
, file_flags
);
855 store_size
+= file_size
;
857 else if (!strncmp(dent
->d_name
, "BB.", 3) && (dent
->d_name
[3] >= '0') && (dent
->d_name
[3] <= '9'))
859 bb_list
= add_to_name_list(bb_list
, dent
->d_name
, file_size
, file_flags
);
860 store_size
+= file_size
;
862 else if ((!strcmp(dent
->d_name
, ".")) || (!strcmp(dent
->d_name
, "..")))
864 else if ((!strcmp(dent
->d_name
, "StoreData")) || (!strcmp(dent
->d_name
, "SweepStore")))
866 else if (!strcmp(dent
->d_name
, ASL_INTERNAL_LOGS_DIR
))
870 debug_log(ASL_LEVEL_ERR
, "aslmanager: unexpected file %s in ASL data store\n", dent
->d_name
);
876 debug_log(ASL_LEVEL_NOTICE
, "Data Store Size = %lu\n", store_size
);
877 asl_core_time_to_str(ttl
, tstr
, sizeof(tstr
));
878 debug_log(ASL_LEVEL_NOTICE
, "Data Store YMD Files (TTL = %s)\n", tstr
);
879 for (e
= ymd_list
; e
!= NULL
; e
= e
->next
)
881 uint32_t age
= ymd_file_age(e
->name
, now
, NULL
, NULL
);
882 asl_core_time_to_str(age
, tstr
, sizeof(tstr
));
883 debug_log(ASL_LEVEL_NOTICE
, " %s %lu (age %s%s)\n", e
->name
, e
->size
, tstr
, (age
> ttl
) ? " - expired" : "");
886 debug_log(ASL_LEVEL_NOTICE
, "Data Store AUX Directories\n");
887 for (e
= aux_list
; e
!= NULL
; e
= e
->next
)
889 uint32_t age
= ymd_file_age(e
->name
+ 4, now
, NULL
, NULL
) / SECONDS_PER_DAY
;
890 asl_core_time_to_str(age
, tstr
, sizeof(tstr
));
891 debug_log(ASL_LEVEL_NOTICE
, " %s %lu (age %s)\n", e
->name
, e
->size
, tstr
, (age
> ttl
) ? " - expired" : "");
894 debug_log(ASL_LEVEL_NOTICE
, "Data Store BB.AUX Directories\n");
895 for (e
= bb_aux_list
; e
!= NULL
; e
= e
->next
)
897 uint32_t age
= ymd_file_age(e
->name
+ 7, now
, NULL
, NULL
);
898 asl_core_time_to_str(age
, tstr
, sizeof(tstr
));
899 debug_log(ASL_LEVEL_NOTICE
, " %s %lu (age %s)\n", e
->name
, e
->size
, tstr
, ((age
/ SECONDS_PER_DAY
) > 0) ? " - expired" : "");
902 debug_log(ASL_LEVEL_NOTICE
, "Data Store BB Files\n");
903 for (e
= bb_list
; e
!= NULL
; e
= e
->next
)
905 uint32_t age
= ymd_file_age(e
->name
+ 3, now
, NULL
, NULL
) / SECONDS_PER_DAY
;
906 asl_core_time_to_str(age
, tstr
, sizeof(tstr
));
907 debug_log(ASL_LEVEL_NOTICE
, " %s %lu (age %s)\n", e
->name
, e
->size
, tstr
, ((age
/ SECONDS_PER_DAY
) > 0) ? " - expired" : "");
910 /* Delete/achive expired YMD files */
911 debug_log(ASL_LEVEL_NOTICE
, "Start YMD File Scan\n");
918 uint32_t age
= ymd_file_age(e
->name
, now
, &ymd_uid
, &ymd_gid
);
922 /* file has expired, archive it if required, then unlink it */
923 if (dst
->rotate_dir
!= NULL
)
926 asprintf(&str
, "%s/%s", dst
->rotate_dir
, e
->name
);
927 if (str
== NULL
) return -1;
929 filesystem_copy(dst
, e
->name
, str
, 0);
933 filesystem_unlink(e
->name
);
934 store_size
-= e
->size
;
937 else if ((e
->flags
& NAME_LIST_FLAG_COMPRESSED
) == 0)
939 uint32_t i
, bit
, keep_mask
;
940 mode_t ymd_mode
= 0600;
942 /* check if there are any per-level TTLs and filter the file if required */
945 keep_mask
= 0x000000ff;
947 for (i
= 0; i
<= 7; i
++)
949 if ((dst
->ttl
[i
] > 0) && (age
>= dst
->ttl
[i
])) keep_mask
&= ~bit
;
953 memset(&sb
, 0, sizeof(struct stat
));
954 if (stat(e
->name
, &sb
) == 0) ymd_mode
= sb
.st_mode
& 0777;
956 if (keep_mask
!= 0x000000ff) ymd_file_filter(e
->name
, dst
->path
, keep_mask
, ymd_mode
, ymd_uid
, ymd_gid
);
959 if ((age
> since_midnight
) && (dst
->flags
& MODULE_FLAG_COMPRESS
))
961 char gzdst
[MAXPATHLEN
];
963 snprintf(gzdst
, sizeof(gzdst
), "%s.gz", e
->name
);
964 debug_log(ASL_LEVEL_NOTICE
, " compress %s ---> %s\n", e
->name
, gzdst
);
968 int status
= copy_compress_file(dst
, e
->name
, gzdst
);
971 filesystem_unlink(e
->name
);
975 debug_log(ASL_LEVEL_ERR
, " FAILED status %d errno %d [%s] compress %s ---> %s\n", status
, errno
, strerror(errno
), e
->name
, gzdst
);
985 debug_log(ASL_LEVEL_NOTICE
, "Finished YMD File Scan\n");
987 /* Delete/achive expired YMD AUX directories */
988 debug_log(ASL_LEVEL_NOTICE
, "Start AUX Directory Scan\n");
993 uint32_t age
= ymd_file_age(e
->name
+ 4, now
, NULL
, NULL
);
997 if (dst
->rotate_dir
!= NULL
)
1000 asprintf(&str
, "%s/%s", dst
->rotate_dir
, e
->name
);
1001 if (str
== NULL
) return -1;
1003 filesystem_copy(dst
, e
->name
, str
, 0);
1007 remove_directory(e
->name
);
1008 store_size
-= e
->size
;
1015 debug_log(ASL_LEVEL_NOTICE
, "Finished AUX Directory Scan\n");
1017 /* Delete/achive expired BB.AUX directories */
1018 debug_log(ASL_LEVEL_NOTICE
, "Start BB.AUX Directory Scan\n");
1023 uint32_t age
= ymd_file_age(e
->name
+ 7, now
, NULL
, NULL
);
1027 if (dst
->rotate_dir
!= NULL
)
1030 asprintf(&str
, "%s/%s", dst
->rotate_dir
, e
->name
);
1031 if (str
== NULL
) return -1;
1033 filesystem_copy(dst
, e
->name
, str
, 0);
1037 remove_directory(e
->name
);
1038 store_size
-= e
->size
;
1045 debug_log(ASL_LEVEL_NOTICE
, "Finished BB.AUX Directory Scan\n");
1047 /* Delete/achive expired BB files */
1048 debug_log(ASL_LEVEL_NOTICE
, "Start BB Scan\n");
1053 uint32_t age
= ymd_file_age(e
->name
+ 3, now
, NULL
, NULL
);
1057 if (dst
->rotate_dir
!= NULL
)
1060 asprintf(&str
, "%s/%s", dst
->rotate_dir
, e
->name
);
1061 if (str
== NULL
) return -1;
1063 /* syslog -x [str] -f [e->name] */
1064 filesystem_copy(dst
, e
->name
, str
, 0);
1068 filesystem_unlink(e
->name
);
1069 store_size
-= e
->size
;
1076 debug_log(ASL_LEVEL_NOTICE
, "Finished BB Scan\n");
1080 /* if data store is over max_size, delete/archive more YMD files */
1081 if (store_size
> all_max
) debug_log(ASL_LEVEL_NOTICE
, "Additional YMD Scan\n");
1084 while ((e
!= NULL
) && (store_size
> all_max
))
1088 uint32_t age
= ymd_file_age(e
->name
, now
, NULL
, NULL
);
1091 /* do not touch active file YYYY.MM.DD.asl */
1096 if (dst
->rotate_dir
!= NULL
)
1099 asprintf(&str
, "%s/%s", dst
->rotate_dir
, e
->name
);
1100 if (str
== NULL
) return -1;
1102 /* syslog -x [str] -f [e->name] */
1103 filesystem_copy(dst
, e
->name
, str
, 0);
1107 filesystem_unlink(e
->name
);
1108 store_size
-= e
->size
;
1115 /* if data store is over all_max, delete/archive more BB files */
1116 if (store_size
> all_max
) debug_log(ASL_LEVEL_NOTICE
, "Additional BB Scan\n");
1119 while ((e
!= NULL
) && (store_size
> all_max
))
1123 if (dst
->rotate_dir
!= NULL
)
1126 asprintf(&str
, "%s/%s", dst
->rotate_dir
, e
->name
);
1127 if (str
== NULL
) return -1;
1129 /* syslog -x [str] -f [e->name] */
1130 filesystem_copy(dst
, e
->name
, str
, 0);
1134 filesystem_unlink(e
->name
);
1135 store_size
-= e
->size
;
1143 free_name_list(ymd_list
);
1144 free_name_list(bb_list
);
1145 free_name_list(aux_list
);
1146 free_name_list(bb_aux_list
);
1148 debug_log(ASL_LEVEL_NOTICE
, "Data Store Size = %lu\n", store_size
);
1153 static asl_out_file_list_t
*
1154 _remove_youngest_activity_tracing_file(asl_out_file_list_t
*l
)
1156 asl_out_file_list_t
*f
;
1158 /* ignore youngest activity tracing file - it is the active file */
1159 if (l
->next
== NULL
)
1161 debug_log(ASL_LEVEL_INFO
, " ignore youngest (only) activity tracing file %s\n", l
->name
);
1162 asl_out_file_list_free(l
);
1166 for (f
= l
; f
->next
->next
!= NULL
; f
= f
->next
);
1167 debug_log(ASL_LEVEL_INFO
, " ignore youngest activity tracing file %s\n", f
->next
->name
);
1168 asl_out_file_list_free(f
->next
);
1173 /* move sequenced source files to dst dir, renaming as we go */
1175 module_copy_rename(asl_out_dst_data_t
*dst
)
1177 asl_out_file_list_t
*src_list
, *dst_list
, *f
;
1179 char fpathsrc
[MAXPATHLEN
], fpathdst
[MAXPATHLEN
];
1180 uint32_t src_count
, dst_count
;
1183 if (dst
== NULL
) return -1;
1184 if (dst
->path
== NULL
) return -1;
1186 src_list
= asl_list_src_files(dst
);
1189 * Note: the unmarked file (e.g. system.log) is included in src_list.
1190 * If it is from a MODULE_FLAG_EXTERNAL dst and it is less than 24 hours old,
1191 * we ignore it. If it is not external, we also ignore it since syslogd will
1192 * checkpoint it to create system.log.Tnnnnnnnnnn.
1194 if ((src_list
!= NULL
) && (src_list
->stamp
== STAMP_STYLE_NULL
))
1196 bool ignore_it
= false;
1198 if (dst
->flags
& MODULE_FLAG_EXTERNAL
)
1200 if ((time(NULL
) - src_list
->ftime
) < SECONDS_PER_DAY
)
1202 debug_log(ASL_LEVEL_INFO
, " ignore src file %s since it is external and less than a day old\n", src_list
->name
);
1208 debug_log(ASL_LEVEL_INFO
, " ignore src file %s since it is internal and syslogd will checkpoint it when it needs to be renamed\n", src_list
->name
);
1214 asl_out_file_list_t
*first
= src_list
;
1215 src_list
= src_list
->next
;
1217 asl_out_file_list_free(first
);
1221 if (src_list
== NULL
)
1223 debug_log(ASL_LEVEL_INFO
, " no src files\n");
1227 debug_log(ASL_LEVEL_INFO
, " src files\n");
1230 for (f
= src_list
; f
!= NULL
; f
= f
->next
)
1232 debug_log(ASL_LEVEL_INFO
, " %s\n", f
->name
);
1236 dst_list
= asl_list_dst_files(dst
);
1238 if ((dst_list
!= NULL
) && (dst
->flags
& MODULE_FLAG_ACTIVITY
))
1240 dst_list
= _remove_youngest_activity_tracing_file(dst_list
);
1243 dst_dir
= dst
->rotate_dir
;
1244 if (dst_dir
== NULL
) dst_dir
= dst
->dir
;
1248 if (dst_list
== NULL
) debug_log(ASL_LEVEL_INFO
, " no dst files\n");
1249 else debug_log(ASL_LEVEL_INFO
, " dst files\n");
1251 for (f
= dst_list
; f
!= NULL
; f
= f
->next
)
1253 debug_log(ASL_LEVEL_INFO
, " %s\n", f
->name
);
1257 if (dst
->style_flags
& MODULE_NAME_STYLE_STAMP_SEQ
)
1259 for (f
= dst_list
; f
!= NULL
; f
= f
->next
)
1262 char *dot
= strrchr(f
->name
, '.');
1263 if ((dot
!= NULL
) && (!strcmp(dot
, ".gz"))) is_gz
= 1;
1265 snprintf(fpathsrc
, sizeof(fpathsrc
), "%s/%s", dst_dir
, f
->name
);
1267 if (dst
->style_flags
& MODULE_NAME_STYLE_FORMAT_BS
)
1269 snprintf(fpathdst
, sizeof(fpathdst
), "%s/%s.%d%s", dst_dir
, dst
->base
, f
->seq
+src_count
, (is_gz
== 1) ? ".gz" : "");
1271 else if (dst
->style_flags
& MODULE_NAME_STYLE_FORMAT_BES
)
1273 snprintf(fpathdst
, sizeof(fpathdst
), "%s/%s.%s.%d%s", dst_dir
, dst
->base
, dst
->ext
, f
->seq
+src_count
, (is_gz
== 1) ? ".gz" : "");
1275 else if (dst
->style_flags
& MODULE_NAME_STYLE_FORMAT_BSE
)
1277 snprintf(fpathdst
, sizeof(fpathdst
), "%s/%s.%d.%s%s", dst_dir
, dst
->base
, f
->seq
+src_count
, dst
->ext
, (is_gz
== 1) ? ".gz" : "");
1280 filesystem_rename(fpathsrc
, fpathdst
);
1283 for (f
= src_list
, x
= 0; f
!= NULL
; f
= f
->next
, x
++)
1285 snprintf(fpathsrc
, sizeof(fpathsrc
), "%s/%s", dst
->dir
, f
->name
);
1287 if (dst
->style_flags
& MODULE_NAME_STYLE_FORMAT_BS
)
1289 snprintf(fpathdst
, sizeof(fpathdst
), "%s/%s.%d", dst_dir
, dst
->base
, x
);
1291 else if (dst
->style_flags
& MODULE_NAME_STYLE_FORMAT_BES
)
1293 snprintf(fpathdst
, sizeof(fpathdst
), "%s/%s.%s.%d", dst_dir
, dst
->base
, dst
->ext
, x
);
1295 else if (dst
->style_flags
& MODULE_NAME_STYLE_FORMAT_BSE
)
1297 snprintf(fpathdst
, sizeof(fpathdst
), "%s/%s.%d.%s", dst_dir
, dst
->base
, x
, dst
->ext
);
1300 moved
= filesystem_copy(dst
, fpathsrc
, fpathdst
, dst
->flags
);
1303 if (dst
->flags
& MODULE_FLAG_TRUNCATE
)
1305 filesystem_truncate(fpathsrc
);
1306 filesystem_reset_ctime(fpathsrc
);
1310 filesystem_unlink(fpathsrc
);
1317 for (f
= src_list
; f
!= NULL
; f
= f
->next
)
1319 /* final / active base stamped file looks like a checkpointed file - ignore it */
1320 if ((dst
->flags
& MODULE_FLAG_BASESTAMP
) && (f
->next
== NULL
)) break;
1322 snprintf(fpathsrc
, sizeof(fpathsrc
), "%s/%s", dst
->dir
, f
->name
);
1324 /* MODULE_FLAG_EXTERNAL files are not decorated with a timestamp */
1325 if (dst
->flags
& MODULE_FLAG_EXTERNAL
)
1329 asl_make_timestamp(f
->ftime
, dst
->style_flags
, tstamp
, sizeof(tstamp
));
1331 if (dst
->style_flags
& MODULE_NAME_STYLE_FORMAT_BS
)
1333 snprintf(fpathdst
, sizeof(fpathdst
), "%s/%s.%s", dst_dir
, dst
->base
, tstamp
);
1335 else if (dst
->style_flags
& MODULE_NAME_STYLE_FORMAT_BES
)
1337 snprintf(fpathdst
, sizeof(fpathdst
), "%s/%s.%s.%s", dst_dir
, dst
->base
, dst
->ext
, tstamp
);
1339 else if (dst
->style_flags
& MODULE_NAME_STYLE_FORMAT_BSE
)
1341 snprintf(fpathdst
, sizeof(fpathdst
), "%s/%s.%s.%s", dst_dir
, dst
->base
, tstamp
, dst
->ext
);
1347 snprintf(fpathdst
, sizeof(fpathdst
), "%s/%s", dst_dir
, f
->name
);
1350 moved
= filesystem_copy(dst
, fpathsrc
, fpathdst
, dst
->flags
);
1353 if (dst
->flags
& MODULE_FLAG_TRUNCATE
) filesystem_truncate(fpathsrc
);
1354 else filesystem_unlink(fpathsrc
);
1359 asl_out_file_list_free(src_list
);
1360 asl_out_file_list_free(dst_list
);
1365 /* delete expired files */
1367 module_expire(asl_out_dst_data_t
*dst
, asl_out_dst_data_t
*opts
)
1369 asl_out_file_list_t
*dst_list
, *f
;
1370 char *base
, *dst_dir
, fpath
[MAXPATHLEN
];
1371 time_t now
, ttl
, age
;
1373 if (dst
== NULL
) return -1;
1374 if (dst
->path
== NULL
) return -1;
1375 if (dst
->ttl
[LEVEL_ALL
] == 0) return 0;
1377 ttl
= dst
->ttl
[LEVEL_ALL
];
1378 if ((opts
!= NULL
) && (opts
->ttl
[LEVEL_ALL
] > 0)) ttl
= opts
->ttl
[LEVEL_ALL
];
1381 if (ttl
> now
) return 0;
1383 base
= strrchr(dst
->path
, '/');
1384 if (base
== NULL
) return -1;
1386 dst_list
= asl_list_dst_files(dst
);
1388 if ((dst_list
!= NULL
) && (dst
->flags
& MODULE_FLAG_ACTIVITY
))
1390 dst_list
= _remove_youngest_activity_tracing_file(dst_list
);
1395 dst_dir
= dst
->rotate_dir
;
1396 if (dst_dir
== NULL
) dst_dir
= dst
->dir
;
1398 if (dst_list
== NULL
)
1400 debug_log(ASL_LEVEL_INFO
, " no dst files\n");
1404 debug_log(ASL_LEVEL_INFO
, " dst files\n");
1405 for (f
= dst_list
; f
!= NULL
; f
= f
->next
)
1408 age
= now
- f
->ftime
;
1410 asl_core_time_to_str(age
, tstr
, sizeof(tstr
));
1411 debug_log(ASL_LEVEL_INFO
, " %s (age %s%s)\n", f
->name
, tstr
, (age
> ttl
) ? " - expired" : "");
1415 for (f
= dst_list
; f
!= NULL
; f
= f
->next
)
1417 age
= now
- f
->ftime
;
1420 snprintf(fpath
, sizeof(fpath
), "%s/%s", dst_dir
, f
->name
);
1421 filesystem_unlink(fpath
);
1425 asl_out_file_list_free(dst_list
);
1427 if (base
!= NULL
) *base
= '/';
1433 * Check all_max size and delete files (oldest first) to stay within size limit.
1434 * If query is true, then just report total size.
1437 module_check_size(asl_out_dst_data_t
*dst
, asl_out_dst_data_t
*opts
, bool query
, size_t *msize
)
1439 asl_out_file_list_t
*dst_list
, *f
, *dst_end
;
1440 char *dst_dir
, fpath
[MAXPATHLEN
];
1443 size_t all_max
= dst
->all_max
;
1444 if ((opts
!= NULL
) && (opts
->all_max
> 0)) all_max
= opts
->all_max
;
1446 if (dst
== NULL
) return -1;
1447 if (dst
->path
== NULL
) return -1;
1449 if (all_max
== 0) return 0;
1451 dst_list
= asl_list_dst_files(dst
);
1453 if ((dst_list
!= NULL
) && (dst
->flags
& MODULE_FLAG_ACTIVITY
))
1455 dst_list
= _remove_youngest_activity_tracing_file(dst_list
);
1458 if (dst_list
== NULL
)
1460 debug_log(ASL_LEVEL_INFO
, " no dst files\n");
1464 dst_dir
= dst
->rotate_dir
;
1465 if (dst_dir
== NULL
) dst_dir
= dst
->dir
;
1467 debug_log(ASL_LEVEL_INFO
, " dst files\n");
1469 for (f
= dst_list
; f
!= NULL
; f
= f
->next
)
1472 debug_log(ASL_LEVEL_INFO
, " %s size %lu\n", f
->name
, f
->size
);
1476 for (f
= dst_list
; f
!= NULL
; f
= f
->next
) total
+= f
->size
;
1480 for (f
= dst_list
; (total
> all_max
) && (f
!= NULL
); f
= f
->next
)
1482 snprintf(fpath
, sizeof(fpath
), "%s/%s", dst_dir
, f
->name
);
1483 filesystem_unlink(fpath
);
1488 if (msize
!= NULL
) *msize
= total
;
1490 asl_out_file_list_free(dst_list
);
1496 process_dst(asl_out_dst_data_t
*dst
, asl_out_dst_data_t
*opts
)
1498 uint32_t ttl
= dst
->ttl
[LEVEL_ALL
];
1499 if ((opts
!= NULL
) && (opts
->ttl
[LEVEL_ALL
] > 0)) ttl
= opts
->ttl
[LEVEL_ALL
];
1501 size_t all_max
= dst
->all_max
;
1502 if ((opts
!= NULL
) && (opts
->all_max
> 0)) all_max
= opts
->all_max
;
1506 debug_log(ASL_LEVEL_NOTICE
, "NULL dst data for output rule - skipped\n");
1508 else if (dst
->flags
& MODULE_FLAG_ROTATE
)
1510 debug_log(ASL_LEVEL_NOTICE
, "Checking file %s\n", dst
->path
);
1511 debug_log(ASL_LEVEL_NOTICE
, "- Rename, move to destination directory, and compress as required\n");
1513 module_copy_rename(dst
);
1519 asl_core_time_to_str(ttl
, tstr
, sizeof(tstr
));
1520 debug_log(ASL_LEVEL_NOTICE
, "- Check for expired files - TTL = %s\n", tstr
);
1521 module_expire(dst
, opts
);
1526 debug_log(ASL_LEVEL_NOTICE
, "- Check total storage used - MAX = %lu\n", all_max
);
1527 module_check_size(dst
, opts
, false, NULL
);
1530 else if ((dst
->flags
& MODULE_FLAG_TYPE_ASL_DIR
) && (ttl
> 0))
1532 process_asl_data_store(dst
, opts
);
1539 process_module(asl_out_module_t
*mod
, asl_out_dst_data_t
*opts
)
1544 if (mod
== NULL
) return -1;
1546 if (opts
!= NULL
) flags
= opts
->flags
;
1548 debug_log(ASL_LEVEL_NOTICE
, "----------------------------------------\n");
1549 debug_log(ASL_LEVEL_NOTICE
, "Processing module %s\n", (mod
->name
== NULL
) ? "asl.conf" : mod
->name
);
1551 for (r
= mod
->ruleset
; r
!= NULL
; r
= r
->next
)
1553 if (r
->action
== ACTION_OUT_DEST
)
1555 if ((flags
== 0) || ((flags
& r
->dst
->flags
) != 0)) process_dst(r
->dst
, opts
);
1559 debug_log(ASL_LEVEL_NOTICE
, "Finished processing module %s\n", (mod
->name
== NULL
) ? "asl.conf" : mod
->name
);
1564 cache_delete_task(bool query
, size_t *size
)
1566 dispatch_sync(work_queue
, ^{
1567 asl_out_module_t
*mod
, *m
;
1568 asl_out_dst_data_t opts
;
1569 size_t total_size
= 0;
1571 memset(&opts
, 0, sizeof(opts
));
1572 if ((!query
) && (size
!= NULL
)) opts
.all_max
= *size
;
1574 debug_log(ASL_LEVEL_NOTICE
, "cache_delete_process%s size %lu\n", query
? " query" : "", opts
.all_max
);
1576 mod
= asl_out_module_init();
1578 for (m
= mod
; m
!= NULL
; m
= m
->next
)
1580 bool logged
= false;
1583 for (r
= m
->ruleset
; r
!= NULL
; r
= r
->next
)
1585 if (r
->action
== ACTION_OUT_DEST
)
1587 if (r
->dst
->flags
& MODULE_FLAG_ACTIVITY
)
1591 debug_log(ASL_LEVEL_NOTICE
, "----------------------------------------\n");
1592 debug_log(ASL_LEVEL_NOTICE
, "Processing activity module %s\n", (m
->name
== NULL
) ? "asl.conf" : m
->name
);
1597 module_check_size(r
->dst
, &opts
, false, &dsize
);
1598 total_size
+= dsize
;
1603 if (logged
) debug_log(ASL_LEVEL_NOTICE
, "Finished processing activity module %s\n", (m
->name
== NULL
) ? "asl.conf" : m
->name
);
1606 asl_out_module_free(mod
);
1608 if (size
!= NULL
) *size
= total_size
;
1615 control_query(asl_msg_t
*a
)
1617 asl_msg_list_t
*out
;
1618 char *qstr
, *str
, *res
;
1619 uint32_t len
, reslen
, status
;
1620 uint64_t cmax
, qmin
;
1621 kern_return_t kstatus
;
1623 security_token_t sec
;
1625 if (asl_server_port
== MACH_PORT_NULL
)
1627 kstatus
= bootstrap_look_up2(bootstrap_port
, ASL_SERVICE_NAME
, &asl_server_port
, 0, BOOTSTRAP_PRIVILEGED_SERVER
);
1628 if (asl_server_port
== MACH_PORT_NULL
) return NULL
;
1631 qstr
= asl_msg_to_string((asl_msg_t
*)a
, &len
);
1636 asprintf(&str
, "1\nQ [= ASLOption control]\n");
1640 asprintf(&str
, "1\n%s [= ASLOption control]\n", qstr
);
1644 if (str
== NULL
) return NULL
;
1646 /* length includes trailing nul */
1647 len
= strlen(str
) + 1;
1656 status
= ASL_STATUS_OK
;
1658 kstatus
= vm_allocate(mach_task_self(), (vm_address_t
*)&vmstr
, len
, VM_FLAGS_ANYWHERE
| VM_MAKE_TAG(VM_MEMORY_ASL
));
1659 if (kstatus
!= KERN_SUCCESS
) return NULL
;
1661 memmove(vmstr
, str
, len
);
1665 kstatus
= _asl_server_query(asl_server_port
, vmstr
, len
, qmin
, 1, 0, (caddr_t
*)&res
, &reslen
, &cmax
, (int *)&status
, &sec
);
1666 if (kstatus
!= KERN_SUCCESS
) return NULL
;
1668 if (res
== NULL
) return NULL
;
1670 out
= asl_msg_list_from_string(res
);
1671 vm_deallocate(mach_task_self(), (vm_address_t
)res
, reslen
);
1677 checkpoint(const char *name
)
1679 /* send checkpoint message to syslogd */
1680 debug_log(ASL_LEVEL_NOTICE
, "Checkpoint module %s\n", (name
== NULL
) ? "*" : name
);
1681 if (dryrun
) return 0;
1683 asl_msg_t
*qmsg
= asl_msg_new(ASL_TYPE_QUERY
);
1685 asl_msg_list_t
*res
;
1687 asprintf(&tmp
, "%s checkpoint", (name
== NULL
) ? "*" : name
);
1688 asl_msg_set_key_val_op(qmsg
, "action", tmp
, ASL_QUERY_OP_EQUAL
);
1691 res
= control_query(qmsg
);
1693 asl_msg_list_release(res
);