From fbc451923c71119a8dc7c6db5e262770bbb57d1f Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Mon, 14 Jul 2008 13:12:25 +0000 Subject: [PATCH] Move exitLikeProcess to libvserver. git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2739 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- .../exitlikeprocess.c | 64 +++++++++------------- lib/vserver.h | 2 + lib_internal/Makefile-files | 2 - lib_internal/util-exitlikeprocess.h | 25 --------- lib_internal/util.h | 1 - src/context-sync.hc | 4 +- src/vnamespace.c | 6 +- src/vps.c | 2 +- src/vspace.c | 6 +- 9 files changed, 37 insertions(+), 75 deletions(-) rename lib_internal/util-exitlikeprocess.c => lib/exitlikeprocess.c (59%) delete mode 100644 lib_internal/util-exitlikeprocess.h diff --git a/lib_internal/util-exitlikeprocess.c b/lib/exitlikeprocess.c similarity index 59% rename from lib_internal/util-exitlikeprocess.c rename to lib/exitlikeprocess.c index 5c45020..9236c47 100644 --- a/lib_internal/util-exitlikeprocess.c +++ b/lib/exitlikeprocess.c @@ -20,9 +20,6 @@ # include #endif -#include "util.h" -#include - #include #include #include @@ -31,14 +28,35 @@ #include #include #include +#include + +#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); } @@ -49,42 +67,12 @@ exitLikeProcess(int pid, char const *cmd, int 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); - } } diff --git a/lib/vserver.h b/lib/vserver.h index fa42afb..f647ac3 100644 --- a/lib/vserver.h +++ b/lib/vserver.h @@ -1049,6 +1049,8 @@ extern "C" { 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 diff --git a/lib_internal/Makefile-files b/lib_internal/Makefile-files index 1feb631..68a3d5b 100644 --- a/lib_internal/Makefile-files +++ b/lib_internal/Makefile-files @@ -71,7 +71,6 @@ noinst_HEADERS += \ 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 \ @@ -99,7 +98,6 @@ lib_internal_libinternal_common_SRCS = \ 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 \ diff --git a/lib_internal/util-exitlikeprocess.h b/lib_internal/util-exitlikeprocess.h deleted file mode 100644 index d31a804..0000000 --- a/lib_internal/util-exitlikeprocess.h +++ /dev/null @@ -1,25 +0,0 @@ -// $Id$ --*- c -*-- - -// Copyright (C) 2004 Enrico Scholz -// -// 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 -void exitLikeProcess(pid_t pid, char const /*@null@*/ *cmd, int ret) NORETURN; - -#endif // H_UTILVSERVER_LIB_INTERNAL_UTIL_EXITLIKEPROCESS_H diff --git a/lib_internal/util.h b/lib_internal/util.h index ad3a442..078d5e3 100644 --- a/lib_internal/util.h +++ b/lib_internal/util.h @@ -25,7 +25,6 @@ #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" diff --git a/src/context-sync.hc b/src/context-sync.hc index 4f8ef33..fd9d730 100644 --- a/src/context-sync.hc +++ b/src/context-sync.hc @@ -83,7 +83,7 @@ waitOnSync(pid_t pid, int p[2][2], bool is_prevent_race) 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); } diff --git a/src/vnamespace.c b/src/vnamespace.c index c71cc9f..d840fbb 100644 --- a/src/vnamespace.c +++ b/src/vnamespace.c @@ -88,7 +88,7 @@ showVersion() } static void -newNamespace(char const *cmd) +newNamespace(void) { pid_t pid; @@ -107,7 +107,7 @@ newNamespace(char const *cmd) case 0 : break; default : - exitLikeProcess(pid, cmd, wrapper_exit_code); + vc_exitLikeProcess(pid, wrapper_exit_code); } } @@ -181,7 +181,7 @@ int main(int argc, char *argv[]) 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); diff --git a/src/vps.c b/src/vps.c index d903f3a..d72cf51 100644 --- a/src/vps.c +++ b/src/vps.c @@ -267,5 +267,5 @@ int main(int argc, char *argv[]) Eclose(p[0]); processOutput(data, len); - exitLikeProcess(pid, "ps", wrapper_exit_code); + vc_exitLikeProcess(pid, wrapper_exit_code); } diff --git a/src/vspace.c b/src/vspace.c index 202012b..30d1ab4 100644 --- a/src/vspace.c +++ b/src/vspace.c @@ -106,7 +106,7 @@ showVersion() } static void -newSpaces(uint_least64_t mask, const char *cmd) +newSpaces(uint_least64_t mask) { pid_t pid; @@ -131,7 +131,7 @@ newSpaces(uint_least64_t mask, const char *cmd) case 0 : break; default : - exitLikeProcess(pid, cmd, wrapper_exit_code); + vc_exitLikeProcess(pid, wrapper_exit_code); } } @@ -213,7 +213,7 @@ int main(int argc, char *argv[]) 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); -- 1.8.1.5