X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fsrc%2Fvkill.c;h=cdf77c7e134695a29b343ada86e579b86e190745;hb=a917f24ef7b003dcef54a3db2644cf9cb4bc2db2;hp=dfb4d61e61a86eda9f2a68ba75810484cd19d96e;hpb=f2366c490d44f1bdb230a0ec6732ccfeac1445e4;p=util-vserver.git diff --git a/util-vserver/src/vkill.c b/util-vserver/src/vkill.c index dfb4d61..cdf77c7 100644 --- a/util-vserver/src/vkill.c +++ b/util-vserver/src/vkill.c @@ -19,10 +19,10 @@ #ifdef HAVE_CONFIG_H # include #endif -#include "compat.h" #include "vserver.h" #include "linuxvirtual.h" +#include "util.h" #include #include @@ -35,24 +35,25 @@ #include #include -#define VERSION_COPYRIGHT_DISCLAIMER +#define ENSC_WRAPPERS_VSERVER 1 +#include #define CMD_HELP 0x8000 #define CMD_VERSION 0x8001 -#define WRITE_MSG(FD,X) (void)(write(FD,X,sizeof(X)-1)) -#define WRITE_STR(FD,X) writeStr(FD,X) +int wrapper_exit_code = 1; static struct option const CMDLINE_OPTIONS[] = { - { "help", no_argument, 0, CMD_HELP }, - { "version", no_argument, 0, CMD_VERSION }, + { "help", no_argument, 0, CMD_HELP }, + { "version", no_argument, 0, CMD_VERSION }, + { "xid", required_argument, 0, 'c' }, { 0,0,0,0 } }; struct Arguments { - xid_t ctx; + xid_t xid; int sig; }; @@ -65,19 +66,13 @@ static char const * const SIGNALS[] = { 0, }; -inline static void UNUSED -writeStr(int fd, char const *cmd) -{ - (void)write(fd, cmd, strlen(cmd)); -} - static void showHelp(int fd, char const *cmd, int res) { WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, - " [-c ] [-s ] [--] *\n" + " [--xid|-c ] [-s ] [--] *\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); } @@ -115,11 +110,11 @@ str2sig(char const *str) #if defined(VC_ENABLE_API_LEGACY) inline static ALWAYSINLINE int -kill_wrapper_legacy(xid_t ctx, char const *proc, int sig) +kill_wrapper_legacy(xid_t UNUSED xid, char const *proc, int UNUSED sig) { pid_t pid = fork(); if (pid==-1) { - perror("fork()"); + perror("vkill: fork()"); exit(1); } else if (pid==0) { @@ -132,21 +127,21 @@ kill_wrapper_legacy(xid_t ctx, char const *proc, int sig) } execl(LEGACYDIR "/vkill", "legacy/vkill", proc, (void *)(0)); - perror("execl()"); + perror("vkill: execl()"); exit(1); } static int -kill_wrapper(xid_t ctx, char const *pid, int sig) +kill_wrapper(xid_t xid, char const *pid, int sig) { - //printf("kill_wrapper(%u, %s, %i)\n", ctx, pid, sig); - if (vc_ctx_kill(ctx,atoi(pid),sig)==-1) { + //printf("kill_wrapper(%u, %s, %i)\n", xid, pid, sig); + if (vc_ctx_kill(xid,atoi(pid),sig)==-1) { int err = errno; if (vc_get_version(VC_CAT_COMPAT)==-1) - return kill_wrapper_legacy(ctx, pid, sig); + return kill_wrapper_legacy(xid, pid, sig); else { errno = err; - perror("vc_ctx_kill()"); + perror("vkill: vc_ctx_kill()"); return 1; } } @@ -155,10 +150,10 @@ kill_wrapper(xid_t ctx, char const *pid, int sig) } #else // VC_ENABLE_API_LEGACY inline static int -kill_wrapper(xid_t ctx, char const *pid, int sig) +kill_wrapper(xid_t xid, char const *pid, int sig) { - if (vc_ctx_kill(ctx,atoi(pid),sig)==-1) { - perror("vc_ctx_kill()"); + if (vc_ctx_kill(xid,atoi(pid),sig)==-1) { + perror("vkill: vc_ctx_kill()"); return 1; } return 0; @@ -170,7 +165,7 @@ int main(int argc, char *argv[]) { int fail = 0; struct Arguments args = { - .ctx = VC_NOCTX, + .xid = VC_NOCTX, .sig = SIGTERM, }; @@ -181,8 +176,8 @@ int main(int argc, char *argv[]) switch (c) { case CMD_HELP : showHelp(1, argv[0], 0); case CMD_VERSION : showVersion(); - case 'c' : args.ctx = atoi(optarg); break; - case 's' : args.sig = str2sig(optarg); break; + case 'c' : args.xid = Evc_xidopt2xid(optarg,true); break; + case 's' : args.sig = str2sig(optarg); break; default : WRITE_MSG(2, "Try '"); WRITE_STR(2, argv[0]); @@ -197,15 +192,15 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - if (args.ctx==VC_NOCTX && optind==argc) { + if (args.xid==VC_NOCTX && optind==argc) { WRITE_MSG(2, "No pid specified\n"); return EXIT_FAILURE; } if (optind==argc) - fail += kill_wrapper(args.ctx, "0", args.sig); + fail += kill_wrapper(args.xid, "0", args.sig); else for (;optind