Move exitLikeProcess to libvserver.
authorDaniel Hokka Zakrisson <daniel@hozac.com>
Mon, 14 Jul 2008 13:12:25 +0000 (13:12 +0000)
committerDaniel Hokka Zakrisson <daniel@hozac.com>
Mon, 14 Jul 2008 13:12:25 +0000 (13:12 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2739 94cd875c-1c1d-0410-91d2-eb244daf1a30

lib/exitlikeprocess.c [moved from lib_internal/util-exitlikeprocess.c with 59% similarity]
lib/vserver.h
lib_internal/Makefile-files
lib_internal/util-exitlikeprocess.h [deleted file]
lib_internal/util.h
src/context-sync.hc
src/vnamespace.c
src/vps.c
src/vspace.c

similarity index 59%
rename from lib_internal/util-exitlikeprocess.c
rename to lib/exitlikeprocess.c
index 5c45020..9236c47 100644 (file)
@@ -20,9 +20,6 @@
 #  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);
   }
@@ -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);
-  }
 }
index fa42afb..f647ac3 100644 (file)
@@ -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
index 1feb631..68a3d5b 100644 (file)
@@ -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 (file)
index d31a804..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-// $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
index ad3a442..078d5e3 100644 (file)
@@ -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"
index 4f8ef33..fd9d730 100644 (file)
@@ -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);
 }
index c71cc9f..d840fbb 100644 (file)
@@ -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);
index d903f3a..d72cf51 100644 (file)
--- 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);
 }
index 202012b..30d1ab4 100644 (file)
@@ -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);