X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fsrc%2Fsave_ctxinfo.c;h=3163596c50440ae22f03920880b6cb0d8b585120;hb=54dca8e1902c0329b2a070098ea93b001a22cc5b;hp=6dc899e406adcc0a08ff4f511d98121dc2f8c486;hpb=a10f15f15ac3c657f960b3a67e05dffc422f0c71;p=util-vserver.git diff --git a/util-vserver/src/save_ctxinfo.c b/util-vserver/src/save_ctxinfo.c index 6dc899e..3163596 100644 --- a/util-vserver/src/save_ctxinfo.c +++ b/util-vserver/src/save_ctxinfo.c @@ -25,6 +25,8 @@ #include "vserver.h" #include "internal.h" #include "util.h" +#include "wrappers.h" +#include "wrappers-vserver.h" #include #include @@ -32,8 +34,10 @@ #include #include +int wrapper_exit_code = 255; + inline static void -checkParams(int argc, char *argv[]) +checkParams(int argc, char UNUSED * argv[]) { if (argc<3) { WRITE_MSG(2, "Usage: save_ctxinfo *\n"); @@ -43,50 +47,44 @@ checkParams(int argc, char *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]; + char buf[6]; ctx_t ctx; - size_t len; - size_t len1 = strlen(argv[1]); + ssize_t len; + ssize_t len1 = strlen(argv[1]); strcpy(runfile, argv[1]); strcpy(runfile+len1, "/run"); - ctx=getcctx(); - if (ctx==-1) { - perror("getctx()"); - return -1; - } + ctx=Evc_X_getctx(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; } + Ereadlink(runfile, dstfile, sizeof(dstfile)); len = utilvserver_uint2str(buf, sizeof(buf), ctx, 10); + 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()"); 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); }