From 17e6ba68d6d41f30cce566fe96033e4683f2f164 Mon Sep 17 00:00:00 2001 From: J. Ali Harlow Date: Thu, 8 Jan 2009 14:35:18 +0000 Subject: [PATCH] Don't attempt to use chroot() on systems that don't support it. This has the added bonus of allowing us to use popen() rather than fork()/exec() for improved portability. Of course, the loss of an install root is a major reduction of functionality but it's hard to see what else we could substitute for chroot(). --- configure.ac | 12 +++++++++++- librazor/rpm.c | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletions(-) diff --git a/configure.ac b/configure.ac index cb56d56..2fea7b2 100644 --- a/configure.ac +++ b/configure.ac @@ -24,13 +24,23 @@ AM_PROG_CC_STDC AC_HEADER_STDC AC_CHECK_HEADERS([sys/mman.h]) gl_INIT -AC_CHECK_FUNCS([symlink]) +AC_CHECK_FUNCS([symlink chroot]) AM_PROG_LIBTOOL AC_PROG_MAKE_SET AC_PROG_LN_S AC_SYS_LARGEFILE AM_PROG_CC_C_O +AC_MSG_CHECKING([for Microsoft Windows native API]) +case $host_os in + *mingw*) AC_DEFINE([MSWIN_API], 1, + [Define to 1 to use Microsoft Windows native API.]) + mswin_api=yes;; + *) mswin_api=no;; +esac +AC_MSG_RESULT([$mswin_api]) +AM_CONDITIONAL(MSWIN_API, test "$mswin_api" = "yes") + # Taken from dbus AC_ARG_ENABLE(ansi, [ --enable-ansi enable -ansi -pedantic gcc flags],enable_ansi=$enableval,enable_ansi=no) AC_ARG_ENABLE(verbose-mode, [ --enable-verbose-mode support verbose debug mode],enable_verbose_mode=$enableval,enable_verbose_mode=$USE_MAINTAINER_MODE) diff --git a/librazor/rpm.c b/librazor/rpm.c index c4eafb9..f271e7a 100644 --- a/librazor/rpm.c +++ b/librazor/rpm.c @@ -567,7 +567,11 @@ static int run_script(struct installer *installer, unsigned int program_tag, unsigned int script_tag) { +#if HAVE_CHROOT int pid, status, fd[2]; +#else + FILE *fp; +#endif const char *script = NULL, *program = NULL; program = razor_rpm_get_indirect(installer->rpm, program_tag, NULL); @@ -575,9 +579,21 @@ run_script(struct installer *installer, if (program == NULL && script == NULL) { return 0; } else if (program == NULL) { +#if MSWIN_API + program = getenv("COMSPEC"); + if (program) { + program = strchr(program, '='); + if (program) + program++; + } + if (!program) + program = "c:\\windows\\system32\\cmd.exe"; +#else program = "/bin/sh"; +#endif } +#if HAVE_CHROOT if (pipe(fd) < 0) { fprintf(stderr, "failed to create pipe\n"); return -1; @@ -621,6 +637,14 @@ run_script(struct installer *installer, if (status) printf("script exited with status %d\n", status); } +#else + fp = popen(program, "w"); + if (fwrite(script, strlen(script), 1, fp) != 1) { + fprintf(stderr, "failed to pipe script, %m\n"); + return -1; + } + pclose(fp); +#endif return 0; } -- 1.7.1