mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-21 18:03:41 +03:00
basic: move container_get_leader() to process-util.[ch]
basic/util.[ch] is a grab-bag of unrelated functions. Let's move a few of the remaning functions to better locations.
This commit is contained in:
parent
baa6a42d27
commit
3ec2ad35ba
@ -22,12 +22,14 @@
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "architecture.h"
|
||||
#include "env-file.h"
|
||||
#include "env-util.h"
|
||||
#include "errno-util.h"
|
||||
#include "escape.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "fs-util.h"
|
||||
#include "hostname-util.h"
|
||||
#include "locale-util.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
@ -35,6 +37,7 @@
|
||||
#include "missing_sched.h"
|
||||
#include "missing_syscall.h"
|
||||
#include "namespace-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
#include "raw-clone.h"
|
||||
@ -253,6 +256,47 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags
|
||||
return 0;
|
||||
}
|
||||
|
||||
int container_get_leader(const char *machine, pid_t *pid) {
|
||||
_cleanup_free_ char *s = NULL, *class = NULL;
|
||||
const char *p;
|
||||
pid_t leader;
|
||||
int r;
|
||||
|
||||
assert(machine);
|
||||
assert(pid);
|
||||
|
||||
if (streq(machine, ".host")) {
|
||||
*pid = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!hostname_is_valid(machine, 0))
|
||||
return -EINVAL;
|
||||
|
||||
p = strjoina("/run/systemd/machines/", machine);
|
||||
r = parse_env_file(NULL, p,
|
||||
"LEADER", &s,
|
||||
"CLASS", &class);
|
||||
if (r == -ENOENT)
|
||||
return -EHOSTDOWN;
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (!s)
|
||||
return -EIO;
|
||||
|
||||
if (!streq_ptr(class, "container"))
|
||||
return -EIO;
|
||||
|
||||
r = parse_pid(s, &leader);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (leader <= 1)
|
||||
return -EIO;
|
||||
|
||||
*pid = leader;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int update_argv(const char name[], size_t l) {
|
||||
static int can_do = -1;
|
||||
|
||||
|
@ -50,6 +50,8 @@ int get_process_environ(pid_t pid, char **ret);
|
||||
int get_process_ppid(pid_t pid, pid_t *ret);
|
||||
int get_process_umask(pid_t pid, mode_t *ret);
|
||||
|
||||
int container_get_leader(const char *machine, pid_t *pid);
|
||||
|
||||
int wait_for_terminate(pid_t pid, siginfo_t *status);
|
||||
|
||||
typedef enum WaitFlags {
|
||||
|
@ -21,47 +21,6 @@
|
||||
int saved_argc = 0;
|
||||
char **saved_argv = NULL;
|
||||
|
||||
int container_get_leader(const char *machine, pid_t *pid) {
|
||||
_cleanup_free_ char *s = NULL, *class = NULL;
|
||||
const char *p;
|
||||
pid_t leader;
|
||||
int r;
|
||||
|
||||
assert(machine);
|
||||
assert(pid);
|
||||
|
||||
if (streq(machine, ".host")) {
|
||||
*pid = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!hostname_is_valid(machine, 0))
|
||||
return -EINVAL;
|
||||
|
||||
p = strjoina("/run/systemd/machines/", machine);
|
||||
r = parse_env_file(NULL, p,
|
||||
"LEADER", &s,
|
||||
"CLASS", &class);
|
||||
if (r == -ENOENT)
|
||||
return -EHOSTDOWN;
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (!s)
|
||||
return -EIO;
|
||||
|
||||
if (!streq_ptr(class, "container"))
|
||||
return -EIO;
|
||||
|
||||
r = parse_pid(s, &leader);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (leader <= 1)
|
||||
return -EIO;
|
||||
|
||||
*pid = leader;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int version(void) {
|
||||
printf("systemd " STRINGIFY(PROJECT_VERSION) " (" GIT_VERSION ")\n%s\n",
|
||||
systemd_features);
|
||||
|
@ -66,8 +66,6 @@ static inline unsigned log2u_round_up(unsigned x) {
|
||||
return log2u(x - 1) + 1;
|
||||
}
|
||||
|
||||
int container_get_leader(const char *machine, pid_t *pid);
|
||||
|
||||
int version(void);
|
||||
|
||||
void disable_coredumps(void);
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "namespace-util.h"
|
||||
#include "process-util.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
|
||||
int bus_container_connect_socket(sd_bus *b) {
|
||||
_cleanup_close_pair_ int pair[2] = { -1, -1 };
|
||||
|
@ -40,7 +40,6 @@
|
||||
#include "terminal-util.h"
|
||||
#include "time-util.h"
|
||||
#include "utf8.h"
|
||||
#include "util.h"
|
||||
#include "web-util.h"
|
||||
|
||||
/* up to three lines (each up to 100 characters) or 300 characters, whichever is less */
|
||||
|
Loading…
x
Reference in New Issue
Block a user