int main (int argc, char const *const *argv, char const *const *envp) { unsigned int backlog = 20 ; int flagreuse = 1 ; PROG = "s6-ipcserver-socketbinder" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "Ddb:", &l) ; if (opt == -1) break ; switch (opt) { case 'D' : flagreuse = 0 ; break ; case 'd' : flagreuse = 1 ; break ; case 'b' : if (!uint0_scan(l.arg, &backlog)) dieusage() ; break ; default : dieusage() ; } } argc -= l.ind ; argv += l.ind ; } if (argc < 2) dieusage() ; close(0) ; if (ipc_stream()) strerr_diefu1sys(111, "create socket") ; { mode_t m = umask(0) ; if ((flagreuse ? ipc_bind_reuse(0, argv[0]) : ipc_bind(0, argv[0])) < 0) strerr_diefu2sys(111, "bind to ", argv[0]) ; umask(m) ; } if (ipc_listen(0, backlog) < 0) strerr_diefu2sys(111, "listen to ", argv[0]) ; pathexec_run(argv[1], argv + 1, envp) ; strerr_dieexec(111, argv[1]) ; }
static gpointer wt_ipc_mainloop (gpointer __unused) { struct timespec timestruc; timestruc.tv_sec = ((unsigned long long) (delay * NSEC_COUNT)) / NSEC_COUNT; timestruc.tv_nsec = ((unsigned long long) (delay * NSEC_COUNT)) % NSEC_COUNT; for (;;) { if (mutex_trylock (mutex)) { mutex_unlock (mutex); break; } ipc_listen (); ipc_interact (); nanosleep (×truc, 0); } g_thread_exit (0); return 0; }
/* Open socket on a specific port for reading. */ int ipc_bind_listen_port(u16 port) { return ipc_listen(port); }