homed: make default storage/file system type configurable in homed.conf

This commit is contained in:
Lennart Poettering 2020-05-05 09:57:04 +02:00
parent c07bf7a4ed
commit c76dd733af
9 changed files with 140 additions and 1 deletions

View File

@ -1492,6 +1492,7 @@ meson_apply_m4 = find_program('tools/meson-apply-m4.sh')
includes = include_directories('src/basic',
'src/boot',
'src/home',
'src/shared',
'src/systemd',
'src/journal',

51
src/home/homed-conf.c Normal file
View File

@ -0,0 +1,51 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "conf-parser.h"
#include "def.h"
#include "home-util.h"
#include "homed-conf.h"
int manager_parse_config_file(Manager *m) {
int r;
assert(m);
r = config_parse_many_nulstr(PKGSYSCONFDIR "/homed.conf",
CONF_PATHS_NULSTR("systemd/homed.conf.d"),
"Home\0",
config_item_perf_lookup, homed_gperf_lookup,
CONFIG_PARSE_WARN, m);
if (r < 0)
return r;
return 0;
}
DEFINE_CONFIG_PARSE_ENUM(config_parse_default_storage, user_storage, UserStorage, "Failed to parse default storage setting");
int config_parse_default_file_system_type(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
char **s = data;
assert(rvalue);
assert(s);
if (!isempty(rvalue) && !supported_fstype(rvalue)) {
log_syntax(unit, LOG_ERR, filename, line, 0, "Unsupported file system, ignoring: %s", rvalue);
return 0;
}
return free_and_strdup_warn(s, empty_to_null(rvalue));
}

12
src/home/homed-conf.h Normal file
View File

@ -0,0 +1,12 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include "conf-parser.h"
#include "homed-manager.h"
int manager_parse_config_file(Manager *m);
const struct ConfigPerfItem* homed_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
CONFIG_PARSER_PROTOTYPE(config_parse_default_storage);
CONFIG_PARSER_PROTOTYPE(config_parse_default_file_system_type);

View File

@ -0,0 +1,21 @@
%{
#if __GNUC__ >= 7
_Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"")
#endif
#include <stddef.h>
#include "conf-parser.h"
#include "homed-conf.h"
%}
struct ConfigPerfItem;
%null_strings
%language=ANSI-C
%define slot-name section_and_lvalue
%define hash-function-name homed_gperf_hash
%define lookup-function-name homed_gperf_lookup
%readonly-tables
%omit-struct-type
%struct-type
%includes
%%
Home.DefaultStorage, config_parse_default_storage, 0, offsetof(Manager, default_storage)
Home.DefaultFileSystemType, config_parse_default_file_system_type, 0, offsetof(Manager, default_file_system_type)

View File

@ -1011,6 +1011,18 @@ static int home_start_work(Home *h, const char *verb, UserRecord *hr, UserRecord
_exit(EXIT_FAILURE);
}
if (h->manager->default_storage >= 0)
if (setenv("SYSTEMD_HOME_DEFAULT_STORAGE", user_storage_to_string(h->manager->default_storage), 1) < 0) {
log_error_errno(errno, "Failed to set $SYSTEMD_HOME_DEFAULT_STORAGE: %m");
_exit(EXIT_FAILURE);
}
if (h->manager->default_file_system_type)
if (setenv("SYSTEMD_HOME_DEFAULT_FILE_SYSTEM_TYPE", h->manager->default_file_system_type, 1) < 0) {
log_error_errno(errno, "Failed to set $SYSTEMD_HOME_DEFAULT_FILE_SYSTEM_TYPE: %m");
_exit(EXIT_FAILURE);
}
r = rearrange_stdio(stdin_fd, stdout_fd, STDERR_FILENO);
if (r < 0) {
log_error_errno(r, "Failed to rearrange stdin/stdout/stderr: %m");

View File

@ -24,6 +24,7 @@
#include "fs-util.h"
#include "gpt.h"
#include "home-util.h"
#include "homed-conf.h"
#include "homed-home-bus.h"
#include "homed-home.h"
#include "homed-manager-bus.h"
@ -184,10 +185,18 @@ int manager_new(Manager **ret) {
assert(ret);
m = new0(Manager, 1);
m = new(Manager, 1);
if (!m)
return -ENOMEM;
*m = (Manager) {
.default_storage = _USER_STORAGE_INVALID,
};
r = manager_parse_config_file(m);
if (r < 0)
return r;
r = sd_event_default(&m->event);
if (r < 0)
return r;
@ -251,6 +260,8 @@ Manager* manager_free(Manager *m) {
varlink_server_unref(m->varlink_server);
free(m->default_file_system_type);
return mfree(m);
}

View File

@ -28,6 +28,8 @@ struct Manager {
Hashmap *homes_by_sysfs;
bool scan_slash_home;
UserStorage default_storage;
char *default_file_system_type;
sd_event_source *inotify_event_source;

16
src/home/homed.conf Normal file
View File

@ -0,0 +1,16 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See homed.conf(5) for details
[Resolve]
#DefaultStorage=
#DefaultFileSystemType=ext4

View File

@ -31,6 +31,8 @@ systemd_homed_sources = files('''
home-util.h
homed-bus.c
homed-bus.h
homed-conf.c
homed-conf.h
homed-home-bus.c
homed-home-bus.h
homed-home.c
@ -52,6 +54,14 @@ systemd_homed_sources = files('''
user-record-util.h
'''.split())
homed_gperf_c = custom_target(
'homed_gperf.c',
input : 'homed-gperf.gperf',
output : 'homed-gperf.c',
command : [gperf, '@INPUT@', '--output-file', '@OUTPUT@'])
systemd_homed_sources += [homed_gperf_c]
homectl_sources = files('''
home-util.c
home-util.h
@ -78,4 +88,7 @@ if conf.get('ENABLE_HOMED') == 1
install_dir : dbussystemservicedir)
install_data('org.freedesktop.home1.policy',
install_dir : polkitpolicydir)
install_data('homed.conf',
install_dir : pkgsysconfdir)
endif