/* * ser2net - A program for allowing telnet connection to serial ports * Copyright (C) 2001 Corey Minyard * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* This is the entry point for the ser2net program. It reads parameters, initializes everything, then starts the select loop. */ /* TODO * * Add some type of security */ #include #include #include #include #include #include #include #include "readconfig.h" #include "controller.h" #include "utils.h" #include "selector.h" #include "dataxfer.h" static char *config_file = "/usr/local/etc/ser2net.conf"; static char *config_port = NULL; static int detach = 1; static int debug = 0; #ifdef USE_UUCP_LOCKING int uucp_locking_enabled = 1; #endif int cisco_ios_baud_rates = 0; selector_t *ser2net_sel; static char *help_string = "%s: Valid parameters are:\n" " -c - use a config file besides /usr/local/etc/ser2net.conf\n" " -C - Handle a single configuration line. This may be\n" " specified multiple times for multiple lines. This is just like a\n" " line in the config file. This disables the default config file,\n" " you must specify a -c after the last -C to have it read a config\n" " file, too." " -p - Start a controller session on the given TCP port\n" " -n - Don't detach from the controlling terminal\n" " -d - Don't detach and send debug I/O to standard output\n" #ifdef USE_UUCP_LOCKING " -u - Disable UUCP locking\n" #endif " -b - Do CISCO IOS baud-rate negotiation, instead of RFC2217\n" " -v - print the program's version and exit\n"; void reread_config(void) { if (config_file) { syslog(LOG_INFO, "Got SIGHUP, re-reading configuration"); readconfig(config_file); } } void arg_error(char *name) { fprintf(stderr, help_string, name); exit(1); } int main(int argc, char *argv[]) { int i; int err; err = sel_alloc_selector(&ser2net_sel); if (err) { fprintf(stderr, "Could not initialize ser2net selector: '%s'\n", strerror(err)); return -1; } for (i=1; i 0) { exit(0); } else if (pid < 0) { syslog(LOG_ERR, "Error forking first fork"); exit(1); } else { /* setsid() is necessary if we really want to demonize */ setsid(); /* Second fork to really deamonize me. */ if ((pid = fork()) > 0) { exit(0); } else if (pid < 0) { syslog(LOG_ERR, "Error forking second fork"); exit(1); } } /* Close all my standard I/O. */ chdir("/"); close(0); close(1); close(2); } else if (debug) { openlog("ser2net", LOG_PID | LOG_CONS | LOG_PERROR, LOG_DAEMON); } /* Ignore SIGPIPEs so they don't kill us. */ signal(SIGPIPE, SIG_IGN); set_sighup_handler(reread_config); sel_select_loop(ser2net_sel); return 0; }