summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2001-11-26 05:04:34 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2001-11-26 05:04:34 +0000
commit42c156187e1501831aed701070935c6e1cc4fcb3 (patch)
tree604514bb78ab651f88a031808e09ad4ab444c6b4 /usr.sbin
parenta97cf58f2b9ffb68f4c476a5bd2e42a6e0d1648c (diff)
mostly mark signal races
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_install/add/perform.c24
-rw-r--r--usr.sbin/pkg_install/create/perform.c21
-rw-r--r--usr.sbin/pkg_install/delete/perform.c8
-rw-r--r--usr.sbin/pkg_install/info/perform.c8
-rw-r--r--usr.sbin/pkg_install/lib/pen.c19
-rw-r--r--usr.sbin/pkg_install/sign/sha1.c4
6 files changed, 50 insertions, 34 deletions
diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c
index 1e2d4a4ded8..99937e8b3f9 100644
--- a/usr.sbin/pkg_install/add/perform.c
+++ b/usr.sbin/pkg_install/add/perform.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: perform.c,v 1.21 2001/11/17 10:40:05 espie Exp $ */
+/* $OpenBSD: perform.c,v 1.22 2001/11/26 05:04:33 deraadt Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: perform.c,v 1.21 2001/11/17 10:40:05 espie Exp $";
+static const char *rcsid = "$OpenBSD: perform.c,v 1.22 2001/11/26 05:04:33 deraadt Exp $";
#endif
/*
@@ -28,9 +28,10 @@ static const char *rcsid = "$OpenBSD: perform.c,v 1.21 2001/11/17 10:40:05 espie
#include "lib.h"
#include "add.h"
+#include <sys/wait.h>
#include <ctype.h>
#include <signal.h>
-#include <sys/wait.h>
+#include <errno.h>
static int pkg_do(char *);
static int sanity_check(char *);
@@ -583,22 +584,29 @@ sanity_check(char *pkg)
void
cleanup(int signo)
{
+ int save_errno = errno;
static int alreadyCleaning;
void (*oldint)(int);
void (*oldhup)(int);
+ char buf[1024];
oldint = signal(SIGINT, SIG_IGN);
oldhup = signal(SIGHUP, SIG_IGN);
+ /* XXX big signal race, nearly all of it! */
if (!alreadyCleaning) {
alreadyCleaning = 1;
- if (signo)
- printf("Signal %d received, cleaning up\n", signo);
+ if (signo) {
+ snprintf(buf, sizeof buf,
+ "Signal %d received, cleaning up\n", signo);
+ write(STDOUT_FILENO, buf, strlen(buf));
+ }
if (!Fake && zapLogDir && LogDir[0])
- vsystem("%s -rf %s", REMOVE_CMD, LogDir);
- leave_playpen(Home);
+ vsystem("%s -rf %s", REMOVE_CMD, LogDir); /* XXX */
+ leave_playpen(Home); /* XXX */
if (signo)
- exit(1);
+ _exit(1);
}
signal(SIGINT, oldint);
signal(SIGHUP, oldhup);
+ errno = save_errno;
}
diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c
index e7be0d9c2ea..c098c1c0f78 100644
--- a/usr.sbin/pkg_install/create/perform.c
+++ b/usr.sbin/pkg_install/create/perform.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: perform.c,v 1.12 2001/02/10 17:21:11 millert Exp $ */
+/* $OpenBSD: perform.c,v 1.13 2001/11/26 05:04:33 deraadt Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: perform.c,v 1.12 2001/02/10 17:21:11 millert Exp $";
+static const char *rcsid = "$OpenBSD: perform.c,v 1.13 2001/11/26 05:04:33 deraadt Exp $";
#endif
/*
@@ -27,10 +27,12 @@ static const char *rcsid = "$OpenBSD: perform.c,v 1.12 2001/02/10 17:21:11 mille
#include "lib.h"
#include "create.h"
-#include <err.h>
-#include <signal.h>
#include <sys/syslimits.h>
#include <sys/wait.h>
+
+#include <err.h>
+#include <errno.h>
+#include <signal.h>
#include <unistd.h>
static void sanity_check(void);
@@ -348,20 +350,25 @@ sanity_check()
void
cleanup(int sig)
{
+ int save_errno = errno;
static int alreadyCleaning;
void (*oldint)(int);
void (*oldhup)(int);
+ char buf[1024];
oldint = signal(SIGINT, SIG_IGN);
oldhup = signal(SIGHUP, SIG_IGN);
if (!alreadyCleaning) {
alreadyCleaning = 1;
- if (sig)
- printf("Signal %d received, cleaning up.\n", sig);
+ if (sig) {
+ snprintf(buf, sizeof buf, "Signal %d received, cleaning up.\n", sig);
+ write(STDOUT_FILENO, buf, strlen(buf));
+ }
leave_playpen(home);
if (sig)
- exit(1);
+ _exit(1);
}
signal(SIGINT, oldint);
signal(SIGHUP, oldhup);
+ errno = save_errno;
}
diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c
index 7e06f704757..6090641b198 100644
--- a/usr.sbin/pkg_install/delete/perform.c
+++ b/usr.sbin/pkg_install/delete/perform.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: perform.c,v 1.10 2001/04/17 21:51:33 espie Exp $ */
+/* $OpenBSD: perform.c,v 1.11 2001/11/26 05:04:33 deraadt Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: perform.c,v 1.10 2001/04/17 21:51:33 espie Exp $";
+static const char *rcsid = "$OpenBSD: perform.c,v 1.11 2001/11/26 05:04:33 deraadt Exp $";
#endif
/*
@@ -255,9 +255,7 @@ sanity_check(char *pkg)
void
cleanup(int sig)
{
- /* Nothing to do */
- if(sig) /* in case this is ever used as a signal handler */
- exit(1);
+ exit(1);
}
/* deppkgname is the pkg from which's +REQUIRED_BY file we are
diff --git a/usr.sbin/pkg_install/info/perform.c b/usr.sbin/pkg_install/info/perform.c
index 83f09fe2845..14d987277b6 100644
--- a/usr.sbin/pkg_install/info/perform.c
+++ b/usr.sbin/pkg_install/info/perform.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: perform.c,v 1.10 2001/04/18 14:34:31 espie Exp $ */
+/* $OpenBSD: perform.c,v 1.11 2001/11/26 05:04:33 deraadt Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: perform.c,v 1.10 2001/04/18 14:34:31 espie Exp $";
+static const char *rcsid = "$OpenBSD: perform.c,v 1.11 2001/11/26 05:04:33 deraadt Exp $";
#endif
/* This is OpenBSD pkg_install, based on:
@@ -255,8 +255,8 @@ check4pkg(char *pkgspec, char *dbdir)
void
cleanup(int sig)
{
- leave_playpen(Home);
- exit(1);
+ leave_playpen(Home); /* XXX signal race */
+ _exit(1);
}
int
diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c
index 55160413ddb..5253fa7aa79 100644
--- a/usr.sbin/pkg_install/lib/pen.c
+++ b/usr.sbin/pkg_install/lib/pen.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: pen.c,v 1.9 2001/04/08 16:45:48 espie Exp $ */
+/* $OpenBSD: pen.c,v 1.10 2001/11/26 05:04:33 deraadt Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: pen.c,v 1.9 2001/04/08 16:45:48 espie Exp $";
+static const char *rcsid = "$OpenBSD: pen.c,v 1.10 2001/11/26 05:04:33 deraadt Exp $";
#endif
/*
@@ -29,6 +29,7 @@ static const char *rcsid = "$OpenBSD: pen.c,v 1.9 2001/04/08 16:45:48 espie Exp
#include <sys/signal.h>
#include <sys/param.h>
#include <sys/mount.h>
+#include <errno.h>
/* For keeping track of where we are */
static char Current[FILENAME_MAX];
@@ -139,27 +140,31 @@ make_playpen(char *pen, size_t pensize, size_t sz)
void
leave_playpen(char *save)
{
+ int save_errno = errno;
void (*oldsig)(int);
+ /* XXX big signal race! */
/* Don't interrupt while we're cleaning up */
oldsig = signal(SIGINT, SIG_IGN);
if (Previous[0] && chdir(Previous) == FAIL) {
- cleanup(0);
- errx(2, "can't chdir back to '%s'", Previous);
+ cleanup(0); /* XXX */
+ warnx("can't chdir back to '%s'", Previous);
+ _exit(2);
} else if (Current[0] && strcmp(Current, Previous)) {
if (strcmp(Current,"/")==0) {
fprintf(stderr,"PANIC: About to rm -rf / (not doing so, aborting)\n");
- abort();
+ abort(); /* XXX is abort safe? */
}
if (vsystem("rm -rf %s", Current))
pwarnx("couldn't remove temporary dir '%s'", Current);
- strcpy(Current, Previous);
+ strcpy(Current, Previous); /* XXX */
}
if (save)
- strcpy(Previous, save);
+ strcpy(Previous, save); /* XXX */
else
Previous[0] = '\0';
signal(SIGINT, oldsig);
+ errno = save_errno;
}
off_t
diff --git a/usr.sbin/pkg_install/sign/sha1.c b/usr.sbin/pkg_install/sign/sha1.c
index 0381441f40d..bca6e5a7f27 100644
--- a/usr.sbin/pkg_install/sign/sha1.c
+++ b/usr.sbin/pkg_install/sign/sha1.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sha1.c,v 1.2 2001/04/08 16:45:48 espie Exp $ */
+/* $OpenBSD: sha1.c,v 1.3 2001/11/26 05:04:33 deraadt Exp $ */
/*-
* Copyright (c) 1999 Marc Espie.
*
@@ -38,7 +38,6 @@
#include "gzip.h"
#include "extern.h"
-
/* private context for sha1 signature checker */
struct sha1_checker {
SHA1_CTX context;
@@ -46,7 +45,6 @@ struct sha1_checker {
const char *filename;
};
-
#define SHA1_TEMPLATE "SHA1 (%s) = "
#define BUFSIZE (MAXID+sizeof(SHA1_TEMPLATE)+2*SHA1_DIGESTSIZE+1)