8 void print_mach_service(launch_data_t obj
, const char *key
, void *context
)
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);
15 fprintf(stdout
, "%s: not a mach port\n", key
);
21 launch_data_t resp
, tmp
, msg
= launch_data_new_string(LAUNCH_KEY_CHECKIN
);
23 resp
= launch_msg(msg
);
26 fprintf(stderr
, "launch_msg(): %s\n", strerror(errno
));
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
));
36 tmp
= launch_data_dict_lookup(resp
, LAUNCH_JOBKEY_MACHSERVICES
);
39 fprintf(stderr
, "no mach services found!\n");
43 launch_data_dict_iterate(tmp
, print_mach_service
, NULL
);