OSDN Git Service

id.c #ifdefectomy. (ifdefs belong in headers, not in C code.)
authorRob Landley <rob@landley.net>
Fri, 16 Jan 2015 19:43:09 +0000 (13:43 -0600)
committerRob Landley <rob@landley.net>
Fri, 16 Jan 2015 19:43:09 +0000 (13:43 -0600)
lib/portability.h
toys/posix/id.c

index 67ac5b5..4097def 100644 (file)
@@ -239,4 +239,7 @@ pid_t xfork(void);
 
 #if CFG_TOYBOX_SELINUX
 #include <selinux/selinux.h>
+#else
+#define is_selinux_enabled() 0
+int getcon(void* con);
 #endif
index 4e1ec8c..353aa04 100644 (file)
@@ -146,17 +146,18 @@ void do_id(char *username)
     }
   }
 
-#if CFG_TOYBOX_SELINUX
-  char *context = NULL;
-  if (is_selinux_enabled() < 1) {
-    if (TT.do_Z)
-      error_exit("SELinux disabled");
-  } else if (getcon(&context) == 0) {
-    if (!TT.do_Z) xputc(' ');
-    printf("context=%s", context);
+  if (CFG_TOYBOX_SELINUX) {
+    char *context = NULL;
+
+    if (is_selinux_enabled() < 1) {
+      if (TT.do_Z)
+        error_exit("SELinux disabled");
+    } else if (getcon(&context) == 0) {
+      if (!TT.do_Z) xputc(' ');
+      printf("context=%s", context);
+    }
+    if (CFG_TOYBOX_FREE) free(context);
   }
-  if (CFG_TOYBOX_FREE) free(context);
-#endif
 
   xputc('\n');
 }