# include <config.h>
#endif
-#include "util.h"
-#include <lib/internal.h>
-
#include <stdlib.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <signal.h>
#include <sys/resource.h>
#include <stdio.h>
+#include <errno.h>
+
+#include "vserver.h"
+
+static int pid;
+static void
+signalHandler(int signum)
+{
+ xid_t xid = vc_get_task_xid(pid);
+ if (xid)
+ vc_ctx_kill(xid, pid, signum);
+ else
+ kill(pid, signum);
+}
void
-exitLikeProcess(int pid, char const *cmd, int ret)
+vc_exitLikeProcess(int p, int ret)
{
- int status;
-
+ int status, i;
+
+ pid = p;
+
+ for (i = 0; i < 32; i++)
+ signal(i, signalHandler);
+
+retry:
if (wait4(pid, &status, 0,0)==-1) {
-
+ if (errno==EINTR)
+ goto retry;
perror("wait()");
exit(ret);
}
if (WIFSIGNALED(status)) {
struct rlimit lim = { 0,0 };
- if (cmd) {
- char buf[sizeof(int)*3 + 2];
- size_t l = utilvserver_fmt_uint(buf, pid);
-
- WRITE_MSG(2, "command '");
- WRITE_STR(2, cmd);
- WRITE_MSG(2, "' (pid ");
- Vwrite (2, buf, l);
- WRITE_MSG(2, ") exited with signal ");
- l = utilvserver_fmt_uint(buf, WTERMSIG(status));
- Vwrite (2, buf, l);
- WRITE_MSG(2, "; following it...\n");
- }
-
// prevent coredumps which might override the real ones
setrlimit(RLIMIT_CORE, &lim);
kill(getpid(), WTERMSIG(status));
exit(1);
}
- else {
- char buf[sizeof(int)*3 + 2];
- size_t l = utilvserver_fmt_uint(buf, WTERMSIG(status));
-
- WRITE_MSG(2, "Unexpected status ");
- Vwrite (2, buf, l);
- WRITE_MSG(2, " from '");
- if (cmd) {
- WRITE_STR(2, cmd);
- WRITE_MSG(2, " (pid ");
- }
- l = utilvserver_fmt_uint(buf, pid);
- Vwrite (2, buf, l);
- if (cmd) WRITE_MSG(2, ")\n");
- else WRITE_MSG(2, "\n");
-
+ else
exit(ret);
- }
}
int vc_compareVserverById(char const *lhs, vcCfgStyle lhs_style,
char const *rhs, vcCfgStyle rhs_style);
+
+ void vc_exitLikeProcess(int pid, int ret) VC_ATTR_NORETURN;
#define vcSKEL_INTERFACES 1u
#define vcSKEL_PKGMGMT 2u
lib_internal/util-declarecmd.h \
lib_internal/util-dimof.h \
lib_internal/util-dotfile.h \
- lib_internal/util-exitlikeprocess.h \
lib_internal/util-io.h \
lib_internal/util-lockfile.h \
lib_internal/util-mem.h \
lib_internal/unify-unify.c \
lib_internal/unify-isiunlinkable.c \
lib_internal/util-canonify.c \
- lib_internal/util-exitlikeprocess.c \
lib_internal/util-isnumber.hc \
lib_internal/util-isnumber.c \
lib_internal/util-isnumberunsigned.c \
+++ /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_UTILVSERVER_LIB_INTERNAL_UTIL_EXITLIKEPROCESS_H
-#define H_UTILVSERVER_LIB_INTERNAL_UTIL_EXITLIKEPROCESS_H
-
-#include <sys/types.h>
-void exitLikeProcess(pid_t pid, char const /*@null@*/ *cmd, int ret) NORETURN;
-
-#endif // H_UTILVSERVER_LIB_INTERNAL_UTIL_EXITLIKEPROCESS_H
#include "util-declarecmd.h"
#include "util-dimof.h"
#include "util-dotfile.h"
-#include "util-exitlikeprocess.h"
#include "util-io.h"
#include "util-lockfile.h"
#include "util-mem.h"
Eclose(p[1][1]);
l = Eread(p[1][0], &c, 1);
- if (l!=1) exitLikeProcess(pid,0, wrapper_exit_code);
+ if (l!=1) vc_exitLikeProcess(pid, wrapper_exit_code);
l = Eread(p[1][0], &c, 1);
- if (l!=0) exitLikeProcess(pid,0, wrapper_exit_code);
+ if (l!=0) vc_exitLikeProcess(pid, wrapper_exit_code);
}
}
static void
-newNamespace(char const *cmd)
+newNamespace(void)
{
pid_t pid;
case 0 :
break;
default :
- exitLikeProcess(pid, cmd, wrapper_exit_code);
+ vc_exitLikeProcess(pid, wrapper_exit_code);
}
}
else if (optind==argc && (do_new || do_enter))
WRITE_MSG(2, "No command specified; try '--help' for more information\n");
else {
- if (do_new) newNamespace(argv[optind]);
+ if (do_new) newNamespace();
else if (do_set) setNamespace(VC_SAMECTX, CLONE_NEWNS|CLONE_FS);
else if (do_cleanup) cleanupNamespace();
else if (do_enter) enterNamespace(xid, CLONE_NEWNS|CLONE_FS);
Eclose(p[0]);
processOutput(data, len);
- exitLikeProcess(pid, "ps", wrapper_exit_code);
+ vc_exitLikeProcess(pid, wrapper_exit_code);
}
}
static void
-newSpaces(uint_least64_t mask, const char *cmd)
+newSpaces(uint_least64_t mask)
{
pid_t pid;
case 0 :
break;
default :
- exitLikeProcess(pid, cmd, wrapper_exit_code);
+ vc_exitLikeProcess(pid, wrapper_exit_code);
}
}
else if (optind==argc && (do_new || do_enter))
WRITE_MSG(2, "No command specified; try '--help' for more information\n");
else {
- if (do_new) newSpaces(mask, argv[optind]);
+ if (do_new) newSpaces(mask);
else if (do_set) setSpaces(VC_SAMECTX, mask);
else if (do_enter) enterSpaces(xid, mask);