cleanups
[util-vserver.git] / util-vserver / src / vps.c
index aac59f4..ead995d 100644 (file)
 #endif
 
 #include "util.h"
-#include "wrappers.h"
-#include "wrappers-vserver.h"
 #include "pathconfig.h"
 
 #include <lib/vserver.h>
 #include <lib/fmt.h>
 #include <assert.h>
+#include <fcntl.h>
+
+#define ENSC_WRAPPERS_VSERVER  1
+#define ENSC_WRAPPERS_STDLIB   1
+#define ENSC_WRAPPERS_UNISTD   1
+#define ENSC_WRAPPERS_FCNTL    1
+#include <wrappers.h>
 
 #define CTXNR_WIDTH    5
-#define HUNK_SIZE      0x40;
+#define HUNK_SIZE      0x4000
 #define CONTEXT_WIDTH  20
 #define CONTEXT_PLACE  "                    "
 
@@ -44,6 +49,30 @@ struct ContextMapping {
 static struct ContextMapping           *mapping    = 0;
 static size_t                          mapping_len = 0;
 
+
+static void
+showHelp(int fd, char const *cmd, int res)
+{
+  WRITE_MSG(fd, "Usage:  ");
+  WRITE_STR(fd, cmd);
+  WRITE_MSG(fd,
+           " <ps-opts>*\n\n"
+           "Please report bugs to " PACKAGE_BUGREPORT "\n");
+  exit(res);
+}
+
+static void
+showVersion()
+{
+  WRITE_MSG(1,
+           "vps " VERSION " -- shows processes in vserver-contexts\n"
+           "This program is part of " PACKAGE_STRING "\n\n"
+           "Copyright (C) 2004 Enrico Scholz\n"
+           VERSION_COPYRIGHT_DISCLAIMER);
+  exit(0);
+}
+
+
 static size_t
 writeContextInfo(xid_t ctx, char const *name)
 {
@@ -72,7 +101,7 @@ extractCtx(char *pid_str)
   while (*pid_str==' ') ++pid_str;
   pid = atoi(pid_str);
 
-  return vc_X_getctx(pid);
+  return vc_get_task_xid(pid);
 }
 
 static char const *
@@ -173,6 +202,7 @@ processOutput(char *data, size_t len)
     write(1, data, pid_end);
     l = writeContextInfo(ctx, vserver_name);
     if (l<CONTEXT_WIDTH) write(1, CONTEXT_PLACE, CONTEXT_WIDTH-l);
+    else                 write(1, " ", 1);
     write(1, data+pid_end, eol_pos-(data+pid_end));
     write(1, "\n", 1);
     
@@ -187,9 +217,17 @@ int main(int argc, char *argv[])
   pid_t                pid;
   char *       data;
   size_t       len;
+  char const * errptr;
 
-  if (vc_X_getctx(0)!=1)
-    Evc_new_s_context(1, vc_get_securecaps(), 0);
+  if (argc>1) {
+    if (strcmp(argv[1], "--help")   ==0) showHelp(1, argv[0], 0);
+    if (strcmp(argv[1], "--version")==0) showVersion();
+  }
+
+  if (!switchToWatchXid(&errptr)) {
+    perror(errptr);
+    exit(wrapper_exit_code);
+  }
 
   Epipe(p);
   pid = Efork();