1
0
mirror of https://github.com/systemd/systemd synced 2026-03-23 23:34:52 +01:00

Compare commits

...

7 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
23a0ffa59f systemctl: allow set-property to be called with a glob pattern
We call "systemctl set-property … Markers=+needs-restart" and this should
also work for globs, e.g. "user@*.service" or "syncthing@*.service".

https://bugzilla.redhat.com/show_bug.cgi?id=1986258
2021-07-29 10:47:28 +02:00
Lennart Poettering
5b74168814
Merge pull request #20337 from poettering/oom-adj-fix
make oom_score_adjust_is_valid() shared again
2021-07-29 10:47:10 +02:00
Lennart Poettering
78d4d37401
Merge pull request #20339 from poettering/bus-vtable-indent-fix
sd-bus: fix indentation in macros
2021-07-29 10:46:50 +02:00
Lennart Poettering
0c4801738e sd-bus: add brief inline comment explaining the "reserved" field in the bus vtable structure
Follow-up for: #20253
2021-07-28 20:44:49 +02:00
Lennart Poettering
02f2d2b33b sd-bus: fix indentation in macros
We use multiples of 8 spaces indentation in our C code, do it here too.
2021-07-28 20:39:18 +02:00
Lennart Poettering
c62f67f730 parse-util: use oom_score_adjust_is_valid() at one more place 2021-07-28 18:39:41 +02:00
Lennart Poettering
c4412d4d33 Revert "Make oom_score_adjust_is_valid() static"
This reverts commit 6bf3c6c9007ca87376d5dff1e029186a38736cdc.
2021-07-28 18:39:41 +02:00
6 changed files with 81 additions and 65 deletions

View File

@ -2,7 +2,6 @@
#include <errno.h> #include <errno.h>
#include <inttypes.h> #include <inttypes.h>
#include <linux/oom.h>
#include <net/if.h> #include <net/if.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -731,7 +730,7 @@ int parse_oom_score_adjust(const char *s, int *ret) {
if (r < 0) if (r < 0)
return r; return r;
if (v < OOM_SCORE_ADJ_MIN || v > OOM_SCORE_ADJ_MAX) if (!oom_score_adjust_is_valid(v))
return -ERANGE; return -ERANGE;
*ret = v; *ret = v;

View File

@ -1037,6 +1037,10 @@ bool is_main_thread(void) {
return cached > 0; return cached > 0;
} }
bool oom_score_adjust_is_valid(int oa) {
return oa >= OOM_SCORE_ADJ_MIN && oa <= OOM_SCORE_ADJ_MAX;
}
unsigned long personality_from_string(const char *p) { unsigned long personality_from_string(const char *p) {
int architecture; int architecture;

View File

@ -82,6 +82,8 @@ int pid_from_same_root_fs(pid_t pid);
bool is_main_thread(void); bool is_main_thread(void);
bool oom_score_adjust_is_valid(int oa);
#ifndef PERSONALITY_INVALID #ifndef PERSONALITY_INVALID
/* personality(7) documents that 0xffffffffUL is used for querying the /* personality(7) documents that 0xffffffffUL is used for querying the
* current personality, hence let's use that here as error * current personality, hence let's use that here as error

View File

@ -1,6 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <linux/oom.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <sys/prctl.h> #include <sys/prctl.h>
@ -95,10 +94,6 @@ static int property_get_environment_files(
return sd_bus_message_close_container(reply); return sd_bus_message_close_container(reply);
} }
static bool oom_score_adjust_is_valid(int oa) {
return oa >= OOM_SCORE_ADJ_MIN && oa <= OOM_SCORE_ADJ_MAX;
}
static int property_get_oom_score_adjust( static int property_get_oom_score_adjust(
sd_bus *bus, sd_bus *bus,
const char *path, const char *path,

View File

@ -6,33 +6,20 @@
#include "systemctl-util.h" #include "systemctl-util.h"
#include "systemctl.h" #include "systemctl.h"
int set_property(int argc, char *argv[], void *userdata) { static int set_property_one(sd_bus *bus, const char *name, char **properties) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_free_ char *n = NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
UnitType t;
sd_bus *bus;
int r; int r;
r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0)
return r;
polkit_agent_open_maybe();
r = bus_message_new_method_call(bus, &m, bus_systemd_mgr, "SetUnitProperties"); r = bus_message_new_method_call(bus, &m, bus_systemd_mgr, "SetUnitProperties");
if (r < 0) if (r < 0)
return bus_log_create_error(r); return bus_log_create_error(r);
r = unit_name_mangle(argv[1], arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN, &n); UnitType t = unit_name_to_type(name);
if (r < 0)
return log_error_errno(r, "Failed to mangle unit name: %m");
t = unit_name_to_type(n);
if (t < 0) if (t < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid unit type: %s", n); return log_error_errno(t, "Invalid unit type: %s", name);
r = sd_bus_message_append(m, "sb", n, arg_runtime); r = sd_bus_message_append(m, "sb", name, arg_runtime);
if (r < 0) if (r < 0)
return bus_log_create_error(r); return bus_log_create_error(r);
@ -40,7 +27,7 @@ int set_property(int argc, char *argv[], void *userdata) {
if (r < 0) if (r < 0)
return bus_log_create_error(r); return bus_log_create_error(r);
r = bus_append_unit_property_assignment_many(m, t, strv_skip(argv, 2)); r = bus_append_unit_property_assignment_many(m, t, properties);
if (r < 0) if (r < 0)
return r; return r;
@ -50,7 +37,33 @@ int set_property(int argc, char *argv[], void *userdata) {
r = sd_bus_call(bus, m, 0, &error, NULL); r = sd_bus_call(bus, m, 0, &error, NULL);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to set unit properties on %s: %s", n, bus_error_message(&error, r)); return log_error_errno(r, "Failed to set unit properties on %s: %s",
name, bus_error_message(&error, r));
return 0; return 0;
} }
int set_property(int argc, char *argv[], void *userdata) {
sd_bus *bus;
_cleanup_strv_free_ char **names = NULL;
char **name;
int r, k;
r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0)
return r;
polkit_agent_open_maybe();
r = expand_unit_names(bus, STRV_MAKE(argv[1]), NULL, &names, NULL);
if (r < 0)
return log_error_errno(r, "Failed to expand '%s' into names: %m", argv[1]);
r = 0;
STRV_FOREACH(name, names) {
k = set_property_one(bus, *name, strv_skip(argv, 2));
if (k < 0 && r >= 0)
r = k;
}
return r;
}

View File

@ -76,7 +76,10 @@ struct sd_bus_vtable {
const unsigned *vtable_format_reference; const unsigned *vtable_format_reference;
} start; } start;
struct { struct {
size_t reserved; /* This field exists only to make sure we have something to initialize in
* SD_BUS_VTABLE_END in a way that is both compatible with pedantic versions of C and
* C++. It's unused otherwise. */
size_t _reserved;
} end; } end;
struct { struct {
const char *member; const char *member;
@ -106,11 +109,11 @@ struct sd_bus_vtable {
.type = _SD_BUS_VTABLE_START, \ .type = _SD_BUS_VTABLE_START, \
.flags = _flags, \ .flags = _flags, \
.x = { \ .x = { \
.start = { \ .start = { \
.element_size = sizeof(sd_bus_vtable), \ .element_size = sizeof(sd_bus_vtable), \
.features = _SD_BUS_VTABLE_PARAM_NAMES, \ .features = _SD_BUS_VTABLE_PARAM_NAMES, \
.vtable_format_reference = &sd_bus_object_vtable_format, \ .vtable_format_reference = &sd_bus_object_vtable_format, \
}, \ }, \
}, \ }, \
} }
@ -122,14 +125,14 @@ struct sd_bus_vtable {
.type = _SD_BUS_VTABLE_METHOD, \ .type = _SD_BUS_VTABLE_METHOD, \
.flags = _flags, \ .flags = _flags, \
.x = { \ .x = { \
.method = { \ .method = { \
.member = _member, \ .member = _member, \
.signature = _signature, \ .signature = _signature, \
.result = _result, \ .result = _result, \
.handler = _handler, \ .handler = _handler, \
.offset = _offset, \ .offset = _offset, \
.names = _in_names _out_names, \ .names = _in_names _out_names, \
}, \ }, \
}, \ }, \
} }
#define SD_BUS_METHOD_WITH_OFFSET(_member, _signature, _result, _handler, _offset, _flags) \ #define SD_BUS_METHOD_WITH_OFFSET(_member, _signature, _result, _handler, _offset, _flags) \
@ -144,14 +147,14 @@ struct sd_bus_vtable {
.type = _SD_BUS_VTABLE_SIGNAL, \ .type = _SD_BUS_VTABLE_SIGNAL, \
.flags = _flags, \ .flags = _flags, \
.x = { \ .x = { \
.signal = { \ .signal = { \
.member = _member, \ .member = _member, \
.signature = _signature, \ .signature = _signature, \
.names = _out_names, \ .names = _out_names, \
}, \ }, \
}, \ }, \
} }
#define SD_BUS_SIGNAL(_member, _signature, _flags) \ #define SD_BUS_SIGNAL(_member, _signature, _flags) \
SD_BUS_SIGNAL_WITH_NAMES(_member, _signature, "", _flags) SD_BUS_SIGNAL_WITH_NAMES(_member, _signature, "", _flags)
#define SD_BUS_PROPERTY(_member, _signature, _get, _offset, _flags) \ #define SD_BUS_PROPERTY(_member, _signature, _get, _offset, _flags) \
@ -159,13 +162,13 @@ struct sd_bus_vtable {
.type = _SD_BUS_VTABLE_PROPERTY, \ .type = _SD_BUS_VTABLE_PROPERTY, \
.flags = _flags, \ .flags = _flags, \
.x = { \ .x = { \
.property = { \ .property = { \
.member = _member, \ .member = _member, \
.signature = _signature, \ .signature = _signature, \
.get = _get, \ .get = _get, \
.set = NULL, \ .set = NULL, \
.offset = _offset, \ .offset = _offset, \
}, \ }, \
}, \ }, \
} }
@ -174,13 +177,13 @@ struct sd_bus_vtable {
.type = _SD_BUS_VTABLE_WRITABLE_PROPERTY, \ .type = _SD_BUS_VTABLE_WRITABLE_PROPERTY, \
.flags = _flags, \ .flags = _flags, \
.x = { \ .x = { \
.property = { \ .property = { \
.member = _member, \ .member = _member, \
.signature = _signature, \ .signature = _signature, \
.get = _get, \ .get = _get, \
.set = _set, \ .set = _set, \
.offset = _offset, \ .offset = _offset, \
}, \ }, \
}, \ }, \
} }
@ -189,9 +192,9 @@ struct sd_bus_vtable {
.type = _SD_BUS_VTABLE_END, \ .type = _SD_BUS_VTABLE_END, \
.flags = 0, \ .flags = 0, \
.x = { \ .x = { \
.end = { \ .end = { \
.reserved = 0, \ ._reserved = 0, \
}, \ }, \
}, \ }, \
} }