Minor cleanups in wserv.c
Rename global variable 's' to a longer name. Rename function 'ignore' to a name that reflects what it actually does. Make sigint_handler() and my_exit() static, because they're only used in this file.
This commit is contained in:
parent
ba1b9742ec
commit
70ce80dced
|
@ -28,11 +28,11 @@ static char rcsid[] = "@(#)$Id$";
|
|||
#include <errno.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
static int s;
|
||||
static char buffer[256];
|
||||
static int sock;
|
||||
static char buffer[256];
|
||||
|
||||
void my_exit(int);
|
||||
void ignore (int value);
|
||||
static void my_exit(int);
|
||||
static void sigint_handler(int value);
|
||||
|
||||
#ifdef CLOAKED
|
||||
extern char **Argv;
|
||||
|
@ -54,7 +54,7 @@ int main (int argc, char **argv)
|
|||
#endif
|
||||
my_signal(SIGHUP, SIG_IGN, 0);
|
||||
my_signal(SIGQUIT, SIG_IGN, 0);
|
||||
my_signal(SIGINT, ignore, 0);
|
||||
my_signal(SIGINT, sigint_handler, 0);
|
||||
|
||||
if (argc != 3) /* no socket is passed */
|
||||
my_exit(1);
|
||||
|
@ -64,8 +64,8 @@ int main (int argc, char **argv)
|
|||
if (!port)
|
||||
my_exit(2); /* what the hey */
|
||||
|
||||
s = connect_by_number(host, &port, SERVICE_CLIENT, PROTOCOL_TCP, 0);
|
||||
if (s < 0)
|
||||
sock = connect_by_number(host, &port, SERVICE_CLIENT, PROTOCOL_TCP, 0);
|
||||
if (sock < 0)
|
||||
my_exit(23);
|
||||
|
||||
/*
|
||||
|
@ -74,7 +74,7 @@ int main (int argc, char **argv)
|
|||
*/
|
||||
tmp = ttyname(0);
|
||||
snprintf(stuff, sizeof stuff, "%s\n", tmp);
|
||||
t = write(s, stuff, strlen(stuff));
|
||||
t = write(sock, stuff, strlen(stuff));
|
||||
term_init(NULL);
|
||||
printf("t is %d", t);
|
||||
|
||||
|
@ -86,8 +86,8 @@ int main (int argc, char **argv)
|
|||
{
|
||||
FD_ZERO(&reads);
|
||||
FD_SET(0, &reads);
|
||||
FD_SET(s, &reads);
|
||||
if (select(s + 1, &reads, NULL, NULL, NULL) <= 0)
|
||||
FD_SET(sock, &reads);
|
||||
if (select(sock + 1, &reads, NULL, NULL, NULL) <= 0)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
|
@ -99,13 +99,13 @@ int main (int argc, char **argv)
|
|||
{
|
||||
nread = read(0, buffer, sizeof buffer);
|
||||
if (nread > 0)
|
||||
write(s, buffer, nread);
|
||||
write(sock, buffer, nread);
|
||||
else
|
||||
my_exit(3);
|
||||
}
|
||||
if (FD_ISSET(s, &reads))
|
||||
if (FD_ISSET(sock, &reads))
|
||||
{
|
||||
nread = read(s, buffer, sizeof buffer);
|
||||
nread = read(sock, buffer, sizeof buffer);
|
||||
if (nread > 0)
|
||||
write(1, buffer, nread);
|
||||
else
|
||||
|
@ -116,14 +116,14 @@ int main (int argc, char **argv)
|
|||
my_exit(8);
|
||||
}
|
||||
|
||||
void ignore (int value)
|
||||
static void sigint_handler(int value)
|
||||
{
|
||||
/* send a ^C */
|
||||
char foo = 3;
|
||||
write(s, &foo, 1);
|
||||
static const char ctrl_c = 3;
|
||||
write(sock, &ctrl_c, 1);
|
||||
}
|
||||
|
||||
void my_exit(int value)
|
||||
static void my_exit(int value)
|
||||
{
|
||||
printf("exiting with %d!\n", value);
|
||||
printf("errno is %d (%s)\n", errno, strerror(errno));
|
||||
|
|
Loading…
Reference in New Issue