diff --git a/moxerver.c b/moxerver.c index a306aca..ecd27c7 100644 --- a/moxerver.c +++ b/moxerver.c @@ -46,6 +46,7 @@ int main(int argc, char *argv[]) { unsigned int tcp_port = -1; char tty_path[DEV_PATH] = {'\0'}; + struct tty_t tty_dev; fd_set read_fds; int fdmax; @@ -96,6 +97,9 @@ int main(int argc, char *argv[]) { fprintf(stderr, "[%s] error: tty path was not specified\n\n", NAME); usage(); return -1; + } else { + /* set tty device path to in tty_dev struct */ + strcpy(tty_dev.path, tty_path); } /* introduction message */ @@ -110,6 +114,12 @@ int main(int argc, char *argv[]) { //TODO this is a good place to create and start the TTY thread, use "tty_path" when opening device + if (tty_open(&tty_dev) < 0) { + fprintf(stderr, "[%s] error: opening of tty device at %s failed\n" + "\t-> continuing in echo mode\n", NAME, tty_path); + //return -1; + } + ret = pthread_create(&tty_thread, NULL, tty_thread_func, "starting tty thread..."); /* loop with timeouts waiting for client connection and data*/ diff --git a/moxerver.h b/moxerver.h index 5130333..ef0c36a 100644 --- a/moxerver.h +++ b/moxerver.h @@ -62,7 +62,7 @@ int telnet_handle_client_write(char *databuf, int *datalen); /* Opens the tty device and configures it. */ -int tty_open(struct tty_t *tty_dev, char* path); +int tty_open(struct tty_t *tty_dev); /* Closes the tty device. */ int tty_close(struct tty_t *tty_dev); /* Reconfigures the tty device. */ diff --git a/tty.c b/tty.c index 64966a7..4656f80 100644 --- a/tty.c +++ b/tty.c @@ -4,13 +4,20 @@ #define NAME "tty" /* Opens the tty device and configures it. */ -int tty_open(struct tty_t *tty_dev, char* path) { +int tty_open(struct tty_t *tty_dev) { + int fd; // PROPOSAL: // open tty device to get file descriptor @tty_dev.fd // setup tty device parameters @tty_dev.ttyset // apply settings by calling tcsetattr(fd, ttyset) // on success copy path to @tty_dev.path + if ((fd = open (tty_dev->path, O_RDWR | O_NOCTTY | O_SYNC)) < 0) + return -errno; + else + tty_dev->fd = fd; + return 0; + } /* Closes the tty device. */ int tty_close(struct tty_t *tty_dev) {