void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event) { pid_t child; if (ctdb->notification_script == NULL) { return; } child = ctdb_fork(ctdb); if (child == (pid_t)-1) { DEBUG(DEBUG_ERR,("Failed to fork() a notification child process\n")); return; } if (child == 0) { int ret; prctl_set_comment("ctdb_notification"); debug_extra = talloc_asprintf(NULL, "notification-%s:", event); ret = ctdb_run_notification_script_child(ctdb, event); if (ret != 0) { DEBUG(DEBUG_ERR,(__location__ " Notification script failed\n")); } _exit(0); } return; }
static bool lsasd_child_init(struct tevent_context *ev_ctx, int child_id, struct pf_worker_data *pf) { NTSTATUS status; struct messaging_context *msg_ctx = server_messaging_context(); bool ok; status = reinit_after_fork(msg_ctx, ev_ctx, true); if (!NT_STATUS_IS_OK(status)) { DEBUG(0,("reinit_after_fork() failed\n")); smb_panic("reinit_after_fork() failed"); } prctl_set_comment("lsasd-child"); lsasd_child_id = child_id; lsasd_reopen_logs(child_id); ok = lsasd_setup_chld_hup_handler(ev_ctx); if (!ok) { return false; } if (!serverid_register(messaging_server_id(msg_ctx), FLAG_MSG_GENERAL)) { return false; } messaging_register(msg_ctx, ev_ctx, MSG_SMB_CONF_UPDATED, lsasd_smb_conf_updated); messaging_register(msg_ctx, ev_ctx, MSG_PREFORK_PARENT_EVENT, parent_ping); id_cache_register_msgs(msg_ctx); status = rpc_lsarpc_init(NULL); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("Failed to register lsarpc rpc inteface! (%s)\n", nt_errstr(status))); return false; } status = rpc_samr_init(NULL); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("Failed to register samr rpc inteface! (%s)\n", nt_errstr(status))); return false; } status = rpc_netlogon_init(NULL); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("Failed to register netlogon rpc inteface! (%s)\n", nt_errstr(status))); return false; } return true; }
static bool smbd_scavenger_start(struct smbd_scavenger_state *state) { struct server_id self = messaging_server_id(state->msg); struct tevent_fd *fde = NULL; int fds[2]; int ret; uint64_t unique_id; bool ok; SMB_ASSERT(server_id_equal(&state->parent_id, &self)); if (smbd_scavenger_running(state)) { DEBUG(10, ("scavenger %s already running\n", server_id_str(talloc_tos(), state->scavenger_id))); return true; } if (state->scavenger_id != NULL) { DEBUG(10, ("scavenger zombie %s, cleaning up\n", server_id_str(talloc_tos(), state->scavenger_id))); TALLOC_FREE(state->scavenger_id); } state->scavenger_id = talloc_zero(state, struct server_id); if (state->scavenger_id == NULL) { DEBUG(2, ("Out of memory\n")); goto fail; } talloc_set_destructor(state->scavenger_id, smbd_scavenger_server_id_destructor); ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds); if (ret == -1) { DEBUG(2, ("socketpair failed: %s", strerror(errno))); goto fail; } smb_set_close_on_exec(fds[0]); smb_set_close_on_exec(fds[1]); unique_id = serverid_get_random_unique_id(); ret = fork(); if (ret == -1) { int err = errno; close(fds[0]); close(fds[1]); DEBUG(0, ("fork failed: %s", strerror(err))); goto fail; } if (ret == 0) { /* child */ NTSTATUS status; close(fds[0]); am_parent = NULL; set_my_unique_id(unique_id); status = reinit_after_fork(state->msg, state->ev, true); if (!NT_STATUS_IS_OK(status)) { DEBUG(2, ("reinit_after_fork failed: %s\n", nt_errstr(status))); exit_server("reinit_after_fork failed"); return false; } prctl_set_comment("smbd-scavenger"); state->am_scavenger = true; *state->scavenger_id = messaging_server_id(state->msg); scavenger_setup_sig_term_handler(state->ev); serverid_register(*state->scavenger_id, FLAG_MSG_GENERAL); ok = scavenger_say_hello(fds[1], *state->scavenger_id); if (!ok) { DEBUG(2, ("scavenger_say_hello failed\n")); exit_server("scavenger_say_hello failed"); return false; } fde = tevent_add_fd(state->ev, state->scavenger_id, fds[1], TEVENT_FD_READ, smbd_scavenger_parent_dead, state); if (fde == NULL) { DEBUG(2, ("tevent_add_fd(smbd_scavenger_parent_dead) " "failed\n")); exit_server("tevent_add_fd(smbd_scavenger_parent_dead) " "failed"); return false; } tevent_fd_set_auto_close(fde); ret = smbd_scavenger_main(state); DEBUG(10, ("scavenger ended: %d\n", ret)); exit_server_cleanly("scavenger ended"); return false; } /* parent */ close(fds[1]); ok = scavenger_wait_hello(fds[0], state->scavenger_id); if (!ok) { close(fds[0]); goto fail; } fde = tevent_add_fd(state->ev, state->scavenger_id, fds[0], TEVENT_FD_READ, smbd_scavenger_done, state); if (fde == NULL) { close(fds[0]); goto fail; } tevent_fd_set_auto_close(fde); return true; fail: TALLOC_FREE(state->scavenger_id); return false; }
static bool spoolss_child_init(struct tevent_context *ev_ctx, int child_id, struct pf_worker_data *pf) { NTSTATUS status; struct rpc_srv_callbacks spoolss_cb; struct messaging_context *msg_ctx = messaging_init(NULL, ev_ctx); bool ok; status = reinit_after_fork(msg_ctx, ev_ctx, true); if (!NT_STATUS_IS_OK(status)) { DEBUG(0,("reinit_after_fork() failed\n")); smb_panic("reinit_after_fork() failed"); } prctl_set_comment("spoolssd-child"); spoolss_child_id = child_id; spoolss_reopen_logs(child_id); ok = spoolss_setup_chld_hup_handler(ev_ctx, msg_ctx, pf); if (!ok) { return false; } if (!serverid_register(messaging_server_id(msg_ctx), FLAG_MSG_GENERAL | FLAG_MSG_PRINT_GENERAL)) { return false; } if (!locking_init()) { return false; } messaging_register(msg_ctx, ev_ctx, MSG_SMB_CONF_UPDATED, smb_conf_updated); messaging_register(msg_ctx, ev_ctx, MSG_PREFORK_PARENT_EVENT, parent_ping); /* As soon as messaging is up check if pcap has been loaded already. * If so then we probably missed a message and should load_printers() * ourselves. If pcap has not been loaded yet, then ignore, we will get * a message as soon as the bq process completes the reload. */ if (pcap_cache_loaded(NULL)) { load_printers(ev_ctx, msg_ctx); } /* try to reinit rpc queues */ spoolss_cb.init = spoolss_init_cb; spoolss_cb.shutdown = spoolss_shutdown_cb; spoolss_cb.private_data = msg_ctx; status = rpc_winreg_init(NULL); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("Failed to register winreg rpc inteface! (%s)\n", nt_errstr(status))); return false; } status = rpc_spoolss_init(&spoolss_cb); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("Failed to register spoolss rpc inteface! (%s)\n", nt_errstr(status))); return false; } return true; }
void start_epmd(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx) { struct rpc_srv_callbacks epmapper_cb; NTSTATUS status; pid_t pid; bool ok; int rc; epmapper_cb.init = NULL; epmapper_cb.shutdown = epmapper_shutdown_cb; epmapper_cb.private_data = NULL; DEBUG(1, ("Forking Endpoint Mapper Daemon\n")); pid = fork(); if (pid == -1) { DEBUG(0, ("Failed to fork Endpoint Mapper [%s], aborting ...\n", strerror(errno))); exit(1); } if (pid) { /* parent */ return; } status = smbd_reinit_after_fork(msg_ctx, ev_ctx, true); if (!NT_STATUS_IS_OK(status)) { DEBUG(0,("reinit_after_fork() failed\n")); smb_panic("reinit_after_fork() failed"); } prctl_set_comment("epmd"); epmd_reopen_logs(); epmd_setup_sig_term_handler(ev_ctx); epmd_setup_sig_hup_handler(ev_ctx, msg_ctx); ok = serverid_register(messaging_server_id(msg_ctx), FLAG_MSG_GENERAL | FLAG_MSG_PRINT_GENERAL); if (!ok) { DEBUG(0, ("Failed to register serverid in epmd!\n")); exit(1); } messaging_register(msg_ctx, ev_ctx, MSG_SMB_CONF_UPDATED, epmd_smb_conf_updated); status = rpc_epmapper_init(&epmapper_cb); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("Failed to register epmd rpc interface! (%s)\n", nt_errstr(status))); exit(1); } status = rpc_setup_tcpip_sockets(ev_ctx, msg_ctx, &ndr_table_epmapper, NULL, 135); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("Failed to open epmd tcpip sockets!\n")); exit(1); } ok = setup_dcerpc_ncalrpc_socket(ev_ctx, msg_ctx, "EPMAPPER", srv_epmapper_delete_endpoints); if (!ok) { DEBUG(0, ("Failed to open epmd ncalrpc pipe!\n")); exit(1); } ok = setup_named_pipe_socket("epmapper", ev_ctx, msg_ctx); if (!ok) { DEBUG(0, ("Failed to open epmd named pipe!\n")); exit(1); } DEBUG(1, ("Endpoint Mapper Daemon Started (%u)\n", (unsigned int)getpid())); /* loop forever */ rc = tevent_loop_wait(ev_ctx); /* should not be reached */ DEBUG(0,("background_queue: tevent_loop_wait() exited with %d - %s\n", rc, (rc == 0) ? "out of events" : strerror(errno))); exit(1); }