use stdout instead of stderr for the no-compat API warnings on '--help';
[util-vserver.git] / util-vserver / src / chcontext.c
index 6102aa6..1d88b0d 100644 (file)
@@ -40,6 +40,7 @@
 #include <assert.h>
 #include <fcntl.h>
 #include <libgen.h>
+#include <signal.h>
 
 #define ENSC_WRAPPERS_PREFIX   "chcontext: "
 #define ENSC_WRAPPERS_VSERVER  1
@@ -94,6 +95,10 @@ static void
 showHelp(int fd, char const *cmd, int res)
 {
   VSERVER_DECLARE_CMD(cmd);
+
+#if !defined(VC_ENABLE_API_COMPAT) && !defined(VC_ENABLE_API_LEGACY)
+  WRITE_MSG(1, "ERROR: tools were built without legacy API support; chcontext will not work!\n\n");
+#endif
   
   WRITE_MSG(fd, "Usage: ");
   WRITE_STR(fd, cmd);
@@ -177,6 +182,8 @@ showVersion()
   exit(0);
 }
 
+#if defined(VC_ENABLE_API_COMPAT) || defined(VC_ENABLE_API_LEGACY)
+
 static inline void
 setCap(char const *str, uint32_t *add_caps, uint32_t *remove_caps)
 {
@@ -206,11 +213,11 @@ setFlags(char const *str, uint32_t *flags)
 {
   struct vc_err_listparser     err;
   
-  *flags = vc_list2flag_compat(str, 0, &err);
+  *flags = vc_list2cflag_compat(str, 0, &err);
 
   if (err.ptr!=0) {
     WRITE_MSG(2, "Unknown flag '");
-    write(2, err.ptr, err.len);
+    Vwrite(2, err.ptr, err.len);
     WRITE_MSG(2, "'\n");
     exit(wrapper_exit_code);
   }
@@ -259,12 +266,15 @@ tellContext(xid_t ctx)
   l = utilvserver_fmt_long(buf,ctx);
 
   WRITE_MSG(1, "New security context is ");
-  write(1, buf, l);
+  Vwrite(1, buf, l);
   WRITE_MSG(1, "\n");
 }
 
 #include "context-sync.hc"
 
+#endif
+
+
 int main (int argc, char *argv[])
 {
   struct Arguments args = {
@@ -277,13 +287,17 @@ int main (int argc, char *argv[])
     .hostname      = 0,
     .domainname    = 0
   };
+
+#if defined(VC_ENABLE_API_COMPAT) || defined(VC_ENABLE_API_LEGACY)
   xid_t                newctx;
   int          xflags;
   int          p[2][2];
   pid_t                pid;
+#endif
   
   global_args = &args;
-  
+  signal(SIGCHLD, SIG_DFL);
+
   while (1) {
     int                c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0);
     if (c==-1) break;
@@ -296,11 +310,12 @@ int main (int argc, char *argv[])
       case CMD_DOMAINNAME      :  args.domainname    = optarg; break;
       case CMD_HOSTNAME                :  args.hostname      = optarg; break;
        
+#if defined(VC_ENABLE_API_COMPAT) || defined(VC_ENABLE_API_LEGACY)
       case CMD_CAP             :
        setCap(optarg, &args.add_caps, &args.remove_caps);
        break;
       case CMD_SECURE          :
-       args.remove_caps |= vc_get_insecurecaps();
+       args.remove_caps |= vc_get_insecurebcaps();
        break;
       case CMD_FLAG            :
        setFlags(optarg, &args.flags);
@@ -314,7 +329,12 @@ int main (int argc, char *argv[])
        }
        args.ctxs[args.nbctx++] = Evc_xidopt2xid(optarg, true);
        break;
-
+#else
+      case CMD_CAP             :
+      case CMD_SECURE          :
+      case CMD_FLAG            :
+      case CMD_CTX             :  break;
+#endif 
          
       default          :
        WRITE_MSG(2, "Try '");
@@ -325,6 +345,7 @@ int main (int argc, char *argv[])
     }
   }
 
+#if defined(VC_ENABLE_API_COMPAT) || defined(VC_ENABLE_API_LEGACY)
   if (optind>=argc) {
     WRITE_MSG(2, "No command given; use '--help' for more information.\n");
     exit(255);
@@ -362,8 +383,14 @@ int main (int argc, char *argv[])
 
   waitOnSync(pid, p, args.ctxs[0]!=VC_DYNAMIC_XID);
   return EXIT_SUCCESS;
+#else
+  WRITE_MSG(2, "chcontext: tools were built without legacy API support; can not continue\n");
+  return EXIT_FAILURE;
+#endif
 }
 
+#if defined(VC_ENABLE_API_COMPAT) || defined(VC_ENABLE_API_LEGACY)
+
 #ifdef ENSC_TESTSUITE
 #define FLAG_TEST(STR,EXP) \
   {                       \
@@ -392,3 +419,7 @@ test()
   CAP_TEST("!CAP_CHOWN", 0, 1);
 }
 #endif
+
+#else
+void test() {}
+#endif