ready for tagging
[util-vserver.git] / src / chbind.c
index bc68711..8e87e51 100644 (file)
@@ -1,4 +1,4 @@
-// $Id: chbind.c,v 1.9 2004/03/16 14:30:10 ensc Exp $
+// $Id: chbind.c 2588 2007-08-16 02:31:33Z dhozac $
 
 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
 // based on chbind.cc by Jacques Gelinas
@@ -24,6 +24,8 @@
 #include "vserver.h"
 #include "util.h"
 
+#include <lib/internal.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -41,6 +43,7 @@
 #define ENSC_WRAPPERS_PREFIX   "chbind: "
 #define ENSC_WRAPPERS_IO       1
 #define ENSC_WRAPPERS_UNISTD   1
+#define ENSC_WRAPPERS_VSERVER  1
 #include "wrappers.h"
 
 #define CMD_HELP       0x1000
@@ -49,6 +52,7 @@
 #define CMD_SILENT     0x2000
 #define CMD_IP         0x2001
 #define CMD_BCAST      0x2002
+#define CMD_NID                0x2003
 
 int wrapper_exit_code = 255;
 
@@ -60,6 +64,7 @@ CMDLINE_OPTIONS[] = {
   { "silent",   no_argument,  0, CMD_SILENT },
   { "ip",       required_argument, 0, CMD_IP },
   { "bcast",    required_argument, 0, CMD_BCAST },
+  { "nid",     required_argument, 0, CMD_NID },
   { 0,0,0,0 }
 };
 
@@ -69,7 +74,7 @@ showHelp(int fd, char const *cmd, int res)
   WRITE_MSG(fd, "Usage:\n  ");
   WRITE_STR(fd, cmd);
   WRITE_MSG(fd,
-           " [--silent] [--ip <ip_num>[/<mask>]] [--bcast <broadcast>] [--] <commands> <args>*\n\n"
+           " [--silent] [--nid <nid>] [--ip <ip_num>[/<mask>]] [--bcast <broadcast>] [--] <commands> <args>*\n\n"
            "Please report bugs to " PACKAGE_BUGREPORT "\n");
 
   exit(res);
@@ -254,6 +259,7 @@ int main (int argc, char *argv[])
       case CMD_VERSION         :  showVersion();
       case CMD_SILENT          :  is_silent = true; break;
       case CMD_BCAST           :  readBcast(optarg, &bcast); break;
+      case CMD_NID             :  WRITE_MSG(2, "WARNING: --nid is not supported by this version\n"); break;
       case CMD_IP              :
        if (nbaddrs>=nb_ipv4root) {
          WRITE_MSG(2, "Too many IP numbers, max 16\n");
@@ -265,7 +271,7 @@ int main (int argc, char *argv[])
       default          :
        WRITE_MSG(2, "Try '");
        WRITE_STR(2, argv[0]);
-       WRITE_MSG(2, " --help\" for more information.\n");
+       WRITE_MSG(2, " --help' for more information.\n");
        exit(wrapper_exit_code);
        break;
     }
@@ -276,11 +282,21 @@ int main (int argc, char *argv[])
     exit(wrapper_exit_code);
   }
   
-
+#if !defined(VC_ENABLE_API_COMPAT) && !defined(VC_ENABLE_API_LEGACY)
+#  warning building a dummy chbind-compat with no available APIs
+#endif
+  
+#if defined(VC_ENABLE_API_COMPAT) || defined(VC_ENABLE_API_LEGACY)
   if (vc_set_ipv4root(bcast,nbaddrs,ips)!=0) {
     perror("chbind: vc_set_ipv4root()");
     exit(wrapper_exit_code);
   }
+#else
+  {
+    WRITE_MSG(2, "chbind: kernel does not provide network isolation\n");
+    exit(wrapper_exit_code);
+  }
+#endif
 
   if (!is_silent) {
     size_t             i;