--- /dev/null
+#! /bin/sh
+
+# Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+set -e
+
+confflags="-C --enable-maintainer-mode --prefix=/usr --sysconfdir=/etc --localstatedir=/var"
+configure="`pwd`/configure $confflags"
+make=eval\ "${CLEAN:+make -j2 silent.clean}${CLEAN:-:}; \
+ echo -e \"== executing 'make all'...\" && \
+ make -j2 ${SILENT:+-s silent.}all && \
+ echo -e \"\n== executing 'make check'...\" && \
+ make -j2 ${SILENT:+-s silent.}check"
+
+LANG=C
+
+## Usage: xtermTitle <title>
+function xtermTitle
+{
+ tty -s || return 0
+ echo -ne "\e]0;$@\007"
+}
+
+## Usage: operate <dir> <configure-opts>*
+function operate()
+{
+ d=$1
+ shift
+
+ echo "******************"
+ echo $"** Operating in directory '$d'..."
+ xtermTitle "Operating in directory '$d'... ($@)"
+
+ mkdir -p $d && cd $d
+
+ test -e Makefile || $configure "$@"
+ $make
+ cd -
+}
+
+case "$1" in
+ dist)
+ test -e Makefile || ./configure $confflags
+ $make
+ exit
+ ;;
+ debian-woody|debian-sarge|fc-1-90|fc-1)
+ cat util-vserver-"$2".tar.bz2 | \
+ ssh $1 "cd /tmp && rm -rf /tmp/util-vserver-* && \
+ tar xjf - && cd util-vserver-$2 && \
+ export PATH=/usr/lib/ccache:/usr/lib/ccache/bin:\$PATH && \
+ ./configure && \
+ make ${SILENT:+-s silent.}all && \
+ echo -e '\n\n\n' &&
+ make ${SILENT:+-s silent.}check"
+ exit
+ ;;
+ *) test -z "$1" || {
+ echo $"Unknown option '$1'" >&2
+ exit 1
+ }
+esac
+
+test -d "Build" || {
+ d=$(mktemp -d /tmp/build-ensc.XXXXXX)
+ rm -f Build
+ ln -sf $d Build
+}
+
+operate Build/diet-noopt CFLAGS='-O0 -g3' CXXFLAGS='-O0 -g3'
+operate Build/diet-opt --enable-release
+operate Build/nodiet-noopt --disable-dietlibc CFLAGS='-O0 -g3' CXXFLAGS='-O0 -g3'
+operate Build/nodiet-opt --enable-release --disable-dietlibc
+operate Build/gcc32-opt --enable-release --disable-dietlibc CC='ccache gcc32' CXX='ccache g++'
+operate Build/gcc34-opt --enable-release --disable-dietlibc CC='ccache gcc33' CXX='ccache g++33'
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "command.h"
+
+void
+Command_appendParameter(struct Command *cmd, char const *param)
+{
+ char const ** p = Vector_pushback(&cmd->params);
+ *p = param;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "command.h"
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <assert.h>
+
+static inline bool
+initPipes(int p[2])
+{
+ return (pipe(p)!=-1 &&
+ fcntl(p[1], F_SETFD, FD_CLOEXEC)!=-1);
+}
+
+bool
+Command_exec(struct Command *cmd, bool do_fork)
+{
+ int p[2];
+
+ Vector_zeroEnd(&cmd->params);
+
+ if (!do_fork)
+ cmd->pid = 0;
+ else if (!initPipes(p) ||
+ (cmd->pid = fork())==-1) {
+ cmd->err = errno;
+ return false;
+ }
+
+ if (cmd->pid==0) {
+ if (do_fork) close(p[0]);
+
+ execv(cmd->filename ? cmd->filename : ((char **)(Vector_begin(&cmd->params)))[0],
+ cmd->params.data);
+ cmd->err = errno;
+ assert(cmd->err != 0);
+
+ if (do_fork) {
+ write(p[1], &cmd->err, sizeof(cmd->err));
+ _exit(1); // implicates 'close(p[1])'
+ }
+ }
+ else {
+ close(p[1]);
+ if (read(p[0], &cmd->err, sizeof(cmd->err))==0)
+ cmd->err = 0;
+ else // cleanup zombies
+ while (wait4(cmd->pid, 0,0,0)==-1 &&
+ (errno==EINTR || errno==EAGAIN)) {};
+ close(p[0]);
+ }
+
+ return cmd->err==0;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "command.h"
+
+void
+Command_free(struct Command *cmd)
+{
+ Vector_free(&cmd->params);
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "command.h"
+
+void
+Command_init(struct Command *cmd, size_t UNUSED param_count)
+{
+ Vector_init(&cmd->params, sizeof(char *));
+ cmd->filename = 0;
+ cmd->pid = -1;
+ cmd->rc = -1;
+ cmd->err = 0;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "command.h"
+
+void
+Command_reset(struct Command *cmd)
+{
+ cmd->pid = -1;
+ cmd->rc = -1;
+ cmd->err = 0;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "command.h"
+#include <errno.h>
+
+bool
+Command_wait(struct Command *cmd, bool do_block)
+{
+ int rc;
+
+ if (cmd->rc!=-1) return true;
+
+ switch (wait4(cmd->pid, &rc,
+ !do_block ? WNOHANG : 0,
+ &cmd->rusage)==-1) {
+ case 0 : break;
+ case -1 : cmd->err = errno; break;
+ default : cmd->rc = rc; return true;
+ }
+
+ return false;
+}
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifndef H_UTIL_VSERVER_LIB_INTERNAL_COMMAND_H
+#define H_UTIL_VSERVER_LIB_INTERNAL_COMMAND_H
+
+#include <ensc_vector/vector.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+#include <stdbool.h>
+
+struct Command
+{
+ char const * filename;
+ struct Vector params;
+ pid_t pid;
+ int rc;
+ int err;
+ struct rusage rusage;
+};
+
+void Command_init(struct Command *, size_t param_count);
+void Command_free(struct Command *);
+void Command_reset(struct Command *);
+bool Command_exec(struct Command *, bool do_fork);
+void Command_appendParameter(struct Command *, char const *);
+/**
+ * \args do_hang when true, do not return before command exited, or
+ * an error (e.g. signal) occured
+ * \returns \c true iff command/processes exited; in this case,
+ * exitcode is available in the \c rc member
+ */
+bool Command_wait(struct Command *, bool do_block);
+
+#endif // H_UTIL_VSERVER_LIB_INTERNAL_COMMAND_H
--- /dev/null
+.libs
+.libs
--- /dev/null
+## $Id$ --*- makefile -*--
+
+## Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; version 2 of the License.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+check_PROGRAMS += lib_internal/testsuite/command
+
+lib_internal_testsuite_command_SOURCES = lib_internal/testsuite/command.c
+lib_internal_testsuite_command_LDADD = lib_internal/libinternal.a \
+ libensc_vector.a
--- /dev/null
+// $Id$ --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <lib_internal/util.h>
+#include <lib_internal/command.h>
+
+int wrapper_exit_code = 255;
+
+int
+main(int argc, char *argv[])
+{
+ struct Command cmd;
+ ssize_t i;
+
+ if (argc<3) {
+ WRITE_MSG(2, "Not enough parameters\n");
+ return EXIT_FAILURE;
+ }
+
+ Command_init(&cmd, 5);
+ for (i=2; i<argc; ++i)
+ Command_appendParameter(&cmd, argv[i]);
+
+ if (Command_exec(&cmd, argv[1][0]!=0)) {
+ Command_wait(&cmd, true);
+ }
+
+ Command_free(&cmd);
+}