void avim_group_impl::start() { recive_client_message.connect(std::bind(&avim_group_impl::forward_client_message, shared_from_this(), std::placeholders::_1)); boost::asio::spawn(m_io_service, std::bind(&avim_group_impl::internal_loop_coroutine, shared_from_this(), std::placeholders::_1)); start_login(); }
/* ARGSUSED */ void startslave(const char *host, int autologin, char *autoname) { int i; #if defined(AUTHENTICATE) if (!autoname || !autoname[0]) autologin = 0; if (autologin < auth_level) { fatal(net, "Authorization failed"); exit(1); } #endif i = fork(); if (i < 0) fatalperror(net, "fork"); if (i) { /* parent */ signal(SIGHUP,SIG_IGN); close(ptyslavefd); } else { /* child */ signal(SIGHUP,SIG_IGN); getptyslave(); start_login(host, autologin, autoname); /*NOTREACHED*/ } }
/* ARGSUSED */ void startslave(char *host, int autologin, char *autoname) { int i; #ifdef AUTHENTICATION if (!autoname || !autoname[0]) autologin = 0; if (autologin < auth_level) { fatal(net, "Authorization failed"); exit(1); } #endif if ((i = fork()) < 0) fatalperror(net, "fork"); if (i) { } else { getptyslave(); start_login(host, autologin, autoname); /*NOTREACHED*/ } }
void avim_group_impl::internal_login_coroutine(boost::asio::yield_context yield_context) { m_con.reset(new avjackif(m_io_service)); m_con->set_pki(m_key, m_cert); try { if (!m_con->async_connect("avim.avplayer.org", "24950", yield_context)) return start_login(); if (!m_con->async_handshake(yield_context)) { // stop loop std::cerr << "avim login failed!" << std::endl; return; } m_con->signal_notify_remove.connect([this]() { start_login(); }); m_core.add_interface(m_con); m_me_addr = av_address_to_string(*m_con->if_address()); // 添加路由表, metric越大,优先级越低 m_core.add_route(".+@.+", m_me_addr, m_con->get_ifname(), 100); on_group_created(m_me_addr); }catch(const std::exception&) { start_login(); } }
/* MAIN */ int main(int argc, char **argv) { pid_t pid; struct sigaction sa; if (argc < 1) { fprintf(stderr,"Usage: echocon program args...\n"); exit(-1); } if (geteuid() != 0) { fprintf(stderr,"You must be root in order to run %s\n",argv[0]); exit(-1); } if (fork()) exit(0); /* decouple from terminal */ pid = setsid(); if (pid == -1) { fprintf(stderr,"setsid failed: %d,%d\n",pid,errno); exit(-1); } setjmp(env); settitle("consoled"); if ((console = open("/dev/console",O_RDWR,0)) < 0) { fprintf(stderr,"could not open /dev/console\n"); exit(-1); } if (openpty(&master,&slave,0,0,0) < 0) { fprintf(stderr,"out of ptys\n"); return -1; } /* child signal handler */ sa.sa_handler = pchild; sa.sa_flags = SA_NOCLDSTOP; sa.sa_mask = 0xffffffff; if (sigaction(SIGCHLD,&sa,NULL) != 0) { fprintf(stderr,"sigaction child failed\n"); exit(-1); } /* kill consoled, kills it children and exits. */ sa.sa_handler = wrapup; sa.sa_flags = 0; sa.sa_mask = 0xffffffff; if (sigaction(SIGHUP,&sa,NULL) != 0) { fprintf(stderr,"sigaction child failed\n"); exit(-1); } sa.sa_handler = wrapup; sa.sa_flags = 0; sa.sa_mask = 0xffffffff; #if 0 if (sigaction(SIGTERM,&sa,NULL) != 0) { fprintf(stderr,"sigaction child failed\n"); exit(-1); } #endif progpid = start_login(slave); if (progpid == -1) { fprintf(stderr,"start login failed\n"); exit(-1); } close(slave); do_console(master,console); /* Never reached */ assert(0); return 0; }
/* ARGSUSED */ void startslave(const char *host, const char *utmp_host, int autologin, char *autoname) { int i; #ifdef AUTHENTICATION if (!autoname || !autoname[0]) autologin = 0; if (autologin < auth_level) { fatal(net, "Authorization failed"); exit(1); } #endif { char *tbuf = "\r\n*** Connection not encrypted! " "Communication may be eavesdropped. ***\r\n"; #ifdef ENCRYPTION if (!no_warn && (encrypt_output == 0 || decrypt_input == 0)) #endif writenet(tbuf, strlen(tbuf)); } # ifdef PARENT_DOES_UTMP utmp_sig_init(); # endif /* PARENT_DOES_UTMP */ if ((i = fork()) < 0) fatalperror(net, "fork"); if (i) { # ifdef PARENT_DOES_UTMP /* * Cray parent will create utmp entry for child and send * signal to child to tell when done. Child waits for signal * before doing anything important. */ int pid = i; void sigjob (int); setpgrp(); utmp_sig_reset(); /* reset handler to default */ /* * Create utmp entry for child */ wtmp.ut_time = time(NULL); wtmp.ut_type = LOGIN_PROCESS; wtmp.ut_pid = pid; strncpy(wtmp.ut_user, "LOGIN", sizeof(wtmp.ut_user)); strncpy(wtmp.ut_host, utmp_host, sizeof(wtmp.ut_host)); strncpy(wtmp.ut_line, clean_ttyname(line), sizeof(wtmp.ut_line)); #ifdef HAVE_STRUCT_UTMP_UT_ID strncpy(wtmp.ut_id, wtmp.ut_line + 3, sizeof(wtmp.ut_id)); #endif pututline(&wtmp); endutent(); if ((i = open(wtmpf, O_WRONLY|O_APPEND)) >= 0) { write(i, &wtmp, sizeof(struct utmp)); close(i); } #ifdef _CRAY signal(WJSIGNAL, sigjob); #endif utmp_sig_notify(pid); # endif /* PARENT_DOES_UTMP */ } else { getptyslave(); #if defined(DCE) /* if we authenticated via K5, try and join the PAG */ kerberos5_dfspag(); #endif start_login(host, autologin, autoname); /*NOTREACHED*/ } }
int main (void) { struct sigaction sa; int f, i, fd, status; pid_t pid;; umask (022); klogctl (6, NULL, 0); if ((getpid ()) != 1) { exit (1); } /* * Ignore all signals. */ for (f = 1; f <= NSIG; f++) signal (f, SIG_IGN); signal (SIGCHLD, SIG_DFL); signal (SIGUSR1, signal_handler); signal (SIGUSR2, signal_handler); /* Close whatever files are open, and reset the console. */ close (0); close (1); close (2); console_stty (); setsid (); /* * Set default PATH variable. */ setenv ("PATH", PATH_DEFAULT, 1 /* Overwrite */ ); /* * Initialize /var/run/utmp (only works if /var is on * root and mounted rw) */ if ((fd = open (UTMP_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0644)) >= 0) close (fd); /* * Say hello to the world */ initlog ("Welcome to \033[34m LFS-Linux\033[0m"); sysinit (); initlog ("starting login ..."); start_login (); while (1) { pid = wait (&status); if (pid == login_pid) { start_login (); } } return (0); }