summaryrefslogtreecommitdiffstats
path: root/src/home
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-11-05 18:03:05 +0100
committerLennart Poettering <lennart@poettering.net>2021-11-05 18:35:28 +0100
commit005daeed2bcf665a5bdf268b4a18ea923c9de527 (patch)
tree7f59fb7197c8ecbc6ae58fcde471bf8a40b01707 /src/home
parenttest: Add test for flag macros (diff)
downloadsystemd-005daeed2bcf665a5bdf268b4a18ea923c9de527.tar.xz
systemd-005daeed2bcf665a5bdf268b4a18ea923c9de527.zip
homed: add env var to override dir where we fine stored user records
This adds an env var which we can use to redirect where homed stores and looks for user records kept on the host. This is useful for debugging purposes so that one can easily run another homed instnce that doesn't interfere with the main instance.
Diffstat (limited to 'src/home')
-rw-r--r--src/home/home-util.c4
-rw-r--r--src/home/home-util.h2
-rw-r--r--src/home/homed-home.c6
-rw-r--r--src/home/homed-manager.c6
4 files changed, 12 insertions, 6 deletions
diff --git a/src/home/home-util.c b/src/home/home-util.c
index cd971b7cda..c777d7b0eb 100644
--- a/src/home/home-util.c
+++ b/src/home/home-util.c
@@ -133,3 +133,7 @@ int bus_message_append_secret(sd_bus_message *m, UserRecord *secret) {
return sd_bus_message_append(m, "s", formatted);
}
+
+const char *home_record_dir(void) {
+ return secure_getenv("SYSTEMD_HOME_RECORD_DIR") ?: "/var/lib/systemd/home/";
+}
diff --git a/src/home/home-util.h b/src/home/home-util.h
index f7bf637dd2..5e633ea4af 100644
--- a/src/home/home-util.h
+++ b/src/home/home-util.h
@@ -25,3 +25,5 @@ int bus_message_append_secret(sd_bus_message *m, UserRecord *secret);
/* Many of our operations might be slow due to crypto, fsck, recursive chown() and so on. For these
* operations permit a *very* long timeout */
#define HOME_SLOW_BUS_CALL_TIMEOUT_USEC (2*USEC_PER_MINUTE)
+
+const char *home_record_dir(void);
diff --git a/src/home/homed-home.c b/src/home/homed-home.c
index c111bfa782..10bb96a797 100644
--- a/src/home/homed-home.c
+++ b/src/home/homed-home.c
@@ -300,9 +300,9 @@ int home_save_record(Home *h) {
return r;
(void) mkdir("/var/lib/systemd/", 0755);
- (void) mkdir("/var/lib/systemd/home/", 0700);
+ (void) mkdir(home_record_dir(), 0700);
- fn = strjoina("/var/lib/systemd/home/", h->user_name, ".identity");
+ fn = strjoina(home_record_dir(), "/", h->user_name, ".identity");
r = write_string_file(fn, text, WRITE_STRING_FILE_ATOMIC|WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_MODE_0600|WRITE_STRING_FILE_SYNC);
if (r < 0)
@@ -316,7 +316,7 @@ int home_unlink_record(Home *h) {
assert(h);
- fn = strjoina("/var/lib/systemd/home/", h->user_name, ".identity");
+ fn = strjoina(home_record_dir(), "/", h->user_name, ".identity");
if (unlink(fn) < 0 && errno != ENOENT)
return -errno;
diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c
index fbfbdaeb77..34bb4d84ba 100644
--- a/src/home/homed-manager.c
+++ b/src/home/homed-manager.c
@@ -436,7 +436,7 @@ unlink_this_file:
if (unlinkat(dir_fd, fname, 0) < 0)
return log_error_errno(errno, "Failed to remove empty user record file %s: %m", fname);
- log_notice("Discovered empty user record file /var/lib/systemd/home/%s, removed automatically.", fname);
+ log_notice("Discovered empty user record file %s/%s, removed automatically.", home_record_dir(), fname);
return 0;
}
@@ -446,10 +446,10 @@ static int manager_enumerate_records(Manager *m) {
assert(m);
- d = opendir("/var/lib/systemd/home/");
+ d = opendir(home_record_dir());
if (!d)
return log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_ERR, errno,
- "Failed to open /var/lib/systemd/home/: %m");
+ "Failed to open %s: %m", home_record_dir());
FOREACH_DIRENT(de, d, return log_error_errno(errno, "Failed to read record directory: %m")) {
_cleanup_free_ char *n = NULL;