X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fvkill.c;h=1ce6e529d1bb012b359dc525255c02633f0c0478;hb=dbbb75087e2a59a419e8c3ef76458f3262dfe8cd;hp=489046feec77a6f9da37ce6b46e5db2dbc86382a;hpb=517fb954f46091a78f471435b7f284668138a2da;p=util-vserver.git diff --git a/src/vkill.c b/src/vkill.c index 489046f..1ce6e52 100644 --- a/src/vkill.c +++ b/src/vkill.c @@ -119,7 +119,7 @@ kill_wrapper_legacy(xid_t UNUSED xid, char const *proc, int UNUSED sig) signal(SIGCHLD, SIG_DFL); pid = Efork(); - if (pid==0) { + if (pid>0) { int status; int res; while ((res=wait4(pid, &status, 0,0))==-1 && @@ -132,35 +132,39 @@ kill_wrapper_legacy(xid_t UNUSED xid, char const *proc, int UNUSED sig) perror("vkill: execl()"); exit(1); } +#endif -static int -kill_wrapper(xid_t xid, char const *pid, int sig) +inline static int +kill_wrapper(xid_t xid, char const *pid_s, int sig) { - //printf("kill_wrapper(%u, %s, %i)\n", xid, pid, sig); - if (vc_ctx_kill(xid,atoi(pid),sig)==-1) { + pid_t pid; + long tmp; + + if (!isNumber(pid_s, &tmp, true)) { + WRITE_MSG(2, "vkill: '"); + WRITE_STR(2, pid_s); + WRITE_MSG(2, "' is not a number\n"); + } + pid = (pid_t) tmp; + + if (xid==VC_NOCTX) + xid = vc_get_task_xid(pid); + if (vc_ctx_kill(xid,pid,sig)==-1) { +#if defined(VC_ENABLE_API_LEGACY) int err = errno; if (vc_get_version(VC_CAT_COMPAT)==-1) - return kill_wrapper_legacy(xid, pid, sig); + return kill_wrapper_legacy(xid, pid_s, sig); else { errno = err; +#else + { +#endif perror("vkill: vc_ctx_kill()"); return 1; } } - return 0; } -#else // VC_ENABLE_API_LEGACY -inline static int -kill_wrapper(xid_t xid, char const *pid, int sig) -{ - if (vc_ctx_kill(xid,atoi(pid),sig)==-1) { - perror("vkill: vc_ctx_kill()"); - return 1; - } - return 0; -} -#endif int main(int argc, char *argv[])