mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 08:56:15 +09:00
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.
This commit is contained in:
@@ -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/";
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user