diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 23 | ||||
-rw-r--r-- | src/modem.c | 6 | ||||
-rw-r--r-- | src/modem.h | 10 |
3 files changed, 25 insertions, 14 deletions
@@ -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 + * */ |