chiark / gitweb /
systemctl: show connection counters only for Accept=yes sockets
[elogind.git] / src / systemctl.c
index 01deafe2a13b1d0edc3bcfe8633343ccc1eab471..dc6fb5ea40debad9f81cbd824dbdf7b8b5c486dd 100644 (file)
@@ -947,6 +947,7 @@ typedef struct UnitStatusInfo {
         /* Socket */
         unsigned n_accepted;
         unsigned n_connections;
+        bool accept;
 
         /* Device */
         const char *sysfs_path;
@@ -997,7 +998,7 @@ static void print_status_info(UnitStatusInfo *i) {
         if (i->status_text)
                 printf("\t  Status: \"%s\"\n", i->status_text);
 
-        if (i->id && endswith(i->id, ".socket"))
+        if (i->accept)
                 printf("\tAccepted: %u; Connected: %u\n", i->n_accepted, i->n_connections);
 
         if (i->main_pid > 0 || i->control_pid > 0) {
@@ -1093,6 +1094,17 @@ static int status_property(const char *name, DBusMessageIter *iter, UnitStatusIn
                 break;
         }
 
+        case DBUS_TYPE_BOOLEAN: {
+                dbus_bool_t b;
+
+                dbus_message_iter_get_basic(iter, &b);
+
+                if (streq(name, "Accept"))
+                        i->accept = b;
+
+                break;
+        }
+
         case DBUS_TYPE_UINT32: {
                 uint32_t u;
 
@@ -3156,6 +3168,11 @@ static int start_with_fallback(DBusConnection *bus) {
 static int halt_main(DBusConnection *bus) {
         int r;
 
+        if (geteuid() != 0) {
+                log_error("Must to be root.");
+                return -EPERM;
+        }
+
         if (!arg_dry && !arg_immediate)
                 return start_with_fallback(bus);