Lines Matching +full:- +full:- +full:detach +full:- +full:sig
2 * main.c - Point-to-Point Protocol main module
4 * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
25 * Pittsburgh, PA 15213-3890
26 * (412) 268-4387, fax: (412) 268-7395
27 * tech-transfer@andrew.cmu.edu
42 * Copyright (c) 1999-2004 Paul Mackerras. All rights reserved.
103 #include "chap-new.h"
137 uid_t uid; /* Our real user-id */
168 static int fd_loop; /* fd for getting demand-dial packets */
171 int devfd = -1; /* fd of underlying device */
172 int fd_ppp = -1; /* fd for talking PPP */
197 char *no_ppp_msg = "Sorry - this system lacks PPP kernel support\n";
331 hostname[MAXNAMELEN-1] = 0;
353 (*protp->init)(0);
376 if (!parse_args(argc-1, argv+1))
382 || !parse_args(argc-1, argv+1))
393 if (the_channel->process_extra_options)
394 (*the_channel->process_extra_options)();
404 option_error("must be root to run %s, since it is not setuid-root",
426 if (protp->check_options != NULL)
427 (*protp->check_options)();
428 if (the_channel->check_options)
429 (*the_channel->check_options)();
453 * Initialize system-dependent stuff.
471 * Detach ourselves from the terminal, if required,
475 detach();
479 if (pw != NULL && pw->pw_name != NULL)
480 p = pw->pw_name;
499 * If we're doing dial-on-demand, set up the interface now.
520 devfd = -1;
607 for (chp = children; chp != NULL; chp = chp->next)
608 dbglog(" script %s, pid %d", chp->prog, chp->pid);
622 * handle_events - wait for something to happen and respond to it.
668 * setup_signals - initialize signal handling.
751 * set_ifunit - do things we need to do once we know which ppp
768 * detach - detach us from the controlling terminal.
771 detach() in detach() function
779 if (pipe(pipefd) == -1) in detach()
780 pipefd[0] = pipefd[1] = -1; in detach()
782 error("Couldn't detach (fork failed: %m)"); in detach()
802 log_to_fd = -1; in detach()
813 * reopen_log - (re)open our connection to syslog.
854 slprintf(linkpidfile, sizeof(linkpidfile), "%sppp-%s.pid",
869 * remove_pidfile - remove our pid files
884 * holdoff_end - called via a timeout when the holdoff period ends.
907 { 0x33, "Stream Protocol ST-II" },
911 { 0x3d, "Multi-Link" },
917 { 0x49, "Serial Data Transport Protocol (PPP-SDTP)" },
926 { 0x5b, "Vendor-Specific Network Protocol" },
929 { 0x65, "RTP IPHC Compressed non-TCP" },
935 { 0xfb, "single-link compression" },
942 { 0x020b, "STP - Scheduled Transfer Protocol" },
943 { 0x020d, "EDP - Extreme Discovery Protocol" },
951 { 0x0285, "IEEE p1284.4 standard - data packets" },
968 { 0x405b, "Vendor-Specific Protocol (VSP)" },
978 { 0x803d, "Multi-Link Control Protocol" },
984 { 0x8049, "Serial Data Control Protocol (PPP-SDCP)" },
993 { 0x805b, "Vendor-Specific Network Control Protocol (VSNCP)" },
1001 { 0x820b, "STP - Control Protocol" },
1002 { 0x820d, "EDPCP - Extreme Discovery Protocol Ctrl Prtcl" },
1005 { 0x8285, "IEEE p1284.4 standard - Protocol Control" },
1015 { 0xc05b, "Vendor-Specific Authentication Protocol (VSAP)" },
1029 * protocol_name - find a name for a PPP protocol.
1037 for (lp = protocol_list; lp->proto != 0; ++lp)
1038 if (proto == lp->proto)
1039 return lp->name;
1044 * get_input - called when incoming data is available.
1084 len -= PPP_HDRLEN; in get_input()
1087 * Toss all non-LCP packets unless LCP is OPEN. in get_input()
1090 dbglog("Discarded non-LCP packet when LCP not open"); in get_input()
1111 if (protp->protocol == protocol && protp->enabled_flag) { in get_input()
1112 (*protp->input)(0, p, len); in get_input()
1115 if (protocol == (protp->protocol & ~0x8000) && protp->enabled_flag in get_input()
1116 && protp->datainput != NULL) { in get_input()
1117 (*protp->datainput)(0, p, len); in get_input()
1129 lcp_sprotrej(0, p - PPP_HDRLEN, len + PPP_HDRLEN); in get_input()
1133 * ppp_send_config - configure the transmit-side characteristics of
1134 * the ppp interface. Returns -1, indicating an error, if the channel
1146 if (the_channel->send_config == NULL)
1149 (*the_channel->send_config)(mtu, accm, pcomp, accomp);
1150 return (error_count != errs)? -1: 0;
1154 * ppp_recv_config - configure the receive-side characteristics of
1155 * the ppp interface. Returns -1, indicating an error, if the channel
1167 if (the_channel->recv_config == NULL)
1170 (*the_channel->recv_config)(mru, accm, pcomp, accomp);
1171 return (error_count != errs)? -1: 0;
1175 * new_phase - signal the start of a new phase of pppd's operation.
1188 * die - clean up state and exit with the specified status.
1203 * cleanup - restore anything which needs to be restored before we exit
1212 the_channel->disestablish_ppp(devfd); in cleanup()
1213 if (the_channel->cleanup) in cleanup()
1214 (*the_channel->cleanup)(); in cleanup()
1240 * reset_link_stats - "reset" stats when link goes up.
1252 * update_link_stats - get stats at link termination.
1264 link_connect_time = now.tv_sec - start_time.tv_sec;
1267 link_stats.bytes_in -= old_link_stats.bytes_in;
1268 link_stats.bytes_out -= old_link_stats.bytes_out;
1269 link_stats.pkts_in -= old_link_stats.pkts_in;
1270 link_stats.pkts_out -= old_link_stats.pkts_out;
1292 * timeout - Schedule a timeout.
1307 newp->c_arg = arg;
1308 newp->c_func = func;
1310 newp->c_time.tv_sec = timenow.tv_sec + secs;
1311 newp->c_time.tv_usec = timenow.tv_usec + usecs;
1312 if (newp->c_time.tv_usec >= 1000000) {
1313 newp->c_time.tv_sec += newp->c_time.tv_usec / 1000000;
1314 newp->c_time.tv_usec %= 1000000;
1320 for (pp = &callout; (p = *pp); pp = &p->c_next)
1321 if (newp->c_time.tv_sec < p->c_time.tv_sec
1322 || (newp->c_time.tv_sec == p->c_time.tv_sec
1323 && newp->c_time.tv_usec < p->c_time.tv_usec))
1325 newp->c_next = p;
1331 * untimeout - Unschedule a timeout.
1343 for (copp = &callout; (freep = *copp); copp = &freep->c_next)
1344 if (freep->c_func == func && freep->c_arg == arg) {
1345 *copp = freep->c_next;
1353 * calltimeout - Call any timeout routines which are now due.
1365 if (!(p->c_time.tv_sec < timenow.tv_sec in calltimeout()
1366 || (p->c_time.tv_sec == timenow.tv_sec in calltimeout()
1367 && p->c_time.tv_usec <= timenow.tv_usec))) in calltimeout()
1370 callout = p->c_next; in calltimeout()
1371 (*p->c_func)(p->c_arg); in calltimeout()
1379 * timeleft - return the length of time until the next timeout is due.
1389 tvp->tv_sec = callout->c_time.tv_sec - timenow.tv_sec;
1390 tvp->tv_usec = callout->c_time.tv_usec - timenow.tv_usec;
1391 if (tvp->tv_usec < 0) {
1392 tvp->tv_usec += 1000000;
1393 tvp->tv_sec -= 1;
1395 if (tvp->tv_sec < 0)
1396 tvp->tv_sec = tvp->tv_usec = 0;
1403 * kill_my_pg - send a signal to our process group, and ignore it ourselves.
1404 * We assume that sig is currently blocked.
1407 kill_my_pg(sig) in kill_my_pg() argument
1408 int sig; in kill_my_pg()
1419 for (chp = children; chp != NULL; chp = chp->next)
1420 if (chp->killable)
1421 kill(chp->pid, sig);
1429 kill(0, sig);
1441 sigaction(sig, &act, &oldact);
1442 sigaction(sig, &oldact, NULL);
1447 * hup - Catch SIGHUP signal.
1454 hup(sig) in hup() argument
1455 int sig; in hup()
1461 kill_my_pg(sig);
1462 notify(sigreceived, sig);
1469 * term - Catch SIGTERM signal and SIGINT signal (^C/del).
1475 term(sig) in term() argument
1476 int sig; in term()
1479 got_sigterm = sig;
1482 kill_my_pg(sig);
1483 notify(sigreceived, sig);
1490 * chld - Catch SIGCHLD signal.
1494 chld(sig) in chld() argument
1495 int sig; in chld()
1504 * toggle_debug - Catch SIGUSR1 signal.
1510 toggle_debug(sig) in toggle_debug() argument
1511 int sig; in toggle_debug()
1523 * open_ccp - Catch SIGUSR2 signal.
1529 open_ccp(sig) in open_ccp() argument
1530 int sig; in open_ccp()
1539 * bad_signal - We've caught a fatal signal. Clean up state and exit.
1542 bad_signal(sig) in bad_signal() argument
1543 int sig; in bad_signal()
1550 error("Fatal signal %d", sig);
1553 notify(sigreceived, sig);
1558 * safe_fork - Create a child process. The child closes all the
1579 if (pipe(pipefd) == -1) in safe_fork()
1580 pipefd[0] = pipefd[1] = -1; in safe_fork()
1584 return -1; in safe_fork()
1621 if (the_channel->close) in safe_fork()
1622 (*the_channel->close)(); in safe_fork()
1651 free(newstring - 1);
1666 free(script_env[pos] - 1);
1672 * update_system_environment - process the list of set/unset options
1680 for (uep = userenv_list; uep != NULL; uep = uep->ue_next) { in update_system_environment()
1681 if (uep->ue_isset) in update_system_environment()
1682 setenv(uep->ue_name, uep->ue_value, 1); in update_system_environment()
1684 unsetenv(uep->ue_name); in update_system_environment()
1689 * device_script - run a program to talk to the specified fds
1700 int status = -1;
1715 --conn_running;
1717 return -1;
1730 --conn_running;
1732 return (status == 0 ? 0 : -1);
1744 execl("/system/bin/sh", "sh", "-c", program, NULL);
1746 execl("/bin/sh", "sh", "-c", program, (char *)0);
1755 * update_script_environment - process the list of set/unset options
1766 for (uep = userenv_list; uep != NULL; uep = uep->ue_next) { in update_script_environment()
1769 int nlen = strlen(uep->ue_name); in update_script_environment()
1772 if (strncmp(p, uep->ue_name, nlen) == 0 && p[nlen] == '=') in update_script_environment()
1775 if (uep->ue_isset) { in update_script_environment()
1776 nlen += strlen(uep->ue_value) + 2; in update_script_environment()
1781 slprintf(newstring, nlen, "%s=%s", uep->ue_name, uep->ue_value); in update_script_environment()
1793 * run_program - execute a program with given arguments,
1794 * but don't wait for it unless wait is non-zero.
1797 * Returns -1 if it couldn't fork, 0 if the file doesn't exist
1818 * example, "/etc/ppp/ip-up-vpn" will be executed when IPCP is up and
1823 snprintf(file, MAXPATHLEN, "%s-%s", prog, linkname);
1824 file[MAXPATHLEN - 1] = '\0';
1832 * real user-id, which might not be root, and the script
1844 if (pid == -1) {
1846 return -1;
1891 * record_child - add a child process to the list for reap_kids
1910 chp->pid = pid;
1911 chp->prog = prog;
1912 chp->done = done;
1913 chp->arg = arg;
1914 chp->next = children;
1915 chp->killable = killable;
1921 * childwait_end - we got fed up waiting for the child processes to
1930 for (chp = children; chp != NULL; chp = chp->next) {
1932 dbglog("sending SIGTERM to process %d", chp->pid);
1933 kill(chp->pid, SIGTERM);
1939 * forget_child - clean up after a dead child
1947 for (prevp = &children; (chp = *prevp) != NULL; prevp = &chp->next) {
1948 if (chp->pid == pid) {
1949 --n_children;
1950 *prevp = chp->next;
1956 (chp? chp->prog: "??"), pid, WTERMSIG(status));
1959 (chp? chp->prog: "??"), pid,
1961 if (chp && chp->done)
1962 (*chp->done)(chp->arg);
1968 * reap_kids - get status from any dead child processes,
1978 while ((pid = waitpid(-1, &status, WNOHANG)) != -1 && pid != 0) { in reap_kids()
1981 if (pid == -1) { in reap_kids()
1983 return -1; in reap_kids()
1991 * add_notifier - add a new function to be called when something happens.
2004 np->next = *notif;
2005 np->func = func;
2006 np->arg = arg;
2011 * remove_notifier - remove a function from the list of things to
2022 for (; (np = *notif) != 0; notif = &np->next) {
2023 if (np->func == func && np->arg == arg) {
2024 *notif = np->next;
2032 * notify - call a set of functions registered with add_notifier.
2042 notif = np->next;
2043 (*np->func)(np->arg, val);
2048 * novm - log an error message saying we ran out of memory, and die.
2058 * script_setenv - set an environment variable value to be used
2059 * for scripts that we run (e.g. ip-up, auth-up, etc.)
2082 if (p[-1] && pppdb != NULL)
2085 free(p-1);
2102 free(newstring - 1);
2121 * script_unsetenv - remove a variable from the environment
2137 if (p[-1] && pppdb != NULL)
2157 * lock_db - get an exclusive lock on the TDB database.
2172 * unlock_db - remove the exclusive lock obtained by lock_db.
2187 * update_db_entry - update our entry in the database.
2206 q += slprintf(q, vbuf + vlen - q, "%s;", p); in update_db_entry()
2221 * add_db_key - add a key that we can use to look up our database entry.
2238 * delete_db_key - delete a key for looking up our database entry.
2252 * cleanup_db - delete all the entries we put in the database.
2265 if (p[-1]) in cleanup_db()