summaryrefslogtreecommitdiff
path: root/clients
diff options
context:
space:
mode:
authorGravatar Richard Basch <probe@mit.edu>1993-10-16 17:51:26 +0000
committerGravatar Richard Basch <probe@mit.edu>1993-10-16 17:51:26 +0000
commit5ba5e3379dc21d1d53622902114fc9d5e3accdec (patch)
treec62e9dc1f9449a508a62d7c1777e527ed1a0d9d8 /clients
parentecde205da8aba4ef19fd1eed4be6a3d5ab0b6d6e (diff)
POSIX signal handling
Diffstat (limited to 'clients')
-rw-r--r--clients/zleave/zleave.c13
-rw-r--r--clients/zlocate/zlocate.c203
-rw-r--r--clients/zstat/zstat.c23
3 files changed, 134 insertions, 105 deletions
diff --git a/clients/zleave/zleave.c b/clients/zleave/zleave.c
index 27319f5..45cd3ee 100644
--- a/clients/zleave/zleave.c
+++ b/clients/zleave/zleave.c
@@ -221,6 +221,9 @@ long nmins;
long seconds, gseconds;
long daytime;
FILE *fp;
+#ifdef POSIX
+ struct sigaction sa;
+#endif
seconds = 60 * nmins;
if (seconds <= 0)
@@ -282,10 +285,20 @@ long nmins;
(void) perror("fclose on pid file");
}
+#ifdef POSIX
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = SIG_IGN;
+ sigaction(SIGINT, &sa, (struct sigaction *)0);
+ sigaction(SIGQUIT, &sa, (struct sigaction *)0);
+ sigaction(SIGTERM, &sa, (struct sigaction *)0);
+ sigaction(SIGTTOU, &sa, (struct sigaction *)0);
+#else
(void) signal(SIGINT, SIG_IGN);
(void) signal(SIGQUIT, SIG_IGN);
(void) signal(SIGTERM, SIG_IGN);
(void) signal(SIGTTOU, SIG_IGN);
+#endif
if (slp1)
bother(slp1, msg1);
diff --git a/clients/zlocate/zlocate.c b/clients/zlocate/zlocate.c
index a3b7073..c219d06 100644
--- a/clients/zlocate/zlocate.c
+++ b/clients/zlocate/zlocate.c
@@ -73,110 +73,107 @@ main(argc,argv)
int argc;
char *argv[];
{
- char user[BUFSIZ],*whichuser;
- ZAsyncLocateData_t ald;
- int retval,i,numlocs,loc,auth;
- ZNotice_t notice;
+ char user[BUFSIZ],*whichuser;
+ ZAsyncLocateData_t ald;
+ int retval,i,numlocs,loc,auth;
+ ZNotice_t notice;
+#ifdef POSIX
+ struct sigaction sa;
+#endif
- whoami = argv[0];
- auth = -1;
-
- argv++;
- argc--;
-
- for (i=0; i < argc; i++)
- if (argv[i][0] == '-')
- switch (argv[i][1]) {
- case 'a':
- if (auth != -1) usage();
- auth = 1;
- break;
- case 'd':
- if (auth != -1) usage();
- auth = 0;
- break;
- case 'p':
- parallel = 1;
- break;
- case '1':
- oneline = 1;
- break;
- default:
- usage();
- break;
- }
- else
- numusers++;
-
- if (numusers == 0)
- usage();
-
- if (auth == -1) auth = 1;
+ whoami = argv[0];
+ auth = -1;
+
+ argv++;
+ argc--;
+
+ for (i=0; i < argc; i++)
+ if (argv[i][0] == '-')
+ switch (argv[i][1]) {
+ case 'a':
+ if (auth != -1) usage();
+ auth = 1;
+ break;
+ case 'd':
+ if (auth != -1) usage();
+ auth = 0;
+ break;
+ case 'p':
+ parallel = 1;
+ break;
+ case '1':
+ oneline = 1;
+ break;
+ default:
+ usage();
+ break;
+ }
+ else
+ numusers++;
+
+ if (numusers == 0)
+ usage();
+
+ if (auth == -1) auth = 1;
- if ((retval = ZInitialize()) != ZERR_NONE) {
- com_err(whoami,retval,"while initializing");
- exit(1);
- }
-
-#if 0
- {
- int len,len2;
- ZOpenPort((u_short*)0);
- if(getsockopt(ZGetFD(), SOL_SOCKET, SO_RCVBUF, (char *)&len, &len2) == -1)
- perror("getsockopt");
- fprintf(stderr, "socket RCVBUF is %x\n", len);
- len = 56 * 1024;
- if(setsockopt(ZGetFD(), SOL_SOCKET, SO_RCVBUF, (char *)&len, sizeof(int)) == -1)
- perror("setsockopt");
- }
+ if ((retval = ZInitialize()) != ZERR_NONE) {
+ com_err(whoami,retval,"while initializing");
+ exit(1);
+ }
+
+ numleft = numusers;
+
+ i = 0;
+ for (loc = 0; loc < argc; loc++) {
+ if (argv[loc][0] == '-') continue;
+
+ (void) strcpy(user,argv[loc]);
+ if (!index(user,'@')) {
+ (void) strcat(user,"@");
+ (void) strcat(user,ZGetRealm());
+ }
+ if (parallel) {
+ if ((retval = ZRequestLocations(user, &ald, i ? UNSAFE : UNACKED,
+ auth?ZAUTH:ZNOAUTH)) != ZERR_NONE) {
+ com_err(whoami,retval,"requesting location of %s",user);
+ exit(1);
+ }
+ i = 1;
+ } else {
+ if ((retval = ZLocateUser(user,&numlocs,auth?ZAUTH:ZNOAUTH)) != ZERR_NONE) {
+ com_err(whoami,retval,"while locating user %s",user);
+ exit(1);
+ }
+ print_locs(user,numlocs);
+ }
+ }
+
+ if (parallel) {
+#ifdef POSIX
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = timeout;
+ sigaction(SIGALRM, &sa, (struct sigaction *)0);
+#else
+ signal (SIGALRM, timeout);
#endif
-
- numleft = numusers;
-
- i = 0;
- for (loc = 0; loc < argc; loc++) {
- if (argv[loc][0] == '-') continue;
-
- (void) strcpy(user,argv[loc]);
- if (!index(user,'@')) {
- (void) strcat(user,"@");
- (void) strcat(user,ZGetRealm());
- }
- if (parallel) {
- if ((retval = ZRequestLocations(user, &ald, i ? UNSAFE : UNACKED,
- auth?ZAUTH:ZNOAUTH)) != ZERR_NONE) {
- com_err(whoami,retval,"requesting location of %s",user);
- exit(1);
- }
- i = 1;
- } else {
- if ((retval = ZLocateUser(user,&numlocs,auth?ZAUTH:ZNOAUTH)) != ZERR_NONE) {
- com_err(whoami,retval,"while locating user %s",user);
- exit(1);
- }
- print_locs(user,numlocs);
- }
- }
-
- if (parallel) {
- signal (SIGALRM, timeout);
- while (numleft-- > 0) {
- alarm(SRV_TIMEOUT);
- if ((retval = ZReceiveNotice(&notice, NULL)) != ZERR_NONE) {
- com_err(whoami,retval,"while searching notice queue");
- continue;
- }
- if ((retval = ZParseLocations(&notice, (ZAsyncLocateData_t *)NULL,
- &numlocs, &whichuser)) != ZERR_NONE) {
- com_err(whoami,retval,"while parsing locations");
- continue;
- }
- if (numlocs >= 0) {
- print_locs(whichuser,numlocs);
- free(whichuser);
- }
- ZFreeNotice(&notice);
- }
- }
- return(0);
+ while (numleft-- > 0) {
+ alarm(SRV_TIMEOUT);
+ if ((retval = ZReceiveNotice(&notice, NULL)) != ZERR_NONE) {
+ com_err(whoami,retval,"while searching notice queue");
+ continue;
+ }
+ if ((retval = ZParseLocations(&notice, (ZAsyncLocateData_t *)NULL,
+ &numlocs, &whichuser)) != ZERR_NONE) {
+ com_err(whoami,retval,"while parsing locations");
+ continue;
+ }
+ if (numlocs >= 0) {
+ print_locs(whichuser,numlocs);
+ free(whichuser);
+ }
+ ZFreeNotice(&notice);
+ }
+ }
+ return(0);
}
diff --git a/clients/zstat/zstat.c b/clients/zstat/zstat.c
index ed013a1..a72ed4b 100644
--- a/clients/zstat/zstat.c
+++ b/clients/zstat/zstat.c
@@ -163,6 +163,9 @@ hm_stat(host,server)
long runtime;
struct tm *tim;
ZNotice_t notice;
+#ifdef POSIX
+ struct sigaction sa;
+#endif
_BZERO((char *)&sin,sizeof(struct sockaddr_in));
@@ -202,8 +205,14 @@ hm_stat(host,server)
com_err("zstat", ret, "sending notice");
exit(-1);
}
-
+#ifdef POSIX
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = timeout;
+ (void) sigaction(SIGALRM, &sa, (struct sigaction *)0);
+#else
(void) signal(SIGALRM,timeout);
+#endif
outoftime = 0;
(void) alarm(10);
if (((ret = ZReceiveNotice(&notice, (struct sockaddr_in *) 0))
@@ -259,7 +268,10 @@ srv_stat(host)
ZNotice_t notice;
long runtime;
struct tm *tim;
-
+#ifdef POSIX
+ struct sigaction sa;
+#endif
+
_BZERO((char *) &sin,sizeof(struct sockaddr_in));
sin.sin_port = srv_port;
@@ -299,7 +311,14 @@ srv_stat(host)
exit(-1);
}
+#ifdef POSIX
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = timeout;
+ (void) sigaction(SIGALRM, &sa, (struct sigaction *)0);
+#else
(void) signal(SIGALRM,timeout);
+#endif
outoftime = 0;
(void) alarm(10);
if (((ret = ZReceiveNotice(&notice, (struct sockaddr_in *) 0))