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

Compare commits

..

No commits in common. "23a0ffa59f9cb26c4b016c9fd1a3a70da2607f61" and "463aef23a73d7850e0208cf4e96fd448693a755a" have entirely different histories.

6 changed files with 66 additions and 82 deletions

View File

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

View File

@ -1037,10 +1037,6 @@ bool is_main_thread(void) {
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) {
int architecture;

View File

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

View File

@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <linux/oom.h>
#include <sys/mount.h>
#include <sys/prctl.h>
@ -94,6 +95,10 @@ static int property_get_environment_files(
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(
sd_bus *bus,
const char *path,

View File

@ -6,20 +6,33 @@
#include "systemctl-util.h"
#include "systemctl.h"
static int set_property_one(sd_bus *bus, const char *name, char **properties) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
int set_property(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_free_ char *n = NULL;
UnitType t;
sd_bus *bus;
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");
if (r < 0)
return bus_log_create_error(r);
UnitType t = unit_name_to_type(name);
if (t < 0)
return log_error_errno(t, "Invalid unit type: %s", name);
r = unit_name_mangle(argv[1], arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN, &n);
if (r < 0)
return log_error_errno(r, "Failed to mangle unit name: %m");
r = sd_bus_message_append(m, "sb", name, arg_runtime);
t = unit_name_to_type(n);
if (t < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid unit type: %s", n);
r = sd_bus_message_append(m, "sb", n, arg_runtime);
if (r < 0)
return bus_log_create_error(r);
@ -27,7 +40,7 @@ static int set_property_one(sd_bus *bus, const char *name, char **properties) {
if (r < 0)
return bus_log_create_error(r);
r = bus_append_unit_property_assignment_many(m, t, properties);
r = bus_append_unit_property_assignment_many(m, t, strv_skip(argv, 2));
if (r < 0)
return r;
@ -37,33 +50,7 @@ static int set_property_one(sd_bus *bus, const char *name, char **properties) {
r = sd_bus_call(bus, m, 0, &error, NULL);
if (r < 0)
return log_error_errno(r, "Failed to set unit properties on %s: %s",
name, bus_error_message(&error, r));
return log_error_errno(r, "Failed to set unit properties on %s: %s", n, bus_error_message(&error, r));
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,10 +76,7 @@ struct sd_bus_vtable {
const unsigned *vtable_format_reference;
} start;
struct {
/* 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;
size_t reserved;
} end;
struct {
const char *member;
@ -109,11 +106,11 @@ struct sd_bus_vtable {
.type = _SD_BUS_VTABLE_START, \
.flags = _flags, \
.x = { \
.start = { \
.element_size = sizeof(sd_bus_vtable), \
.features = _SD_BUS_VTABLE_PARAM_NAMES, \
.vtable_format_reference = &sd_bus_object_vtable_format, \
}, \
.start = { \
.element_size = sizeof(sd_bus_vtable), \
.features = _SD_BUS_VTABLE_PARAM_NAMES, \
.vtable_format_reference = &sd_bus_object_vtable_format, \
}, \
}, \
}
@ -125,14 +122,14 @@ struct sd_bus_vtable {
.type = _SD_BUS_VTABLE_METHOD, \
.flags = _flags, \
.x = { \
.method = { \
.member = _member, \
.signature = _signature, \
.result = _result, \
.handler = _handler, \
.offset = _offset, \
.names = _in_names _out_names, \
}, \
.method = { \
.member = _member, \
.signature = _signature, \
.result = _result, \
.handler = _handler, \
.offset = _offset, \
.names = _in_names _out_names, \
}, \
}, \
}
#define SD_BUS_METHOD_WITH_OFFSET(_member, _signature, _result, _handler, _offset, _flags) \
@ -147,14 +144,14 @@ struct sd_bus_vtable {
.type = _SD_BUS_VTABLE_SIGNAL, \
.flags = _flags, \
.x = { \
.signal = { \
.member = _member, \
.signature = _signature, \
.names = _out_names, \
}, \
.signal = { \
.member = _member, \
.signature = _signature, \
.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)
#define SD_BUS_PROPERTY(_member, _signature, _get, _offset, _flags) \
@ -162,13 +159,13 @@ struct sd_bus_vtable {
.type = _SD_BUS_VTABLE_PROPERTY, \
.flags = _flags, \
.x = { \
.property = { \
.member = _member, \
.signature = _signature, \
.get = _get, \
.set = NULL, \
.offset = _offset, \
}, \
.property = { \
.member = _member, \
.signature = _signature, \
.get = _get, \
.set = NULL, \
.offset = _offset, \
}, \
}, \
}
@ -177,13 +174,13 @@ struct sd_bus_vtable {
.type = _SD_BUS_VTABLE_WRITABLE_PROPERTY, \
.flags = _flags, \
.x = { \
.property = { \
.member = _member, \
.signature = _signature, \
.get = _get, \
.set = _set, \
.offset = _offset, \
}, \
.property = { \
.member = _member, \
.signature = _signature, \
.get = _get, \
.set = _set, \
.offset = _offset, \
}, \
}, \
}
@ -192,9 +189,9 @@ struct sd_bus_vtable {
.type = _SD_BUS_VTABLE_END, \
.flags = 0, \
.x = { \
.end = { \
._reserved = 0, \
}, \
.end = { \
.reserved = 0, \
}, \
}, \
}