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().
1.1 --- a/configure.ac Thu Jan 08 13:51:07 2009 +0000
1.2 +++ b/configure.ac Thu Jan 08 14:35:18 2009 +0000
1.3 @@ -24,13 +24,23 @@
1.4 AC_HEADER_STDC
1.5 AC_CHECK_HEADERS([sys/mman.h])
1.6 gl_INIT
1.7 -AC_CHECK_FUNCS([symlink])
1.8 +AC_CHECK_FUNCS([symlink chroot])
1.9 AM_PROG_LIBTOOL
1.10 AC_PROG_MAKE_SET
1.11 AC_PROG_LN_S
1.12 AC_SYS_LARGEFILE
1.13 AM_PROG_CC_C_O
1.14
1.15 +AC_MSG_CHECKING([for Microsoft Windows native API])
1.16 +case $host_os in
1.17 + *mingw*) AC_DEFINE([MSWIN_API], 1,
1.18 + [Define to 1 to use Microsoft Windows native API.])
1.19 + mswin_api=yes;;
1.20 + *) mswin_api=no;;
1.21 +esac
1.22 +AC_MSG_RESULT([$mswin_api])
1.23 +AM_CONDITIONAL(MSWIN_API, test "$mswin_api" = "yes")
1.24 +
1.25 # Taken from dbus
1.26 AC_ARG_ENABLE(ansi, [ --enable-ansi enable -ansi -pedantic gcc flags],enable_ansi=$enableval,enable_ansi=no)
1.27 AC_ARG_ENABLE(verbose-mode, [ --enable-verbose-mode support verbose debug mode],enable_verbose_mode=$enableval,enable_verbose_mode=$USE_MAINTAINER_MODE)
2.1 --- a/librazor/rpm.c Thu Jan 08 13:51:07 2009 +0000
2.2 +++ b/librazor/rpm.c Thu Jan 08 14:35:18 2009 +0000
2.3 @@ -567,7 +567,11 @@
2.4 run_script(struct installer *installer,
2.5 unsigned int program_tag, unsigned int script_tag)
2.6 {
2.7 +#if HAVE_CHROOT
2.8 int pid, status, fd[2];
2.9 +#else
2.10 + FILE *fp;
2.11 +#endif
2.12 const char *script = NULL, *program = NULL;
2.13
2.14 program = razor_rpm_get_indirect(installer->rpm, program_tag, NULL);
2.15 @@ -575,9 +579,21 @@
2.16 if (program == NULL && script == NULL) {
2.17 return 0;
2.18 } else if (program == NULL) {
2.19 +#if MSWIN_API
2.20 + program = getenv("COMSPEC");
2.21 + if (program) {
2.22 + program = strchr(program, '=');
2.23 + if (program)
2.24 + program++;
2.25 + }
2.26 + if (!program)
2.27 + program = "c:\\windows\\system32\\cmd.exe";
2.28 +#else
2.29 program = "/bin/sh";
2.30 +#endif
2.31 }
2.32
2.33 +#if HAVE_CHROOT
2.34 if (pipe(fd) < 0) {
2.35 fprintf(stderr, "failed to create pipe\n");
2.36 return -1;
2.37 @@ -621,6 +637,14 @@
2.38 if (status)
2.39 printf("script exited with status %d\n", status);
2.40 }
2.41 +#else
2.42 + fp = popen(program, "w");
2.43 + if (fwrite(script, strlen(script), 1, fp) != 1) {
2.44 + fprintf(stderr, "failed to pipe script, %m\n");
2.45 + return -1;
2.46 + }
2.47 + pclose(fp);
2.48 +#endif
2.49
2.50 return 0;
2.51 }