Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Rather than execve()'ing a second process when it is detected that pkg needs to be re-run, fork the process early-on, let the forked child run, and do whatever wrk is required and signal back to the parent by setting its exit status if it needs to be restarted.
Matthew Seaman committed 12 years ago
commit a930ac549f84752cc27176e30fc7ce43b7a8232a
parent 2163836
2 files changed +9 -6
modified libpkg/pkg.h.in
@@ -38,6 +38,7 @@
#include <sys/sbuf.h>
#include <stringlist.h>
#include <openssl/pem.h>
+
#include <sysexits.h>

/* The expected name of the pkg(8) binary executable. */
#ifndef PKG_EXEC_NAME
@@ -65,6 +66,12 @@
#define OSMAJOR	__DragonFly__
#endif

+
/* Special exit status for worker processes indicating that a restart
+
 * is desired -- eg. after a child has updated pkg(8) itself.  Don't
+
 * clash with any of the sysexits values */
+

+
#define EX_NEEDRESTART	(EX__MAX + 1)
+

struct pkg;
struct pkg_dep;
struct pkg_conflict;
modified src/main.c
@@ -65,7 +65,6 @@ static void usage(const char *, const char *, FILE *, enum pkg_usage_reason, ...
static void usage_help(void);
static int exec_help(int, char **);
bool quiet = false;
-
static char **cmdargv;
bool newpkgversion = false;

static struct commands {
@@ -483,7 +482,6 @@ main(int argc, char **argv)
	/* Set stdout unbuffered */
	setvbuf(stdout, NULL, _IONBF, 0);

-
	cmdargv = argv;
	newargvl = 0;

	if (argc < 2)
@@ -731,10 +729,8 @@ main(int argc, char **argv)
		sbuf_delete(newcmd);
	}

-
	if (ret == EX_OK && newpkgversion) {
-
		if (jail_str == NULL && chroot_path == NULL)
-
			execvp(getprogname(), cmdargv);
-
	}
+
	if (ret == EX_OK && newpkgversion)
+
		return (EX_NEEDRESTART);

	return (ret);
}