From 423f73855138e2b2adf46da0e0f428afa5e93966 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Thu, 11 Jul 2019 22:20:25 +0200 Subject: Headers --- src/main.c | 47 +++++++++++++++++++++++++++++++++-------------- src/main.h | 7 +++++++ 2 files changed, 40 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 65d3a94..5831c1a 100644 --- a/src/main.c +++ b/src/main.c @@ -1,3 +1,10 @@ +/* + * main.c + * (c) 2019, Jonas Gunz, jonasgunz.de + * + * License: MIT +*/ + #include "main.h" #include "serial.h" #include "modem.h" @@ -120,6 +127,7 @@ int main(int argc, char* argv[]) if(params.fork) { FILE* pidfile = fopen(params.pidfile, "w"); + if(!pidfile) { PRINT_ERROR("Unable to open pidfile for writing"); @@ -141,6 +149,11 @@ int main(int argc, char* argv[]) } fclose (pidfile); + + //Close STDIO + close (STDIN_FILENO); + close (STDOUT_FILENO); + close (STDERR_FILENO); }//if params.fork DEBUG_PRINTF("%s, %i\n", params.run_argv[0], params.run_argc); @@ -157,24 +170,30 @@ void dialup_server(struct prog_params params) { printf("Starting dialup server\n"); - int fd = open (params.serial_port, O_RDWR | O_NOCTTY | O_SYNC); - if (fd < 0) - { - PRINT_ERROR("Failed to open serial port"); - return; - } + while(1) { + //Serial port is reopened for every new connection to reset modem over DTR + int fd = open (params.serial_port, O_RDWR | O_NOCTTY | O_SYNC); + if (fd < 0) { + PRINT_ERROR("Failed to open serial port"); + return; + } - set_interface_attribs (fd, params.serial_baudrate, 0); - set_blocking (fd, 0); + set_interface_attribs (fd, params.serial_baudrate, 0); + set_blocking (fd, 0); - int ret = modem_accept_wait(fd); + int ret = modem_accept_wait(fd); - if(ret) - return; + if(ret) { + printf("Modem error %i\n", ret); + close(fd); + break; + } - DEBUG_PRINTF("Connection established\n"); - - modem_run(fd, params.run_argc, params.run_argv); + DEBUG_PRINTF("Connection\n"); + + modem_run(fd, params.run_argc, params.run_argv); + close (fd); + } } void telnet_server(struct prog_params params) diff --git a/src/main.h b/src/main.h index ae8328e..a599ae2 100644 --- a/src/main.h +++ b/src/main.h @@ -1,3 +1,10 @@ +/* + * main.h + * (c) 2019, Jonas Gunz, jonasgunz.de + * + * License: MIT +*/ + #include #include #include -- cgit v1.2.3