diff --git a/man1/stc.1 b/man1/stc.1 index 19cfe9b..12bd00b 100644 --- a/man1/stc.1 +++ b/man1/stc.1 @@ -26,7 +26,7 @@ if it failed to setup terminal if it failed to create epoll instance .TP 5 -if it failed to set signal handler (for SIGINT or SIGTERM) +if it failed to set signal handler for SIGTERM .TP 6 if it failed to add a file descriptor to the epoll instance (for stdin or the socket) @@ -39,6 +39,9 @@ if it failed to receive data .TP 9 if it failed to send data +.TP +10 +if unattended file descriptor is raised while polling .SH AUTHOR Franck STAUFFER .I diff --git a/src/main.c b/src/main.c index 0556edb..c421b80 100644 --- a/src/main.c +++ b/src/main.c @@ -107,7 +107,7 @@ net_init(const char* host, const char* port) void sighandler(int sig) { - fprintf(stderr, "Received %s", (sig == SIGTERM) ? "SIGTERM" : "SIGINT"); + fputs("\n\rINFO: Received SIGTERM\n", stderr); exit(sig); } @@ -147,18 +147,13 @@ main(int argc, char** argv) epoll_fd = epoll_create1(0); if (epoll_fd == -1) { - perror("epoll_create1"); + perror("ERROR: epoll_create1"); return 4; } atexit(cleanup); - if (signal(SIGINT, sighandler) == SIG_ERR) { - perror("signal"); - return 5; - } - if (signal(SIGTERM, sighandler) == SIG_ERR) { - perror("signal"); + perror("ERROR: signal"); return 5; } @@ -168,14 +163,14 @@ main(int argc, char** argv) ev[0].events = EPOLLIN; ev[0].data.fd = 0; if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, 0, &ev[0])) { - perror("epoll_ctl"); + perror("ERROR: epoll_ctl"); return 6; } ev[1].events = EPOLLIN; ev[1].data.fd = sock; if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev[1])) { - perror("epoll_ctl"); + perror("ERROR: epoll_ctl"); return 6; } @@ -185,7 +180,7 @@ main(int argc, char** argv) struct epoll_event events[2]; int_fast8_t count = epoll_wait(epoll_fd, events, 2, -1); if (count == -1) { - perror("epoll_wait"); + perror("ERROR: epoll_wait"); return 7; } @@ -195,7 +190,7 @@ main(int argc, char** argv) memset(buf, 0, 3); int_fast8_t ret = recv(sock, buf, 1, 0); if (ret == -1) { - perror("recv"); + perror("ERROR: recv"); return 8; } @@ -205,7 +200,7 @@ main(int argc, char** argv) if (buf[0] == IAC) { ret = recv(sock, buf + 1, 2, 0); if (ret < 0) { - perror("recv"); + perror("ERROR: recv"); return 8; } @@ -225,7 +220,7 @@ main(int argc, char** argv) } if (send(sock, &chr, 1, 0) != 1) { - perror("send"); + perror("ERROR: send"); return 9; }