• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 20766109442

06 Jan 2026 09:50PM UTC coverage: 72.714% (+0.3%) from 72.444%
20766109442

push

github

YHNdnzj
man: do not manually update man/rules/meson.build

Follow-up for 25393c7c9.

310283 of 426715 relevant lines covered (72.71%)

1142928.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.06
/src/systemctl/systemctl-is-enabled.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <stdlib.h>
4

5
#include "sd-bus.h"
6

7
#include "bus-error.h"
8
#include "bus-locator.h"
9
#include "bus-util.h"
10
#include "install.h"
11
#include "log.h"
12
#include "strv.h"
13
#include "systemctl.h"
14
#include "systemctl-is-enabled.h"
15
#include "systemctl-util.h"
16

17
static int show_installation_targets_client_side(const char *name) {
1✔
18
        InstallChange *changes = NULL;
1✔
19
        size_t n_changes = 0;
1✔
20
        UnitFileFlags flags;
1✔
21
        char **p;
1✔
22
        int r;
1✔
23

24
        CLEANUP_ARRAY(changes, n_changes, install_changes_free);
1✔
25

26
        p = STRV_MAKE(name);
1✔
27
        flags = UNIT_FILE_DRY_RUN |
1✔
28
                (arg_runtime ? UNIT_FILE_RUNTIME : 0);
1✔
29

30
        r = unit_file_disable(arg_runtime_scope, flags, NULL, p, &changes, &n_changes);
1✔
31
        if (r < 0)
1✔
32
                return log_error_errno(r, "Failed to get file links for %s: %m", name);
×
33

34
        FOREACH_ARRAY(c, changes, n_changes)
2✔
35
                if (c->type == INSTALL_CHANGE_UNLINK)
1✔
36
                        printf("  %s\n", c->path);
1✔
37

38
        return 0;
39
}
40

41
static int show_installation_targets(sd_bus *bus, const char *name) {
1✔
42
        _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
1✔
43
        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1✔
44
        const char *link;
1✔
45
        int r;
1✔
46

47
        r = bus_call_method(bus, bus_systemd_mgr, "GetUnitFileLinks", &error, &reply, "sb", name, arg_runtime);
1✔
48
        if (r < 0)
1✔
49
                return log_error_errno(r, "Failed to get unit file links for %s: %s", name, bus_error_message(&error, r));
×
50

51
        r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "s");
1✔
52
        if (r < 0)
1✔
53
                return bus_log_parse_error(r);
×
54

55
        while ((r = sd_bus_message_read(reply, "s", &link)) > 0)
2✔
56
                printf("  %s\n", link);
1✔
57

58
        if (r < 0)
1✔
59
                return bus_log_parse_error(r);
×
60

61
        r = sd_bus_message_exit_container(reply);
1✔
62
        if (r < 0)
1✔
63
                return bus_log_parse_error(r);
×
64

65
        return 0;
66
}
67

68
int verb_is_enabled(int argc, char *argv[], void *userdata) {
449✔
69
        _cleanup_strv_free_ char **names = NULL;
449✔
70
        bool not_found = true, enabled = false;
449✔
71
        int r;
449✔
72

73
        r = mangle_names("to check", strv_skip(argv, 1), &names);
449✔
74
        if (r < 0)
449✔
75
                return r;
76

77
        if (install_client_side() != INSTALL_CLIENT_SIDE_NO)
449✔
78
                STRV_FOREACH(name, names) {
34✔
79
                        UnitFileState state;
17✔
80

81
                        r = unit_file_get_state(arg_runtime_scope, arg_root, *name, &state);
17✔
82
                        if (r == -ENOENT) {
17✔
83
                                if (!arg_quiet)
×
84
                                        puts("not-found");
×
85
                                continue;
×
86
                        } else if (r < 0)
17✔
87
                                return log_error_errno(r, "Failed to get unit file state for %s: %m", *name);
×
88
                        else
89
                                not_found = false;
17✔
90

91
                        if (IN_SET(state,
17✔
92
                                   UNIT_FILE_ENABLED,
93
                                   UNIT_FILE_ENABLED_RUNTIME,
94
                                   UNIT_FILE_STATIC,
95
                                   UNIT_FILE_ALIAS,
96
                                   UNIT_FILE_INDIRECT,
97
                                   UNIT_FILE_GENERATED))
98
                                enabled = true;
5✔
99

100
                        if (!arg_quiet) {
17✔
101
                                puts(unit_file_state_to_string(state));
17✔
102
                                if (arg_full) {
17✔
103
                                        r = show_installation_targets_client_side(*name);
1✔
104
                                        if (r < 0)
1✔
105
                                                return r;
106
                                }
107
                        }
108
                }
109
        else {
110
                _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
432✔
111
                sd_bus *bus;
432✔
112

113
                r = acquire_bus(BUS_MANAGER, &bus);
432✔
114
                if (r < 0)
432✔
115
                        return r;
116

117
                STRV_FOREACH(name, names) {
864✔
118
                        _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
432✔
119
                        const char *s;
432✔
120

121
                        r = bus_call_method(bus, bus_systemd_mgr, "GetUnitFileState", &error, &reply, "s", *name);
432✔
122
                        if (r == -ENOENT) {
432✔
123
                                sd_bus_error_free(&error);
8✔
124

125
                                if (!arg_quiet)
8✔
126
                                        puts("not-found");
7✔
127
                                continue;
8✔
128
                        } else if (r < 0)
424✔
129
                                return log_error_errno(r,
×
130
                                                       "Failed to get unit file state for %s: %s",
131
                                                       *name,
132
                                                       bus_error_message(&error, r));
133
                        else
134
                                not_found = false;
424✔
135

136
                        r = sd_bus_message_read(reply, "s", &s);
424✔
137
                        if (r < 0)
424✔
138
                                return bus_log_parse_error(r);
×
139

140
                        if (STR_IN_SET(s, "enabled", "enabled-runtime", "static", "alias", "indirect", "generated"))
424✔
141
                                enabled = true;
361✔
142

143
                        if (!arg_quiet) {
424✔
144
                                puts(s);
423✔
145
                                if (arg_full) {
423✔
146
                                        r = show_installation_targets(bus, *name);
1✔
147
                                        if (r < 0)
1✔
148
                                                return r;
149
                                }
150
                        }
151
                }
152
        }
153

154
        return enabled ? EXIT_SUCCESS : not_found ? EXIT_PROGRAM_OR_SERVICES_STATUS_UNKNOWN : EXIT_FAILURE;
449✔
155
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc