aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-07-11 22:20:25 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-07-11 22:20:25 +0200
commit423f73855138e2b2adf46da0e0f428afa5e93966 (patch)
tree05671bcffb661177eb47dea157a9a07d75d291ae
parentc743e951a950b4da7f2929ebaace54cc1f7e80c0 (diff)
downloadbbs-423f73855138e2b2adf46da0e0f428afa5e93966.tar.gz
Headers
-rw-r--r--src/main.c47
-rw-r--r--src/main.h7
2 files changed, 40 insertions, 14 deletions
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
+ * <Description>
+ * 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
+ * <Description>
+ * License: MIT
+*/
+
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>