X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fsave_ctxinfo.c;fp=src%2Fsave_ctxinfo.c;h=2f84d3f51fa3f59e96214b3c41b073240b87bf74;hb=9c78378bebc1a9f3d400f422df8ede9efea57dea;hp=0000000000000000000000000000000000000000;hpb=faa778968d1a7dfeaebc9fe4b847e691dc62fd15;p=util-vserver.git diff --git a/src/save_ctxinfo.c b/src/save_ctxinfo.c new file mode 100644 index 0000000..2f84d3f --- /dev/null +++ b/src/save_ctxinfo.c @@ -0,0 +1,97 @@ +// $Id$ --*- c++ -*-- + +// Copyright (C) 2003 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +// Saves current ctx + vserver-info into 'argv[1] + /run' which must be a dead +// symlink + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "pathconfig.h" +#include "vserver.h" +#include "internal.h" +#include "util.h" + +#include +#include +#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[]) +{ + if (argc<3) { + WRITE_MSG(2, "Usage: save_ctxinfo *\n"); + exit(255); + } +} + +int main(int argc, char *argv[]) +{ + char runfile[(checkParams(argc,argv),strlen(argv[1])) + sizeof(DEFAULT_PKGSTATEREVDIR "/99999")]; + char dstfile[PATH_MAX]; + int fd; + 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=Evc_get_task_xid(0); + + if (ctx==0) { + WRITE_MSG(2, "save_ctxinfo: Can not operate in context 0\n"); + return 255; + } + + if (reinterpret_cast(unsigned int)(ctx)>99999) { + WRITE_MSG(2, "save_ctxinfo: unexpected context\n"); + return 255; + } + + len = EreadlinkD(runfile, dstfile, sizeof(dstfile)-1); + dstfile[len] = '\0'; + len = utilvserver_fmt_uint(buf, ctx); + + fd = EopenD(dstfile, O_EXCL|O_CREAT|O_WRONLY, 0644); + if (write(fd, buf, len) !=len || + write(fd, "\n", 1) !=1) { + perror("save_ctxinfo: write()"); + return -1; + } + Eclose(fd); + + strcpy(runfile, DEFAULT_PKGSTATEREVDIR "/"); + strncat(runfile, buf, len); + unlink(runfile); + EsymlinkD(argv[1], runfile); + + Eexecv(argv[2], argv+2); +}