aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-06-28 09:56:35 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-06-28 09:56:35 +0200
commit2b7ba240be298d1d7ffc7d220b83e22a7c4f8c43 (patch)
tree891d8efb554d51c7535306b7dae80af997104cca /src
parentf6ac29dceebb32afc27c2e93294b3c7bb8b2f66f (diff)
downloadbbs-2b7ba240be298d1d7ffc7d220b83e22a7c4f8c43.tar.gz
Minor fixes, documentation
Diffstat (limited to 'src')
-rw-r--r--src/main.c23
-rw-r--r--src/modem.c6
-rw-r--r--src/modem.h10
3 files changed, 25 insertions, 14 deletions
diff --git a/src/main.c b/src/main.c
index 988055e..9b03710 100644
--- a/src/main.c
+++ b/src/main.c
@@ -90,10 +90,9 @@ void handle_connection(int _socket, struct sockaddr_in _addr)
exit(1);
//Redirect STDIO to socket
- close(STDIN_FILENO);
- dup(_socket);
- close(STDOUT_FILENO);
- dup(_socket);
+ dup2(_socket, STDIN_FILENO);
+ dup2(_socket, STDOUT_FILENO);
+ dup2(_socket, STDERR_FILENO);
//RUUNNNN!
execl("/usr/bin/whoami", "/usr/bin/whoami", NULL);
@@ -101,7 +100,7 @@ void handle_connection(int _socket, struct sockaddr_in _addr)
PRINT_ERROR("EXEC failed");
close(_socket);
- exit(0);
+ exit(1);
}
@@ -131,6 +130,7 @@ int main(int argc, char* argv[])
fprintf(pidfile, "%i", pid);
printf("Forked with PID %i\n", pid);
fclose (pidfile);
+ exit(0);
}
fclose (pidfile);
@@ -146,26 +146,25 @@ int main(int argc, char* argv[])
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)
{
- printf ("error %d opening %s: %s\n", errno, params.serial_port, strerror (errno));
+ PRINT_ERROR("Failed to open serial port");
return;
}
- ///TODO Hardcoded Baudrate. change!
- set_interface_attribs (fd, params.serial_baudrate, 0); // set speed to 115,200 bps, 8n1 (no parity)
- set_blocking (fd, 0); // set no blocking
+ set_interface_attribs (fd, params.serial_baudrate, 0);
+ set_blocking (fd, 0);
int ret = modem_accept_wait(fd);
- printf("maw(): %i\n", ret);
if(ret)
return;
- printf("Connection!\n");
-
+ DEBUG_PRINTF("Connection established\n");
+
modem_run(fd, params.run_argc, params.run_argv);
}
diff --git a/src/modem.c b/src/modem.c
index be5c9d6..31e8ee2 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -122,6 +122,7 @@ int modem_run(int fd, int argc, char* argv[])
dup2 (in[0], STDIN_FILENO);
dup2 (out[1], STDOUT_FILENO);
+ dup2 (out[1], STDERR_FILENO);
char *arv = malloc(sizeof(char) * (argc + 1));
memset(arv, 0, sizeof(char) * (argc + 1));
@@ -172,9 +173,10 @@ int modem_run(int fd, int argc, char* argv[])
if(cnt) {
//search for modem error message
char *str = strstr(buff, "NO CARRIER");
- if(str) //Exit if message found
+ if(str){ //Exit if message found
+ kill(pid,SIGTERM);
break;
-
+ }
write(in[1], buff, cnt);
}
}
diff --git a/src/modem.h b/src/modem.h
index 2598273..cf6e9d4 100644
--- a/src/modem.h
+++ b/src/modem.h
@@ -21,7 +21,17 @@
#define _AT_RESET_ON_DTR "AT&D3\r\n"
int modem_accept_wait(int fd);
+/*
+ * Waits for RING, accepts incoming calls. Return is non-zero when cennection fails.
+ * */
int modem_command(int fd, char* cmd, int timeout_ms);
+/*
+ * Execute an AT command. return is non-zero if answer is not OK
+ * */
int modem_run(int fd, int argc, char* argv[]);
+/*
+ * Run a program with modem as STDIO. checks if connection is still alive & process is still active.
+ * will close fd on successful return
+ * */