delete unused patches
This commit is contained in:
parent
604b59d73f
commit
3372e480d8
@ -1,99 +0,0 @@
|
||||
From 81504017f462db1ef4ce2c1f617535f261fe01cc Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Michal=20Koutn=C3=BD?= <mkoutny@suse.com>
|
||||
Date: Tue, 26 Jan 2021 17:07:00 +0100
|
||||
Subject: [PATCH] cgroup: Simplify cg_get_path_and_check
|
||||
|
||||
The function controller_is_accessible() doesn't do really much in case
|
||||
of the unified hierarchy. Move common parts into cg_get_path_and_check
|
||||
and make controller check v1 specific. This is refactoring only.
|
||||
---
|
||||
src/basic/cgroup-util.c | 56 ++++++++++++++++-------------------------
|
||||
1 file changed, 22 insertions(+), 34 deletions(-)
|
||||
|
||||
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
|
||||
index bb20a12294d..fcab1775bd5 100644
|
||||
--- a/src/basic/cgroup-util.c
|
||||
+++ b/src/basic/cgroup-util.c
|
||||
@@ -527,41 +527,16 @@ int cg_get_path(const char *controller, const char *path, const char *suffix, ch
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int controller_is_accessible(const char *controller) {
|
||||
- int r;
|
||||
+static int controller_is_v1_accessible(const char *controller) {
|
||||
+ const char *cc, *dn;
|
||||
|
||||
assert(controller);
|
||||
|
||||
- /* Checks whether a specific controller is accessible,
|
||||
- * i.e. its hierarchy mounted. In the unified hierarchy all
|
||||
- * controllers are considered accessible, except for the named
|
||||
- * hierarchies */
|
||||
-
|
||||
- if (!cg_controller_is_valid(controller))
|
||||
- return -EINVAL;
|
||||
-
|
||||
- r = cg_all_unified();
|
||||
- if (r < 0)
|
||||
- return r;
|
||||
- if (r > 0) {
|
||||
- /* We don't support named hierarchies if we are using
|
||||
- * the unified hierarchy. */
|
||||
-
|
||||
- if (streq(controller, SYSTEMD_CGROUP_CONTROLLER))
|
||||
- return 0;
|
||||
-
|
||||
- if (startswith(controller, "name="))
|
||||
- return -EOPNOTSUPP;
|
||||
-
|
||||
- } else {
|
||||
- const char *cc, *dn;
|
||||
-
|
||||
- dn = controller_to_dirname(controller);
|
||||
- cc = strjoina("/sys/fs/cgroup/", dn);
|
||||
+ dn = controller_to_dirname(controller);
|
||||
+ cc = strjoina("/sys/fs/cgroup/", dn);
|
||||
|
||||
- if (laccess(cc, F_OK) < 0)
|
||||
- return -errno;
|
||||
- }
|
||||
+ if (laccess(cc, F_OK) < 0)
|
||||
+ return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -572,10 +547,23 @@ int cg_get_path_and_check(const char *controller, const char *path, const char *
|
||||
assert(controller);
|
||||
assert(fs);
|
||||
|
||||
- /* Check if the specified controller is actually accessible */
|
||||
- r = controller_is_accessible(controller);
|
||||
+ if (!cg_controller_is_valid(controller))
|
||||
+ return -EINVAL;
|
||||
+
|
||||
+ r = cg_all_unified();
|
||||
if (r < 0)
|
||||
return r;
|
||||
+ if (r > 0) {
|
||||
+ /* In the unified hierarchy all controllers are considered accessible,
|
||||
+ * except for the named hierarchies */
|
||||
+ if (startswith(controller, "name="))
|
||||
+ return -EOPNOTSUPP;
|
||||
+ } else {
|
||||
+ /* Check if the specified controller is actually accessible */
|
||||
+ r = controller_is_v1_accessible(controller);
|
||||
+ if (r < 0)
|
||||
+ return r;
|
||||
+ }
|
||||
|
||||
return cg_get_path(controller, path, suffix, fs);
|
||||
}
|
||||
@@ -1909,7 +1897,7 @@ int cg_mask_supported(CGroupMask *ret) {
|
||||
continue;
|
||||
|
||||
n = cgroup_controller_to_string(c);
|
||||
- if (controller_is_accessible(n) >= 0)
|
||||
+ if (controller_is_v1_accessible(n) >= 0)
|
||||
mask |= bit;
|
||||
}
|
||||
}
|
||||
@ -1,163 +0,0 @@
|
||||
From 0fa7b50053695a3012af71c719dd86c12ab10fc6 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Michal=20Koutn=C3=BD?= <mkoutny@suse.com>
|
||||
Date: Tue, 26 Jan 2021 19:15:45 +0100
|
||||
Subject: [PATCH] core: Make (user) instance aware of delegated cgroup
|
||||
controllers
|
||||
|
||||
systemd user instance assumed same controllers are available to it as to
|
||||
PID 1. That is not true generally, in v1 (legacy, hybrid) we don't delegate any
|
||||
controllers to anyone and in v2 (unified) we may delegate only subset of
|
||||
controllers.
|
||||
The user instance would fail silently when the controller cgroup cannot
|
||||
be created or the controller cannot be enabled on the unified hierarchy.
|
||||
|
||||
The changes in 7b63961415 ("cgroup: Swap cgroup v1 deletion and
|
||||
migration") caused some attempts of operating on non-delegated
|
||||
controllers to be logged.
|
||||
|
||||
Make the user instance first check what controllers are availble to it
|
||||
and narrow operations only to these controllers. The original checks are
|
||||
kept in place.
|
||||
|
||||
Note that daemon-reexec needs to be invoked in order to update the set
|
||||
of unabled controllers after a change.
|
||||
|
||||
Fixes: #18047
|
||||
Fixes: #17862
|
||||
---
|
||||
src/basic/cgroup-util.c | 41 +++++++++++++++++++++++++++--------------
|
||||
src/basic/cgroup-util.h | 1 +
|
||||
src/core/cgroup.c | 2 +-
|
||||
3 files changed, 29 insertions(+), 15 deletions(-)
|
||||
|
||||
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
|
||||
index 19c0a9d..7ef30f2 100644
|
||||
--- a/src/basic/cgroup-util.c
|
||||
+++ b/src/basic/cgroup-util.c
|
||||
@@ -527,15 +527,21 @@ int cg_get_path(const char *controller, const char *path, const char *suffix, ch
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int controller_is_v1_accessible(const char *controller) {
|
||||
- const char *cc, *dn;
|
||||
+static int controller_is_v1_accessible(const char *root, const char *controller) {
|
||||
+ const char *cpath, *dn;
|
||||
|
||||
assert(controller);
|
||||
|
||||
dn = controller_to_dirname(controller);
|
||||
- cc = strjoina("/sys/fs/cgroup/", dn);
|
||||
-
|
||||
- if (laccess(cc, F_OK) < 0)
|
||||
+ cpath = strjoina("/sys/fs/cgroup/", dn);
|
||||
+ if (root)
|
||||
+ /* Also check that:
|
||||
+ * - possible subcgroup is created at root,
|
||||
+ * - we can modify the hierarchy.
|
||||
+ * "Leak" cpath on stack */
|
||||
+ cpath = strjoina(cpath, root, "/cgroup.procs");
|
||||
+
|
||||
+ if (laccess(cpath, root ? W_OK : F_OK) < 0)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
@@ -560,7 +566,7 @@ int cg_get_path_and_check(const char *controller, const char *path, const char *
|
||||
return -EOPNOTSUPP;
|
||||
} else {
|
||||
/* Check if the specified controller is actually accessible */
|
||||
- r = controller_is_v1_accessible(controller);
|
||||
+ r = controller_is_v1_accessible(NULL, controller);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@@ -1829,7 +1835,7 @@ int cg_mask_from_string(const char *value, CGroupMask *ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
-int cg_mask_supported(CGroupMask *ret) {
|
||||
+int cg_mask_supported_subtree(const char *root, CGroupMask *ret) {
|
||||
CGroupMask mask;
|
||||
int r;
|
||||
|
||||
@@ -1841,16 +1847,12 @@ int cg_mask_supported(CGroupMask *ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r > 0) {
|
||||
- _cleanup_free_ char *root = NULL, *controllers = NULL, *path = NULL;
|
||||
+ _cleanup_free_ char *controllers = NULL, *path = NULL;
|
||||
|
||||
/* In the unified hierarchy we can read the supported
|
||||
* and accessible controllers from a the top-level
|
||||
* cgroup attribute */
|
||||
|
||||
- r = cg_get_root_path(&root);
|
||||
- if (r < 0)
|
||||
- return r;
|
||||
-
|
||||
r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, root, "cgroup.controllers", &path);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -1869,7 +1871,7 @@ int cg_mask_supported(CGroupMask *ret) {
|
||||
} else {
|
||||
CGroupController c;
|
||||
|
||||
- /* In the legacy hierarchy, we check which hierarchies are mounted. */
|
||||
+ /* In the legacy hierarchy, we check which hierarchies are accessible. */
|
||||
|
||||
mask = 0;
|
||||
for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) {
|
||||
@@ -1880,7 +1882,7 @@ int cg_mask_supported(CGroupMask *ret) {
|
||||
continue;
|
||||
|
||||
n = cgroup_controller_to_string(c);
|
||||
- if (controller_is_v1_accessible(n) >= 0)
|
||||
+ if (controller_is_v1_accessible(root, n) >= 0)
|
||||
mask |= bit;
|
||||
}
|
||||
}
|
||||
@@ -1889,6 +1891,17 @@ int cg_mask_supported(CGroupMask *ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
+int cg_mask_supported(CGroupMask *ret) {
|
||||
+ _cleanup_free_ char *root = NULL;
|
||||
+ int r;
|
||||
+
|
||||
+ r = cg_get_root_path(&root);
|
||||
+ if (r < 0)
|
||||
+ return r;
|
||||
+
|
||||
+ return cg_mask_supported_subtree(root, ret);
|
||||
+}
|
||||
+
|
||||
int cg_kernel_controllers(Set **ret) {
|
||||
_cleanup_set_free_free_ Set *controllers = NULL;
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h
|
||||
index 2b88571..2b3b068 100644
|
||||
--- a/src/basic/cgroup-util.h
|
||||
+++ b/src/basic/cgroup-util.h
|
||||
@@ -254,6 +254,7 @@ int cg_slice_to_path(const char *unit, char **ret);
|
||||
typedef const char* (*cg_migrate_callback_t)(CGroupMask mask, void *userdata);
|
||||
|
||||
int cg_mask_supported(CGroupMask *ret);
|
||||
+int cg_mask_supported_subtree(const char *root, CGroupMask *ret);
|
||||
int cg_mask_from_string(const char *s, CGroupMask *ret);
|
||||
int cg_mask_to_string(CGroupMask mask, char **ret);
|
||||
|
||||
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
|
||||
index 8b97d15..57b4974 100644
|
||||
--- a/src/core/cgroup.c
|
||||
+++ b/src/core/cgroup.c
|
||||
@@ -3010,7 +3010,7 @@ int manager_setup_cgroup(Manager *m) {
|
||||
(void) cg_set_attribute("memory", "/", "memory.use_hierarchy", "1");
|
||||
|
||||
/* 8. Figure out which controllers are supported */
|
||||
- r = cg_mask_supported(&m->cgroup_supported);
|
||||
+ r = cg_mask_supported_subtree(m->cgroup_root, &m->cgroup_supported);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to determine supported controllers: %m");
|
||||
|
||||
--
|
||||
2.23.0
|
||||
|
||||
@ -1,107 +0,0 @@
|
||||
From 7b7a060e83d6c7de8705904d71978ba4664f0a65 Mon Sep 17 00:00:00 2001
|
||||
From: Anita Zhang <the.anitazha@gmail.com>
|
||||
Date: Tue, 23 Mar 2021 00:49:28 -0700
|
||||
Subject: [PATCH] process-util: dont allocate max length to read
|
||||
/proc/PID/cmdline
|
||||
|
||||
Alternative title: Replace get_process_cmdline()'s fopen()/fread() with
|
||||
read_full_virtual_file().
|
||||
|
||||
When RLIMIT_STACK is set to infinity:infinity, _SC_ARG_MAX will
|
||||
return 4611686018427387903 (depending on the system, but definitely
|
||||
something larger than most systems have). It's impractical to allocate this
|
||||
in one go when most cmdlines are much shorter than that.
|
||||
|
||||
Instead use read_full_virtual_file() which seems to increase the buffer
|
||||
depending on the size of the contents.
|
||||
---
|
||||
src/basic/process-util.c | 28 +++-------------------------
|
||||
src/test/test-process-util.c | 5 +++++
|
||||
2 files changed, 8 insertions(+), 25 deletions(-)
|
||||
|
||||
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
|
||||
index 264ecc276b..7d4301eadb 100644
|
||||
--- a/src/basic/process-util.c
|
||||
+++ b/src/basic/process-util.c
|
||||
@@ -124,14 +124,10 @@ int get_process_comm(pid_t pid, char **ret) {
|
||||
}
|
||||
|
||||
int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags, char **line) {
|
||||
- _cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_free_ char *t = NULL, *ans = NULL;
|
||||
const char *p;
|
||||
- int r;
|
||||
size_t k;
|
||||
-
|
||||
- /* This is supposed to be a safety guard against runaway command lines. */
|
||||
- size_t max_length = sc_arg_max();
|
||||
+ int r;
|
||||
|
||||
assert(line);
|
||||
assert(pid >= 0);
|
||||
@@ -147,36 +143,18 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags
|
||||
* comm_fallback is false). Returns 0 and sets *line otherwise. */
|
||||
|
||||
p = procfs_file_alloca(pid, "cmdline");
|
||||
- r = fopen_unlocked(p, "re", &f);
|
||||
+ r = read_full_virtual_file(p, &t, &k);
|
||||
if (r == -ENOENT)
|
||||
return -ESRCH;
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
- /* We assume that each four-byte character uses one or two columns. If we ever check for combining
|
||||
- * characters, this assumption will need to be adjusted. */
|
||||
- if ((size_t) 4 * max_columns + 1 < max_columns)
|
||||
- max_length = MIN(max_length, (size_t) 4 * max_columns + 1);
|
||||
-
|
||||
- t = new(char, max_length);
|
||||
- if (!t)
|
||||
- return -ENOMEM;
|
||||
-
|
||||
- k = fread(t, 1, max_length, f);
|
||||
if (k > 0) {
|
||||
/* Arguments are separated by NULs. Let's replace those with spaces. */
|
||||
for (size_t i = 0; i < k - 1; i++)
|
||||
if (t[i] == '\0')
|
||||
t[i] = ' ';
|
||||
-
|
||||
- t[k] = '\0'; /* Normally, t[k] is already NUL, so this is just a guard in case of short read */
|
||||
} else {
|
||||
- /* We only treat getting nothing as an error. We *could* also get an error after reading some
|
||||
- * data, but we ignore that case, as such an error is rather unlikely and we prefer to get
|
||||
- * some data rather than none. */
|
||||
- if (ferror(f))
|
||||
- return -errno;
|
||||
-
|
||||
if (!(flags & PROCESS_CMDLINE_COMM_FALLBACK))
|
||||
return -ENOENT;
|
||||
|
||||
@@ -187,7 +165,7 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
- mfree(t);
|
||||
+ free(t);
|
||||
t = strjoin("[", t2, "]");
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c
|
||||
index 0ebef530a0..5ca654e193 100644
|
||||
--- a/src/test/test-process-util.c
|
||||
+++ b/src/test/test-process-util.c
|
||||
@@ -236,6 +236,11 @@ static void test_get_process_cmdline_harder(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
+ /* Set RLIMIT_STACK to infinity to test we don't try to allocate unncessarily large values to read
|
||||
+ * the cmdline. */
|
||||
+ if (setrlimit(RLIMIT_STACK, &RLIMIT_MAKE_CONST(RLIM_INFINITY)) < 0)
|
||||
+ log_warning("Testing without RLIMIT_STACK=infinity");
|
||||
+
|
||||
assert_se(unlink(path) >= 0);
|
||||
|
||||
assert_se(prctl(PR_SET_NAME, "testa") >= 0);
|
||||
--
|
||||
2.23.0
|
||||
|
||||
@ -1,160 +0,0 @@
|
||||
From 9807fdc1da8e037ddedfa4e2c6d2728b6e60051e Mon Sep 17 00:00:00 2001
|
||||
From: Lennart Poettering <lennart@poettering.net>
|
||||
Date: Wed, 20 Jan 2021 19:15:55 +0100
|
||||
Subject: [PATCH] varlink: make 'userdata' pointer inheritance from varlink
|
||||
server to connection optional
|
||||
|
||||
@keszybz's right on
|
||||
https://github.com/systemd/systemd/pull/18248#issuecomment-760798473:
|
||||
swapping out the userdata pointer of a live varlink connection is iffy.
|
||||
|
||||
Let's fix this by making the userdata inheritance from VarlinkServer
|
||||
object to the Varlink connection object optional: we want it for most
|
||||
cases, but not all, i.e. all those cases where the calls implemented as
|
||||
varlink methods are stateless and can be answered synchronously. For the
|
||||
other cases (i.e. where we want per-connection objects that wrap the
|
||||
asynchronous operation as it goes on) let's not do such inheritance but
|
||||
initialize the userdata pointer only once we have it. THis means the
|
||||
original manager object must be manually retrieved from the
|
||||
VarlinkServer object, which in turn needs to be requested from the
|
||||
Varlink connection object.
|
||||
|
||||
The userdata inheritance is now controlled by the
|
||||
VARLINK_INHERIT_USERDATA flag passed at VarlinkServer construction.
|
||||
|
||||
Alternative-to: #18248
|
||||
---
|
||||
src/core/core-varlink.c | 2 +-
|
||||
src/home/homed-manager.c | 2 +-
|
||||
src/journal/journald-server.c | 2 +-
|
||||
src/machine/machined-varlink.c | 2 +-
|
||||
src/resolve/resolved-varlink.c | 8 ++++++--
|
||||
src/shared/varlink.c | 4 +++-
|
||||
src/shared/varlink.h | 9 +++++----
|
||||
7 files changed, 18 insertions(+), 11 deletions(-)
|
||||
|
||||
diff --git a/src/core/core-varlink.c b/src/core/core-varlink.c
|
||||
index dd6c11ab4d..d695106658 100644
|
||||
--- a/src/core/core-varlink.c
|
||||
+++ b/src/core/core-varlink.c
|
||||
@@ -432,7 +432,7 @@ int manager_varlink_init(Manager *m) {
|
||||
if (!MANAGER_IS_SYSTEM(m))
|
||||
return 0;
|
||||
|
||||
- r = varlink_server_new(&s, VARLINK_SERVER_ACCOUNT_UID);
|
||||
+ r = varlink_server_new(&s, VARLINK_SERVER_ACCOUNT_UID|VARLINK_SERVER_INHERIT_USERDATA);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to allocate varlink server object: %m");
|
||||
|
||||
diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c
|
||||
index 365ea4d234..91cabd5cef 100644
|
||||
--- a/src/home/homed-manager.c
|
||||
+++ b/src/home/homed-manager.c
|
||||
@@ -956,7 +956,7 @@ static int manager_bind_varlink(Manager *m) {
|
||||
assert(m);
|
||||
assert(!m->varlink_server);
|
||||
|
||||
- r = varlink_server_new(&m->varlink_server, VARLINK_SERVER_ACCOUNT_UID);
|
||||
+ r = varlink_server_new(&m->varlink_server, VARLINK_SERVER_ACCOUNT_UID|VARLINK_SERVER_INHERIT_USERDATA);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to allocate varlink server object: %m");
|
||||
|
||||
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
|
||||
index 10ebc3e22e..5cad374083 100644
|
||||
--- a/src/journal/journald-server.c
|
||||
+++ b/src/journal/journald-server.c
|
||||
@@ -2033,7 +2033,7 @@ static int server_open_varlink(Server *s, const char *socket, int fd) {
|
||||
|
||||
assert(s);
|
||||
|
||||
- r = varlink_server_new(&s->varlink_server, VARLINK_SERVER_ROOT_ONLY);
|
||||
+ r = varlink_server_new(&s->varlink_server, VARLINK_SERVER_ROOT_ONLY|VARLINK_SERVER_INHERIT_USERDATA);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
diff --git a/src/machine/machined-varlink.c b/src/machine/machined-varlink.c
|
||||
index 2d6c1991a4..009d283acc 100644
|
||||
--- a/src/machine/machined-varlink.c
|
||||
+++ b/src/machine/machined-varlink.c
|
||||
@@ -388,7 +388,7 @@ int manager_varlink_init(Manager *m) {
|
||||
if (m->varlink_server)
|
||||
return 0;
|
||||
|
||||
- r = varlink_server_new(&s, VARLINK_SERVER_ACCOUNT_UID);
|
||||
+ r = varlink_server_new(&s, VARLINK_SERVER_ACCOUNT_UID|VARLINK_SERVER_INHERIT_USERDATA);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to allocate varlink server object: %m");
|
||||
|
||||
diff --git a/src/resolve/resolved-varlink.c b/src/resolve/resolved-varlink.c
|
||||
index 70d6f9056d..2fb9d38dfa 100644
|
||||
--- a/src/resolve/resolved-varlink.c
|
||||
+++ b/src/resolve/resolved-varlink.c
|
||||
@@ -269,11 +269,13 @@ static int vl_method_resolve_hostname(Varlink *link, JsonVariant *parameters, Va
|
||||
_cleanup_(lookup_parameters_destroy) LookupParameters p = {
|
||||
.family = AF_UNSPEC,
|
||||
};
|
||||
- Manager *m = userdata;
|
||||
DnsQuery *q;
|
||||
+ Manager *m;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
+
|
||||
+ m = varlink_server_get_userdata(varlink_get_server(link));
|
||||
assert(m);
|
||||
|
||||
if (FLAGS_SET(flags, VARLINK_METHOD_ONEWAY))
|
||||
@@ -447,11 +449,13 @@ static int vl_method_resolve_address(Varlink *link, JsonVariant *parameters, Var
|
||||
_cleanup_(lookup_parameters_destroy) LookupParameters p = {
|
||||
.family = AF_UNSPEC,
|
||||
};
|
||||
- Manager *m = userdata;
|
||||
DnsQuery *q;
|
||||
+ Manager *m;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
+
|
||||
+ m = varlink_server_get_userdata(varlink_get_server(link));
|
||||
assert(m);
|
||||
|
||||
if (FLAGS_SET(flags, VARLINK_METHOD_ONEWAY))
|
||||
diff --git a/src/shared/varlink.c b/src/shared/varlink.c
|
||||
index 274709abd5..24865fa07e 100644
|
||||
--- a/src/shared/varlink.c
|
||||
+++ b/src/shared/varlink.c
|
||||
@@ -2137,7 +2137,9 @@ int varlink_server_add_connection(VarlinkServer *server, int fd, Varlink **ret)
|
||||
return r;
|
||||
|
||||
v->fd = fd;
|
||||
- v->userdata = server->userdata;
|
||||
+ if (server->flags & VARLINK_SERVER_INHERIT_USERDATA)
|
||||
+ v->userdata = server->userdata;
|
||||
+
|
||||
if (ucred_acquired) {
|
||||
v->ucred = ucred;
|
||||
v->ucred_acquired = true;
|
||||
diff --git a/src/shared/varlink.h b/src/shared/varlink.h
|
||||
index 7ea1f9113f..66a1ff630e 100644
|
||||
--- a/src/shared/varlink.h
|
||||
+++ b/src/shared/varlink.h
|
||||
@@ -41,11 +41,12 @@ typedef enum VarlinkMethodFlags {
|
||||
} VarlinkMethodFlags;
|
||||
|
||||
typedef enum VarlinkServerFlags {
|
||||
- VARLINK_SERVER_ROOT_ONLY = 1 << 0, /* Only accessible by root */
|
||||
- VARLINK_SERVER_MYSELF_ONLY = 1 << 1, /* Only accessible by our own UID */
|
||||
- VARLINK_SERVER_ACCOUNT_UID = 1 << 2, /* Do per user accounting */
|
||||
+ VARLINK_SERVER_ROOT_ONLY = 1 << 0, /* Only accessible by root */
|
||||
+ VARLINK_SERVER_MYSELF_ONLY = 1 << 1, /* Only accessible by our own UID */
|
||||
+ VARLINK_SERVER_ACCOUNT_UID = 1 << 2, /* Do per user accounting */
|
||||
+ VARLINK_SERVER_INHERIT_USERDATA = 1 << 3, /* Initialize Varlink connection userdata from VarlinkServer userdata */
|
||||
|
||||
- _VARLINK_SERVER_FLAGS_ALL = (1 << 3) - 1,
|
||||
+ _VARLINK_SERVER_FLAGS_ALL = (1 << 4) - 1,
|
||||
} VarlinkServerFlags;
|
||||
|
||||
typedef int (*VarlinkMethod)(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
--
|
||||
2.23.0
|
||||
|
||||
@ -1,76 +0,0 @@
|
||||
From 47c1db6730b8a81b01e8505a648624fa6ad0bbd7 Mon Sep 17 00:00:00 2001
|
||||
From: Benjamin Berg <bberg@redhat.com>
|
||||
Date: Mon, 12 Oct 2020 11:02:26 +0200
|
||||
Subject: [PATCH] xdg-autostart: Lower most info messages to debug level
|
||||
|
||||
It is expected for numerous autostart files to not be convertible to
|
||||
corresponding units. The information is only useful for someone
|
||||
debugging why a file might not be started, but it is not generally
|
||||
useful for users in most situations.
|
||||
|
||||
As such, lower the warnings. Anyone wondering why an application is not
|
||||
started will easily notice that the unit is not generated. From there it
|
||||
will be somewhat harder to figure out why, but the overall trade-off is
|
||||
still improved.
|
||||
|
||||
Fixes: #17305
|
||||
---
|
||||
src/xdg-autostart-generator/xdg-autostart-service.c | 12 ++++++------
|
||||
1 file changed, 6 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/src/xdg-autostart-generator/xdg-autostart-service.c b/src/xdg-autostart-generator/xdg-autostart-service.c
|
||||
index c6f39f2..6324c50 100644
|
||||
--- a/src/xdg-autostart-generator/xdg-autostart-service.c
|
||||
+++ b/src/xdg-autostart-generator/xdg-autostart-service.c
|
||||
@@ -483,7 +483,7 @@ static int xdg_autostart_generate_desktop_condition(
|
||||
|
||||
r = find_binary(test_binary, &gnome_autostart_condition_path);
|
||||
if (r < 0) {
|
||||
- log_full_errno(r == -ENOENT ? LOG_INFO : LOG_WARNING, r,
|
||||
+ log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r,
|
||||
"%s not found: %m", test_binary);
|
||||
fprintf(f, "# ExecCondition using %s skipped due to missing binary.\n", test_binary);
|
||||
return r;
|
||||
@@ -514,18 +514,18 @@ int xdg_autostart_service_generate_unit(
|
||||
|
||||
/* Nothing to do for hidden services. */
|
||||
if (service->hidden) {
|
||||
- log_info("Not generating service for XDG autostart %s, it is hidden.", service->name);
|
||||
+ log_debug("Not generating service for XDG autostart %s, it is hidden.", service->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (service->systemd_skip) {
|
||||
- log_info("Not generating service for XDG autostart %s, should be skipped by generator.", service->name);
|
||||
+ log_debug("Not generating service for XDG autostart %s, should be skipped by generator.", service->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Nothing to do if type is not Application. */
|
||||
if (!streq_ptr(service->type, "Application")) {
|
||||
- log_info("Not generating service for XDG autostart %s, only Type=Application is supported.", service->name);
|
||||
+ log_debug("Not generating service for XDG autostart %s, only Type=Application is supported.", service->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -541,7 +541,7 @@ int xdg_autostart_service_generate_unit(
|
||||
if (service->try_exec) {
|
||||
r = find_binary(service->try_exec, NULL);
|
||||
if (r < 0) {
|
||||
- log_full_errno(r == -ENOENT ? LOG_INFO : LOG_WARNING, r,
|
||||
+ log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r,
|
||||
"Not generating service for XDG autostart %s, could not find TryExec= binary %s: %m",
|
||||
service->name, service->try_exec);
|
||||
return 0;
|
||||
@@ -558,7 +558,7 @@ int xdg_autostart_service_generate_unit(
|
||||
|
||||
if (service->gnome_autostart_phase) {
|
||||
/* There is no explicit value for the "Application" phase. */
|
||||
- log_info("Not generating service for XDG autostart %s, startup phases are not supported.",
|
||||
+ log_debug("Not generating service for XDG autostart %s, startup phases are not supported.",
|
||||
service->name);
|
||||
return 0;
|
||||
}
|
||||
--
|
||||
2.23.0
|
||||
|
||||
@ -1,93 +0,0 @@
|
||||
From e67cd21d7d174cdafd12beca4cfb6e19e61f6fb5 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
||||
Date: Mon, 8 Jul 2019 17:33:25 +0200
|
||||
Subject: [PATCH] analyze: add "unit-files" to dump the unit fragment map
|
||||
|
||||
I'm not convinced that this is useful enough to be included... But it is
|
||||
certainly nice when debugging.
|
||||
|
||||
revert analyze add unit files to dump the unit fragment map
|
||||
---
|
||||
src/analyze/analyze.c | 50 --------------------------------------------------
|
||||
1 file changed, 50 deletions(-)
|
||||
|
||||
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
|
||||
index 322be1a..6de26f4 100644
|
||||
--- a/src/analyze/analyze.c
|
||||
+++ b/src/analyze/analyze.c
|
||||
@@ -1546,53 +1546,6 @@ static int get_or_set_log_target(int argc, char *argv[], void *userdata) {
|
||||
return (argc == 1) ? get_log_target(argc, argv, userdata) : set_log_target(argc, argv, userdata);
|
||||
}
|
||||
|
||||
-static bool strv_fnmatch_strv_or_empty(char* const* patterns, char **strv, int flags) {
|
||||
- char **s;
|
||||
- STRV_FOREACH(s, strv)
|
||||
- if (strv_fnmatch_or_empty(patterns, *s, flags))
|
||||
- return true;
|
||||
-
|
||||
- return false;
|
||||
-}
|
||||
-
|
||||
-static int do_unit_files(int argc, char *argv[], void *userdata) {
|
||||
- _cleanup_(lookup_paths_free) LookupPaths lp = {};
|
||||
- _cleanup_hashmap_free_ Hashmap *unit_ids = NULL;
|
||||
- _cleanup_hashmap_free_ Hashmap *unit_names = NULL;
|
||||
- char **patterns = strv_skip(argv, 1);
|
||||
- Iterator i;
|
||||
- const char *k, *dst;
|
||||
- char **v;
|
||||
- int r;
|
||||
-
|
||||
- r = lookup_paths_init(&lp, arg_scope, 0, NULL);
|
||||
- if (r < 0)
|
||||
- return log_error_errno(r, "lookup_paths_init() failed: %m");
|
||||
-
|
||||
- r = unit_file_build_name_map(&lp, &unit_ids, &unit_names, NULL);
|
||||
- if (r < 0)
|
||||
- return log_error_errno(r, "unit_file_build_name_map() failed: %m");
|
||||
-
|
||||
- HASHMAP_FOREACH_KEY(dst, k, unit_ids, i) {
|
||||
- if (!strv_fnmatch_or_empty(patterns, k, FNM_NOESCAPE) &&
|
||||
- !strv_fnmatch_or_empty(patterns, dst, FNM_NOESCAPE))
|
||||
- continue;
|
||||
-
|
||||
- printf("ids: %s → %s\n", k, dst);
|
||||
- }
|
||||
-
|
||||
- HASHMAP_FOREACH_KEY(v, k, unit_names, i) {
|
||||
- if (!strv_fnmatch_or_empty(patterns, k, FNM_NOESCAPE) &&
|
||||
- !strv_fnmatch_strv_or_empty(patterns, v, FNM_NOESCAPE))
|
||||
- continue;
|
||||
-
|
||||
- _cleanup_free_ char *j = strv_join(v, ", ");
|
||||
- printf("aliases: %s ← %s\n", k, j);
|
||||
- }
|
||||
-
|
||||
- return 0;
|
||||
-}
|
||||
-
|
||||
static int dump_unit_paths(int argc, char *argv[], void *userdata) {
|
||||
_cleanup_(lookup_paths_free) LookupPaths paths = {};
|
||||
int r;
|
||||
@@ -2263,7 +2216,6 @@ static int help(int argc, char *argv[], void *userdata) {
|
||||
" log-target [TARGET] Get/set logging target for manager\n"
|
||||
" dump Output state serialization of service manager\n"
|
||||
" cat-config Show configuration file and drop-ins\n"
|
||||
- " unit-files List files and symlinks for units\n"
|
||||
" unit-paths List load directories for units\n"
|
||||
" exit-status [STATUS...] List exit status definitions\n"
|
||||
" syscall-filter [NAME...] Print list of syscalls in seccomp filter\n"
|
||||
@@ -2467,10 +2419,8 @@ static int run(int argc, char *argv[]) {
|
||||
{ "get-log-level", VERB_ANY, 1, 0, get_log_level },
|
||||
{ "set-log-target", 2, 2, 0, set_log_target },
|
||||
{ "get-log-target", VERB_ANY, 1, 0, get_log_target },
|
||||
-
|
||||
{ "dump", VERB_ANY, 1, 0, dump },
|
||||
{ "cat-config", 2, VERB_ANY, 0, cat_config },
|
||||
- { "unit-files", VERB_ANY, VERB_ANY, 0, do_unit_files },
|
||||
{ "unit-paths", 1, 1, 0, dump_unit_paths },
|
||||
{ "exit-status", VERB_ANY, VERB_ANY, 0, dump_exit_status },
|
||||
{ "syscall-filter", VERB_ANY, VERB_ANY, 0, dump_syscall_filters },
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
@ -1,289 +0,0 @@
|
||||
From 91e0ee5f16321656ed6f827742ecbeb2b36027f2 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
||||
Date: Wed, 10 Jul 2019 18:01:13 +0200
|
||||
Subject: [PATCH] pid1: drop unit caches only based on mtime
|
||||
|
||||
v2:
|
||||
- do not watch mtime of transient and generated dirs
|
||||
|
||||
We'd reload the map after every transient unit we created, which we don't
|
||||
need to do, since we create those units ourselves and know their fragment
|
||||
path.
|
||||
|
||||
revert pid1 drop unit caches only based on mtime
|
||||
---
|
||||
src/analyze/analyze.c | 2 +-
|
||||
src/core/load-fragment.c | 9 --------
|
||||
src/core/manager.c | 14 ++++++++++--
|
||||
src/core/manager.h | 1 -
|
||||
src/shared/unit-file.c | 57 +----------------------------------------------
|
||||
src/shared/unit-file.h | 2 --
|
||||
src/systemctl/systemctl.c | 2 +-
|
||||
src/test/test-unit-file.c | 13 +----------
|
||||
8 files changed, 16 insertions(+), 84 deletions(-)
|
||||
|
||||
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
|
||||
index 4d81026..322be1a 100644
|
||||
--- a/src/analyze/analyze.c
|
||||
+++ b/src/analyze/analyze.c
|
||||
@@ -1569,7 +1569,7 @@ static int do_unit_files(int argc, char *argv[], void *userdata) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "lookup_paths_init() failed: %m");
|
||||
|
||||
- r = unit_file_build_name_map(&lp, NULL, &unit_ids, &unit_names, NULL);
|
||||
+ r = unit_file_build_name_map(&lp, &unit_ids, &unit_names, NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "unit_file_build_name_map() failed: %m");
|
||||
|
||||
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
|
||||
index 8eaf8b3..9821a92 100644
|
||||
--- a/src/core/load-fragment.c
|
||||
+++ b/src/core/load-fragment.c
|
||||
@@ -4605,15 +4605,6 @@ int unit_load_fragment(Unit *u) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
- /* Possibly rebuild the fragment map to catch new units */
|
||||
- r = unit_file_build_name_map(&u->manager->lookup_paths,
|
||||
- &u->manager->unit_cache_mtime,
|
||||
- &u->manager->unit_id_map,
|
||||
- &u->manager->unit_name_map,
|
||||
- &u->manager->unit_path_cache);
|
||||
- if (r < 0)
|
||||
- log_error_errno(r, "Failed to rebuild name map: %m");
|
||||
-
|
||||
r = unit_file_find_fragment(u->manager->unit_id_map,
|
||||
u->manager->unit_name_map,
|
||||
u->id,
|
||||
diff --git a/src/core/manager.c b/src/core/manager.c
|
||||
index 5efcf45..8b1ce70 100644
|
||||
--- a/src/core/manager.c
|
||||
+++ b/src/core/manager.c
|
||||
@@ -693,7 +693,6 @@ static void manager_free_unit_name_maps(Manager *m) {
|
||||
m->unit_id_map = hashmap_free(m->unit_id_map);
|
||||
m->unit_name_map = hashmap_free(m->unit_name_map);
|
||||
m->unit_path_cache = set_free_free(m->unit_path_cache);
|
||||
- m->unit_cache_mtime = 0;
|
||||
}
|
||||
|
||||
static int manager_setup_run_queue(Manager *m) {
|
||||
@@ -1642,6 +1641,11 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
|
||||
|
||||
lookup_paths_log(&m->lookup_paths);
|
||||
|
||||
+ manager_free_unit_name_maps(m);
|
||||
+ r = unit_file_build_name_map(&m->lookup_paths, &m->unit_id_map, &m->unit_name_map, &m->unit_path_cache);
|
||||
+ if (r < 0)
|
||||
+ return log_error_errno(r, "Failed to build name map: %m");
|
||||
+
|
||||
{
|
||||
/* This block is (optionally) done with the reloading counter bumped */
|
||||
_cleanup_(manager_reloading_stopp) Manager *reloading = NULL;
|
||||
@@ -2858,6 +2862,10 @@ int manager_loop(Manager *m) {
|
||||
assert(m);
|
||||
assert(m->objective == MANAGER_OK); /* Ensure manager_startup() has been called */
|
||||
|
||||
+ /* Release the path and unit name caches */
|
||||
+ manager_free_unit_name_maps(m);
|
||||
+ // FIXME: once this happens, we cannot load any more units
|
||||
+
|
||||
manager_check_finished(m);
|
||||
|
||||
/* There might still be some zombies hanging around from before we were exec()'ed. Let's reap them. */
|
||||
@@ -3531,8 +3539,10 @@ int manager_reload(Manager *m) {
|
||||
|
||||
lookup_paths_log(&m->lookup_paths);
|
||||
|
||||
- /* We flushed out generated files, for which we don't watch mtime, so we should flush the old map. */
|
||||
manager_free_unit_name_maps(m);
|
||||
+ r = unit_file_build_name_map(&m->lookup_paths, &m->unit_id_map, &m->unit_name_map, &m->unit_path_cache);
|
||||
+ if (r < 0)
|
||||
+ log_warning_errno(r, "Failed to build name map: %m");
|
||||
|
||||
/* First, enumerate what we can from kernel and suchlike */
|
||||
manager_enumerate_perpetual(m);
|
||||
diff --git a/src/core/manager.h b/src/core/manager.h
|
||||
index 815c5ec..9ca82ac 100644
|
||||
--- a/src/core/manager.h
|
||||
+++ b/src/core/manager.h
|
||||
@@ -223,7 +223,6 @@ struct Manager {
|
||||
Hashmap *unit_id_map;
|
||||
Hashmap *unit_name_map;
|
||||
Set *unit_path_cache;
|
||||
- usec_t unit_cache_mtime;
|
||||
|
||||
char **transient_environment; /* The environment, as determined from config files, kernel cmdline and environment generators */
|
||||
char **client_environment; /* Environment variables created by clients through the bus API */
|
||||
diff --git a/src/shared/unit-file.c b/src/shared/unit-file.c
|
||||
index 4a5f23e..bad92a3 100644
|
||||
--- a/src/shared/unit-file.c
|
||||
+++ b/src/shared/unit-file.c
|
||||
@@ -152,47 +152,8 @@ static int unit_ids_map_get(
|
||||
return -ELOOP;
|
||||
}
|
||||
|
||||
-static bool lookup_paths_mtime_exclude(const LookupPaths *lp, const char *path) {
|
||||
- /* Paths that are under our exclusive control. Users shall not alter those directly. */
|
||||
-
|
||||
- return streq_ptr(path, lp->generator) ||
|
||||
- streq_ptr(path, lp->generator_early) ||
|
||||
- streq_ptr(path, lp->generator_late) ||
|
||||
- streq_ptr(path, lp->transient) ||
|
||||
- streq_ptr(path, lp->persistent_control) ||
|
||||
- streq_ptr(path, lp->runtime_control);
|
||||
-}
|
||||
-
|
||||
-static bool lookup_paths_mtime_good(const LookupPaths *lp, usec_t mtime) {
|
||||
- char **dir;
|
||||
-
|
||||
- STRV_FOREACH(dir, (char**) lp->search_path) {
|
||||
- struct stat st;
|
||||
-
|
||||
- if (lookup_paths_mtime_exclude(lp, *dir))
|
||||
- continue;
|
||||
-
|
||||
- /* Determine the latest lookup path modification time */
|
||||
- if (stat(*dir, &st) < 0) {
|
||||
- if (errno == ENOENT)
|
||||
- continue;
|
||||
-
|
||||
- log_debug_errno(errno, "Failed to stat %s, ignoring: %m", *dir);
|
||||
- continue;
|
||||
- }
|
||||
-
|
||||
- if (timespec_load(&st.st_mtim) > mtime) {
|
||||
- log_debug_errno(errno, "Unit dir %s has changed, need to update cache.", *dir);
|
||||
- return false;
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- return true;
|
||||
-}
|
||||
-
|
||||
int unit_file_build_name_map(
|
||||
const LookupPaths *lp,
|
||||
- usec_t *cache_mtime,
|
||||
Hashmap **ret_unit_ids_map,
|
||||
Hashmap **ret_unit_names_map,
|
||||
Set **ret_path_cache) {
|
||||
@@ -210,12 +171,6 @@ int unit_file_build_name_map(
|
||||
_cleanup_set_free_free_ Set *paths = NULL;
|
||||
char **dir;
|
||||
int r;
|
||||
- usec_t mtime = 0;
|
||||
-
|
||||
- /* Before doing anything, check if the mtime that was passed is still valid. If
|
||||
- * yes, do nothing. If *cache_time == 0, always build the cache. */
|
||||
- if (cache_mtime && *cache_mtime > 0 && lookup_paths_mtime_good(lp, *cache_mtime))
|
||||
- return 0;
|
||||
|
||||
if (ret_path_cache) {
|
||||
paths = set_new(&path_hash_ops);
|
||||
@@ -226,7 +181,6 @@ int unit_file_build_name_map(
|
||||
STRV_FOREACH(dir, (char**) lp->search_path) {
|
||||
struct dirent *de;
|
||||
_cleanup_closedir_ DIR *d = NULL;
|
||||
- struct stat st;
|
||||
|
||||
d = opendir(*dir);
|
||||
if (!d) {
|
||||
@@ -235,13 +189,6 @@ int unit_file_build_name_map(
|
||||
continue;
|
||||
}
|
||||
|
||||
- /* Determine the latest lookup path modification time */
|
||||
- if (fstat(dirfd(d), &st) < 0)
|
||||
- return log_error_errno(errno, "Failed to fstat %s: %m", *dir);
|
||||
-
|
||||
- if (!lookup_paths_mtime_exclude(lp, *dir))
|
||||
- mtime = MAX(mtime, timespec_load(&st.st_mtim));
|
||||
-
|
||||
FOREACH_DIRENT_ALL(de, d, log_warning_errno(errno, "Failed to read \"%s\", ignoring: %m", *dir)) {
|
||||
char *filename;
|
||||
_cleanup_free_ char *_filename_free = NULL, *simplified = NULL;
|
||||
@@ -378,14 +325,12 @@ int unit_file_build_name_map(
|
||||
basename(dst), src);
|
||||
}
|
||||
|
||||
- if (cache_mtime)
|
||||
- *cache_mtime = mtime;
|
||||
*ret_unit_ids_map = TAKE_PTR(ids);
|
||||
*ret_unit_names_map = TAKE_PTR(names);
|
||||
if (ret_path_cache)
|
||||
*ret_path_cache = TAKE_PTR(paths);
|
||||
|
||||
- return 1;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
int unit_file_find_fragment(
|
||||
diff --git a/src/shared/unit-file.h b/src/shared/unit-file.h
|
||||
index 54cc787..52e17f7 100644
|
||||
--- a/src/shared/unit-file.h
|
||||
+++ b/src/shared/unit-file.h
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "hashmap.h"
|
||||
-#include "time-util.h"
|
||||
#include "unit-name.h"
|
||||
|
||||
typedef enum UnitFileState UnitFileState;
|
||||
@@ -43,7 +42,6 @@ int unit_validate_alias_symlink_and_warn(const char *filename, const char *targe
|
||||
|
||||
int unit_file_build_name_map(
|
||||
const LookupPaths *lp,
|
||||
- usec_t *ret_time,
|
||||
Hashmap **ret_unit_ids_map,
|
||||
Hashmap **ret_unit_names_map,
|
||||
Set **ret_path_cache);
|
||||
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
|
||||
index dcf76be..69063ee 100644
|
||||
--- a/src/systemctl/systemctl.c
|
||||
+++ b/src/systemctl/systemctl.c
|
||||
@@ -2594,7 +2594,7 @@ static int unit_find_paths(
|
||||
_cleanup_set_free_free_ Set *names = NULL;
|
||||
|
||||
if (!cached_name_map) {
|
||||
- r = unit_file_build_name_map(lp, NULL, &cached_id_map, &cached_name_map, NULL);
|
||||
+ r = unit_file_build_name_map(lp, &cached_id_map, &cached_name_map, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
|
||||
index 8bc5bf6..988ac15 100644
|
||||
--- a/src/test/test-unit-file.c
|
||||
+++ b/src/test/test-unit-file.c
|
||||
@@ -32,12 +32,10 @@ static void test_unit_file_build_name_map(char **ids) {
|
||||
Iterator i;
|
||||
const char *k, *dst;
|
||||
char **v;
|
||||
- usec_t mtime = 0;
|
||||
- int r;
|
||||
|
||||
assert_se(lookup_paths_init(&lp, UNIT_FILE_SYSTEM, 0, NULL) >= 0);
|
||||
|
||||
- assert_se(unit_file_build_name_map(&lp, &mtime, &unit_ids, &unit_names, NULL) == 1);
|
||||
+ assert_se(unit_file_build_name_map(&lp, &unit_ids, &unit_names, NULL) == 0);
|
||||
|
||||
HASHMAP_FOREACH_KEY(dst, k, unit_ids, i)
|
||||
log_info("ids: %s → %s", k, dst);
|
||||
@@ -47,15 +45,6 @@ static void test_unit_file_build_name_map(char **ids) {
|
||||
log_info("aliases: %s ← %s", k, j);
|
||||
}
|
||||
|
||||
- char buf[FORMAT_TIMESTAMP_MAX];
|
||||
- log_debug("Last modification time: %s", format_timestamp(buf, sizeof buf, mtime));
|
||||
-
|
||||
- r = unit_file_build_name_map(&lp, &mtime, &unit_ids, &unit_names, NULL);
|
||||
- assert_se(IN_SET(r, 0, 1));
|
||||
- if (r == 0)
|
||||
- log_debug("Cache rebuild skipped based on mtime.");
|
||||
-
|
||||
-
|
||||
char **id;
|
||||
STRV_FOREACH(id, ids) {
|
||||
const char *fragment, *name;
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,177 +0,0 @@
|
||||
From 7d1e91d1a9504ab1bc03894038f90a8e87a4e982 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
||||
Date: Tue, 2 Apr 2019 11:22:56 +0200
|
||||
Subject: [PATCH] shared/unit-file: add a function to validate unit alias
|
||||
symlinks
|
||||
|
||||
It turns out most possible symlinks are invalid, because the type has to match,
|
||||
and template units can only be linked to template units.
|
||||
|
||||
I'm not sure if the existing code made the same checks consistently. At least
|
||||
I don't see the same rules expressed in a single place.
|
||||
|
||||
revert shared unit file add a function to validate unit alias symlinks
|
||||
---
|
||||
src/shared/unit-file.c | 73 -----------------------------------------------
|
||||
src/shared/unit-file.h | 2 --
|
||||
src/test/meson.build | 4 ---
|
||||
src/test/test-unit-file.c | 34 ----------------------
|
||||
4 files changed, 113 deletions(-)
|
||||
delete mode 100644 src/test/test-unit-file.c
|
||||
|
||||
diff --git a/src/shared/unit-file.c b/src/shared/unit-file.c
|
||||
index cde38c4..deed7dc 100644
|
||||
--- a/src/shared/unit-file.c
|
||||
+++ b/src/shared/unit-file.c
|
||||
@@ -1,7 +1,6 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include "macro.h"
|
||||
-#include "string-util.h"
|
||||
#include "unit-file.h"
|
||||
|
||||
bool unit_type_may_alias(UnitType type) {
|
||||
@@ -22,75 +21,3 @@ bool unit_type_may_template(UnitType type) {
|
||||
UNIT_TIMER,
|
||||
UNIT_PATH);
|
||||
}
|
||||
-
|
||||
-int unit_validate_alias_symlink_and_warn(const char *filename, const char *target) {
|
||||
- const char *src, *dst;
|
||||
- _cleanup_free_ char *src_instance = NULL, *dst_instance = NULL;
|
||||
- UnitType src_unit_type, dst_unit_type;
|
||||
- int src_name_type, dst_name_type;
|
||||
-
|
||||
- /* Check if the *alias* symlink is valid. This applies to symlinks like
|
||||
- * /etc/systemd/system/dbus.service → dbus-broker.service, but not to .wants or .requires symlinks
|
||||
- * and such. Neither does this apply to symlinks which *link* units, i.e. symlinks to outside of the
|
||||
- * unit lookup path.
|
||||
- *
|
||||
- * -EINVAL is returned if the something is wrong with the source filename or the source unit type is
|
||||
- * not allowed to symlink,
|
||||
- * -EXDEV if the target filename is not a valid unit name or doesn't match the source.
|
||||
- */
|
||||
-
|
||||
- src = basename(filename);
|
||||
- dst = basename(target);
|
||||
-
|
||||
- /* src checks */
|
||||
-
|
||||
- src_name_type = unit_name_to_instance(src, &src_instance);
|
||||
- if (src_name_type < 0)
|
||||
- return log_notice_errno(src_name_type,
|
||||
- "%s: not a valid unit name \"%s\": %m", filename, src);
|
||||
-
|
||||
- src_unit_type = unit_name_to_type(src);
|
||||
- assert(src_unit_type >= 0); /* unit_name_to_instance() checked the suffix already */
|
||||
-
|
||||
- if (!unit_type_may_alias(src_unit_type))
|
||||
- return log_notice_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
- "%s: symlinks are not allowed for units of this type, rejecting.",
|
||||
- filename);
|
||||
-
|
||||
- if (src_name_type != UNIT_NAME_PLAIN &&
|
||||
- !unit_type_may_template(src_unit_type))
|
||||
- return log_notice_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
- "%s: templates not allowed for %s units, rejecting.",
|
||||
- filename, unit_type_to_string(src_unit_type));
|
||||
-
|
||||
- /* dst checks */
|
||||
-
|
||||
- dst_name_type = unit_name_to_instance(dst, &dst_instance);
|
||||
- if (dst_name_type < 0)
|
||||
- return log_notice_errno(dst_name_type == -EINVAL ? SYNTHETIC_ERRNO(EXDEV) : dst_name_type,
|
||||
- "%s points to \"%s\" which is not a valid unit name: %m",
|
||||
- filename, dst);
|
||||
-
|
||||
- if (!(dst_name_type == src_name_type ||
|
||||
- (src_name_type == UNIT_NAME_INSTANCE && dst_name_type == UNIT_NAME_TEMPLATE)))
|
||||
- return log_notice_errno(SYNTHETIC_ERRNO(EXDEV),
|
||||
- "%s: symlink target name type \"%s\" does not match source, rejecting.",
|
||||
- filename, dst);
|
||||
-
|
||||
- if (dst_name_type == UNIT_NAME_INSTANCE) {
|
||||
- assert(src_instance);
|
||||
- assert(dst_instance);
|
||||
- if (!streq(src_instance, dst_instance))
|
||||
- return log_notice_errno(SYNTHETIC_ERRNO(EXDEV),
|
||||
- "%s: unit symlink target \"%s\" instance name doesn't match, rejecting.",
|
||||
- filename, dst);
|
||||
- }
|
||||
-
|
||||
- dst_unit_type = unit_name_to_type(dst);
|
||||
- if (dst_unit_type != src_unit_type)
|
||||
- return log_notice_errno(SYNTHETIC_ERRNO(EXDEV),
|
||||
- "%s: symlink target \"%s\" has incompatible suffix, rejecting.",
|
||||
- filename, dst);
|
||||
-
|
||||
- return 0;
|
||||
-}
|
||||
diff --git a/src/shared/unit-file.h b/src/shared/unit-file.h
|
||||
index e57f472..2b9df65 100644
|
||||
--- a/src/shared/unit-file.h
|
||||
+++ b/src/shared/unit-file.h
|
||||
@@ -35,5 +35,3 @@ enum UnitFileScope {
|
||||
|
||||
bool unit_type_may_alias(UnitType type) _const_;
|
||||
bool unit_type_may_template(UnitType type) _const_;
|
||||
-
|
||||
-int unit_validate_alias_symlink_and_warn(const char *filename, const char *target);
|
||||
diff --git a/src/test/meson.build b/src/test/meson.build
|
||||
index de31e97..5625e68 100644
|
||||
--- a/src/test/meson.build
|
||||
+++ b/src/test/meson.build
|
||||
@@ -137,10 +137,6 @@ tests += [
|
||||
[],
|
||||
'ENABLE_EFI'],
|
||||
|
||||
- [['src/test/test-unit-file.c'],
|
||||
- [],
|
||||
- []],
|
||||
-
|
||||
[['src/test/test-unit-name.c',
|
||||
'src/test/test-helper.c'],
|
||||
[libcore,
|
||||
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
|
||||
deleted file mode 100644
|
||||
index b626b5f..0000000
|
||||
--- a/src/test/test-unit-file.c
|
||||
+++ /dev/null
|
||||
@@ -1,34 +0,0 @@
|
||||
-/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
-
|
||||
-#include "path-lookup.h"
|
||||
-#include "set.h"
|
||||
-#include "strv.h"
|
||||
-#include "tests.h"
|
||||
-#include "unit-file.h"
|
||||
-
|
||||
-static void test_unit_validate_alias_symlink_and_warn(void) {
|
||||
- log_info("/* %s */", __func__);
|
||||
-
|
||||
- assert_se(unit_validate_alias_symlink_and_warn("/path/a.service", "/other/b.service") == 0);
|
||||
- assert_se(unit_validate_alias_symlink_and_warn("/path/a.service", "/other/b.socket") == -EXDEV);
|
||||
- assert_se(unit_validate_alias_symlink_and_warn("/path/a.service", "/other/b.foobar") == -EXDEV);
|
||||
- assert_se(unit_validate_alias_symlink_and_warn("/path/a@.service", "/other/b@.service") == 0);
|
||||
- assert_se(unit_validate_alias_symlink_and_warn("/path/a@.service", "/other/b@.socket") == -EXDEV);
|
||||
- assert_se(unit_validate_alias_symlink_and_warn("/path/a@XXX.service", "/other/b@YYY.service") == -EXDEV);
|
||||
- assert_se(unit_validate_alias_symlink_and_warn("/path/a@XXX.service", "/other/b@YYY.socket") == -EXDEV);
|
||||
- assert_se(unit_validate_alias_symlink_and_warn("/path/a@.service", "/other/b@YYY.service") == -EXDEV);
|
||||
- assert_se(unit_validate_alias_symlink_and_warn("/path/a@XXX.service", "/other/b@XXX.service") == 0);
|
||||
- assert_se(unit_validate_alias_symlink_and_warn("/path/a@XXX.service", "/other/b@.service") == 0);
|
||||
- assert_se(unit_validate_alias_symlink_and_warn("/path/a@.service", "/other/b.service") == -EXDEV);
|
||||
- assert_se(unit_validate_alias_symlink_and_warn("/path/a.service", "/other/b@.service") == -EXDEV);
|
||||
- assert_se(unit_validate_alias_symlink_and_warn("/path/a@.slice", "/other/b.slice") == -EINVAL);
|
||||
- assert_se(unit_validate_alias_symlink_and_warn("/path/a.slice", "/other/b.slice") == -EINVAL);
|
||||
-}
|
||||
-
|
||||
-int main(int argc, char **argv) {
|
||||
- test_setup_logging(LOG_DEBUG);
|
||||
-
|
||||
- test_unit_validate_alias_symlink_and_warn();
|
||||
-
|
||||
- return 0;
|
||||
-}
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
13
systemd.spec
13
systemd.spec
@ -20,7 +20,7 @@
|
||||
Name: systemd
|
||||
Url: https://www.freedesktop.org/wiki/Software/systemd
|
||||
Version: 248
|
||||
Release: 1
|
||||
Release: 2
|
||||
License: MIT and LGPLv2+ and GPLv2+
|
||||
Summary: System and Service Manager
|
||||
|
||||
@ -62,10 +62,10 @@ Patch0013: 0013-sd-bus-properly-initialize-containers.patch
|
||||
Patch0014: 0014-Revert-core-one-step-back-again-for-nspawn-we-actual.patch
|
||||
Patch0015: 0015-journal-don-t-enable-systemd-journald-audit.socket-b.patch
|
||||
Patch0016: 0016-systemd-change-time-log-level.patch
|
||||
#Patch0017: fix-capsh-drop-but-ping-success.patch
|
||||
#Patch0018: 0998-resolved-create-etc-resolv.conf-symlink-at-runtime.patch
|
||||
#Patch0019: core-serialize-u-pids-until-the-processes-have-been-.patch
|
||||
#Patch0020: scope-on-unified-make-sure-to-unwatch-all-PIDs-once-.patch
|
||||
#Patch0017: 0017-fix-capsh-drop-but-ping-success.patch
|
||||
#Patch0018: 0018-resolved-create-etc-resolv.conf-symlink-at-runtime.patch
|
||||
#Patch0019: 0019-core-serialize-u-pids-until-the-processes-have-been-.patch
|
||||
#Patch0020: 0020-scope-on-unified-make-sure-to-unwatch-all-PIDs-once-.patch
|
||||
|
||||
BuildRequires: gcc, gcc-c++
|
||||
BuildRequires: libcap-devel, libmount-devel, pam-devel, libselinux-devel
|
||||
@ -1528,6 +1528,9 @@ fi
|
||||
%exclude /usr/share/man/man3/*
|
||||
|
||||
%changelog
|
||||
* Fri 30 Apr 2021 hexiaowen <hexiaowen@huawei.com> - 248-2
|
||||
- delete unused patches
|
||||
|
||||
* Fri 30 Apr 2021 hexiaowen <hexiaowen@huawei.com> - 248-1
|
||||
- Rebase to version 248
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user