don't send to tty device if it was not opened
This commit is contained in:
parent
91becdad1c
commit
d4452bd340
1 changed files with 7 additions and 4 deletions
|
@ -31,6 +31,7 @@ void cleanup(int exit_code) {
|
||||||
tty_close(&tty_dev);
|
tty_close(&tty_dev);
|
||||||
/* close server */
|
/* close server */
|
||||||
server_close(&server);
|
server_close(&server);
|
||||||
|
/* exit */
|
||||||
exit(exit_code);
|
exit(exit_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +52,6 @@ int time2string(time_t time, char* timestamp) {
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
unsigned int tcp_port = -1;
|
unsigned int tcp_port = -1;
|
||||||
|
|
||||||
fd_set read_fds;
|
fd_set read_fds;
|
||||||
|
@ -109,14 +109,15 @@ int main(int argc, char *argv[]) {
|
||||||
fprintf(stderr, "[%s] === MoxaNix ===\n", NAME);
|
fprintf(stderr, "[%s] === MoxaNix ===\n", NAME);
|
||||||
|
|
||||||
/* initialize */
|
/* initialize */
|
||||||
server_setup(&server, tcp_port);
|
if (server_setup(&server, tcp_port) < 0) return -1;
|
||||||
client.socket = -1;
|
client.socket = -1;
|
||||||
|
tty_dev.fd = -1;
|
||||||
|
|
||||||
/* open tty device */
|
/* open tty device */
|
||||||
if (tty_open(&tty_dev) < 0) {
|
if (tty_open(&tty_dev) < 0) {
|
||||||
fprintf(stderr, "[%s] error: opening of tty device at %s failed\n"
|
fprintf(stderr, "[%s] error: opening of tty device at %s failed\n"
|
||||||
"\t\t-> continuing in echo mode\n", NAME, tty_dev.path);
|
"\t\t-> continuing in echo mode\n", NAME, tty_dev.path);
|
||||||
//return -1;
|
debug_messages = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* start thread that handles tty device */
|
/* start thread that handles tty device */
|
||||||
|
@ -180,9 +181,11 @@ int main(int argc, char *argv[]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* pass received data to tty device */
|
/* pass received data to tty device */
|
||||||
|
if (tty_dev.fd != -1) {
|
||||||
tty_write(&tty_dev, client.data, ret);
|
tty_write(&tty_dev, client.data, ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
/* do something with inactive client */
|
/* do something with inactive client */
|
||||||
if (client.socket != -1) {
|
if (client.socket != -1) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue