Skip to content

Commit

Permalink
logind: change user-runtime-dir to query runtime dir size from logind…
Browse files Browse the repository at this point in the history
… via the bus

I think this is a slightly cleaner approach than parsing the
configuration file at multiple places, as this way there's only a single
reload cycle for logind.conf, and that's systemd-logind.service's
runtime.

This means that logind and dbus become a requirement of
user-runtime-dir, but given that XDG_RUNTIME_DIR is not set anyway
without logind and dbus around this isn't really any limitation.

This also simplifies linking a bit as this means user-runtime-dir
doesn't have to link against any code of logind itself.
  • Loading branch information
poettering committed Oct 13, 2018
1 parent 3d0ef5c commit 07ee5ad
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
16 changes: 8 additions & 8 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -1762,15 +1762,15 @@ if conf.get('ENABLE_LOGIND') == 1
args : pam_systemd.full_path())
endif
endif
endif

executable('systemd-user-runtime-dir',
user_runtime_dir_sources,
include_directories : includes,
link_with : [libshared, liblogind_core],
install_rpath : rootlibexecdir,
install : true,
install_dir : rootlibexecdir)
executable('systemd-user-runtime-dir',
user_runtime_dir_sources,
include_directories : includes,
link_with : [libshared],
install_rpath : rootlibexecdir,
install : true,
install_dir : rootlibexecdir)
endif

if conf.get('HAVE_PAM') == 1
executable('systemd-user-sessions',
Expand Down
1 change: 0 additions & 1 deletion src/login/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ loginctl_sources = files('''

user_runtime_dir_sources = files('''
user-runtime-dir.c
logind.h
'''.split())

if conf.get('ENABLE_LOGIND') == 1
Expand Down
37 changes: 24 additions & 13 deletions src/login/user-runtime-dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include <stdint.h>
#include <sys/mount.h>

#include "sd-bus.h"

#include "bus-error.h"
#include "fs-util.h"
#include "label.h"
#include "logind.h"
#include "mkdir.h"
#include "mount-util.h"
#include "path-util.h"
Expand All @@ -17,21 +19,28 @@
#include "strv.h"
#include "user-util.h"

static int gather_configuration(size_t *runtime_dir_size) {
Manager m = {};
static int acquire_runtime_dir_size(uint64_t *ret) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
int r;

manager_reset_config(&m);
r = sd_bus_default_system(&bus);
if (r < 0)
return log_error_errno(r, "Failed to connect to system bus: %m");

r = manager_parse_config_file(&m);
r = sd_bus_get_property_trivial(bus, "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "RuntimeDirectorySize", &error, 't', ret);
if (r < 0)
log_warning_errno(r, "Failed to parse logind.conf: %m");
return log_error_errno(r, "Failed to acquire runtime directory size: %s", bus_error_message(&error, r));

*runtime_dir_size = m.runtime_dir_size;
return 0;
}

static int user_mkdir_runtime_path(const char *runtime_path, uid_t uid, gid_t gid, size_t runtime_dir_size) {
static int user_mkdir_runtime_path(
const char *runtime_path,
uid_t uid,
gid_t gid,
uint64_t runtime_dir_size) {

int r;

assert(runtime_path);
Expand All @@ -49,10 +58,10 @@ static int user_mkdir_runtime_path(const char *runtime_path, uid_t uid, gid_t gi
char options[sizeof("mode=0700,uid=,gid=,size=,smackfsroot=*")
+ DECIMAL_STR_MAX(uid_t)
+ DECIMAL_STR_MAX(gid_t)
+ DECIMAL_STR_MAX(size_t)];
+ DECIMAL_STR_MAX(uint64_t)];

xsprintf(options,
"mode=0700,uid=" UID_FMT ",gid=" GID_FMT ",size=%zu%s",
"mode=0700,uid=" UID_FMT ",gid=" GID_FMT ",size=%" PRIu64 "%s",
uid, gid, runtime_dir_size,
mac_smack_use() ? ",smackfsroot=*" : "");

Expand Down Expand Up @@ -113,7 +122,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)];
size_t runtime_dir_size;
uint64_t runtime_dir_size;
uid_t uid;
gid_t gid;
int r;
Expand All @@ -126,9 +135,11 @@ static int do_mount(const char *user) {
: "Failed to look up user \"%s\": %m",
user);

xsprintf(runtime_path, "/run/user/" UID_FMT, uid);
r = acquire_runtime_dir_size(&runtime_dir_size);
if (r < 0)
return r;

assert_se(gather_configuration(&runtime_dir_size) == 0);
xsprintf(runtime_path, "/run/user/" UID_FMT, uid);

log_debug("Will mount %s owned by "UID_FMT":"GID_FMT, runtime_path, uid, gid);
return user_mkdir_runtime_path(runtime_path, uid, gid, runtime_dir_size);
Expand Down
4 changes: 2 additions & 2 deletions units/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
# (at your option) any later version.

[Unit]
Description=User runtime directory /run/user/%i
Description=User Runtime Directory /run/user/%i
Documentation=man:[email protected](5)
After=systemd-user-sessions.service
After=systemd-user-sessions.service dbus.service
StopWhenUnneeded=yes
IgnoreOnIsolate=yes

Expand Down

0 comments on commit 07ee5ad

Please sign in to comment.