Changeset 2739

Show
Ignore:
Timestamp:
07/14/08 15:12:25 (4 months ago)
Author:
dhozac
Message:

Move exitLikeProcess to libvserver.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/exitlikeprocess.c

    r1954 r2739  
    2121#endif 
    2222 
    23 #include "util.h" 
    24 #include <lib/internal.h> 
    25  
    2623#include <stdlib.h> 
    2724#include <sys/types.h> 
     
    3229#include <sys/resource.h> 
    3330#include <stdio.h> 
     31#include <errno.h> 
     32 
     33#include "vserver.h" 
     34 
     35static int pid; 
     36static void 
     37signalHandler(int signum) 
     38{ 
     39  xid_t xid = vc_get_task_xid(pid); 
     40  if (xid) 
     41    vc_ctx_kill(xid, pid, signum); 
     42  else 
     43    kill(pid, signum); 
     44} 
    3445 
    3546void 
    36 exitLikeProcess(int pid, char const *cmd, int ret) 
     47vc_exitLikeProcess(int p, int ret) 
    3748{ 
    38   int                   status; 
    39    
     49  int status, i; 
     50 
     51  pid = p; 
     52 
     53  for (i = 0; i < 32; i++) 
     54    signal(i, signalHandler); 
     55 
     56retry: 
    4057  if (wait4(pid, &status, 0,0)==-1) { 
    41      
     58    if (errno==EINTR) 
     59      goto retry; 
    4260    perror("wait()"); 
    4361    exit(ret); 
     
    5068    struct rlimit       lim = { 0,0 }; 
    5169 
    52     if (cmd) { 
    53       char              buf[sizeof(int)*3 + 2]; 
    54       size_t            l = utilvserver_fmt_uint(buf, pid); 
    55        
    56       WRITE_MSG(2, "command '"); 
    57       WRITE_STR(2, cmd); 
    58       WRITE_MSG(2, "' (pid "); 
    59       Vwrite   (2, buf, l); 
    60       WRITE_MSG(2, ") exited with signal "); 
    61       l = utilvserver_fmt_uint(buf, WTERMSIG(status));       
    62       Vwrite   (2, buf, l); 
    63       WRITE_MSG(2, "; following it...\n"); 
    64     } 
    65  
    6670    // prevent coredumps which might override the real ones 
    6771    setrlimit(RLIMIT_CORE, &lim); 
     
    7074    exit(1); 
    7175  } 
    72   else { 
    73     char                buf[sizeof(int)*3 + 2]; 
    74     size_t              l = utilvserver_fmt_uint(buf, WTERMSIG(status)); 
    75  
    76     WRITE_MSG(2, "Unexpected status "); 
    77     Vwrite   (2, buf, l); 
    78     WRITE_MSG(2, " from '"); 
    79     if (cmd) { 
    80       WRITE_STR(2, cmd); 
    81       WRITE_MSG(2, " (pid "); 
    82     } 
    83     l = utilvserver_fmt_uint(buf, pid); 
    84     Vwrite   (2, buf, l); 
    85     if (cmd) WRITE_MSG(2, ")\n"); 
    86     else     WRITE_MSG(2, "\n"); 
    87  
     76  else 
    8877    exit(ret); 
    89   } 
    9078} 
  • trunk/lib/vserver.h

    r2736 r2739  
    10501050  int           vc_compareVserverById(char const *lhs, vcCfgStyle lhs_style, 
    10511051                                      char const *rhs, vcCfgStyle rhs_style); 
     1052 
     1053  void          vc_exitLikeProcess(int pid, int ret) VC_ATTR_NORETURN; 
    10521054  
    10531055#define vcSKEL_INTERFACES       1u 
  • trunk/lib_internal/Makefile-files

    r2685 r2739  
    7272                                lib_internal/util-dimof.h \ 
    7373                                lib_internal/util-dotfile.h \ 
    74                                 lib_internal/util-exitlikeprocess.h \ 
    7574                                lib_internal/util-io.h \ 
    7675                                lib_internal/util-lockfile.h \ 
     
    10099                                lib_internal/unify-isiunlinkable.c \ 
    101100                                lib_internal/util-canonify.c \ 
    102                                 lib_internal/util-exitlikeprocess.c \ 
    103101                                lib_internal/util-isnumber.hc \ 
    104102                                lib_internal/util-isnumber.c \ 
  • trunk/lib_internal/util.h

    r2569 r2739  
    2626#include "util-dimof.h" 
    2727#include "util-dotfile.h" 
    28 #include "util-exitlikeprocess.h" 
    2928#include "util-io.h" 
    3029#include "util-lockfile.h" 
  • trunk/src/context-sync.hc

    r2015 r2739  
    8484  Eclose(p[1][1]); 
    8585  l = Eread(p[1][0], &c, 1); 
    86   if (l!=1) exitLikeProcess(pid,0, wrapper_exit_code); 
     86  if (l!=1) vc_exitLikeProcess(pid, wrapper_exit_code); 
    8787  l = Eread(p[1][0], &c, 1); 
    88   if (l!=0) exitLikeProcess(pid,0, wrapper_exit_code); 
     88  if (l!=0) vc_exitLikeProcess(pid, wrapper_exit_code); 
    8989} 
  • trunk/src/vnamespace.c

    r2693 r2739  
    8989 
    9090static void 
    91 newNamespace(char const *cmd) 
     91newNamespace(void) 
    9292{ 
    9393  pid_t         pid; 
     
    108108      break; 
    109109    default     : 
    110       exitLikeProcess(pid, cmd, wrapper_exit_code); 
     110      vc_exitLikeProcess(pid, wrapper_exit_code); 
    111111  } 
    112112} 
     
    182182    WRITE_MSG(2, "No command specified; try '--help' for more information\n"); 
    183183  else { 
    184     if      (do_new)     newNamespace(argv[optind]); 
     184    if      (do_new)     newNamespace(); 
    185185    else if (do_set)     setNamespace(VC_SAMECTX, CLONE_NEWNS|CLONE_FS); 
    186186    else if (do_cleanup) cleanupNamespace(); 
  • trunk/src/vps.c

    r2396 r2739  
    268268   
    269269  processOutput(data, len); 
    270   exitLikeProcess(pid, "ps", wrapper_exit_code); 
    271 } 
     270  vc_exitLikeProcess(pid, wrapper_exit_code); 
     271} 
  • trunk/src/vspace.c

    r2713 r2739  
    107107 
    108108static void 
    109 newSpaces(uint_least64_t mask, const char *cmd
     109newSpaces(uint_least64_t mask
    110110{ 
    111111  pid_t pid; 
     
    132132      break; 
    133133    default     : 
    134       exitLikeProcess(pid, cmd, wrapper_exit_code); 
     134      vc_exitLikeProcess(pid, wrapper_exit_code); 
    135135  } 
    136136} 
     
    214214    WRITE_MSG(2, "No command specified; try '--help' for more information\n"); 
    215215  else { 
    216     if      (do_new)     newSpaces(mask, argv[optind]); 
     216    if      (do_new)     newSpaces(mask); 
    217217    else if (do_set)     setSpaces(VC_SAMECTX, mask); 
    218218    else if (do_enter)   enterSpaces(xid, mask);