basic: Remove circular dependency between process-util.h and pidref.h

PID_AUTOMATIC is moved to constants.h so it can be used by both
process-util.h and pidref.h without one having to include the other.
This commit is contained in:
Daan De Meyer 2025-04-12 19:45:49 +02:00
parent e258806a57
commit c0d1b21422
16 changed files with 19 additions and 7 deletions

View File

@ -20,6 +20,7 @@
#include "macro.h"
#include "parse-util.h"
#include "pidref.h"
#include "process-util.h"
#include "stat-util.h"
#include "user-util.h"

View File

@ -87,3 +87,5 @@
/* Recommended baseline - see README for details */
#define KERNEL_BASELINE_VERSION "5.7"
#define PID_AUTOMATIC ((pid_t) INT_MIN) /* special value indicating "acquire pid from connection peer" */

View File

@ -1,10 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
typedef struct PidRef PidRef;
#include "macro.h"
#include "process-util.h"
/* An embeddable structure carrying a reference to a process. Supposed to be used when tracking processes
* continuously. This combines a PID, a modern Linux pidfd and the 64bit inode number of the pidfd into one
@ -29,7 +26,7 @@ typedef struct PidRef PidRef;
* process. Moreover, most operations will fail with -EREMOTE. Only PidRef structures that are not marked
* *unset* can be marked *remote*.
*/
struct PidRef {
typedef struct PidRef {
pid_t pid; /* > 0 if the PidRef is set, otherwise set to PID_AUTOMATIC if automatic mode is
* desired, or 0 otherwise. */
int fd; /* only valid if pidfd are available in the kernel, and we manage to get an fd. If we
@ -37,7 +34,7 @@ struct PidRef {
* we use -EBADF as indicator the fd is invalid. */
uint64_t fd_id; /* the inode number of pidfd. only useful in kernel 6.9+ where pidfds live in
their own pidfs and each process comes with a unique inode number */
};
} PidRef;
#define PIDREF_NULL (PidRef) { .fd = -EBADF }

View File

@ -153,8 +153,6 @@ static inline bool sched_priority_is_valid(int i) {
return i >= 0 && i <= sched_get_priority_max(SCHED_RR);
}
#define PID_AUTOMATIC ((pid_t) INT_MIN) /* special value indicating "acquire pid from connection peer" */
static inline bool pid_is_valid(pid_t p) {
return p > 0;
}

View File

@ -11,6 +11,7 @@
#include "bus-slot.h"
#include "bus-type.h"
#include "log.h"
#include "set.h"
#include "string-util.h"
#include "strv.h"

View File

@ -7,6 +7,7 @@
#include "bus-objects.h"
#include "bus-slot.h"
#include "log.h"
#include "set.h"
#include "string-util.h"
sd_bus_slot *bus_slot_allocate(

View File

@ -10,6 +10,7 @@
#include "bus-util.h"
#include "devnum-util.h"
#include "fd-util.h"
#include "format-util.h"
#include "logind-brightness.h"
#include "logind-dbus.h"
#include "logind-polkit.h"

View File

@ -2,6 +2,7 @@
#include "logind-utmp.h"
#include "path-util.h"
#include "process-util.h"
#include "utmp-wtmp.h"
int manager_read_utmp(Manager *m) {

View File

@ -2,6 +2,7 @@
#include "cgroup-util.h"
#include "fd-util.h"
#include "format-util.h"
#include "json-util.h"
#include "logind.h"
#include "logind-dbus.h"

View File

@ -13,6 +13,7 @@
#include "json-util.h"
#include "machine.h"
#include "machine-pool.h"
#include "process-util.h"
#include "string-util.h"
typedef struct ImageUpdateParameters {

View File

@ -10,6 +10,7 @@
#include "log.h"
#include "main-func.h"
#include "pretty-print.h"
#include "process-util.h"
#include "ptyfwd.h"
#include "strv.h"

View File

@ -4,6 +4,7 @@
#include "fd-util.h"
#include "log.h"
#include "notify-recv.h"
#include "process-util.h"
#include "socket-util.h"
#include "strv.h"
#include "user-util.h"

View File

@ -1,6 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <string.h>
#include "ansi-color.h"
#include "glyph-util.h"
#include "terminal-util.h"

View File

@ -2,6 +2,7 @@
#include "bitfield.h"
#include "fd-util.h"
#include "format-util.h"
#include "log.h"
#include "main-func.h"
#include "missing_syscall.h"

View File

@ -15,7 +15,9 @@
#include "inotify-util.h"
#include "mkdir.h"
#include "parse-util.h"
#include "process-util.h"
#include "rm-rf.h"
#include "set.h"
#include "stdio-util.h"
#include "string-util.h"
#include "udev-manager.h"

View File

@ -17,6 +17,7 @@
#include "parse-argument.h"
#include "path-util.h"
#include "pretty-print.h"
#include "process-util.h"
#include "terminal-util.h"
#include "varlink-idl-util.h"
#include "varlink-util.h"