summaryrefslogtreecommitdiff
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
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.
-rw-r--r--usr.sbin/lpr/common_source/common.c41
-rw-r--r--usr.sbin/lpr/common_source/lp.h5
-rw-r--r--usr.sbin/lpr/common_source/startdaemon.c17
-rw-r--r--usr.sbin/lpr/lpc/lpc.c49
-rw-r--r--usr.sbin/lpr/lpd/lpd.c7
-rw-r--r--usr.sbin/lpr/lpq/lpq.c6
-rw-r--r--usr.sbin/lpr/lpr/lpr.c6
-rw-r--r--usr.sbin/lpr/lprm/lprm.c6
-rw-r--r--usr.sbin/lpr/pac/pac.c6
9 files changed, 99 insertions, 44 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);
diff --git a/usr.sbin/lpr/common_source/lp.h b/usr.sbin/lpr/common_source/lp.h
index 17baf7112f7..b46c0eac9c2 100644
--- a/usr.sbin/lpr/common_source/lp.h
+++ b/usr.sbin/lpr/common_source/lp.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: lp.h,v 1.4 2001/11/01 18:02:33 mickey Exp $ */
+/* $OpenBSD: lp.h,v 1.5 2001/11/23 03:58:17 deraadt Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -90,6 +90,9 @@ extern char host[MAXHOSTNAMELEN];
extern char *from; /* client's machine name */
extern int remote; /* true if sending files to a remote host */
extern char *printcapdb[]; /* printcap database array */
+
+extern volatile sig_atomic_t gotintr;
+
/*
* Structure used for building a sorted list of control files.
*/
diff --git a/usr.sbin/lpr/common_source/startdaemon.c b/usr.sbin/lpr/common_source/startdaemon.c
index da8c5d0950b..07c376943a2 100644
--- a/usr.sbin/lpr/common_source/startdaemon.c
+++ b/usr.sbin/lpr/common_source/startdaemon.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: startdaemon.c,v 1.4 2001/08/30 17:38:13 millert Exp $ */
+/* $OpenBSD: startdaemon.c,v 1.5 2001/11/23 03:58:17 deraadt Exp $ */
/*
* Copyright (c) 1983, 1993, 1994
@@ -37,11 +37,10 @@
#if 0
static const char sccsid[] = "@(#)startdaemon.c 8.2 (Berkeley) 4/17/94";
#else
-static const char rcsid[] = "$OpenBSD: startdaemon.c,v 1.4 2001/08/30 17:38:13 millert Exp $";
+static const char rcsid[] = "$OpenBSD: startdaemon.c,v 1.5 2001/11/23 03:58:17 deraadt Exp $";
#endif
#endif /* not lint */
-
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/un.h>
@@ -82,18 +81,29 @@ startdaemon(printer)
#define SUN_LEN(unp) (strlen((unp)->sun_path) + 2)
#endif
seteuid(euid);
+ siginterrupt(SIGINT, 1);
if (connect(s, (struct sockaddr *)&un, SUN_LEN(&un)) < 0) {
+ if (errno == EINTR && gotintr) {
+ siginterrupt(SIGINT, 0);
+ seteuid(uid);
+ close(s);
+ return(0);
+ }
+ siginterrupt(SIGINT, 0);
seteuid(uid);
perr("connect");
(void) close(s);
return(0);
}
+ siginterrupt(SIGINT, 0);
seteuid(uid);
if (snprintf(buf, sizeof buf, "\1%s\n", printer) > sizeof buf-1) {
close(s);
return (0);
}
n = strlen(buf);
+
+ /* XXX atomicio inside siginterrupt? */
if (write(s, buf, n) != n) {
perr("write");
(void) close(s);
@@ -108,6 +118,7 @@ startdaemon(printer)
}
while ((n = read(s, buf, sizeof(buf))) > 0)
fwrite(buf, 1, n, stdout);
+
(void) close(s);
return(0);
}
diff --git a/usr.sbin/lpr/lpc/lpc.c b/usr.sbin/lpr/lpc/lpc.c
index 8a7cbcb3fb3..42b23fde8d7 100644
--- a/usr.sbin/lpr/lpc/lpc.c
+++ b/usr.sbin/lpr/lpc/lpc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lpc.c,v 1.9 2001/08/30 17:38:13 millert Exp $ */
+/* $OpenBSD: lpc.c,v 1.10 2001/11/23 03:58:18 deraadt Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -44,7 +44,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)lpc.c 8.3 (Berkeley) 4/28/95";
#else
-static const char rcsid[] = "$OpenBSD: lpc.c,v 1.9 2001/08/30 17:38:13 millert Exp $";
+static const char rcsid[] = "$OpenBSD: lpc.c,v 1.10 2001/11/23 03:58:18 deraadt Exp $";
#endif
#endif /* not lint */
@@ -52,11 +52,11 @@ static const char rcsid[] = "$OpenBSD: lpc.c,v 1.9 2001/08/30 17:38:13 millert E
#include <dirent.h>
#include <signal.h>
-#include <setjmp.h>
#include <syslog.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
+#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <grp.h>
@@ -80,12 +80,9 @@ int fromatty;
char cmdline[MAX_CMDLINE];
int margc;
char *margv[MAX_MARGV];
-int top;
uid_t uid, euid;
-jmp_buf toplevel;
-
-void cmdscanner __P((int));
+void cmdscanner __P((void));
struct cmd *getcmd __P((char *));
void intr __P((int));
void makeargv __P((void));
@@ -122,42 +119,51 @@ main(argc, argv)
exit(0);
}
fromatty = isatty(fileno(stdin));
- top = sigsetjmp(toplevel, 1) == 0;
- if (top)
- signal(SIGINT, intr);
- for (;;) {
- cmdscanner(top);
- top = 1;
- }
+ signal(SIGINT, intr);
+ for (;;)
+ cmdscanner();
}
+volatile sig_atomic_t gotintr;
+
void
intr(signo)
int signo;
{
if (!fromatty)
- exit(0);
- siglongjmp(toplevel, 1);
+ _exit(0);
+ gotintr = 1;
}
/*
* Command parser.
*/
void
-cmdscanner(top)
- int top;
+cmdscanner(void)
{
struct cmd *c;
- if (!top)
- putchar('\n');
for (;;) {
+ if (gotintr) {
+ putchar('\n');
+ gotintr = 0;
+ }
if (fromatty) {
printf("lpc> ");
fflush(stdout);
}
- if (fgets(cmdline, MAX_CMDLINE, stdin) == 0)
+
+ siginterrupt(SIGINT, 1);
+ if (fgets(cmdline, MAX_CMDLINE, stdin) == NULL) {
+ if (errno == EINTR && gotintr) {
+ siginterrupt(SIGINT, 0);
+ return;
+ }
+ siginterrupt(SIGINT, 0);
quit(0, NULL);
+ }
+ siginterrupt(SIGINT, 0);
+
if (cmdline[0] == 0 || cmdline[0] == '\n')
break;
makeargv();
@@ -176,7 +182,6 @@ cmdscanner(top)
}
(*c->c_handler)(margc, margv);
}
- siglongjmp(toplevel, 0);
}
struct cmd *
diff --git a/usr.sbin/lpr/lpd/lpd.c b/usr.sbin/lpr/lpd/lpd.c
index 37e410e1682..1da204184b5 100644
--- a/usr.sbin/lpr/lpd/lpd.c
+++ b/usr.sbin/lpr/lpd/lpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lpd.c,v 1.22 2001/11/19 20:27:13 deraadt Exp $ */
+/* $OpenBSD: lpd.c,v 1.23 2001/11/23 03:58:18 deraadt Exp $ */
/* $NetBSD: lpd.c,v 1.7 1996/04/24 14:54:06 mrg Exp $ */
/*
@@ -45,7 +45,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)lpd.c 8.7 (Berkeley) 5/10/95";
#else
-static const char rcsid[] = "$OpenBSD: lpd.c,v 1.22 2001/11/19 20:27:13 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: lpd.c,v 1.23 2001/11/23 03:58:18 deraadt Exp $";
#endif
#endif /* not lint */
@@ -116,6 +116,9 @@ static void startup __P((void));
static void chkhost __P((struct sockaddr_in *));
static int ckqueue __P((char *));
+/* unused, needed for lpc */
+volatile sig_atomic_t gotintr;
+
uid_t uid, euid;
int
diff --git a/usr.sbin/lpr/lpq/lpq.c b/usr.sbin/lpr/lpq/lpq.c
index 0b7b09cf550..4b2c9b2ab48 100644
--- a/usr.sbin/lpr/lpq/lpq.c
+++ b/usr.sbin/lpr/lpq/lpq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lpq.c,v 1.8 2001/08/30 17:38:13 millert Exp $ */
+/* $OpenBSD: lpq.c,v 1.9 2001/11/23 03:58:18 deraadt Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -44,7 +44,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)lpq.c 8.3 (Berkeley) 5/10/95";
#else
-static const char rcsid[] = "$OpenBSD: lpq.c,v 1.8 2001/08/30 17:38:13 millert Exp $";
+static const char rcsid[] = "$OpenBSD: lpq.c,v 1.9 2001/11/23 03:58:18 deraadt Exp $";
#endif
#endif /* not lint */
@@ -77,6 +77,8 @@ int users; /* # of users in user array */
uid_t uid, euid;
+volatile sig_atomic_t gotintr;
+
static int ckqueue __P((char *));
void usage __P((void));
diff --git a/usr.sbin/lpr/lpr/lpr.c b/usr.sbin/lpr/lpr/lpr.c
index a6a3ba0ca91..eac99c57038 100644
--- a/usr.sbin/lpr/lpr/lpr.c
+++ b/usr.sbin/lpr/lpr/lpr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lpr.c,v 1.21 2001/11/19 20:26:51 deraadt Exp $ */
+/* $OpenBSD: lpr.c,v 1.22 2001/11/23 03:58:18 deraadt Exp $ */
/* $NetBSD: lpr.c,v 1.10 1996/03/21 18:12:25 jtc Exp $ */
/*
@@ -50,7 +50,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)lpr.c 8.4 (Berkeley) 4/28/95";
#else
-static const char rcsid[] = "$OpenBSD: lpr.c,v 1.21 2001/11/19 20:26:51 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: lpr.c,v 1.22 2001/11/23 03:58:18 deraadt Exp $";
#endif
#endif /* not lint */
@@ -106,6 +106,8 @@ static char *width; /* width for versatec printing */
static struct stat statb;
+volatile sig_atomic_t gotintr;
+
static void card __P((int, char *));
static void chkprinter __P((char *));
static void cleanup __P((int));
diff --git a/usr.sbin/lpr/lprm/lprm.c b/usr.sbin/lpr/lprm/lprm.c
index b9ad446c5e4..838224a29ef 100644
--- a/usr.sbin/lpr/lprm/lprm.c
+++ b/usr.sbin/lpr/lprm/lprm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lprm.c,v 1.7 2001/08/30 17:38:13 millert Exp $ */
+/* $OpenBSD: lprm.c,v 1.8 2001/11/23 03:58:18 deraadt Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -44,7 +44,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)lprm.c 8.1 (Berkeley) 6/6/93";
#else
-static const char rcsid[] = "$OpenBSD: lprm.c,v 1.7 2001/08/30 17:38:13 millert Exp $";
+static const char rcsid[] = "$OpenBSD: lprm.c,v 1.8 2001/11/23 03:58:18 deraadt Exp $";
#endif
#endif /* not lint */
@@ -84,6 +84,8 @@ uid_t uid, euid; /* real and effective user id's */
static char luser[MAXLOGNAME]; /* buffer for person */
+volatile sig_atomic_t gotintr;
+
void usage __P((void));
int
diff --git a/usr.sbin/lpr/pac/pac.c b/usr.sbin/lpr/pac/pac.c
index 9899a5fc1e5..7ba97d9615e 100644
--- a/usr.sbin/lpr/pac/pac.c
+++ b/usr.sbin/lpr/pac/pac.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pac.c,v 1.10 2001/08/30 17:38:13 millert Exp $ */
+/* $OpenBSD: pac.c,v 1.11 2001/11/23 03:58:19 deraadt Exp $ */
/* $NetBSD: pac.c,v 1.7 1996/03/21 18:21:20 jtc Exp $ */
/*
@@ -45,7 +45,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)pac.c 8.1 (Berkeley) 6/6/93";
#else
-static const char rcsid[] = "$OpenBSD: pac.c,v 1.10 2001/08/30 17:38:13 millert Exp $";
+static const char rcsid[] = "$OpenBSD: pac.c,v 1.11 2001/11/23 03:58:19 deraadt Exp $";
#endif
#endif /* not lint */
@@ -81,6 +81,8 @@ static int summarize; /* Compress accounting file */
uid_t uid, euid;
+volatile sig_atomic_t gotintr;
+
/*
* Grossness follows:
* Names to be accumulated are hashed into the following