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:
@@ -28,11 +28,11 @@ static char rcsid[] = "@(#)$Id$";
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
|
|
||||||
static int s;
|
static int sock;
|
||||||
static char buffer[256];
|
static char buffer[256];
|
||||||
|
|
||||||
void my_exit(int);
|
static void my_exit(int);
|
||||||
void ignore (int value);
|
static void sigint_handler(int value);
|
||||||
|
|
||||||
#ifdef CLOAKED
|
#ifdef CLOAKED
|
||||||
extern char **Argv;
|
extern char **Argv;
|
||||||
@@ -54,7 +54,7 @@ int main (int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
my_signal(SIGHUP, SIG_IGN, 0);
|
my_signal(SIGHUP, SIG_IGN, 0);
|
||||||
my_signal(SIGQUIT, 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 */
|
if (argc != 3) /* no socket is passed */
|
||||||
my_exit(1);
|
my_exit(1);
|
||||||
@@ -64,8 +64,8 @@ int main (int argc, char **argv)
|
|||||||
if (!port)
|
if (!port)
|
||||||
my_exit(2); /* what the hey */
|
my_exit(2); /* what the hey */
|
||||||
|
|
||||||
s = connect_by_number(host, &port, SERVICE_CLIENT, PROTOCOL_TCP, 0);
|
sock = connect_by_number(host, &port, SERVICE_CLIENT, PROTOCOL_TCP, 0);
|
||||||
if (s < 0)
|
if (sock < 0)
|
||||||
my_exit(23);
|
my_exit(23);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -74,7 +74,7 @@ int main (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
tmp = ttyname(0);
|
tmp = ttyname(0);
|
||||||
snprintf(stuff, sizeof stuff, "%s\n", tmp);
|
snprintf(stuff, sizeof stuff, "%s\n", tmp);
|
||||||
t = write(s, stuff, strlen(stuff));
|
t = write(sock, stuff, strlen(stuff));
|
||||||
term_init(NULL);
|
term_init(NULL);
|
||||||
printf("t is %d", t);
|
printf("t is %d", t);
|
||||||
|
|
||||||
@@ -86,8 +86,8 @@ int main (int argc, char **argv)
|
|||||||
{
|
{
|
||||||
FD_ZERO(&reads);
|
FD_ZERO(&reads);
|
||||||
FD_SET(0, &reads);
|
FD_SET(0, &reads);
|
||||||
FD_SET(s, &reads);
|
FD_SET(sock, &reads);
|
||||||
if (select(s + 1, &reads, NULL, NULL, NULL) <= 0)
|
if (select(sock + 1, &reads, NULL, NULL, NULL) <= 0)
|
||||||
{
|
{
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
@@ -99,13 +99,13 @@ int main (int argc, char **argv)
|
|||||||
{
|
{
|
||||||
nread = read(0, buffer, sizeof buffer);
|
nread = read(0, buffer, sizeof buffer);
|
||||||
if (nread > 0)
|
if (nread > 0)
|
||||||
write(s, buffer, nread);
|
write(sock, buffer, nread);
|
||||||
else
|
else
|
||||||
my_exit(3);
|
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)
|
if (nread > 0)
|
||||||
write(1, buffer, nread);
|
write(1, buffer, nread);
|
||||||
else
|
else
|
||||||
@@ -116,14 +116,14 @@ int main (int argc, char **argv)
|
|||||||
my_exit(8);
|
my_exit(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ignore (int value)
|
static void sigint_handler(int value)
|
||||||
{
|
{
|
||||||
/* send a ^C */
|
/* send a ^C */
|
||||||
char foo = 3;
|
static const char ctrl_c = 3;
|
||||||
write(s, &foo, 1);
|
write(sock, &ctrl_c, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void my_exit(int value)
|
static void my_exit(int value)
|
||||||
{
|
{
|
||||||
printf("exiting with %d!\n", value);
|
printf("exiting with %d!\n", value);
|
||||||
printf("errno is %d (%s)\n", errno, strerror(errno));
|
printf("errno is %d (%s)\n", errno, strerror(errno));
|
||||||
|
|||||||
Reference in New Issue
Block a user