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

systemd / systemd / 14785896885

01 May 2025 10:34AM UTC coverage: 72.243% (+0.02%) from 72.225%
14785896885

push

github

yuwata
build(deps): bump softprops/action-gh-release from 2.2.1 to 2.2.2

Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 2.2.1 to 2.2.2.
- [Release notes](https://github.com/softprops/action-gh-release/releases)
- [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md)
- [Commits](https://github.com/softprops/action-gh-release/compare/c95fe1489...da05d5525)

---
updated-dependencies:
- dependency-name: softprops/action-gh-release
  dependency-version: 2.2.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

297212 of 411406 relevant lines covered (72.24%)

692806.75 hits per line

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

88.89
/src/basic/process-util.h
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2
#pragma once
3

4
#include <errno.h>
5
#include <sched.h>
6
#include <signal.h>
7
#include <stdbool.h>
8
#include <stddef.h>
9
#include <stdio.h>
10
#include <string.h>
11
#include <sys/resource.h>
12
#include <sys/types.h>
13

14
#include "alloc-util.h"
15
#include "assert-util.h"
16
#include "fileio.h"
17
#include "format-util.h"
18
#include "macro.h"
19
#include "pidref.h"
20
#include "time-util.h"
21

22
#define procfs_file_alloca(pid, field)                                  \
23
        ({                                                              \
24
                pid_t _pid_ = (pid);                                    \
25
                const char *_field_ = (field);                          \
26
                char *_r_;                                              \
27
                if (_pid_ == 0)                                         \
28
                        _r_ = strjoina("/proc/self/", _field_);         \
29
                else {                                                  \
30
                        assert(_pid_ > 0);                              \
31
                        _r_ = newa(char, STRLEN("/proc/") + DECIMAL_STR_MAX(pid_t) + 1 + strlen(_field_) + 1); \
32
                        sprintf(_r_, "/proc/" PID_FMT "/%s", _pid_, _field_); \
33
                }                                                       \
34
                (const char*) _r_;                                      \
35
        })
36

37
static inline int procfs_file_get_field(pid_t pid, const char *name, const char *key, char **ret) {
24,354✔
38
        return get_proc_field(procfs_file_alloca(pid, name), key, ret);
98,478✔
39
}
40

41
typedef enum ProcessCmdlineFlags {
42
        PROCESS_CMDLINE_COMM_FALLBACK = 1 << 0,
43
        PROCESS_CMDLINE_USE_LOCALE    = 1 << 1,
44
        PROCESS_CMDLINE_QUOTE         = 1 << 2,
45
        PROCESS_CMDLINE_QUOTE_POSIX   = 1 << 3,
46
} ProcessCmdlineFlags;
47

48
int pid_get_comm(pid_t pid, char **ret);
46,336✔
49
int pidref_get_comm(const PidRef *pid, char **ret);
29✔
50
int pid_get_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags, char **ret);
12,748✔
51
int pidref_get_cmdline(const PidRef *pid, size_t max_columns, ProcessCmdlineFlags flags, char **ret);
99✔
52
int pid_get_cmdline_strv(pid_t pid, ProcessCmdlineFlags flags, char ***ret);
4,831✔
53
int pidref_get_cmdline_strv(const PidRef *pid, ProcessCmdlineFlags flags, char ***ret);
×
54
int get_process_exe(pid_t pid, char **ret);
12,106✔
55
int pid_get_uid(pid_t pid, uid_t *ret);
2,918✔
56
int pidref_get_uid(const PidRef *pid, uid_t *ret);
54✔
57
int get_process_gid(pid_t pid, gid_t *ret);
2,909✔
58
int get_process_cwd(pid_t pid, char **ret);
13✔
59
int get_process_root(pid_t pid, char **ret);
13✔
60
int get_process_environ(pid_t pid, char **ret);
15✔
61
int pid_get_ppid(pid_t pid, pid_t *ret);
1,390✔
62
int pidref_get_ppid(const PidRef *pidref, pid_t *ret);
2,395✔
63
int pidref_get_ppid_as_pidref(const PidRef *pidref, PidRef *ret);
17✔
64
int pid_get_start_time(pid_t pid, usec_t *ret);
658✔
65
int pidref_get_start_time(const PidRef *pid, usec_t *ret);
658✔
66
int get_process_umask(pid_t pid, mode_t *ret);
18,525✔
67

68
int container_get_leader(const char *machine, pid_t *pid);
10✔
69

70
static inline bool SIGINFO_CODE_IS_DEAD(int code) {
32,576✔
71
        return IN_SET(code, CLD_EXITED, CLD_KILLED, CLD_DUMPED);
32,576✔
72
}
73

74
int wait_for_terminate(pid_t pid, siginfo_t *ret);
864✔
75

76
typedef enum WaitFlags {
77
        WAIT_LOG_ABNORMAL             = 1 << 0,
78
        WAIT_LOG_NON_ZERO_EXIT_STATUS = 1 << 1,
79

80
        /* A shortcut for requesting the most complete logging */
81
        WAIT_LOG = WAIT_LOG_ABNORMAL|WAIT_LOG_NON_ZERO_EXIT_STATUS,
82
} WaitFlags;
83

84
int pidref_wait_for_terminate_and_check(const char *name, PidRef *pidref, WaitFlags flags);
9,080✔
85
int wait_for_terminate_and_check(const char *name, pid_t pid, WaitFlags flags);
7,961✔
86

87
int wait_for_terminate_with_timeout(pid_t pid, usec_t timeout);
×
88

89
void sigkill_wait(pid_t pid);
70✔
90
void sigkill_waitp(pid_t *pid);
11,775✔
91
void sigterm_wait(pid_t pid);
65✔
92
void sigkill_nowait(pid_t pid);
×
93
void sigkill_nowaitp(pid_t *pid);
×
94

95
int kill_and_sigcont(pid_t pid, int sig);
65✔
96

97
int pid_is_kernel_thread(pid_t pid);
3,483✔
98
int pidref_is_kernel_thread(const PidRef *pid);
1,415✔
99

100
int getenv_for_pid(pid_t pid, const char *field, char **_value);
4,689✔
101

102
int pid_is_alive(pid_t pid);
9,937✔
103
int pidref_is_alive(const PidRef *pidref);
9,932✔
104
int pid_is_unwaited(pid_t pid);
7,110✔
105
int pidref_is_unwaited(PidRef *pidref);
7,767✔
106
int pid_is_my_child(pid_t pid);
×
107
int pidref_is_my_child(PidRef *pidref);
2,361✔
108
int pidref_from_same_root_fs(PidRef *a, PidRef *b);
13,577✔
109

110
bool is_main_thread(void);
6,735,212✔
111

112
bool oom_score_adjust_is_valid(int oa);
5,650✔
113

114
#ifndef PERSONALITY_INVALID
115
/* personality(2) documents that 0xFFFFFFFFUL is used for querying the
116
 * current personality, hence let's use that here as error
117
 * indicator. */
118
#define PERSONALITY_INVALID 0xFFFFFFFFUL
119
#endif
120

121
/* The personality() syscall returns a 32-bit value where the top three bytes are reserved for flags that
122
 * emulate historical or architectural quirks, and only the least significant byte reflects the actual
123
 * personality we're interested in. */
124
#define OPINIONATED_PERSONALITY_MASK 0xFFUL
125

126
unsigned long personality_from_string(const char *p);
9✔
127
const char* personality_to_string(unsigned long);
1,264✔
128

129
int safe_personality(unsigned long p);
1,505✔
130
int opinionated_personality(unsigned long *ret);
1,490✔
131

132
const char* sigchld_code_to_string(int i) _const_;
7,579✔
133
int sigchld_code_from_string(const char *s) _pure_;
×
134

135
int sched_policy_to_string_alloc(int i, char **s);
×
136
int sched_policy_from_string(const char *s);
3✔
137

138
static inline pid_t PTR_TO_PID(const void *p) {
1,215✔
139
        return (pid_t) ((uintptr_t) p);
1,215✔
140
}
141

142
static inline void* PID_TO_PTR(pid_t pid) {
415,109✔
143
        return (void*) ((uintptr_t) pid);
415,070✔
144
}
145

146
void valgrind_summary_hack(void);
47✔
147

148
int pid_compare_func(const pid_t *a, const pid_t *b);
1,620✔
149

150
static inline bool nice_is_valid(int n) {
733✔
151
        return n >= PRIO_MIN && n < PRIO_MAX;
733✔
152
}
153

154
static inline bool sched_policy_is_valid(int i) {
×
155
        return IN_SET(i, SCHED_OTHER, SCHED_BATCH, SCHED_IDLE, SCHED_FIFO, SCHED_RR);
×
156
}
157

158
static inline bool sched_priority_is_valid(int i) {
159
        return i >= 0 && i <= sched_get_priority_max(SCHED_RR);
160
}
161

162
#define PID_AUTOMATIC ((pid_t) INT_MIN) /* special value indicating "acquire pid from connection peer" */
163

164
static inline bool pid_is_valid(pid_t p) {
165
        return p > 0;
166
}
167

168
static inline bool pid_is_automatic(pid_t p) {
1✔
169
        return p == PID_AUTOMATIC;
1✔
170
}
171

172
pid_t getpid_cached(void);
77,748,827✔
173
void reset_cached_pid(void);
3,161✔
174

175
int must_be_root(void);
59✔
176

177
pid_t clone_with_nested_stack(int (*fn)(void *), int flags, void *userdata);
2,924✔
178

179
/* 💣 Note that FORK_NEW_USERNS, FORK_NEW_MOUNTNS, FORK_NEW_NETNS or FORK_NEW_PIDNS should not be called in threaded
180
 * programs, because they cause us to use raw_clone() which does not synchronize the glibc malloc() locks,
181
 * and thus will cause deadlocks if the parent uses threads and the child does memory allocations. Hence: if
182
 * the parent is threaded these flags may not be used. These flags cannot be used if the parent uses threads
183
 * or the child uses malloc(). 💣 */
184
typedef enum ForkFlags {
185
        FORK_RESET_SIGNALS      = 1 <<  0, /* Reset all signal handlers and signal mask */
186
        FORK_CLOSE_ALL_FDS      = 1 <<  1, /* Close all open file descriptors in the child, except for 0,1,2 */
187
        FORK_DEATHSIG_SIGTERM   = 1 <<  2, /* Set PR_DEATHSIG in the child to SIGTERM */
188
        FORK_DEATHSIG_SIGINT    = 1 <<  3, /* Set PR_DEATHSIG in the child to SIGINT */
189
        FORK_DEATHSIG_SIGKILL   = 1 <<  4, /* Set PR_DEATHSIG in the child to SIGKILL */
190
        FORK_REARRANGE_STDIO    = 1 <<  5, /* Connect 0,1,2 to specified fds or /dev/null */
191
        FORK_REOPEN_LOG         = 1 <<  6, /* Reopen log connection */
192
        FORK_LOG                = 1 <<  7, /* Log above LOG_DEBUG log level about failures */
193
        FORK_WAIT               = 1 <<  8, /* Wait until child exited */
194
        FORK_MOUNTNS_SLAVE      = 1 <<  9, /* Make child's mount namespace MS_SLAVE */
195
        FORK_PRIVATE_TMP        = 1 << 10, /* Mount new /tmp/ in the child (combine with FORK_NEW_MOUNTNS!) */
196
        FORK_RLIMIT_NOFILE_SAFE = 1 << 11, /* Set RLIMIT_NOFILE soft limit to 1K for select() compat */
197
        FORK_STDOUT_TO_STDERR   = 1 << 12, /* Make stdout a copy of stderr */
198
        FORK_FLUSH_STDIO        = 1 << 13, /* fflush() stdout (and stderr) before forking */
199
        FORK_CLOEXEC_OFF        = 1 << 14, /* In the child: turn off O_CLOEXEC on all fds in except_fds[] */
200
        FORK_KEEP_NOTIFY_SOCKET = 1 << 15, /* Unless this specified, $NOTIFY_SOCKET will be unset. */
201
        FORK_DETACH             = 1 << 16, /* Double fork if needed to ensure PID1/subreaper is parent */
202
        FORK_PACK_FDS           = 1 << 17, /* Rearrange the passed FDs to be FD 3,4,5,etc. Updates the array in place (combine with FORK_CLOSE_ALL_FDS!) */
203
        FORK_NEW_MOUNTNS        = 1 << 18, /* Run child in its own mount namespace                               💣 DO NOT USE IN THREADED PROGRAMS! 💣 */
204
        FORK_NEW_USERNS         = 1 << 19, /* Run child in its own user namespace                                💣 DO NOT USE IN THREADED PROGRAMS! 💣 */
205
        FORK_NEW_NETNS          = 1 << 20, /* Run child in its own network namespace                             💣 DO NOT USE IN THREADED PROGRAMS! 💣 */
206
        FORK_NEW_PIDNS          = 1 << 21, /* Run child in its own PID namespace                                 💣 DO NOT USE IN THREADED PROGRAMS! 💣 */
207
        FORK_FREEZE             = 1 << 22, /* Don't return in child, just call freeze() instead */
208
        FORK_PID_ONLY           = 1 << 23, /* Don't open a pidfd referencing the child process */
209
} ForkFlags;
210

211
int pidref_safe_fork_full(
31,412✔
212
                const char *name,
213
                const int stdio_fds[3],
214
                int except_fds[],
215
                size_t n_except_fds,
216
                ForkFlags flags,
217
                PidRef *ret_pid);
218

219
static inline int pidref_safe_fork(const char *name, ForkFlags flags, PidRef *ret_pid) {
6,345✔
220
        return pidref_safe_fork_full(name, NULL, NULL, 0, flags, ret_pid);
6,345✔
221
}
222

223
int safe_fork_full(
13,031✔
224
                const char *name,
225
                const int stdio_fds[3],
226
                int except_fds[],
227
                size_t n_except_fds,
228
                ForkFlags flags,
229
                pid_t *ret_pid);
230

231
static inline int safe_fork(const char *name, ForkFlags flags, pid_t *ret_pid) {
9,053✔
232
        return safe_fork_full(name, NULL, NULL, 0, flags, ret_pid);
9,053✔
233
}
234

235
int namespace_fork(
165✔
236
                const char *outer_name,
237
                const char *inner_name,
238
                int except_fds[],
239
                size_t n_except_fds,
240
                ForkFlags flags,
241
                int pidns_fd,
242
                int mntns_fd,
243
                int netns_fd,
244
                int userns_fd,
245
                int root_fd,
246
                pid_t *ret_pid);
247

248
int set_oom_score_adjust(int value);
3,943✔
249
int get_oom_score_adjust(int *ret);
1,017✔
250

251
/* The highest possibly (theoretic) pid_t value on this architecture. */
252
#define PID_T_MAX ((pid_t) INT32_MAX)
253
/* The maximum number of concurrent processes Linux allows on this architecture, as well as the highest valid PID value
254
 * the kernel will potentially assign. This reflects a value compiled into the kernel (PID_MAX_LIMIT), and sets the
255
 * upper boundary on what may be written to the /proc/sys/kernel/pid_max sysctl (but do note that the sysctl is off by
256
 * 1, since PID 0 can never exist and there can hence only be one process less than the limit would suggest). Since
257
 * these values are documented in proc(5) we feel quite confident that they are stable enough for the near future at
258
 * least to define them here too. */
259
#define TASKS_MAX 4194303U
260

261
assert_cc(TASKS_MAX <= (unsigned long) PID_T_MAX);
262

263
/* Like TAKE_PTR() but for pid_t, resetting them to 0 */
264
#define TAKE_PID(pid) TAKE_GENERIC(pid, pid_t, 0)
265

266
int setpriority_closest(int priority);
24✔
267

268
_noreturn_ void freeze(void);
×
269

270
int get_process_threads(pid_t pid);
7✔
271

272
int is_reaper_process(void);
3,026✔
273
int make_reaper_process(bool b);
596✔
274

275
int posix_spawn_wrapper(
2,194✔
276
                const char *path,
277
                char * const *argv,
278
                char * const *envp,
279
                const char *cgroup,
280
                PidRef *ret_pidref);
281

282
int proc_dir_open(DIR **ret);
11✔
283
int proc_dir_read(DIR *d, pid_t *ret);
980✔
284
int proc_dir_read_pidref(DIR *d, PidRef *ret);
936✔
285

286
_noreturn_ void report_errno_and_exit(int errno_fd, int error);
48✔
287
int read_errno(int errno_fd);
1✔
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