]> git.saurik.com Git - apple/launchd.git/blob - launchd/testing/loginwindow_helper_code.c
launchd-152.tar.gz
[apple/launchd.git] / launchd / testing / loginwindow_helper_code.c
1 #include <mach/port.h>
2 #include <servers/bootstrap.h>
3 #include <unistd.h>
4 #include <launch.h>
5 #include <launch_priv.h>
6 #include <string.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <stdbool.h>
11
12 int main(void)
13 {
14 mach_port_t oldbsport = bootstrap_port;
15 pid_t p;
16
17 if (getuid() != 0) {
18 fprintf(stderr, "This test tool must be run as root.\n");
19 exit(EXIT_FAILURE);
20 }
21
22 p = create_and_switch_to_per_session_launchd("www");
23
24 if (p > 0) {
25 fprintf(stdout, "Our PID: %d\n", getpid());
26 fprintf(stdout, "Per session launchd PID: %d\n", p);
27 fprintf(stdout, "Old bootstrap port: 0x%x\n", oldbsport);
28 fprintf(stdout, "New bootstrap port: 0x%x\n", bootstrap_port);
29 for (;;) {
30 pause();
31 }
32 } else if (p == -1) {
33 fprintf(stderr, "create_and_switch_to_per_session_launchd() failed: %s\n", strerror(errno));
34 } else if (p == 0) {
35 fprintf(stderr, "create_and_switch_to_per_session_launchd() returned zero?!?\n");
36 }
37 exit(EXIT_FAILURE);
38 }