LCOV - code coverage report
Current view: top level - basic - unit-def.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 23 43 53.5 %
Date: 2019-08-22 15:41:25 Functions: 33 36 91.7 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: LGPL-2.1+ */
       2             : 
       3             : #include "alloc-util.h"
       4             : #include "bus-label.h"
       5             : #include "string-table.h"
       6             : #include "unit-def.h"
       7             : #include "unit-name.h"
       8             : 
       9           0 : char *unit_dbus_path_from_name(const char *name) {
      10           0 :         _cleanup_free_ char *e = NULL;
      11             : 
      12           0 :         assert(name);
      13             : 
      14           0 :         e = bus_label_escape(name);
      15           0 :         if (!e)
      16           0 :                 return NULL;
      17             : 
      18           0 :         return strjoin("/org/freedesktop/systemd1/unit/", e);
      19             : }
      20             : 
      21         283 : int unit_name_from_dbus_path(const char *path, char **name) {
      22             :         const char *e;
      23             :         char *n;
      24             : 
      25         283 :         e = startswith(path, "/org/freedesktop/systemd1/unit/");
      26         283 :         if (!e)
      27           0 :                 return -EINVAL;
      28             : 
      29         283 :         n = bus_label_unescape(e);
      30         283 :         if (!n)
      31           0 :                 return -ENOMEM;
      32             : 
      33         283 :         *name = n;
      34         283 :         return 0;
      35             : }
      36             : 
      37           0 : const char* unit_dbus_interface_from_type(UnitType t) {
      38             : 
      39             :         static const char *const table[_UNIT_TYPE_MAX] = {
      40             :                 [UNIT_SERVICE] = "org.freedesktop.systemd1.Service",
      41             :                 [UNIT_SOCKET] = "org.freedesktop.systemd1.Socket",
      42             :                 [UNIT_TARGET] = "org.freedesktop.systemd1.Target",
      43             :                 [UNIT_DEVICE] = "org.freedesktop.systemd1.Device",
      44             :                 [UNIT_MOUNT] = "org.freedesktop.systemd1.Mount",
      45             :                 [UNIT_AUTOMOUNT] = "org.freedesktop.systemd1.Automount",
      46             :                 [UNIT_SWAP] = "org.freedesktop.systemd1.Swap",
      47             :                 [UNIT_TIMER] = "org.freedesktop.systemd1.Timer",
      48             :                 [UNIT_PATH] = "org.freedesktop.systemd1.Path",
      49             :                 [UNIT_SLICE] = "org.freedesktop.systemd1.Slice",
      50             :                 [UNIT_SCOPE] = "org.freedesktop.systemd1.Scope",
      51             :         };
      52             : 
      53           0 :         if (t < 0)
      54           0 :                 return NULL;
      55           0 :         if (t >= _UNIT_TYPE_MAX)
      56           0 :                 return NULL;
      57             : 
      58           0 :         return table[t];
      59             : }
      60             : 
      61           0 : const char *unit_dbus_interface_from_name(const char *name) {
      62             :         UnitType t;
      63             : 
      64           0 :         t = unit_name_to_type(name);
      65           0 :         if (t < 0)
      66           0 :                 return NULL;
      67             : 
      68           0 :         return unit_dbus_interface_from_type(t);
      69             : }
      70             : 
      71             : static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
      72             :         [UNIT_SERVICE] = "service",
      73             :         [UNIT_SOCKET] = "socket",
      74             :         [UNIT_TARGET] = "target",
      75             :         [UNIT_DEVICE] = "device",
      76             :         [UNIT_MOUNT] = "mount",
      77             :         [UNIT_AUTOMOUNT] = "automount",
      78             :         [UNIT_SWAP] = "swap",
      79             :         [UNIT_TIMER] = "timer",
      80             :         [UNIT_PATH] = "path",
      81             :         [UNIT_SLICE] = "slice",
      82             :         [UNIT_SCOPE] = "scope",
      83             : };
      84             : 
      85      333584 : DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);
      86             : 
      87             : static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
      88             :         [UNIT_STUB] = "stub",
      89             :         [UNIT_LOADED] = "loaded",
      90             :         [UNIT_NOT_FOUND] = "not-found",
      91             :         [UNIT_BAD_SETTING] = "bad-setting",
      92             :         [UNIT_ERROR] = "error",
      93             :         [UNIT_MERGED] = "merged",
      94             :         [UNIT_MASKED] = "masked"
      95             : };
      96             : 
      97        1208 : DEFINE_STRING_TABLE_LOOKUP(unit_load_state, UnitLoadState);
      98             : 
      99             : static const char* const unit_active_state_table[_UNIT_ACTIVE_STATE_MAX] = {
     100             :         [UNIT_ACTIVE] = "active",
     101             :         [UNIT_RELOADING] = "reloading",
     102             :         [UNIT_INACTIVE] = "inactive",
     103             :         [UNIT_FAILED] = "failed",
     104             :         [UNIT_ACTIVATING] = "activating",
     105             :         [UNIT_DEACTIVATING] = "deactivating",
     106             :         [UNIT_MAINTENANCE] = "maintenance",
     107             : };
     108             : 
     109        1208 : DEFINE_STRING_TABLE_LOOKUP(unit_active_state, UnitActiveState);
     110             : 
     111             : static const char* const automount_state_table[_AUTOMOUNT_STATE_MAX] = {
     112             :         [AUTOMOUNT_DEAD] = "dead",
     113             :         [AUTOMOUNT_WAITING] = "waiting",
     114             :         [AUTOMOUNT_RUNNING] = "running",
     115             :         [AUTOMOUNT_FAILED] = "failed"
     116             : };
     117             : 
     118          12 : DEFINE_STRING_TABLE_LOOKUP(automount_state, AutomountState);
     119             : 
     120             : static const char* const device_state_table[_DEVICE_STATE_MAX] = {
     121             :         [DEVICE_DEAD] = "dead",
     122             :         [DEVICE_TENTATIVE] = "tentative",
     123             :         [DEVICE_PLUGGED] = "plugged",
     124             : };
     125             : 
     126        3706 : DEFINE_STRING_TABLE_LOOKUP(device_state, DeviceState);
     127             : 
     128             : static const char* const mount_state_table[_MOUNT_STATE_MAX] = {
     129             :         [MOUNT_DEAD] = "dead",
     130             :         [MOUNT_MOUNTING] = "mounting",
     131             :         [MOUNT_MOUNTING_DONE] = "mounting-done",
     132             :         [MOUNT_MOUNTED] = "mounted",
     133             :         [MOUNT_REMOUNTING] = "remounting",
     134             :         [MOUNT_UNMOUNTING] = "unmounting",
     135             :         [MOUNT_REMOUNTING_SIGTERM] = "remounting-sigterm",
     136             :         [MOUNT_REMOUNTING_SIGKILL] = "remounting-sigkill",
     137             :         [MOUNT_UNMOUNTING_SIGTERM] = "unmounting-sigterm",
     138             :         [MOUNT_UNMOUNTING_SIGKILL] = "unmounting-sigkill",
     139             :         [MOUNT_FAILED] = "failed"
     140             : };
     141             : 
     142         446 : DEFINE_STRING_TABLE_LOOKUP(mount_state, MountState);
     143             : 
     144             : static const char* const path_state_table[_PATH_STATE_MAX] = {
     145             :         [PATH_DEAD] = "dead",
     146             :         [PATH_WAITING] = "waiting",
     147             :         [PATH_RUNNING] = "running",
     148             :         [PATH_FAILED] = "failed"
     149             : };
     150             : 
     151          52 : DEFINE_STRING_TABLE_LOOKUP(path_state, PathState);
     152             : 
     153             : static const char* const scope_state_table[_SCOPE_STATE_MAX] = {
     154             :         [SCOPE_DEAD] = "dead",
     155             :         [SCOPE_RUNNING] = "running",
     156             :         [SCOPE_ABANDONED] = "abandoned",
     157             :         [SCOPE_STOP_SIGTERM] = "stop-sigterm",
     158             :         [SCOPE_STOP_SIGKILL] = "stop-sigkill",
     159             :         [SCOPE_FAILED] = "failed",
     160             : };
     161             : 
     162          28 : DEFINE_STRING_TABLE_LOOKUP(scope_state, ScopeState);
     163             : 
     164             : static const char* const service_state_table[_SERVICE_STATE_MAX] = {
     165             :         [SERVICE_DEAD] = "dead",
     166             :         [SERVICE_CONDITION] = "condition",
     167             :         [SERVICE_START_PRE] = "start-pre",
     168             :         [SERVICE_START] = "start",
     169             :         [SERVICE_START_POST] = "start-post",
     170             :         [SERVICE_RUNNING] = "running",
     171             :         [SERVICE_EXITED] = "exited",
     172             :         [SERVICE_RELOAD] = "reload",
     173             :         [SERVICE_STOP] = "stop",
     174             :         [SERVICE_STOP_WATCHDOG] = "stop-watchdog",
     175             :         [SERVICE_STOP_SIGTERM] = "stop-sigterm",
     176             :         [SERVICE_STOP_SIGKILL] = "stop-sigkill",
     177             :         [SERVICE_STOP_POST] = "stop-post",
     178             :         [SERVICE_FINAL_SIGTERM] = "final-sigterm",
     179             :         [SERVICE_FINAL_SIGKILL] = "final-sigkill",
     180             :         [SERVICE_FAILED] = "failed",
     181             :         [SERVICE_AUTO_RESTART] = "auto-restart",
     182             :         [SERVICE_CLEANING] = "cleaning",
     183             : };
     184             : 
     185         126 : DEFINE_STRING_TABLE_LOOKUP(service_state, ServiceState);
     186             : 
     187             : static const char* const slice_state_table[_SLICE_STATE_MAX] = {
     188             :         [SLICE_DEAD] = "dead",
     189             :         [SLICE_ACTIVE] = "active"
     190             : };
     191             : 
     192          20 : DEFINE_STRING_TABLE_LOOKUP(slice_state, SliceState);
     193             : 
     194             : static const char* const socket_state_table[_SOCKET_STATE_MAX] = {
     195             :         [SOCKET_DEAD] = "dead",
     196             :         [SOCKET_START_PRE] = "start-pre",
     197             :         [SOCKET_START_CHOWN] = "start-chown",
     198             :         [SOCKET_START_POST] = "start-post",
     199             :         [SOCKET_LISTENING] = "listening",
     200             :         [SOCKET_RUNNING] = "running",
     201             :         [SOCKET_STOP_PRE] = "stop-pre",
     202             :         [SOCKET_STOP_PRE_SIGTERM] = "stop-pre-sigterm",
     203             :         [SOCKET_STOP_PRE_SIGKILL] = "stop-pre-sigkill",
     204             :         [SOCKET_STOP_POST] = "stop-post",
     205             :         [SOCKET_FINAL_SIGTERM] = "final-sigterm",
     206             :         [SOCKET_FINAL_SIGKILL] = "final-sigkill",
     207             :         [SOCKET_FAILED] = "failed"
     208             : };
     209             : 
     210          30 : DEFINE_STRING_TABLE_LOOKUP(socket_state, SocketState);
     211             : 
     212             : static const char* const swap_state_table[_SWAP_STATE_MAX] = {
     213             :         [SWAP_DEAD] = "dead",
     214             :         [SWAP_ACTIVATING] = "activating",
     215             :         [SWAP_ACTIVATING_DONE] = "activating-done",
     216             :         [SWAP_ACTIVE] = "active",
     217             :         [SWAP_DEACTIVATING] = "deactivating",
     218             :         [SWAP_DEACTIVATING_SIGTERM] = "deactivating-sigterm",
     219             :         [SWAP_DEACTIVATING_SIGKILL] = "deactivating-sigkill",
     220             :         [SWAP_FAILED] = "failed"
     221             : };
     222             : 
     223         188 : DEFINE_STRING_TABLE_LOOKUP(swap_state, SwapState);
     224             : 
     225             : static const char* const target_state_table[_TARGET_STATE_MAX] = {
     226             :         [TARGET_DEAD] = "dead",
     227             :         [TARGET_ACTIVE] = "active"
     228             : };
     229             : 
     230          38 : DEFINE_STRING_TABLE_LOOKUP(target_state, TargetState);
     231             : 
     232             : static const char* const timer_state_table[_TIMER_STATE_MAX] = {
     233             :         [TIMER_DEAD] = "dead",
     234             :         [TIMER_WAITING] = "waiting",
     235             :         [TIMER_RUNNING] = "running",
     236             :         [TIMER_ELAPSED] = "elapsed",
     237             :         [TIMER_FAILED] = "failed"
     238             : };
     239             : 
     240          14 : DEFINE_STRING_TABLE_LOOKUP(timer_state, TimerState);
     241             : 
     242             : static const char* const unit_dependency_table[_UNIT_DEPENDENCY_MAX] = {
     243             :         [UNIT_REQUIRES] = "Requires",
     244             :         [UNIT_REQUISITE] = "Requisite",
     245             :         [UNIT_WANTS] = "Wants",
     246             :         [UNIT_BINDS_TO] = "BindsTo",
     247             :         [UNIT_PART_OF] = "PartOf",
     248             :         [UNIT_REQUIRED_BY] = "RequiredBy",
     249             :         [UNIT_REQUISITE_OF] = "RequisiteOf",
     250             :         [UNIT_WANTED_BY] = "WantedBy",
     251             :         [UNIT_BOUND_BY] = "BoundBy",
     252             :         [UNIT_CONSISTS_OF] = "ConsistsOf",
     253             :         [UNIT_CONFLICTS] = "Conflicts",
     254             :         [UNIT_CONFLICTED_BY] = "ConflictedBy",
     255             :         [UNIT_BEFORE] = "Before",
     256             :         [UNIT_AFTER] = "After",
     257             :         [UNIT_ON_FAILURE] = "OnFailure",
     258             :         [UNIT_TRIGGERS] = "Triggers",
     259             :         [UNIT_TRIGGERED_BY] = "TriggeredBy",
     260             :         [UNIT_PROPAGATES_RELOAD_TO] = "PropagatesReloadTo",
     261             :         [UNIT_RELOAD_PROPAGATED_FROM] = "ReloadPropagatedFrom",
     262             :         [UNIT_JOINS_NAMESPACE_OF] = "JoinsNamespaceOf",
     263             :         [UNIT_REFERENCES] = "References",
     264             :         [UNIT_REFERENCED_BY] = "ReferencedBy",
     265             : };
     266             : 
     267        3050 : DEFINE_STRING_TABLE_LOOKUP(unit_dependency, UnitDependency);
     268             : 
     269             : static const char* const notify_access_table[_NOTIFY_ACCESS_MAX] = {
     270             :         [NOTIFY_NONE] = "none",
     271             :         [NOTIFY_MAIN] = "main",
     272             :         [NOTIFY_EXEC] = "exec",
     273             :         [NOTIFY_ALL] = "all"
     274             : };
     275             : 
     276          56 : DEFINE_STRING_TABLE_LOOKUP(notify_access, NotifyAccess);

Generated by: LCOV version 1.14