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

systemd / systemd / 13610116813

01 Mar 2025 03:22PM UTC coverage: 71.857% (+0.04%) from 71.822%
13610116813

push

github

DaanDeMeyer
Add a few more bypass environment variables

When we're building ParticleOS images, we don't want the package
manager (or mkosi) to run systemd-sysusers, systemd-tmpfiles or
systemctl preset so let's add a few more bypass environment
variables that we can set to have execution of these skipped like
we already have $SYSTEMD_HWDB_UPDATE_BYPASS and $KERNEL_INSTALL_BYPASS.

12 of 16 new or added lines in 7 files covered. (75.0%)

4203 existing lines in 46 files now uncovered.

294791 of 410246 relevant lines covered (71.86%)

717494.72 hits per line

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

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

4
/* Missing glibc definitions to access certain kernel APIs */
5

6
#include <errno.h>
7
#include <fcntl.h>
8
#include <linux/time_types.h>
9
#include <signal.h>
10
#include <sys/syscall.h>
11
#include <sys/types.h>
12
#include <sys/wait.h>
13
#include <unistd.h>
14

15
#ifdef ARCH_MIPS
16
#include <asm/sgidefs.h>
17
#endif
18

19
#include "macro.h"
20
#include "missing_keyctl.h"
21
#include "missing_sched.h"
22
#include "missing_syscall_def.h"
23

24
/* ======================================================================= */
25

26
#if !HAVE_FCHMODAT2
27
static inline int missing_fchmodat2(int dirfd, const char *path, mode_t mode, int flags) {
24,901✔
28
#  ifdef __NR_fchmodat2
29
        return syscall(__NR_fchmodat2, dirfd, path, mode, flags);
24,901✔
30
#  else
31
        errno = ENOSYS;
32
        return -1;
33
#  endif
34
}
35

36
#  define fchmodat2 missing_fchmodat2
37
#endif
38

39
/* ======================================================================= */
40

41
#if !HAVE_PIVOT_ROOT
42
static inline int missing_pivot_root(const char *new_root, const char *put_old) {
2,874✔
43
        return syscall(__NR_pivot_root, new_root, put_old);
2,874✔
44
}
45

46
#  define pivot_root missing_pivot_root
47
#endif
48

49
/* ======================================================================= */
50

51
#if !HAVE_IOPRIO_GET
52
static inline int missing_ioprio_get(int which, int who) {
2,066✔
53
        return syscall(__NR_ioprio_get, which, who);
2,066✔
54
}
55

56
#  define ioprio_get missing_ioprio_get
57
#endif
58

59
/* ======================================================================= */
60

61
#if !HAVE_IOPRIO_SET
62
static inline int missing_ioprio_set(int which, int who, int ioprio) {
9✔
63
        return syscall(__NR_ioprio_set, which, who, ioprio);
9✔
64
}
65

66
#  define ioprio_set missing_ioprio_set
67
#endif
68

69
/* ======================================================================= */
70

71
#if !HAVE_MEMFD_CREATE
72
static inline int missing_memfd_create(const char *name, unsigned int flags) {
73
        return syscall(__NR_memfd_create, name, flags);
74
}
75

76
#  define memfd_create missing_memfd_create
77
#endif
78

79
/* ======================================================================= */
80

81
#if !HAVE_GETRANDOM
82
/* glibc says getrandom() returns ssize_t */
83
static inline ssize_t missing_getrandom(void *buffer, size_t count, unsigned flags) {
84
        return syscall(__NR_getrandom, buffer, count, flags);
85
}
86

87
#  define getrandom missing_getrandom
88
#endif
89

90
/* ======================================================================= */
91

92
/* The syscall has been defined since forever, but the glibc wrapper was missing. */
93
#if !HAVE_GETTID
94
static inline pid_t missing_gettid(void) {
95
#  if defined __NR_gettid && __NR_gettid >= 0
96
        return (pid_t) syscall(__NR_gettid);
97
#  else
98
#    error "__NR_gettid not defined"
99
#  endif
100
}
101

102
#  define gettid missing_gettid
103
#endif
104

105
/* ======================================================================= */
106

107
#if !HAVE_NAME_TO_HANDLE_AT
108
struct file_handle {
109
        unsigned int handle_bytes;
110
        int handle_type;
111
        unsigned char f_handle[0];
112
};
113

114
static inline int missing_name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
115
#  ifdef __NR_name_to_handle_at
116
        return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
117
#  else
118
        errno = ENOSYS;
119
        return -1;
120
#  endif
121
}
122

123
#  define name_to_handle_at missing_name_to_handle_at
124
#endif
125

126
/* ======================================================================= */
127

128
#if !HAVE_SETNS
129
static inline int missing_setns(int fd, int nstype) {
130
        return syscall(__NR_setns, fd, nstype);
131
}
132

133
#  define setns missing_setns
134
#endif
135

136
/* ======================================================================= */
137

138
static inline pid_t raw_getpid(void) {
133,942✔
139
#if defined(__alpha__)
140
        return (pid_t) syscall(__NR_getxpid);
141
#else
142
        return (pid_t) syscall(__NR_getpid);
133,942✔
143
#endif
144
}
145

146
/* ======================================================================= */
147

148
#if !HAVE_RENAMEAT2
149
static inline int missing_renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
150
        return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
151
}
152

153
#  define renameat2 missing_renameat2
154
#endif
155

156
/* ======================================================================= */
157

158
#if !HAVE_KCMP
159
static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
7,360✔
160
        return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
7,360✔
161
}
162

163
#  define kcmp missing_kcmp
164
#endif
165

166
/* ======================================================================= */
167

168
#if !HAVE_KEYCTL
169
static inline long missing_keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5) {
22,020✔
170
        return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
22,020✔
171

172
#  define keyctl missing_keyctl
173
}
174

175
static inline key_serial_t missing_add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
10,336✔
176
        return syscall(__NR_add_key, type, description, payload, plen, ringid);
10,336✔
177

178
#  define add_key missing_add_key
179
}
180

181
static inline key_serial_t missing_request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
12✔
182
        return syscall(__NR_request_key, type, description, callout_info, destringid);
12✔
183

184
#  define request_key missing_request_key
185
}
186
#endif
187

188
/* ======================================================================= */
189

190
#if !HAVE_COPY_FILE_RANGE
191
static inline ssize_t missing_copy_file_range(int fd_in, loff_t *off_in,
192
                                              int fd_out, loff_t *off_out,
193
                                              size_t len,
194
                                              unsigned int flags) {
195
#  ifdef __NR_copy_file_range
196
        return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags);
197
#  else
198
        errno = ENOSYS;
199
        return -1;
200
#  endif
201
}
202

203
#  define copy_file_range missing_copy_file_range
204
#endif
205

206
/* ======================================================================= */
207

208
#if !HAVE_BPF
209
union bpf_attr;
210

211
static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size) {
2,911✔
212
#ifdef __NR_bpf
213
        return (int) syscall(__NR_bpf, cmd, attr, size);
2,911✔
214
#else
215
        errno = ENOSYS;
216
        return -1;
217
#endif
218
}
219

220
#  define bpf missing_bpf
221
#endif
222

223
/* ======================================================================= */
224

225
#if !HAVE_SET_MEMPOLICY
226
enum {
227
        MPOL_DEFAULT,
228
        MPOL_PREFERRED,
229
        MPOL_BIND,
230
        MPOL_INTERLEAVE,
231
        MPOL_LOCAL,
232
};
233

234
static inline long missing_set_mempolicy(int mode, const unsigned long *nodemask,
17✔
235
                           unsigned long maxnode) {
236
        long i;
17✔
237
#  if defined __NR_set_mempolicy && __NR_set_mempolicy >= 0
238
        i = syscall(__NR_set_mempolicy, mode, nodemask, maxnode);
17✔
239
#  else
240
        errno = ENOSYS;
241
        i = -1;
242
#  endif
243
        return i;
17✔
244
}
245

246
#  define set_mempolicy missing_set_mempolicy
247
#endif
248

249
#if !HAVE_GET_MEMPOLICY
250
static inline long missing_get_mempolicy(int *mode, unsigned long *nodemask,
19✔
251
                           unsigned long maxnode, void *addr,
252
                           unsigned long flags) {
253
        long i;
19✔
254
#  if defined __NR_get_mempolicy && __NR_get_mempolicy >= 0
255
        i = syscall(__NR_get_mempolicy, mode, nodemask, maxnode, addr, flags);
19✔
256
#  else
257
        errno = ENOSYS;
258
        i = -1;
259
#  endif
260
        return i;
19✔
261
}
262

263
#  define get_mempolicy missing_get_mempolicy
264
#endif
265

266
/* ======================================================================= */
267

268
#if !HAVE_PIDFD_SEND_SIGNAL
269
static inline int missing_pidfd_send_signal(int fd, int sig, siginfo_t *info, unsigned flags) {
270
        return syscall(__NR_pidfd_send_signal, fd, sig, info, flags);
271
}
272

273
#  define pidfd_send_signal missing_pidfd_send_signal
274
#endif
275

276
#if !HAVE_PIDFD_OPEN
277
static inline int missing_pidfd_open(pid_t pid, unsigned flags) {
278
        return syscall(__NR_pidfd_open, pid, flags);
279
}
280

281
#  define pidfd_open missing_pidfd_open
282
#endif
283

284
/* ======================================================================= */
285

286
#if !HAVE_RT_SIGQUEUEINFO
287
static inline int missing_rt_sigqueueinfo(pid_t tgid, int sig, siginfo_t *info) {
288
#  if defined __NR_rt_sigqueueinfo && __NR_rt_sigqueueinfo >= 0
289
        return syscall(__NR_rt_sigqueueinfo, tgid, sig, info);
290
#  else
291
#    error "__NR_rt_sigqueueinfo not defined"
292
#  endif
293
}
294

295
#  define rt_sigqueueinfo missing_rt_sigqueueinfo
296
#endif
297

298
/* ======================================================================= */
299

300
#if !HAVE_RT_TGSIGQUEUEINFO
UNCOV
301
static inline int missing_rt_tgsigqueueinfo(pid_t tgid, pid_t tid, int sig, siginfo_t *info) {
×
302
#  if defined __NR_rt_tgsigqueueinfo && __NR_rt_tgsigqueueinfo >= 0
UNCOV
303
        return syscall(__NR_rt_tgsigqueueinfo, tgid, tid, sig, info);
×
304
#  else
305
#    error "__NR_rt_tgsigqueueinfo not defined"
306
#  endif
307
}
308

309
#  define rt_tgsigqueueinfo missing_rt_tgsigqueueinfo
310
#endif
311

312
/* ======================================================================= */
313

314
#if !HAVE_EXECVEAT
315
static inline int missing_execveat(int dirfd, const char *pathname,
316
                                   char *const argv[], char *const envp[],
317
                                   int flags) {
318
#  if defined __NR_execveat && __NR_execveat >= 0
319
        return syscall(__NR_execveat, dirfd, pathname, argv, envp, flags);
320
#  else
321
        errno = ENOSYS;
322
        return -1;
323
#  endif
324
}
325

326
#  undef AT_EMPTY_PATH
327
#  define AT_EMPTY_PATH 0x1000
328
#  define execveat missing_execveat
329
#endif
330

331
/* ======================================================================= */
332

333
#if !HAVE_CLOSE_RANGE
334
static inline int missing_close_range(unsigned first_fd, unsigned end_fd, unsigned flags) {
335
#  ifdef __NR_close_range
336
        /* Kernel-side the syscall expects fds as unsigned integers (just like close() actually), while
337
         * userspace exclusively uses signed integers for fds. glibc chose to expose it 1:1 however, hence we
338
         * do so here too, even if we end up passing signed fds to it most of the time. */
339
        return syscall(__NR_close_range,
340
                       first_fd,
341
                       end_fd,
342
                       flags);
343
#  else
344
        errno = ENOSYS;
345
        return -1;
346
#  endif
347
}
348

349
#  define close_range missing_close_range
350
#endif
351

352
/* ======================================================================= */
353

354
#if !HAVE_MOUNT_SETATTR
355

356
#if !HAVE_STRUCT_MOUNT_ATTR
357
struct mount_attr {
358
        uint64_t attr_set;
359
        uint64_t attr_clr;
360
        uint64_t propagation;
361
        uint64_t userns_fd;
362
};
363
#else
364
struct mount_attr;
365
#endif
366

367
#ifndef MOUNT_ATTR_RDONLY
368
#define MOUNT_ATTR_RDONLY       0x00000001 /* Mount read-only */
369
#endif
370

371
#ifndef MOUNT_ATTR_NOSUID
372
#define MOUNT_ATTR_NOSUID       0x00000002 /* Ignore suid and sgid bits */
373
#endif
374

375
#ifndef MOUNT_ATTR_NODEV
376
#define MOUNT_ATTR_NODEV        0x00000004 /* Disallow access to device special files */
377
#endif
378

379
#ifndef MOUNT_ATTR_NOEXEC
380
#define MOUNT_ATTR_NOEXEC       0x00000008 /* Disallow program execution */
381
#endif
382

383
#ifndef MOUNT_ATTR__ATIME
384
#define MOUNT_ATTR__ATIME       0x00000070 /* Setting on how atime should be updated */
385
#endif
386

387
#ifndef MOUNT_ATTR_RELATIME
388
#define MOUNT_ATTR_RELATIME     0x00000000 /* - Update atime relative to mtime/ctime. */
389
#endif
390

391
#ifndef MOUNT_ATTR_NOATIME
392
#define MOUNT_ATTR_NOATIME      0x00000010 /* - Do not update access times. */
393
#endif
394

395
#ifndef MOUNT_ATTR_STRICTATIME
396
#define MOUNT_ATTR_STRICTATIME  0x00000020 /* - Always perform atime updates */
397
#endif
398

399
#ifndef MOUNT_ATTR_NODIRATIME
400
#define MOUNT_ATTR_NODIRATIME   0x00000080 /* Do not update directory access times */
401
#endif
402

403
#ifndef MOUNT_ATTR_IDMAP
404
#define MOUNT_ATTR_IDMAP        0x00100000 /* Idmap mount to @userns_fd in struct mount_attr. */
405
#endif
406

407
#ifndef MOUNT_ATTR_NOSYMFOLLOW
408
#define MOUNT_ATTR_NOSYMFOLLOW  0x00200000 /* Do not follow symlinks */
409
#endif
410

411
#ifndef MOUNT_ATTR_SIZE_VER0
412
#define MOUNT_ATTR_SIZE_VER0    32 /* sizeof first published struct */
413
#endif
414

415
#ifndef AT_RECURSIVE
416
#define AT_RECURSIVE 0x8000
417
#endif
418

419
static inline int missing_mount_setattr(
420
                int dfd,
421
                const char *path,
422
                unsigned flags,
423
                struct mount_attr *attr,
424
                size_t size) {
425

426
#  if defined __NR_mount_setattr && __NR_mount_setattr >= 0
427
        return syscall(__NR_mount_setattr, dfd, path, flags, attr, size);
428
#  else
429
        errno = ENOSYS;
430
        return -1;
431
#  endif
432
}
433

434
#  define mount_setattr missing_mount_setattr
435
#endif
436

437
/* ======================================================================= */
438

439
#if !HAVE_OPEN_TREE
440

441
#ifndef OPEN_TREE_CLONE
442
#define OPEN_TREE_CLONE 1
443
#endif
444

445
#ifndef OPEN_TREE_CLOEXEC
446
#define OPEN_TREE_CLOEXEC O_CLOEXEC
447
#endif
448

449
static inline int missing_open_tree(
450
                int dfd,
451
                const char *filename,
452
                unsigned flags) {
453

454
#  if defined __NR_open_tree && __NR_open_tree >= 0
455
        return syscall(__NR_open_tree, dfd, filename, flags);
456
#  else
457
        errno = ENOSYS;
458
        return -1;
459
#  endif
460
}
461

462
#  define open_tree missing_open_tree
463
#endif
464

465
/* ======================================================================= */
466

467
#ifndef MOVE_MOUNT_BENEATH
468
#define MOVE_MOUNT_BENEATH 0x00000200
469
#endif
470

471
#if !HAVE_MOVE_MOUNT
472

473
#ifndef MOVE_MOUNT_F_EMPTY_PATH
474
#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */
475
#endif
476

477
#ifndef MOVE_MOUNT_T_EMPTY_PATH
478
#define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */
479
#endif
480

481
static inline int missing_move_mount(
482
                int from_dfd,
483
                const char *from_pathname,
484
                int to_dfd,
485
                const char *to_pathname,
486
                unsigned flags) {
487

488
#  if defined __NR_move_mount && __NR_move_mount >= 0
489
        return syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd, to_pathname, flags);
490
#  else
491
        errno = ENOSYS;
492
        return -1;
493
#  endif
494
}
495

496
#  define move_mount missing_move_mount
497
#endif
498

499
/* ======================================================================= */
500

501
#if !HAVE_FSOPEN
502

503
#ifndef FSOPEN_CLOEXEC
504
#define FSOPEN_CLOEXEC 0x00000001
505
#endif
506

507
static inline int missing_fsopen(const char *fsname, unsigned flags) {
508
#  if defined __NR_fsopen && __NR_fsopen >= 0
509
        return syscall(__NR_fsopen, fsname, flags);
510
#  else
511
        errno = ENOSYS;
512
        return -1;
513
#  endif
514
}
515

516
#  define fsopen missing_fsopen
517
#endif
518

519
/* ======================================================================= */
520

521
#if !HAVE_FSCONFIG
522

523
#ifndef FSCONFIG_SET_FLAG
524
#define FSCONFIG_SET_FLAG 0 /* Set parameter, supplying no value */
525
#endif
526

527
#ifndef FSCONFIG_SET_STRING
528
#define FSCONFIG_SET_STRING 1 /* Set parameter, supplying a string value */
529
#endif
530

531
#ifndef FSCONFIG_SET_FD
532
#define FSCONFIG_SET_FD 5 /* Set parameter, supplying an object by fd */
533
#endif
534

535
#ifndef FSCONFIG_CMD_CREATE
536
#define FSCONFIG_CMD_CREATE 6 /* Invoke superblock creation */
537
#endif
538

539
static inline int missing_fsconfig(int fd, unsigned cmd, const char *key, const void *value, int aux) {
540
#  if defined __NR_fsconfig && __NR_fsconfig >= 0
541
        return syscall(__NR_fsconfig, fd, cmd, key, value, aux);
542
#  else
543
        errno = ENOSYS;
544
        return -1;
545
#  endif
546
}
547

548
#  define fsconfig missing_fsconfig
549
#endif
550

551
/* ======================================================================= */
552

553
#if !HAVE_FSMOUNT
554

555
#ifndef FSMOUNT_CLOEXEC
556
#define FSMOUNT_CLOEXEC 0x00000001
557
#endif
558

559
static inline int missing_fsmount(int fd, unsigned flags, unsigned ms_flags) {
560
#  if defined __NR_fsmount && __NR_fsmount >= 0
561
        return syscall(__NR_fsmount, fd, flags, ms_flags);
562
#  else
563
        errno = ENOSYS;
564
        return -1;
565
#  endif
566
}
567

568
#  define fsmount missing_fsmount
569
#endif
570

571
/* ======================================================================= */
572

573
#if !HAVE_GETDENTS64
574

575
static inline ssize_t missing_getdents64(int fd, void *buffer, size_t length) {
576
#  if defined __NR_getdents64 && __NR_getdents64 >= 0
577
        return syscall(__NR_getdents64, fd, buffer, length);
578
#  else
579
        errno = ENOSYS;
580
        return -1;
581
#  endif
582
}
583

584
#  define getdents64 missing_getdents64
585
#endif
586

587
/* ======================================================================= */
588

589
#if !HAVE_SCHED_SETATTR
590

591
static inline ssize_t missing_sched_setattr(pid_t pid, struct sched_attr *attr, unsigned int flags) {
592
        return syscall(__NR_sched_setattr, pid, attr, flags);
593
}
594

595
#  define sched_setattr missing_sched_setattr
596
#endif
597

598
/* ======================================================================= */
599

600
/* glibc does not provide clone() on ia64, only clone2(). Not only that, but it also doesn't provide a
601
 * prototype, only the symbol in the shared library (it provides a prototype for clone(), but not the
602
 * symbol in the shared library). */
603
#if defined(__ia64__)
604
int __clone2(int (*fn)(void *), void *stack_base, size_t stack_size, int flags, void *arg);
605
#define HAVE_CLONE 0
606
#else
607
/* We know that everywhere else clone() is available, so we don't bother with a meson check (that takes time
608
 * at build time) and just define it. Once the kernel drops ia64 support, we can drop this too. */
609
#define HAVE_CLONE 1
610
#endif
611

612
/* ======================================================================= */
613

614
#if !HAVE_QUOTACTL_FD
615

616
static inline int missing_quotactl_fd(int fd, int cmd, int id, void *addr) {
312✔
617
#  ifdef __NR_quotactl_fd
618
        return syscall(__NR_quotactl_fd, fd, cmd, id, addr);
312✔
619
#  else
620
        errno = ENOSYS;
621
        return -1;
622
#  endif
623
}
624

625
#  define quotactl_fd missing_quotactl_fd
626
#endif
627

628
/* ======================================================================= */
629

630
#if !HAVE_SETXATTRAT
631
struct xattr_args {
632
        _align_(8) uint64_t value;
633
        uint32_t size;
634
        uint32_t flags;
635
};
636

637
static inline int missing_setxattrat(int fd, const char *path, int at_flags, const char *name, const struct xattr_args *args, size_t size) {
1✔
638
#  ifdef __NR_setxattrat
639
        return syscall(__NR_setxattrat, fd, path, at_flags, name, args, size);
1✔
640
#  else
641
        errno = ENOSYS;
642
        return -1;
643
#  endif
644
}
645

646
#  define setxattrat missing_setxattrat
647
#endif
648

649
#if !HAVE_REMOVEXATTRAT
UNCOV
650
static inline int missing_removexattrat(int fd, const char *path, int at_flags, const char *name) {
×
651
#  ifdef __NR_removexattrat
UNCOV
652
        return syscall(__NR_removexattrat, fd, path, at_flags, name);
×
653
#  else
654
        errno = ENOSYS;
655
        return -1;
656
#  endif
657
}
658

659
#  define removexattrat missing_removexattrat
660
#endif
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