]> git.saurik.com Git - apple/system_cmds.git/blame - bootlog.tproj/bootlog.c
system_cmds-498.2.tar.gz
[apple/system_cmds.git] / bootlog.tproj / bootlog.c
CommitLineData
34d340d7
A
1/*
2 * Copyright (c) 2006 Apple Computer, 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 OR NON-INFRINGEMENT. Please see the
18 * License for the specific language governing rights and limitations
19 * under the License."
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#include <string.h>
25#include <sys/types.h>
26#include <sys/socket.h>
27#include <sys/sysctl.h>
28#include <sys/time.h>
29#include <sys/un.h>
30#include <fcntl.h>
31#include <stdlib.h>
32#include <unistd.h>
33#include <utmpx.h>
34
35#define _PATH_ASL_IN "/var/run/asl_input"
36
37#define REPEAT 100
38#define SLEEP 2
39
40static void
41asl_running(void)
42{
43 int sock, i;
44 struct sockaddr_un server;
45 socklen_t len;
46 int status;
47
48 sock = socket(AF_UNIX, SOCK_STREAM, 0);
49 if (sock < 0)
50 exit(1);
51
52 memset(&server, 0, sizeof(struct sockaddr_un));
53 server.sun_family = AF_UNIX;
54
55 strcpy(server.sun_path, _PATH_ASL_IN);
56 server.sun_len = strlen(server.sun_path) + 1;
57 len = sizeof(server.sun_len) + sizeof(server.sun_family) + server.sun_len;
58
59 i = REPEAT;
60 for(;;) {
61 status = connect(sock, (const struct sockaddr *)&server, len);
62 if (status >= 0)
63 break;
64 if(--i <= 0)
65 exit(1);
66 sleep(SLEEP);
67 }
68
69 close(sock);
70}
71
72int
73main()
74{
75 int mib[2] = {CTL_KERN, KERN_BOOTTIME};
76 struct utmpx utx;
77 size_t len;
78
79 bzero(&utx, sizeof(utx));
80 utx.ut_type = BOOT_TIME;
ef8ad44b 81 utx.ut_pid = 1; // on behalf of launchd
34d340d7
A
82
83 /* get the boot time */
84 len = sizeof(struct timeval);
85 if(sysctl(mib, 2, &utx.ut_tv, &len, NULL, 0) < 0)
86 gettimeofday(&utx.ut_tv, NULL); /* fallback to now */
87
88 /* wait for asl before logging */
89 asl_running();
90 pututxline(&utx);
91 return 0;
92}