X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fsrc%2Fsave_ctxinfo.c;h=2dd49f024dda329bdc839f680961424caeb76661;hb=19b505f485927357115dcd74d4576f5c7f4dd995;hp=91645251788ba32a8c8e3c2af0f15724e789a88d;hpb=f041d999ff7e47925c6fb5dd6e9e39d828520f3c;p=util-vserver.git diff --git a/util-vserver/src/save_ctxinfo.c b/util-vserver/src/save_ctxinfo.c index 9164525..2dd49f0 100644 --- a/util-vserver/src/save_ctxinfo.c +++ b/util-vserver/src/save_ctxinfo.c @@ -21,7 +21,6 @@ #ifdef HAVE_CONFIG_H # include #endif -#include "compat.h" #include "vserver.h" #include "internal.h" @@ -32,6 +31,15 @@ #include #include #include +#include + +#define ENSC_WRAPPERS_PREFIX "save_ctxinfo: " +#define ENSC_WRAPPERS_VSERVER 1 +#define ENSC_WRAPPERS_UNISTD 1 +#define ENSC_WRAPPERS_FCNTL 1 +#include + +int wrapper_exit_code = 255; inline static void checkParams(int argc, char UNUSED * argv[]) @@ -44,50 +52,44 @@ checkParams(int argc, char UNUSED * argv[]) int main(int argc, char *argv[]) { - char runfile[(checkParams(argc,argv),strlen(argv[1])) + sizeof("/run")]; + char runfile[(checkParams(argc,argv),strlen(argv[1])) + sizeof("/run.rev/99999")]; char dstfile[PATH_MAX]; int fd; - char buf[32]; - ctx_t ctx; + char buf[sizeof(int)*3+2]; + xid_t ctx; ssize_t len; ssize_t len1 = strlen(argv[1]); strcpy(runfile, argv[1]); strcpy(runfile+len1, "/run"); - ctx=vc_X_getcctx(); - if (ctx==-1) { - perror("vc_X_getcctx()"); - return -1; - } + ctx=Evc_get_task_xid(0); - if (readlink(runfile, dstfile, sizeof(dstfile))==-1) { - perror("readlink()"); - return -1; + if (ctx==0) { + WRITE_MSG(2, "save_ctxinfo: Can not operate in context 0\n"); + return 255; } - fd = open(dstfile, O_EXCL|O_CREAT|O_WRONLY, 0644); - if (fd==-1) { - perror("open()"); - return -1; + if (reinterpret_cast(unsigned int)(ctx)>99999) { + WRITE_MSG(2, "save_ctxinfo: unexpected context\n"); + return 255; } - len = utilvserver_uint2str(buf, sizeof(buf), ctx, 10); + Ereadlink(runfile, dstfile, sizeof(dstfile)); + len = utilvserver_fmt_uint(buf, ctx); + fd = Eopen(dstfile, O_EXCL|O_CREAT|O_WRONLY, 0644); if (write(fd, buf, len) !=len || - write(fd, "\n", 1) !=1 || - write(fd, argv[1], len1)!=len1 || write(fd, "\n", 1) !=1) { - perror("write()"); + perror("save_ctxinfo: write()"); return -1; } + Eclose(fd); - if (close(fd)==-1) { - perror("close()"); - return -1; - } + strcat(runfile, ".rev/"); + strcat(runfile, buf); + unlink(runfile); + Esymlink(argv[1], runfile); - execv(argv[2], argv+2); - perror("execv()"); - return -1; + Eexecv(argv[2], argv+2); }