]>
Commit | Line | Data |
---|---|---|
ed34e3c3 A |
1 | #include <launch.h> |
2 | #include <unistd.h> | |
3 | #include <stdio.h> | |
4 | #include <stdlib.h> | |
5 | #include <string.h> | |
6 | #include <errno.h> | |
7 | ||
8 | void print_mach_service(launch_data_t obj, const char *key, void *context) | |
9 | { | |
10 | if (launch_data_get_type(obj) == LAUNCH_DATA_MACHPORT) { | |
11 | fprintf(stdout, "%s: %d\n", key, launch_data_get_machport(obj)); | |
12 | mach_port_deallocate(mach_task_self(), launch_data_get_machport(obj)); | |
13 | mach_port_mod_refs(mach_task_self(), launch_data_get_machport(obj), MACH_PORT_RIGHT_RECEIVE, -1); | |
14 | } else { | |
15 | fprintf(stdout, "%s: not a mach port\n", key); | |
16 | } | |
17 | } | |
18 | ||
19 | int main(void) | |
20 | { | |
21 | launch_data_t resp, tmp, msg = launch_data_new_string(LAUNCH_KEY_CHECKIN); | |
22 | ||
23 | resp = launch_msg(msg); | |
24 | ||
25 | if (resp == NULL) { | |
26 | fprintf(stderr, "launch_msg(): %s\n", strerror(errno)); | |
27 | exit(EXIT_FAILURE); | |
28 | } | |
29 | ||
30 | if (launch_data_get_type(resp) == LAUNCH_DATA_ERRNO) { | |
31 | errno = launch_data_get_errno(resp); | |
32 | fprintf(stderr, "launch_msg() response: %s\n", strerror(errno)); | |
33 | exit(EXIT_FAILURE); | |
34 | } | |
35 | ||
36 | tmp = launch_data_dict_lookup(resp, LAUNCH_JOBKEY_MACHSERVICES); | |
37 | ||
38 | if (tmp == NULL) { | |
39 | fprintf(stderr, "no mach services found!\n"); | |
40 | exit(EXIT_FAILURE); | |
41 | } | |
42 | ||
43 | launch_data_dict_iterate(tmp, print_mach_service, NULL); | |
44 | ||
45 | sleep(1); | |
46 | exit(EXIT_SUCCESS); | |
47 | } |