use new exitLikeProcess() interface
[util-vserver.git] / util-vserver / src / save_ctxinfo.c
index 24d77f8..03709de 100644 (file)
 #include "vserver.h"
 #include "internal.h"
 #include "util.h"
-#include "wrappers.h"
-#include "wrappers-vserver.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <limits.h>
+#include <errno.h>
+
+#define ENSC_WRAPPERS_PREFIX   "save_ctxinfo: "
+#define ENSC_WRAPPERS_VSERVER  1
+#define ENSC_WRAPPERS_UNISTD   1
+#define ENSC_WRAPPERS_FCNTL    1
+#include <wrappers.h>
 
 int    wrapper_exit_code = 255;
 
@@ -51,14 +56,14 @@ int main(int argc, char *argv[])
   char         dstfile[PATH_MAX];
   int          fd;
   char         buf[sizeof(int)*3+2];
-  ctx_t                ctx;
+  xid_t                ctx;
   ssize_t      len;
   ssize_t      len1 = strlen(argv[1]);
 
   strcpy(runfile,      argv[1]);
   strcpy(runfile+len1, "/run");
 
-  ctx=Evc_X_getctx(0);
+  ctx=Evc_get_task_xid(0);
 
   if (ctx==0) {
     WRITE_MSG(2, "save_ctxinfo: Can not operate in context 0\n");
@@ -70,21 +75,21 @@ int main(int argc, char *argv[])
     return 255;
   }
 
-  Ereadlink(runfile, dstfile, sizeof(dstfile));
+  EreadlinkD(runfile, dstfile, sizeof(dstfile));
   len  = utilvserver_fmt_uint(buf, ctx);
 
-  fd = Eopen(dstfile, O_EXCL|O_CREAT|O_WRONLY, 0644);
+  fd = EopenD(dstfile, O_EXCL|O_CREAT|O_WRONLY, 0644);
   if (write(fd, buf,     len) !=len  ||
       write(fd, "\n",    1)   !=1) {
-    perror("write()");
+    perror("save_ctxinfo: write()");
     return -1;
   }
   Eclose(fd);
 
   strcat(runfile, ".rev/");
-  strcat(runfile, buf);
+  strncat(runfile, buf, len);
   unlink(runfile);
-  Esymlink(argv[1], runfile);
+  EsymlinkD(argv[1], runfile);
 
   Eexecv(argv[2], argv+2);
 }