summaryrefslogtreecommitdiff
path: root/usr.sbin/lpr/common_source/common.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2001-11-23 03:58:20 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2001-11-23 03:58:20 +0000
commit303691bd4aa8c95441d01f02bcdb86f75e1bdaf6 (patch)
treee526bb85aee1ee03ee11ec7f886bb1429e24dbd2 /usr.sbin/lpr/common_source/common.c
parent5bce9eb803ff87338cbef6aa2e55f2ae8d7ddf00 (diff)
use the same siginterrupt() trick in lpc(1) as in timedc(1). we have to hack
a global into the other programs since they share some source.
Diffstat (limited to 'usr.sbin/lpr/common_source/common.c')
-rw-r--r--usr.sbin/lpr/common_source/common.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/usr.sbin/lpr/common_source/common.c b/usr.sbin/lpr/common_source/common.c
index e0164cd5fae..592f4eef608 100644
--- a/usr.sbin/lpr/common_source/common.c
+++ b/usr.sbin/lpr/common_source/common.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: common.c,v 1.12 2001/08/30 17:38:13 millert Exp $ */
+/* $OpenBSD: common.c,v 1.13 2001/11/23 03:58:17 deraadt Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -42,7 +42,7 @@
#if 0
static const char sccsid[] = "@(#)common.c 8.5 (Berkeley) 4/28/95";
#else
-static const char rcsid[] = "$OpenBSD: common.c,v 1.12 2001/08/30 17:38:13 millert Exp $";
+static const char rcsid[] = "$OpenBSD: common.c,v 1.13 2001/11/23 03:58:17 deraadt Exp $";
#endif
#endif /* not lint */
@@ -149,9 +149,17 @@ getport(rhost, rport)
if (inet_aton(rhost, &sin.sin_addr) == 1)
sin.sin_family = AF_INET;
else {
+ siginterrupt(SIGINT, 1);
hp = gethostbyname(rhost);
- if (hp == NULL)
+ if (hp == NULL) {
+ if (errno == EINTR && gotintr) {
+ siginterrupt(SIGINT, 0);
+ return (-1);
+ }
+ siginterrupt(SIGINT, 0);
fatal("unknown host %s", rhost);
+ }
+ siginterrupt(SIGINT, 0);
bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length);
sin.sin_family = hp->h_addrtype;
}
@@ -168,14 +176,22 @@ getport(rhost, rport)
*/
retry:
seteuid(euid);
+ siginterrupt(SIGINT, 1);
s = rresvport(&lport);
+ siginterrupt(SIGINT, 0);
seteuid(uid);
if (s < 0)
return(-1);
+ siginterrupt(SIGINT, 1);
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
err = errno;
(void) close(s);
+ siginterrupt(SIGINT, 0);
errno = err;
+ if (errno == EINTR && gotintr) {
+ close(s);
+ return (-1);
+ }
if (errno == EADDRINUSE) {
lport--;
goto retry;
@@ -187,6 +203,7 @@ retry:
}
return(-1);
}
+ siginterrupt(SIGINT, 0);
/* Don't bother if we get an error here. */
setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *)&on, sizeof on);
@@ -327,13 +344,21 @@ checkremote()
/* get the official name of the local host */
gethostname(name, sizeof(name));
name[sizeof(name)-1] = '\0';
+ siginterrupt(SIGINT, 1);
hp = gethostbyname(name);
if (hp == (struct hostent *) NULL) {
- (void) snprintf(errbuf, sizeof(errbuf),
- "unable to get official name for local machine %s",
- name);
- return errbuf;
- } else (void) strcpy(name, hp->h_name);
+ if (errno == EINTR && gotintr) {
+ siginterrupt(SIGINT, 0);
+ return NULL;
+ }
+ siginterrupt(SIGINT, 0);
+ (void) snprintf(errbuf, sizeof(errbuf),
+ "unable to get official name for local machine %s",
+ name);
+ return errbuf;
+ } else
+ strlcpy(name, hp->h_name, sizeof name);
+ siginterrupt(SIGINT, 0);
/* get the official name of RM */
hp = gethostbyname(RM);