static inline void test_no_stop(void) { SC_HANDLE service_handle = register_service("no_stop"); SERVICE_STATUS status; BOOL res; if(!service_handle) return; trace("starting...\n"); res = StartServiceA(service_handle, 0, NULL); ok(res, "StartService failed: %u\n", GetLastError()); if(!res) { DeleteService(service_handle); return; } expect_event("RUNNING"); /* Let service thread terminate */ Sleep(1000); res = QueryServiceStatus(service_handle, &status); ok(res, "QueryServiceStatus failed: %d\n", GetLastError()); todo_wine ok(status.dwServiceType == SERVICE_WIN32_OWN_PROCESS, "status.dwServiceType = %x\n", status.dwServiceType); ok(status.dwCurrentState == SERVICE_RUNNING, "status.dwCurrentState = %x\n", status.dwCurrentState); ok(status.dwControlsAccepted == (SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN), "status.dwControlsAccepted = %x\n", status.dwControlsAccepted); ok(status.dwWin32ExitCode == 0, "status.dwExitCode = %d\n", status.dwWin32ExitCode); ok(status.dwServiceSpecificExitCode == 0, "status.dwServiceSpecificExitCode = %d\n", status.dwServiceSpecificExitCode); ok(status.dwCheckPoint == 0, "status.dwCheckPoint = %d\n", status.dwCheckPoint); todo_wine ok(status.dwWaitHint == 0, "status.dwWaitHint = %d\n", status.dwWaitHint); res = ControlService(service_handle, SERVICE_CONTROL_STOP, &status); ok(res, "ControlService failed: %u\n", GetLastError()); expect_event("STOP"); res = QueryServiceStatus(service_handle, &status); ok(res, "QueryServiceStatus failed: %d\n", GetLastError()); todo_wine ok(status.dwServiceType == SERVICE_WIN32_OWN_PROCESS, "status.dwServiceType = %x\n", status.dwServiceType); ok(status.dwCurrentState==SERVICE_STOPPED || status.dwCurrentState==SERVICE_STOP_PENDING, "status.dwCurrentState = %x\n", status.dwCurrentState); ok(status.dwControlsAccepted == 0, "status.dwControlsAccepted = %x\n", status.dwControlsAccepted); ok(status.dwWin32ExitCode == 0, "status.dwExitCode = %d\n", status.dwWin32ExitCode); ok(status.dwServiceSpecificExitCode == 0, "status.dwServiceSpecificExitCode = %d\n", status.dwServiceSpecificExitCode); ok(status.dwCheckPoint == 0, "status.dwCheckPoint = %d\n", status.dwCheckPoint); ok(status.dwWaitHint == 0, "status.dwWaitHint = %d\n", status.dwWaitHint); res = DeleteService(service_handle); ok(res, "DeleteService failed: %u\n", GetLastError()); res = QueryServiceStatus(service_handle, &status); ok(res, "QueryServiceStatus failed: %d\n", GetLastError()); todo_wine ok(status.dwServiceType == SERVICE_WIN32_OWN_PROCESS, "status.dwServiceType = %x\n", status.dwServiceType); ok(status.dwCurrentState==SERVICE_STOPPED || status.dwCurrentState==SERVICE_STOP_PENDING, "status.dwCurrentState = %x\n", status.dwCurrentState); ok(status.dwControlsAccepted == 0, "status.dwControlsAccepted = %x\n", status.dwControlsAccepted); ok(status.dwWin32ExitCode == 0, "status.dwExitCode = %d\n", status.dwWin32ExitCode); ok(status.dwServiceSpecificExitCode == 0, "status.dwServiceSpecificExitCode = %d\n", status.dwServiceSpecificExitCode); ok(status.dwCheckPoint == 0, "status.dwCheckPoint = %d\n", status.dwCheckPoint); ok(status.dwWaitHint == 0, "status.dwWaitHint = %d\n", status.dwWaitHint); CloseServiceHandle(service_handle); res = QueryServiceStatus(service_handle, &status); ok(!res, "QueryServiceStatus should have failed\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError = %d\n", GetLastError()); }
int main(int ac, char *av[]) { char *p = NULL; kern_return_t kr = KERN_FAILURE; long n; int ch; mach_msg_header_t hdr; while ((ch = getopt(ac, av, "dt:")) != -1) switch (ch) { case 'd': opt_debug = 1; break; case 't': n = strtol(optarg, &p, 0); if ('\0' == optarg[0] || '\0' != *p || n > LONG_MAX || n < 0) { fprintf(stderr, "Invalid idle timeout: %s\n", optarg); exit(EXIT_FAILURE); } maxidle = n; break; case '?': default: fprintf(stderr, "Usage: mDNSResponderHelper [-d] [-t maxidle]\n"); exit(EXIT_FAILURE); } ac -= optind; av += optind; initialize_logging(); helplog(ASL_LEVEL_INFO, "Starting"); initialize_id(); #ifndef NO_SECURITYFRAMEWORK // We should normally be running as a system daemon. However, that might not be the case in some scenarios (e.g. debugging). // Explicitly ensure that our Keychain operations utilize the system domain. if (opt_debug) SecKeychainSetPreferenceDomain(kSecPreferencesDomainSystem); #endif gPort = checkin(kmDNSHelperServiceName); if (!gPort) { helplog(ASL_LEVEL_ERR, "Launchd provided no launchdata; will open Mach port explicitly"); gPort = register_service(kmDNSHelperServiceName); } if (maxidle) actualidle = maxidle; signal(SIGTERM, handle_sigterm); if (initialize_timer()) exit(EXIT_FAILURE); for (n=0; n<100000; n++) if (!gRunLoop) usleep(100); if (!gRunLoop) { helplog(ASL_LEVEL_ERR, "gRunLoop not set after waiting"); exit(EXIT_FAILURE); } for(;;) { hdr.msgh_bits = 0; hdr.msgh_local_port = gPort; hdr.msgh_remote_port = MACH_PORT_NULL; hdr.msgh_size = sizeof(hdr); hdr.msgh_id = 0; kr = mach_msg(&hdr, MACH_RCV_LARGE | MACH_RCV_MSG, 0, hdr.msgh_size, gPort, 0, 0); if (MACH_RCV_TOO_LARGE != kr) helplog(ASL_LEVEL_ERR, "kr: %d: %s", kr, mach_error_string(kr)); safe_vproc_transaction_begin(); kr = mach_msg_server_once(helper_server, MAX_MSG_SIZE, gPort, MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_AUDIT) | MACH_RCV_TRAILER_TYPE(MACH_MSG_TRAILER_FORMAT_0)); if (KERN_SUCCESS != kr) { helplog(ASL_LEVEL_ERR, "mach_msg_server: %s\n", mach_error_string(kr)); exit(EXIT_FAILURE); } safe_vproc_transaction_end(); } exit(EXIT_SUCCESS); }
void zathura_plugin_manager_load(zathura_plugin_manager_t* plugin_manager) { if (plugin_manager == NULL || plugin_manager->path == NULL) { return; } GIRARA_LIST_FOREACH(plugin_manager->path, char*, iter, plugindir) /* read all files in the plugin directory */ GDir* dir = g_dir_open(plugindir, 0, NULL); if (dir == NULL) { girara_error("could not open plugin directory: %s", plugindir); girara_list_iterator_next(iter); continue; } char* name = NULL; while ((name = (char*) g_dir_read_name(dir)) != NULL) { char* path = g_build_filename(plugindir, name, NULL); if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == 0) { girara_info("%s is not a regular file. Skipping.", path); g_free(path); continue; } zathura_plugin_t* plugin = NULL; /* load plugin */ GModule* handle = g_module_open(path, G_MODULE_BIND_LOCAL); if (handle == NULL) { girara_error("could not load plugin %s (%s)", path, g_module_error()); g_free(path); continue; } /* resolve symbols and check API and ABI version*/ zathura_plugin_api_version_t api_version = NULL; if (g_module_symbol(handle, PLUGIN_API_VERSION_FUNCTION, (gpointer*) &api_version) == FALSE || api_version == NULL) { girara_error("could not find '%s' function in plugin %s", PLUGIN_API_VERSION_FUNCTION, path); g_free(path); g_module_close(handle); continue; } if (api_version() != ZATHURA_API_VERSION) { girara_error("plugin %s has been built againt zathura with a different API version (plugin: %d, zathura: %d)", path, api_version(), ZATHURA_API_VERSION); g_free(path); g_module_close(handle); continue; } zathura_plugin_abi_version_t abi_version = NULL; if (g_module_symbol(handle, PLUGIN_ABI_VERSION_FUNCTION, (gpointer*) &abi_version) == FALSE || abi_version == NULL) { girara_error("could not find '%s' function in plugin %s", PLUGIN_ABI_VERSION_FUNCTION, path); g_free(path); g_module_close(handle); continue; } if (abi_version() != ZATHURA_ABI_VERSION) { girara_error("plugin %s has been built againt zathura with a different ABI version (plugin: %d, zathura: %d)", path, abi_version(), ZATHURA_ABI_VERSION); g_free(path); g_module_close(handle); continue; } zathura_plugin_register_service_t register_service = NULL; if (g_module_symbol(handle, PLUGIN_REGISTER_FUNCTION, (gpointer*) ®ister_service) == FALSE || register_service == NULL) { girara_error("could not find '%s' function in plugin %s", PLUGIN_REGISTER_FUNCTION, path); g_free(path); g_module_close(handle); continue; } plugin = g_malloc0(sizeof(zathura_plugin_t)); plugin->content_types = girara_list_new2(g_free); plugin->handle = handle; register_service(plugin); /* register functions */ if (plugin->register_function == NULL) { girara_error("plugin has no document functions register function"); g_free(path); g_free(plugin); g_module_close(handle); continue; } plugin->register_function(&(plugin->functions)); plugin->path = path; bool ret = register_plugin(plugin_manager, plugin); if (ret == false) { girara_error("could not register plugin %s", path); zathura_plugin_free(plugin); } else { girara_info("successfully loaded plugin %s", path); zathura_plugin_version_function_t plugin_major = NULL, plugin_minor = NULL, plugin_rev = NULL; g_module_symbol(handle, PLUGIN_VERSION_MAJOR_FUNCTION, (gpointer*) &plugin_major); g_module_symbol(handle, PLUGIN_VERSION_MINOR_FUNCTION, (gpointer*) &plugin_minor); g_module_symbol(handle, PLUGIN_VERSION_REVISION_FUNCTION, (gpointer*) &plugin_rev); if (plugin_major != NULL && plugin_minor != NULL && plugin_rev != NULL) { plugin->version.major = plugin_major(); plugin->version.minor = plugin_minor(); plugin->version.rev = plugin_rev(); girara_debug("plugin '%s': version %u.%u.%u", path, plugin->version.major, plugin->version.minor, plugin->version.rev); } } } g_dir_close(dir); GIRARA_LIST_FOREACH_END(zathura->plugins.path, char*, iter, plugindir); }
int main (int argc, char **argv) { xmmsc_connection_t *conn; gchar *path; gchar *gp = NULL; gchar **s; gchar **ipcsplit; int i; printf ("Starting XMMS2 mDNS Agent...\n"); path = getenv ("XMMS_PATH_FULL"); if (!path) { printf ("Sorry you need XMMS_PATH_FULL set\n"); exit (1); } ipcsplit = g_strsplit (path, ";", 0); for (i = 0; ipcsplit[i]; i++) { if (g_ascii_strncasecmp (ipcsplit[i], "tcp://", 6) == 0) { gp = ipcsplit[i]; } } if (!gp) { printf ("Need to have a socket listening to TCP before we can do that!\n"); exit (1); } s = g_strsplit (gp, ":", 0); if (s && s[2]) { port = strtol (s[2], NULL, 10); } else { port = XMMS_DEFAULT_TCP_PORT; } conn = xmmsc_init ("xmms2-mdns"); if (!conn) { printf ("Could not init xmmsc_connection!\n"); exit (1); } if (!xmmsc_connect (conn, gp)) { printf ("Could not connect to xmms2d: %s\n", xmmsc_get_last_error (conn)); exit (1); } avahi_set_allocator (avahi_glib_allocator ()); ml = g_main_loop_new (NULL, FALSE); XMMS_CALLBACK_SET (conn, xmmsc_broadcast_quit, handle_quit, ml); xmmsc_disconnect_callback_set (conn, disconnected, NULL); register_service (); xmmsc_mainloop_gmain_init (conn); g_main_loop_run (ml); xmmsc_unref (conn); printf ("XMMS2-mDNS shutting down...\n"); g_main_loop_unref (ml); avahi_free (name); return 0; }
int main(int argc, char **argv) { printf("%s: HelenOS IPC Naming Service\n", NAME); int rc = service_init(); if (rc != EOK) return rc; rc = clonable_init(); if (rc != EOK) return rc; rc = task_init(); if (rc != EOK) return rc; printf("%s: Accepting connections\n", NAME); while (true) { process_pending_conn(); process_pending_wait(); ipc_call_t call; ipc_callid_t callid = ipc_wait_for_call(&call); task_id_t id; sysarg_t retval; switch (IPC_GET_IMETHOD(call)) { case IPC_M_PHONE_HUNGUP: retval = ns_task_disconnect(&call); break; case IPC_M_CONNECT_TO_ME: /* * Server requests service registration. */ if (service_clonable(IPC_GET_ARG1(call))) { register_clonable(IPC_GET_ARG1(call), IPC_GET_ARG5(call), &call, callid); continue; } else { retval = register_service(IPC_GET_ARG1(call), IPC_GET_ARG5(call), &call); } break; case IPC_M_CONNECT_ME_TO: /* * Client requests to be connected to a service. */ if (service_clonable(IPC_GET_ARG1(call))) { connect_to_clonable(IPC_GET_ARG1(call), &call, callid); continue; } else { connect_to_service(IPC_GET_ARG1(call), &call, callid); continue; } break; case NS_PING: retval = EOK; break; case NS_TASK_WAIT: id = (task_id_t) MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); wait_for_task(id, &call, callid); continue; case NS_ID_INTRO: retval = ns_task_id_intro(&call); break; case NS_RETVAL: retval = ns_task_retval(&call); break; default: retval = ENOENT; break; } if (!(callid & IPC_CALLID_NOTIFICATION)) ipc_answer_0(callid, retval); } /* Not reached */ return 0; }