X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fexitlikeprocess.c;fp=lib_internal%2Futil-exitlikeprocess.c;h=9236c478250c73f07f38ab70827b2027ec6e6a91;hb=fbc451923c71119a8dc7c6db5e262770bbb57d1f;hp=5c4502074eb2887c87fab33768cd0763db917330;hpb=17d04acb0a5885b60d12d5c782d8b1af897c22d7;p=util-vserver.git 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); - } }