]> arthur.barton.de Git - netdata.git/blobdiff - src/apps_plugin.c
report running uid and euid when not running properly
[netdata.git] / src / apps_plugin.c
index c17560c1910d75a5773ede2a1d560f83993b163b..cfb2298a04622096a63286e15cc0b28adc12371e 100644 (file)
@@ -3013,16 +3013,15 @@ static void parse_args(int argc, char **argv)
 }
 
 static int am_i_running_as_root() {
-    if(getuid() != 0) {
-        if(debug)
-            info("I am not running as root.");
-        return 0;
-    }
+    uid_t uid = getuid(), euid = geteuid();
 
-    if(debug)
-        info("I am running as root.");
+    if(uid == 0 || euid == 0) {
+        if(debug) info("I am running with escalated privileges, uid = %u, euid = %u.", uid, euid);
+        return 1;
+    }
 
-    return 1;
+    if(debug) info("I am not running with escalated privileges, uid = %u, euid = %u.", uid, euid);
+    return 0;
 }
 
 #ifdef HAVE_CAPABILITY
@@ -3136,23 +3135,26 @@ int main(int argc, char **argv) {
 
     parse_args(argc, argv);
 
-    if(!am_i_running_as_root())
-        if(!check_capabilities())
+    if(!am_i_running_as_root()) {
+        if(!check_capabilities()) {
+            uid_t uid = getuid(), euid = geteuid();
 #ifdef HAVE_CAPABILITY
-            error("apps.plugin should either run as root or have special capabilities. "
+            error("apps.plugin should either run as root (now running with uid %u, euid %u) or have special capabilities. "
                           "Without these, apps.plugin cannot report disk I/O utilization of other processes. "
-                          "To enable capabilities run: sudo setcap cap_dac_read_search,cap_sys_ptrace+ep %1$s; "
-                          "To enable setuid to root run: sudo chown root %1$s; sudo chmod 4755 %1$s; "
-                  , argv[0]
+                          "To enable capabilities run: sudo setcap cap_dac_read_search,cap_sys_ptrace+ep %s; "
+                          "To enable setuid to root run: sudo chown root %s; sudo chmod 4755 %s; "
+                  , uid, euid, argv[0], argv[0], argv[0]
             );
 #else
-            error("apps.plugin should either run as root or have special capabilities. "
+            error("apps.plugin should either run as root (now running with uid %u, euid %u) or have special capabilities. "
                           "Without these, apps.plugin cannot report disk I/O utilization of other processes. "
                           "Your system does not support capabilities. "
-                          "To enable setuid to root run: sudo chown root %1$s; sudo chmod 4755 %1$s; "
-                  , argv[0]
+                          "To enable setuid to root run: sudo chown root %s; sudo chmod 4755 %s; "
+                  , uid, euid, argv[0], argv[0]
             );
 #endif
+        }
+    }
 
     all_pids_sortlist = callocz(sizeof(pid_t), (size_t)pid_max);
     all_pids          = callocz(sizeof(struct pid_stat *), (size_t) pid_max);