/* * kern_return_t * bootstrap_status(mach_port_t bootstrap_port, * name_t service_name, * bootstrap_status_t *service_active); * * Returns: service_active indicates if service is available. * * Errors: Returns appropriate kernel errors on rpc failure. * Returns BOOTSTRAP_UNKNOWN_SERVICE, if service does not exist. */ kern_return_t x_bootstrap_status( mach_port_t bootstrap_port, name_t service_name, bootstrap_status_t *service_active) { service_t *servicep; bootstrap_info_t *bootstrap; bootstrap = lookup_bootstrap_by_port(bootstrap_port); servicep = lookup_service_by_name(bootstrap, service_name); if (servicep == NULL) { if (forward_ok) { debug("bootstrap_status forwarding status, server %s", service_name); return bootstrap_status(inherited_bootstrap_port, service_name, service_active); } else { debug("bootstrap_status service %s unknown", service_name); return BOOTSTRAP_UNKNOWN_SERVICE; } } *service_active = bsstatus(servicep); debug("bootstrap_status server %s %sactive", service_name, servicep->isActive ? "" : "in"); return BOOTSTRAP_SUCCESS; }
/* Radar 6386278 New launchd api is npot on embedded yet */ int ppp_mach_start_server() { boolean_t active; kern_return_t status; CFRunLoopSourceRef rls; active = FALSE; status = bootstrap_status(bootstrap_port, PPPCONTROLLER_SERVER, &active); switch (status) { case BOOTSTRAP_SUCCESS: if (active) { fprintf(stderr, "\"%s\" is currently active.\n", PPPCONTROLLER_SERVER); return -1; } break; case BOOTSTRAP_UNKNOWN_SERVICE: break; default: fprintf(stderr, "bootstrap_status(): %s\n", mach_error_string(status)); return -1; } gServer_cfport = CFMachPortCreate(NULL, server_handle_request, NULL, NULL); rls = CFMachPortCreateRunLoopSource(NULL, gServer_cfport, 0); gControllerRunloop = CFRunLoopGetCurrent(); CFRunLoopAddSource(gControllerRunloop, rls, kCFRunLoopDefaultMode); CFRunLoopAddSource(gControllerRunloop, gTerminalrls, kCFRunLoopDefaultMode); CFRelease(rls); status = bootstrap_register(bootstrap_port, PPPCONTROLLER_SERVER, CFMachPortGetPort(gServer_cfport)); if (status != BOOTSTRAP_SUCCESS) { mach_error("bootstrap_register", status); return -1; } return 0; }
int main(int argc, char **argv) { extern int optind; extern char *optarg; #ifdef __OPENSTEP__ extern int getopt(int argc, char **argv, char *optstring); #endif int c; int bflag = 0, hflag = 0, pflag = 0, eflag = 0, dflag = 0; int sflag = 0; int errflag = 0; char *ofile = "gmon.out"; char *dylib; port_t server_port; port_t control_port; enum profile_state state; enum request_type request = -1, control_request = -1; char gmon_file[MAXPATHLEN]; boolean_t profile_active, control_active; enum result_code result; kern_return_t ret; progname = argv[0]; if (argc == 1) { usage(); exit(2); } while ((c = getopt(argc, argv, "crbhpo:eds")) != EOF) switch (c) { case 'c': request = NSCreateProfileBufferForLibrary; break; case 'r': request = NSRemoveProfileBufferForLibrary; break; case 'b': bflag = 1; request = NSStartProfilingForLibrary; break; case 'h': hflag = 1; request = NSStopProfilingForLibrary; break; case 'p': request = NSBufferFileForLibrary, pflag = 1; break; case 'o': ofile = optarg; break; case 'e': eflag = 1; control_request = NSEnableProfiling; break; case 'd': dflag = 1; control_request = NSDisableProfiling; break; case 's': sflag = 1; break; default: errflag = 1; break; } if (dflag && eflag) { fprintf(stderr, "You must specify only one of -d and -e.\n"); usage(); exit(2); } if (bflag && hflag) { fprintf(stderr, "You must specify only one of -b and -h.\n"); usage(); exit(2); } if (errflag || (!(dflag || eflag || sflag) && optind >= argc)) { usage(); exit(2); } dylib = argv[optind]; if (bootstrap_look_up(bootstrap_port, PROFILE_SERVER_NAME, &server_port) != BOOTSTRAP_SUCCESS || bootstrap_status(bootstrap_port, PROFILE_SERVER_NAME, &profile_active) != BOOTSTRAP_SUCCESS) { fprintf(stderr, "%s: couldn't locate profile server port\n",progname); exit(3); } if (bootstrap_look_up(bootstrap_port, PROFILE_CONTROL_NAME, &control_port) != BOOTSTRAP_SUCCESS || bootstrap_status(bootstrap_port, PROFILE_CONTROL_NAME, &control_active) != BOOTSTRAP_SUCCESS) { fprintf(stderr, "%s: couldn't locate profile control port\n",progname); exit(3); } if (sflag) { if (!control_active) { printf("Profiling service not found\n"); exit(0); } if (!profile_active) { printf("Profiling service not enabled\n"); exit(0); } print_status(server_port); exit(0); } *gmon_file = '\0'; if (dflag || eflag) { if (!control_active) { fprintf(stderr, "%s: profile server isn't running\n", progname); exit(3); } if ((ret = send_request(control_port, control_request, "", &state, &result, gmon_file)) != KERN_SUCCESS) { fprintf(stderr, "%s: msg_send failed: %s", progname, mach_error_string(ret)); exit(3); } if (result != NSSuccess) { profile_error(control_request, dylib, result); exit(3); } exit(0); } if (request != -1) { if (!profile_active) { fprintf(stderr, "%s: profile server isn't active.\n", progname); fprintf(stderr, "Use '%s -e' to enable it.\n", progname); exit(3); } if ((ret = send_request(server_port, request, dylib, &state, &result, gmon_file)) != KERN_SUCCESS) { fprintf(stderr, "%s: msg_send failed: %s\n", progname, mach_error_string(ret)); exit(3); } if (result != NSSuccess) { profile_error(request, dylib, result); exit(3); } } if (pflag) { if (*gmon_file == '\0' || state == NSBufferNotCreated) { fprintf(stderr, "%s: dylib %s not found\n",progname,dylib); exit(1); } errflag = copy_file(gmon_file, ofile); if (errflag) { fprintf(stderr,"%s: couldn't write to %s\n", progname, ofile); exit(errflag); } } exit(0); }