Last active
August 29, 2015 13:58
-
-
Save danzimm/9967725 to your computer and use it in GitHub Desktop.
List the mach services on your computer, or at least all the ones up the default bootstrap chain!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <mach/mach.h> | |
#include <bootstrap_priv.h> | |
#include <stdlib.h> | |
void error(int a, int r, const char *str) { | |
const char *err = bootstrap_strerror(r); | |
fprintf(stderr, "%s (%#02x) %s\n", str, r, err); | |
exit(a); | |
} | |
void list_services(mach_port_t bp) { | |
mach_port_array_t children = NULL; | |
name_array_t names = NULL; | |
bootstrap_property_array_t props = NULL; | |
mach_msg_type_number_t nchild = 0; | |
int i = 0; | |
int ret = bootstrap_lookup_children(bp, &children, &names, &props, &nchild); | |
if (ret && ret != BOOTSTRAP_NO_CHILDREN) | |
error(1,ret,"bootstrap_lookup_children"); | |
printf("Got %d children!\n", nchild); | |
for (i = 0; i < nchild; i++) { | |
printf("Found service: %s\n", names[i]); | |
} | |
} | |
int main(int argc, const char *argv[]) { | |
mach_port_t bp = bootstrap_port, tmp = MACH_PORT_NULL; | |
while (bp != tmp) { | |
if (tmp) | |
puts("Looking at parent"); | |
list_services(bp); | |
tmp = bp; | |
bootstrap_parent(bp, &bp); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment