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

systemd / systemd / 18810271929

25 Oct 2025 04:50PM UTC coverage: 72.26%. Remained the same
18810271929

push

github

YHNdnzj
core/exec-invoke: relax restriction for process name length

Previously, we limit the length of process name by 8.
This relax the restriction then at least process comm or
program_invocation_name contains the untrucated process name.

Closes #38367.

24 of 28 new or added lines in 3 files covered. (85.71%)

486 existing lines in 52 files now uncovered.

304829 of 421852 relevant lines covered (72.26%)

1095984.64 hits per line

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

87.64
/src/shared/parse-argument.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include "alloc-util.h"
4
#include "ansi-color.h"
5
#include "bus-util.h"
6
#include "format-table.h"
7
#include "hostname-util.h"
8
#include "log.h"
9
#include "parse-argument.h"
10
#include "parse-util.h"
11
#include "path-util.h"
12
#include "signal-util.h"
13
#include "string-table.h"
14
#include "string-util.h"
15

16
/* All functions in this file emit warnings. */
17

18
int parse_boolean_argument(const char *optname, const char *s, bool *ret) {
1,242✔
19
        int r;
1,242✔
20

21
        /* Returns the result through *ret and the return value. */
22

23
        if (s) {
1,242✔
24
                r = parse_boolean(s);
1,237✔
25
                if (r < 0)
1,237✔
26
                        return log_error_errno(r, "Failed to parse boolean argument to %s: %s.", optname, s);
33✔
27

28
                if (ret)
1,204✔
29
                        *ret = r;
967✔
30
                return r;
1,204✔
31
        } else {
32
                /* s may be NULL. This is controlled by getopt_long() parameters. */
33
                if (ret)
5✔
34
                        *ret = true;
5✔
35
                return true;
5✔
36
        }
37
}
38

39
int parse_tristate_argument(const char *optname, const char *s, int *ret) {
119✔
40
        int r;
119✔
41

42
        if (s) {
119✔
43
                r = parse_boolean(s);
119✔
44
                if (r < 0)
119✔
UNCOV
45
                        return log_error_errno(r, "Failed to parse boolean argument to %s: %s.", optname, s);
×
46

47
                if (ret)
119✔
48
                        *ret = r;
119✔
49

50
                return r;
119✔
51
        } else {
52
                if (ret)
×
UNCOV
53
                        *ret = -1;
×
54

UNCOV
55
                return 0;
×
56
        }
57
}
58

59
int parse_json_argument(const char *s, sd_json_format_flags_t *ret) {
304✔
60
        assert(s);
304✔
61
        assert(ret);
304✔
62

63
        if (streq(s, "pretty"))
304✔
64
                *ret = SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_COLOR_AUTO;
98✔
65
        else if (streq(s, "short"))
206✔
66
                *ret = SD_JSON_FORMAT_NEWLINE;
184✔
67
        else if (streq(s, "off"))
22✔
68
                *ret = SD_JSON_FORMAT_OFF;
11✔
69
        else if (streq(s, "help")) {
11✔
70
                puts("pretty\n"
3✔
71
                     "short\n"
72
                     "off");
73
                return 0; /* 0 means → we showed a brief help, exit now */
3✔
74
        } else
75
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown argument to --json= switch: %s", s);
8✔
76

77
        return 1; /* 1 means → properly parsed */
78
}
79

80
int parse_path_argument(const char *path, bool suppress_root, char **arg) {
2,227✔
81
        char *p;
2,227✔
82
        int r;
2,227✔
83

84
        /*
85
         * This function is intended to be used in command line parsers, to handle paths that are passed
86
         * in. It makes the path absolute, and reduces it to NULL if omitted or root (the latter optionally).
87
         *
88
         * NOTE THAT THIS WILL FREE THE PREVIOUS ARGUMENT POINTER ON SUCCESS!
89
         * Hence, do not pass in uninitialized pointers.
90
         */
91

92
        if (isempty(path)) {
2,227✔
93
                *arg = mfree(*arg);
8✔
94
                return 0;
8✔
95
        }
96

97
        r = path_make_absolute_cwd(path, &p);
2,219✔
98
        if (r < 0)
2,219✔
UNCOV
99
                return log_error_errno(r, "Failed to parse path \"%s\" and make it absolute: %m", path);
×
100

101
        path_simplify(p);
2,219✔
102
        if (suppress_root && empty_or_root(p))
2,219✔
103
                p = mfree(p);
3✔
104

105
        return free_and_replace(*arg, p);
2,219✔
106
}
107

108
int parse_signal_argument(const char *s, int *ret) {
30✔
109
        int r;
30✔
110

111
        assert(s);
30✔
112
        assert(ret);
30✔
113

114
        if (streq(s, "help"))
30✔
115
                return DUMP_STRING_TABLE(signal, int, _NSIG);
132✔
116

117
        if (streq(s, "list")) {
28✔
118
                _cleanup_(table_unrefp) Table *table = NULL;
1✔
119

120
                table = table_new("signal", "name");
1✔
121
                if (!table)
1✔
UNCOV
122
                        return log_oom();
×
123

124
                for (int i = 1; i < _NSIG; i++) {
65✔
125
                        r = table_add_many(
64✔
126
                                        table,
127
                                        TABLE_INT, i,
128
                                        TABLE_SIGNAL, i);
129
                        if (r < 0)
64✔
UNCOV
130
                                return table_log_add_error(r);
×
131
                }
132

133
                r = table_print(table, NULL);
1✔
134
                if (r < 0)
1✔
UNCOV
135
                        return table_log_print_error(r);
×
136

137
                return 0;
138
        }
139

140
        r = signal_from_string(s);
27✔
141
        if (r < 0)
27✔
UNCOV
142
                return log_error_errno(r, "Failed to parse signal string \"%s\".", s);
×
143

144
        *ret = r;
27✔
145
        return 1; /* work to do */
27✔
146
}
147

148
int parse_machine_argument(const char *s, const char **ret_host, BusTransport *ret_transport) {
106✔
149
        int r;
106✔
150

151
        assert(s);
106✔
152
        assert(ret_host);
106✔
153

154
        r = machine_spec_valid(s);
106✔
155
        if (r < 0)
106✔
UNCOV
156
                return log_error_errno(r, "Failed to validate --machine= argument '%s': %m", s);
×
157
        if (r == 0)
106✔
UNCOV
158
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid --machine= specified: %s", s);
×
159

160
        *ret_host = s;
106✔
161

162
        if (ret_transport)
106✔
163
                *ret_transport = BUS_TRANSPORT_MACHINE;
106✔
164

165
        return 0;
166
}
167

168
int parse_background_argument(const char *s, char **arg) {
9✔
169
        if (!isempty(s) && !looks_like_ansi_color_code(s))
17✔
170
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid --background= argument: %s", s);
4✔
171

172
        return free_and_strdup_warn(arg, s);
5✔
173
}
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