diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md index 565a2e46bde..2c61935b6bb 100644 --- a/docs/ENVIRONMENT.md +++ b/docs/ENVIRONMENT.md @@ -401,3 +401,35 @@ and `homectl`: current and a future password are required, for example if the password is to be changed. In that case `$PASSWORD` shall carry the current (i.e. old) password and `$NEWPASSWORD` the new. + +`systemd-homed`: + +* `$SYSTEMD_HOME_ROOT` – defines an absolute path where to look for home + directories/images. When unspecified defaults to `/home/`. This is useful for + debugging purposes in order to run a secondary `systemd-homed` instance that + operates on a different directory where home directories/images are placed. + +* `$SYSTEMD_HOME_RECORD_DIR` – defines an absolute path where to look for + fixated home records kept on the host. When unspecified defaults to + `/var/lib/systemd/home/`. Similar to `$SYSTEMD_HOME_ROOT` this is useful for + debugging purposes, in order to run a secondary `systemd-homed` instance that + operates on a record database entirely separate from the host's. + +* `$SYSTEMD_HOME_DEBUG_SUFFIX` – takes a short string that is suffixed to + `systemd-homed`'s D-Bus and Varlink service names/sockets. This is also + understood by `homectl`. This too is useful for running an additiona copy of + `systemd-homed` that doesn't interfere with the host's main one. + +* `$SYSTEMD_HOMEWORK_PATH` – configures the path to the `systemd-homework` + binary to invoke. If not specified defaults to + `/usr/lib/systemd/systemd-homework`. + + Combining these four environment variables is pretty useful when + debugging/developing `systemd-homed`: +```sh +SYSTEMD_HOME_DEBUG_SUFFIX=foo \ + SYSTEMD_HOMEWORK_PATH=/home/lennart/projects/systemd/build/systemd-homework \ + SYSTEMD_HOME_ROOT=/home.foo/ \ + SYSTEMD_HOME_RECORD_DIR=/var/lib/systemd/home.foo/ \ + /home/lennart/projects/systemd/build/systemd-homed +``` diff --git a/src/home/home-util.c b/src/home/home-util.c index cd971b7cda4..c777d7b0eb6 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 f7bf637dd2e..5e633ea4af4 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 c111bfa7825..10bb96a797c 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 fbfbdaeb77e..34bb4d84baf 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;