mirror of
https://github.com/systemd/systemd
synced 2024-10-02 22:37:25 +00:00
Merge pull request #33391 from YHNdnzj/runtime-dir-cleanup
login/user-runtime-dir: free ignored sd_bus_error, avoid triggering assertion
This commit is contained in:
commit
4632505865
|
@ -25,27 +25,38 @@
|
||||||
#include "strv.h"
|
#include "strv.h"
|
||||||
#include "user-util.h"
|
#include "user-util.h"
|
||||||
|
|
||||||
static int acquire_runtime_dir_properties(uint64_t *size, uint64_t *inodes) {
|
static int acquire_runtime_dir_properties(uint64_t *ret_size, uint64_t *ret_inodes) {
|
||||||
_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_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
||||||
|
uint64_t size, inodes;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
assert(ret_size);
|
||||||
|
assert(ret_inodes);
|
||||||
|
|
||||||
r = sd_bus_default_system(&bus);
|
r = sd_bus_default_system(&bus);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to connect to system bus: %m");
|
return log_error_errno(r, "Failed to connect to system bus: %m");
|
||||||
|
|
||||||
r = bus_get_property_trivial(bus, bus_login_mgr, "RuntimeDirectorySize", &error, 't', size);
|
r = bus_get_property_trivial(bus, bus_login_mgr, "RuntimeDirectorySize", &error, 't', &size);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_warning_errno(r, "Failed to acquire runtime directory size, ignoring: %s", bus_error_message(&error, r));
|
log_warning_errno(r, "Failed to acquire runtime directory size, ignoring: %s", bus_error_message(&error, r));
|
||||||
*size = physical_memory_scale(10U, 100U); /* 10% */
|
sd_bus_error_free(&error);
|
||||||
|
|
||||||
|
size = physical_memory_scale(10U, 100U); /* 10% */
|
||||||
}
|
}
|
||||||
|
|
||||||
r = bus_get_property_trivial(bus, bus_login_mgr, "RuntimeDirectoryInodesMax", &error, 't', inodes);
|
r = bus_get_property_trivial(bus, bus_login_mgr, "RuntimeDirectoryInodesMax", &error, 't', &inodes);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_warning_errno(r, "Failed to acquire number of inodes for runtime directory, ignoring: %s", bus_error_message(&error, r));
|
log_warning_errno(r, "Failed to acquire number of inodes for runtime directory, ignoring: %s", bus_error_message(&error, r));
|
||||||
*inodes = DIV_ROUND_UP(*size, 4096);
|
sd_bus_error_free(&error);
|
||||||
|
|
||||||
|
inodes = DIV_ROUND_UP(size, 4096);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*ret_size = size;
|
||||||
|
*ret_inodes = inodes;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +81,7 @@ static int user_mkdir_runtime_path(
|
||||||
if (path_is_mount_point(runtime_path) > 0)
|
if (path_is_mount_point(runtime_path) > 0)
|
||||||
log_debug("%s is already a mount point", runtime_path);
|
log_debug("%s is already a mount point", runtime_path);
|
||||||
else {
|
else {
|
||||||
char options[sizeof("mode=0700,uid=,gid=,size=,nr_inodes=,smackfsroot=*")
|
char options[STRLEN("mode=0700,uid=,gid=,size=,nr_inodes=,smackfsroot=*")
|
||||||
+ DECIMAL_STR_MAX(uid_t)
|
+ DECIMAL_STR_MAX(uid_t)
|
||||||
+ DECIMAL_STR_MAX(gid_t)
|
+ DECIMAL_STR_MAX(gid_t)
|
||||||
+ DECIMAL_STR_MAX(uint64_t)
|
+ DECIMAL_STR_MAX(uint64_t)
|
||||||
|
@ -140,7 +151,7 @@ static int user_remove_runtime_path(const char *runtime_path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_mount(const char *user) {
|
static int do_mount(const char *user) {
|
||||||
char runtime_path[sizeof("/run/user") + DECIMAL_STR_MAX(uid_t)];
|
char runtime_path[STRLEN("/run/user/") + DECIMAL_STR_MAX(uid_t)];
|
||||||
uint64_t runtime_dir_size, runtime_dir_inodes;
|
uint64_t runtime_dir_size, runtime_dir_inodes;
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
|
@ -165,7 +176,7 @@ static int do_mount(const char *user) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_umount(const char *user) {
|
static int do_umount(const char *user) {
|
||||||
char runtime_path[sizeof("/run/user") + DECIMAL_STR_MAX(uid_t)];
|
char runtime_path[STRLEN("/run/user/") + DECIMAL_STR_MAX(uid_t)];
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue