void login_proxy_detach(struct login_proxy *proxy) { struct client *client = proxy->client; const unsigned char *data; size_t size; i_assert(proxy->client_fd == -1); i_assert(proxy->server_input != NULL); i_assert(proxy->server_output != NULL); if (proxy->to != NULL) timeout_remove(&proxy->to); proxy->client_fd = i_stream_get_fd(client->input); proxy->client_input = client->input; proxy->client_output = client->output; i_stream_set_persistent_buffers(client->input, FALSE); o_stream_set_max_buffer_size(client->output, (size_t)-1); o_stream_set_flush_callback(client->output, proxy_client_output, proxy); client->input = NULL; client->output = NULL; /* send all pending client input to proxy */ data = i_stream_get_data(proxy->client_input, &size); if (size != 0) o_stream_nsend(proxy->server_output, data, size); /* from now on, just do dummy proxying */ io_remove(&proxy->server_io); proxy->server_io = io_add(proxy->server_fd, IO_READ, server_input, proxy); proxy->client_io = io_add_istream(proxy->client_input, proxy_client_input, proxy); o_stream_set_flush_callback(proxy->server_output, server_output, proxy); i_stream_destroy(&proxy->server_input); if (proxy->notify_refresh_secs != 0) { proxy->to_notify = timeout_add(proxy->notify_refresh_secs * 1000, login_proxy_notify, proxy); } proxy->callback = NULL; if (login_proxy_ipc_server == NULL) { login_proxy_ipc_server = ipc_server_init(LOGIN_PROXY_IPC_PATH, LOGIN_PROXY_IPC_NAME, login_proxy_ipc_cmd); } DLLIST_REMOVE(&login_proxies_pending, proxy); DLLIST_PREPEND(&login_proxies, proxy); client->fd = -1; client->login_proxy = NULL; }
/* Init everything before forking, so we can fail and return an * error code in the parent and the initscript will fail */ static void start_server(int background) { int sd, api = 0; if (background && daemonize()) return; smclog(LOG_NOTICE, 0, "%s", version_info); /* Build list of multicast-capable physical interfaces that * are currently assigned an IP address. */ iface_init(); if (!mroute4_enable()) api++; if (!mroute6_enable()) api++; /* At least one API (IPv4 or IPv6) must have initialized successfully * otherwise we abort the server initialization. */ if (!api) { smclog(LOG_INIT, ENOPROTOOPT, "Kernel does not support multicast routing"); exit(1); } sd = ipc_server_init(); if (sd < 0) smclog(LOG_WARNING, errno, "Failed setting up IPC socket, client communication disabled"); atexit(clean); signal_init(); read_conf_file(conf_file); /* Everything setup, notify any clients by creating the pidfile */ if (pidfile(NULL)) smclog(LOG_WARNING, errno, "Failed creating pidfile"); server_loop(sd); }
int main(int argc, char *const *argv) { const char *stdouterr_path = low_level_debug ? _PATH_CONSOLE : _PATH_DEVNULL; bool sflag = false; int ch; testfd_or_openfd(STDIN_FILENO, _PATH_DEVNULL, O_RDONLY); testfd_or_openfd(STDOUT_FILENO, stdouterr_path, O_WRONLY); testfd_or_openfd(STDERR_FILENO, stdouterr_path, O_WRONLY); #if 0 if (pid1_magic) { if (!getenv("DYLD_INSERT_LIBRARIES")) { setenv("DYLD_INSERT_LIBRARIES", "/usr/lib/libgmalloc.dylib", 1); setenv("MALLOC_STRICT_SIZE", "1", 1); execv(argv[0], argv); } else { unsetenv("DYLD_INSERT_LIBRARIES"); unsetenv("MALLOC_STRICT_SIZE"); } } #endif while ((ch = getopt(argc, argv, "s")) != -1) { switch (ch) { case 's': sflag = true; break; /* single user */ case '?': /* we should do something with the global optopt variable here */ default: fprintf(stderr, "%s: ignoring unknown arguments\n", getprogname()); break; } } if (getpid() != 1 && getppid() != 1) { fprintf(stderr, "%s: This program is not meant to be run directly.\n", getprogname()); exit(EXIT_FAILURE); } launchd_runtime_init(); if( pid1_magic ) { if( low_level_debug ) { g_console = stdout; } else { if( !launchd_assumes((g_console = fopen(_PATH_CONSOLE, "w")) != NULL) ) { g_console = stdout; } _fd(fileno(g_console)); } } else { g_console = stdout; } if (NULL == getenv("PATH")) { setenv("PATH", _PATH_STDPATH, 1); } if (pid1_magic) { pid1_magic_init(); } else { ipc_server_init(); runtime_log_push(); struct passwd *pwent = getpwuid(getuid()); if( pwent ) { strlcpy(g_username, pwent->pw_name, sizeof(g_username) - 1); } runtime_syslog(LOG_DEBUG, "Per-user launchd for UID %u (%s) has begun.", getuid(), g_username); } if( pid1_magic ) { runtime_syslog(LOG_NOTICE | LOG_CONSOLE, "*** launchd[1] has started up. ***"); struct stat sb; if( stat("/var/db/.launchd_flat_per_user_namespace", &sb) == 0 ) { runtime_syslog(LOG_NOTICE | LOG_CONSOLE, "Flat per-user Mach namespaces enabled."); } /* We just wanted to print status about the per-user namespace. PID 1 doesn't have a flat namespace. */ g_flat_mach_namespace = false; } monitor_networking_state(); if (pid1_magic) { handle_pid1_crashes_separately(); } else { #if !TARGET_OS_EMBEDDED /* prime shared memory before the 'bootstrap_port' global is set to zero */ _vproc_transaction_begin(); _vproc_transaction_end(); #endif } if( pid1_magic ) { /* Start the update thread -- rdar://problem/5039559&6153301 */ pthread_t t = NULL; int err = pthread_create(&t, NULL, update_thread, NULL); launchd_assumes(err == 0); } jobmgr_init(sflag); launchd_runtime_init2(); launchd_runtime(); }