diff options
Diffstat (limited to 'src/login/user-runtime-dir.c')
-rw-r--r-- | src/login/user-runtime-dir.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/login/user-runtime-dir.c b/src/login/user-runtime-dir.c index 575f8eb..b242f83 100644 --- a/src/login/user-runtime-dir.c +++ b/src/login/user-runtime-dir.c @@ -25,27 +25,38 @@ #include "strv.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_flush_close_unrefp) sd_bus *bus = NULL; + uint64_t size, inodes; int r; + assert(ret_size); + assert(ret_inodes); + r = sd_bus_default_system(&bus); if (r < 0) 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) { 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) { 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; } @@ -70,7 +81,7 @@ static int user_mkdir_runtime_path( if (path_is_mount_point(runtime_path) > 0) log_debug("%s is already a mount point", runtime_path); 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(gid_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) { - 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; uid_t uid; gid_t gid; @@ -165,7 +176,7 @@ static int do_mount(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; int r; |