added missing '#include <errno.h>'
[util-vserver.git] / util-vserver / src / vlimit.c
index df73ccb..0091fc8 100644 (file)
@@ -75,7 +75,7 @@ showHelp(int fd, char const *cmd, int res)
   WRITE_MSG(fd, "Usage:  ");
   WRITE_STR(fd, cmd);
   WRITE_MSG(fd,
-           " [-c|--ctx <ctx>] [-a|--all] [-MSH  --<nr> <value>]*\n"
+           " -c <xid> [-a|--all] [-MSH  --<nr> <value>]*\n"
            "Please report bugs to " PACKAGE_BUGREPORT "\n");
   exit(res);
 }
@@ -102,11 +102,9 @@ appendLimit(char *ptr, bool do_it, vc_limit_t lim)
       ptr += 3;
     }
     else {
-      memcpy(ptr, "0x", 2);
-      ptr += 2;
-
-      ptr += utilvserver_uint2str(ptr, 20, (lim>>32),      16);
-      ptr += utilvserver_uint2str(ptr, 20, lim&0xffffffff, 16);
+      memcpy(ptr, "0x", 2); ptr += 2;
+      
+      ptr += utilvserver_fmt_xuint64(ptr, lim);
       *ptr = ' ';
     }
   }
@@ -124,23 +122,24 @@ showAll(int ctx)
   struct vc_rlimit_mask        mask;
   size_t               i;
 
-  if (vc_get_rlimit_mask(-2, &mask)==-1) {
+  if (vc_get_rlimit_mask(ctx, &mask)==-1) {
     perror("vc_get_rlimit_mask()");
-    //exit(1);
+    exit(1);
   }
 
   for (i=0; i<32; ++i) {
     uint32_t           bitmask = (1<<i);
     struct vc_rlimit   limit;
     char               buf[100], *ptr=buf;
-    
+
+    if (((mask.min|mask.soft|mask.hard) & bitmask)==0) continue;
     if (vc_get_rlimit(ctx, i, &limit)==-1) {
       perror("vc_get_rlimit()");
       //continue;
     }
 
     memset(buf, ' ', sizeof buf);
-    ptr += utilvserver_uint2str(ptr, 100, i, 10);
+    ptr += utilvserver_fmt_uint(ptr, i);
     *ptr = ' ';
 
     ptr  = appendLimit(buf+10, mask.min &bitmask, limit.min);
@@ -149,7 +148,7 @@ showAll(int ctx)
 
     *ptr++ = '\n';
     write(1, buf, ptr-buf);
- }
+  }
 }
 
 static void
@@ -171,7 +170,7 @@ int main (int argc, char *argv[])
   int                  set_mask = 0;
   struct vc_rlimit     limits[32];
   bool                 show_all = false;
-  ctx_t                        ctx      = VC_SAMECTX;
+  xid_t                        ctx      = VC_NOCTX;
 
   {
     size_t             i;
@@ -195,7 +194,7 @@ int main (int argc, char *argv[])
 
       if (set_mask & 1) limits[id].min  = val;
       if (set_mask & 2) limits[id].soft = val;
-      if (set_mask & 4) limits[id].soft = val;
+      if (set_mask & 4) limits[id].hard = val;
 
       lim_mask |= (1<<id);
       set_mask  = 0;
@@ -225,6 +224,11 @@ int main (int argc, char *argv[])
     }
   }
 
+  if (ctx==VC_NOCTX) {
+    WRITE_MSG(2, "No context specified; try '--help' for more information\n");
+    return EXIT_FAILURE;
+  }
+
   setLimits(ctx, limits, lim_mask);
   if (show_all) showAll(ctx);