Compare commits

..

No commits in common. "1f4faf21e8fc0605c1ee2b2c6ad4eedee1ab1825" and "c4ae2704b7e921a0b05486a7b201be6770a04ea7" have entirely different histories.

314 changed files with 2701 additions and 2339 deletions

33
fuzzbuzz.yaml Normal file
View File

@ -0,0 +1,33 @@
base: ubuntu:16.04
language: c
setup:
- sudo bash -c "echo 'deb-src http://archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse' >>/etc/apt/sources.list"
- sudo apt-get update -y
- sudo apt-get build-dep -y systemd
- sudo apt-get install -y python3-pip
- sudo apt-get install -y libfdisk-dev libp11-kit-dev libssl-dev libpwquality-dev
- pip3 install meson ninja
- export PATH="$HOME/.local/bin/:$PATH"
- CC=$FUZZ_CC CXX=$FUZZ_CXX meson -Dfuzzbuzz=true -Dfuzzbuzz-engine-dir=$(dirname "$FUZZ_ENGINE") -Dfuzzbuzz-engine=$(cut -d. -f1 <(basename "$FUZZ_ENGINE")) -Db_lundef=false ./build
- ninja -v -C ./build fuzzers
environment:
targets:
- name: fuzz-compress
harness:
binary: ./build/fuzz-compress
- name: fuzz-unit-file
harness:
binary: ./build/fuzz-unit-file
corpus: ./test/fuzz/fuzz-unit-file
- name: fuzz-journald-syslog
harness:
binary: ./build/fuzz-journald-syslog
corpus: ./test/fuzz/fuzz-journald-syslog
- name: fuzz-netdev-parser
harness:
binary: ./build/fuzz-netdev-parser
corpus: ./test/fuzz/fuzz-netdev-parser
- name: fuzz-network-parser
harness:
binary: ./build/fuzz-network-parser
corpus: ./test/fuzz/fuzz-network-parser

View File

@ -141,7 +141,6 @@
<varlistentry>
<term><varname>$SYSTEMD_LOG_TARGET</varname></term>
<term><varname>$SYSTEMD_LOG_LEVEL</varname></term>
<term><varname>$SYSTEMD_LOG_TIME</varname></term>
<term><varname>$SYSTEMD_LOG_COLOR</varname></term>
<term><varname>$SYSTEMD_LOG_LOCATION</varname></term>

View File

@ -63,11 +63,10 @@
<variablelist class='config-directives'>
<varlistentry>
<term><varname>LogColor=</varname></term>
<term><varname>LogLevel=</varname></term>
<term><varname>LogLocation=</varname></term>
<term><varname>LogTarget=</varname></term>
<term><varname>LogTime=</varname></term>
<term><varname>LogColor=</varname></term>
<term><varname>LogLocation=</varname></term>
<term><varname>DumpCore=yes</varname></term>
<term><varname>CrashChangeVT=no</varname></term>
<term><varname>CrashShell=no</varname></term>

View File

@ -1910,16 +1910,6 @@
<listitem><para>Similar to the <varname>DNS=</varname> settings described above, these
settings configure whether and what POP3 server information shall be emitted as part of
the DHCP lease. The same syntax, propagation semantics and defaults apply as for
<term><varname>SMTPServers=</varname></term>
<varname>DNS=</varname>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>SMTPServers=</varname></term>
<listitem><para>Similar to the <varname>DNS=</varname> setting described above, this
setting configures whether and what SMTP server information shall be emitted as part of
the DHCP lease. The same syntax, propagation semantics and defaults apply as for
<varname>DNS=</varname>.</para></listitem>
</varlistentry>

View File

@ -606,13 +606,6 @@
<title>Environment</title>
<variablelist class='environment-variables'>
<varlistentry>
<term><varname>$SYSTEMD_LOG_COLOR</varname></term>
<listitem><para>Controls whether systemd highlights important
log messages. This can be overridden with
<option>--log-color</option>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>$SYSTEMD_LOG_LEVEL</varname></term>
<listitem><para>systemd reads the log level from this
@ -620,13 +613,6 @@
<option>--log-level=</option>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>$SYSTEMD_LOG_LOCATION</varname></term>
<listitem><para>Controls whether systemd prints the code
location along with log messages. This can be overridden with
<option>--log-location</option>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>$SYSTEMD_LOG_TARGET</varname></term>
<listitem><para>systemd reads the log target from this
@ -635,10 +621,17 @@
</varlistentry>
<varlistentry>
<term><varname>$SYSTEMD_LOG_TIME</varname></term>
<listitem><para>Controls whether systemd prefixes log
messages with the current time. This can be overridden with
<option>--log-time=</option>.</para></listitem>
<term><varname>$SYSTEMD_LOG_COLOR</varname></term>
<listitem><para>Controls whether systemd highlights important
log messages. This can be overridden with
<option>--log-color=</option>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>$SYSTEMD_LOG_LOCATION</varname></term>
<listitem><para>Controls whether systemd prints the code
location along with log messages. This can be overridden with
<option>--log-location=</option>.</para></listitem>
</varlistentry>
<varlistentry>
@ -836,21 +829,18 @@
</varlistentry>
<varlistentry>
<term><varname>systemd.log_color</varname></term>
<term><varname>systemd.log_level=</varname></term>
<term><varname>systemd.log_location</varname></term>
<term><varname>systemd.log_target=</varname></term>
<term><varname>systemd.log_time</varname></term>
<term><varname>systemd.log_level=</varname></term>
<term><varname>systemd.log_location=</varname></term>
<term><varname>systemd.log_color</varname></term>
<listitem><para>Controls log output, with the same effect as the
<varname>$SYSTEMD_LOG_COLOR</varname>,
<varname>$SYSTEMD_LOG_TARGET</varname>,
<varname>$SYSTEMD_LOG_LEVEL</varname>,
<varname>$SYSTEMD_LOG_LOCATION</varname>,
<varname>$SYSTEMD_LOG_TARGET</varname>,
<varname>$SYSTEMD_LOG_TIME</varname>, environment variables described above.
<varname>systemd.log_color</varname>, <varname>systemd.log_location</varname>, and
<varname>systemd.log_time</varname> can be specified without an argument, with the
same effect as a positive boolean.</para></listitem>
<varname>$SYSTEMD_LOG_COLOR</varname> environment variables described above.
<varname>systemd.log_color</varname> can be specified without an argument,
with the same effect as a positive boolean.</para></listitem>
</varlistentry>
<varlistentry>
@ -1145,10 +1135,9 @@
</varlistentry>
<varlistentry>
<term><option>--log-color</option></term>
<term><option>--log-target=</option></term>
<listitem><para>Highlight important log messages. See <varname>systemd.log_color</varname> above.
</para></listitem>
<listitem><para>Set log target. See <varname>systemd.log_target</varname> above.</para></listitem>
</varlistentry>
<varlistentry>
@ -1157,6 +1146,13 @@
<listitem><para>Set log level. See <varname>systemd.log_level</varname> above.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--log-color</option></term>
<listitem><para>Highlight important log messages. See <varname>systemd.log_color</varname> above.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--log-location</option></term>
@ -1164,19 +1160,6 @@
above.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--log-target=</option></term>
<listitem><para>Set log target. See <varname>systemd.log_target</varname> above.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--log-time=</option></term>
<listitem><para>Prefix messages with timestamp. See <varname>systemd.log_time</varname> above.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--machine-id=</option></term>

View File

@ -39,22 +39,20 @@ conf.set_quoted('RELATIVE_SOURCE_PATH', relative_source_path)
want_ossfuzz = get_option('oss-fuzz')
want_libfuzzer = get_option('llvm-fuzz')
if want_ossfuzz + want_libfuzzer > 1
error('only one of oss-fuzz or llvm-fuzz can be specified')
want_fuzzbuzz = get_option('fuzzbuzz')
if want_ossfuzz + want_libfuzzer + want_fuzzbuzz > 1
error('only one of oss-fuzz, llvm-fuzz or fuzzbuzz can be specified')
endif
skip_deps = want_ossfuzz or want_libfuzzer
fuzzer_build = want_ossfuzz or want_libfuzzer
fuzzer_build = want_ossfuzz or want_libfuzzer or want_fuzzbuzz
#####################################################################
# Try to install the git pre-commit hook
add_git_hook_sh = find_program('tools/add-git-hook.sh', required : false)
if add_git_hook_sh.found()
git_hook = run_command(add_git_hook_sh)
if git_hook.returncode() == 0
message(git_hook.stdout().strip())
endif
git_hook = run_command(join_paths(project_source_root, 'tools/add-git-hook.sh'))
if git_hook.returncode() == 0
message(git_hook.stdout().strip())
endif
#####################################################################
@ -324,6 +322,8 @@ if want_libfuzzer
endif
elif want_ossfuzz
fuzzing_engine = meson.get_compiler('cpp').find_library('FuzzingEngine')
elif want_fuzzbuzz
fuzzing_engine = meson.get_compiler('cpp').find_library(get_option('fuzzbuzz-engine'), dirs: get_option('fuzzbuzz-engine-dir'))
endif
# Those generate many false positives, and we do not want to change the code to
@ -2506,7 +2506,7 @@ if conf.get('ENABLE_BINFMT') == 1
endif
if conf.get('ENABLE_REPART') == 1
exe = executable('systemd-repart',
executable('systemd-repart',
systemd_repart_sources,
include_directories : includes,
link_with : [libshared],
@ -2518,12 +2518,6 @@ if conf.get('ENABLE_REPART') == 1
install_rpath : rootlibexecdir,
install : true,
install_dir : rootbindir)
if want_tests != 'false'
test('test-repart',
test_repart_sh,
args : exe.full_path())
endif
endif
if conf.get('ENABLE_VCONSOLE') == 1
@ -2968,20 +2962,13 @@ if conf.get('ENABLE_NETWORKD') == 1
install_dir : rootbindir)
public_programs += exe
exe = executable('systemd-network-generator',
executable('systemd-network-generator',
network_generator_sources,
include_directories : includes,
link_with : [networkd_link_with],
install_rpath : rootlibexecdir,
install : true,
install_dir : rootlibexecdir)
if want_tests != 'false'
test('test-network-generator-conversion',
test_network_generator_conversion_sh,
# https://github.com/mesonbuild/meson/issues/2681
args : exe.full_path())
endif
endif
executable('systemd-sulogin-shell',
@ -3112,7 +3099,7 @@ foreach tuple : fuzzers
incs = tuple.length() >= 5 ? tuple[4] : includes
link_args = []
if want_ossfuzz
if want_ossfuzz or want_fuzzbuzz
dependencies += fuzzing_engine
elif want_libfuzzer
if fuzzing_engine.found()
@ -3124,6 +3111,10 @@ foreach tuple : fuzzers
sources += 'src/fuzz/fuzz-main.c'
endif
if want_fuzzbuzz
sources += 'src/fuzz/fuzzer-entry-point.c'
endif
name = sources[0].split('/')[-1].split('.')[0]
fuzzer_exes += executable(
@ -3483,7 +3474,6 @@ foreach tuple : [
['debug siphash'],
['valgrind', conf.get('VALGRIND') == 1],
['trace logging', conf.get('LOG_TRACE') == 1],
['install tests', install_tests],
['link-udev-shared', get_option('link-udev-shared')],
['link-systemctl-shared', get_option('link-systemctl-shared')],
['link-networkd-shared', get_option('link-networkd-shared')],

View File

@ -354,3 +354,9 @@ option('oss-fuzz', type : 'boolean', value : 'false',
description : 'build against oss-fuzz')
option('llvm-fuzz', type : 'boolean', value : 'false',
description : 'build against LLVM libFuzzer')
option('fuzzbuzz', type : 'boolean', value : 'false',
description : 'build against FuzzBuzz')
option('fuzzbuzz-engine', type : 'string',
description : 'the name of the FuzzBuzz fuzzing engine')
option('fuzzbuzz-engine-dir', type : 'string',
description : 'the directory where the FuzzBuzz fuzzing engine is')

View File

@ -17,7 +17,7 @@ PHASES=(${@:-SETUP RUN})
create_container() {
# create autopkgtest LXC image; this sometimes fails with "Unable to fetch
# GPG key from keyserver", so retry a few times
for retry in {1..5}; do
for retry in $(seq 5); do
sudo lxc-create -n $CONTAINER -t download -- -d $DISTRO -r $RELEASE -a $ARCH --keyserver hkp://keyserver.ubuntu.com:80 && break
sleep $((retry*retry))
done

View File

@ -51,7 +51,6 @@ static bool syslog_is_stream = false;
static bool show_color = false;
static bool show_location = false;
static bool show_time = false;
static bool upgrade_syslog_to_journal = false;
static bool always_reopen_console = false;
@ -333,10 +332,8 @@ static int write_to_console(
const char *func,
const char *buffer) {
char location[256],
header_time[FORMAT_TIMESTAMP_MAX],
prefix[1 + DECIMAL_STR_MAX(int) + 2];
struct iovec iovec[8] = {};
char location[256], prefix[1 + DECIMAL_STR_MAX(int) + 2];
struct iovec iovec[6] = {};
const char *on = NULL, *off = NULL;
size_t n = 0;
@ -348,13 +345,6 @@ static int write_to_console(
iovec[n++] = IOVEC_MAKE_STRING(prefix);
}
if (show_time) {
if (format_timestamp(header_time, sizeof(header_time), now(CLOCK_REALTIME))) {
iovec[n++] = IOVEC_MAKE_STRING(header_time);
iovec[n++] = IOVEC_MAKE_STRING(" ");
}
}
if (show_color)
get_log_colors(LOG_PRI(level), &on, &off, NULL);
@ -1109,12 +1099,6 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
if (log_show_location_from_string(value ?: "1") < 0)
log_warning("Failed to parse log location setting '%s'. Ignoring.", value);
} else if (proc_cmdline_key_streq(key, "systemd.log_time")) {
if (log_show_time_from_string(value ?: "1") < 0)
log_warning("Failed to parse log time setting '%s'. Ignoring.", value);
}
return 0;
@ -1146,10 +1130,6 @@ void log_parse_environment_realm(LogRealm realm) {
e = getenv("SYSTEMD_LOG_LOCATION");
if (e && log_show_location_from_string(e) < 0)
log_warning("Failed to parse log location '%s'. Ignoring.", e);
e = getenv("SYSTEMD_LOG_TIME");
if (e && log_show_time_from_string(e) < 0)
log_warning("Failed to parse log time '%s'. Ignoring.", e);
}
LogTarget log_get_target(void) {
@ -1176,14 +1156,6 @@ bool log_get_show_location(void) {
return show_location;
}
void log_show_time(bool b) {
show_time = b;
}
bool log_get_show_time(void) {
return show_time;
}
int log_show_color_from_string(const char *e) {
int t;
@ -1206,17 +1178,6 @@ int log_show_location_from_string(const char *e) {
return 0;
}
int log_show_time_from_string(const char *e) {
int t;
t = parse_boolean(e);
if (t < 0)
return t;
log_show_time(t);
return 0;
}
bool log_on_console(void) {
if (IN_SET(log_target, LOG_TARGET_CONSOLE,
LOG_TARGET_CONSOLE_PREFIXED))

View File

@ -59,12 +59,9 @@ void log_show_color(bool b);
bool log_get_show_color(void) _pure_;
void log_show_location(bool b);
bool log_get_show_location(void) _pure_;
void log_show_time(bool b);
bool log_get_show_time(void) _pure_;
int log_show_color_from_string(const char *e);
int log_show_location_from_string(const char *e);
int log_show_time_from_string(const char *e);
LogTarget log_get_target(void) _pure_;
int log_get_max_level_realm(LogRealm realm) _pure_;

View File

@ -171,7 +171,6 @@ basic_sources = files('''
process-util.h
procfs-util.c
procfs-util.h
pthread-util.h
quota-util.c
quota-util.h
random-util.c

View File

@ -1178,11 +1178,6 @@ int must_be_root(void) {
return log_error_errno(SYNTHETIC_ERRNO(EPERM), "Need to be root.");
}
static void restore_sigsetp(sigset_t **ssp) {
if (*ssp)
(void) sigprocmask(SIG_SETMASK, *ssp, NULL);
}
int safe_fork_full(
const char *name,
const int except_fds[],
@ -1192,8 +1187,7 @@ int safe_fork_full(
pid_t original_pid, pid;
sigset_t saved_ss, ss;
_cleanup_(restore_sigsetp) sigset_t *saved_ssp = NULL;
bool block_signals = false, block_all = false;
bool block_signals = false;
int prio, r;
/* A wrapper around fork(), that does a couple of important initializations in addition to mere forking. Always
@ -1208,7 +1202,7 @@ int safe_fork_full(
* be sure that SIGTERMs are not lost we might send to the child. */
assert_se(sigfillset(&ss) >= 0);
block_signals = block_all = true;
block_signals = true;
} else if (flags & FORK_WAIT) {
/* Let's block SIGCHLD at least, so that we can safely watch for the child process */
@ -1218,31 +1212,28 @@ int safe_fork_full(
block_signals = true;
}
if (block_signals) {
if (block_signals)
if (sigprocmask(SIG_SETMASK, &ss, &saved_ss) < 0)
return log_full_errno(prio, errno, "Failed to set signal mask: %m");
saved_ssp = &saved_ss;
}
if (flags & FORK_NEW_MOUNTNS)
pid = raw_clone(SIGCHLD|CLONE_NEWNS);
else
pid = fork();
if (pid < 0)
return log_full_errno(prio, errno, "Failed to fork: %m");
if (pid < 0) {
r = -errno;
if (block_signals) /* undo what we did above */
(void) sigprocmask(SIG_SETMASK, &saved_ss, NULL);
return log_full_errno(prio, r, "Failed to fork: %m");
}
if (pid > 0) {
/* We are in the parent process */
log_debug("Successfully forked off '%s' as PID " PID_FMT ".", strna(name), pid);
if (flags & FORK_WAIT) {
if (block_all) {
/* undo everything except SIGCHLD */
ss = saved_ss;
assert_se(sigaddset(&ss, SIGCHLD) >= 0);
(void) sigprocmask(SIG_SETMASK, &ss, NULL);
}
r = wait_for_terminate_and_check(name, pid, (flags & FORK_LOG ? WAIT_LOG : 0));
if (r < 0)
return r;
@ -1250,6 +1241,9 @@ int safe_fork_full(
return -EPROTO;
}
if (block_signals) /* undo what we did above */
(void) sigprocmask(SIG_SETMASK, &saved_ss, NULL);
if (ret_pid)
*ret_pid = pid;
@ -1258,9 +1252,6 @@ int safe_fork_full(
/* We are in the child process */
/* Restore signal mask manually */
saved_ssp = NULL;
if (flags & FORK_REOPEN_LOG) {
/* Close the logs if requested, before we log anything. And make sure we reopen it if needed. */
log_close();

View File

@ -1,16 +0,0 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include <pthread.h>
#include "macro.h"
static inline pthread_mutex_t* pthread_mutex_lock_assert(pthread_mutex_t *mutex) {
assert_se(pthread_mutex_lock(mutex) == 0);
return mutex;
}
static inline void pthread_mutex_unlock_assertp(pthread_mutex_t **mutexp) {
if (*mutexp)
assert_se(pthread_mutex_unlock(*mutexp) == 0);
}

View File

@ -542,9 +542,8 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
DEFINE_SETTER(config_parse_level2, log_set_max_level_from_string, "log level");
DEFINE_SETTER(config_parse_target, log_set_target_from_string, "target");
DEFINE_SETTER(config_parse_color, log_show_color_from_string, "color");
DEFINE_SETTER(config_parse_color, log_show_color_from_string, "color" );
DEFINE_SETTER(config_parse_location, log_show_location_from_string, "location");
DEFINE_SETTER(config_parse_time, log_show_time_from_string, "time");
static int config_parse_default_timeout_abort(
const char *unit,
@ -572,7 +571,6 @@ static int parse_config_file(void) {
{ "Manager", "LogTarget", config_parse_target, 0, NULL },
{ "Manager", "LogColor", config_parse_color, 0, NULL },
{ "Manager", "LogLocation", config_parse_location, 0, NULL },
{ "Manager", "LogTime", config_parse_time, 0, NULL },
{ "Manager", "DumpCore", config_parse_bool, 0, &arg_dump_core },
{ "Manager", "CrashChVT", /* legacy */ config_parse_crash_chvt, 0, &arg_crash_chvt },
{ "Manager", "CrashChangeVT", config_parse_crash_chvt, 0, &arg_crash_chvt },
@ -720,7 +718,6 @@ static int parse_argv(int argc, char *argv[]) {
ARG_LOG_TARGET,
ARG_LOG_COLOR,
ARG_LOG_LOCATION,
ARG_LOG_TIME,
ARG_UNIT,
ARG_SYSTEM,
ARG_USER,
@ -748,7 +745,6 @@ static int parse_argv(int argc, char *argv[]) {
{ "log-target", required_argument, NULL, ARG_LOG_TARGET },
{ "log-color", optional_argument, NULL, ARG_LOG_COLOR },
{ "log-location", optional_argument, NULL, ARG_LOG_LOCATION },
{ "log-time", optional_argument, NULL, ARG_LOG_TIME },
{ "unit", required_argument, NULL, ARG_UNIT },
{ "system", no_argument, NULL, ARG_SYSTEM },
{ "user", no_argument, NULL, ARG_USER },
@ -822,18 +818,6 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_LOG_TIME:
if (optarg) {
r = log_show_time_from_string(optarg);
if (r < 0)
return log_error_errno(r, "Failed to parse log time setting \"%s\": %m",
optarg);
} else
log_show_time(true);
break;
case ARG_DEFAULT_STD_OUTPUT:
r = exec_output_from_string(optarg);
if (r < 0)
@ -1053,7 +1037,6 @@ static int help(void) {
" --log-level=LEVEL Set log level (debug, info, notice, warning, err, crit, alert, emerg)\n"
" --log-color[=BOOL] Highlight important log messages\n"
" --log-location[=BOOL] Include code location in log messages\n"
" --log-time[=BOOL] Prefix log messages with current time\n"
" --default-standard-output= Set default standard output for services\n"
" --default-standard-error= Set default standard error output for services\n"
"\nSee the %s for details.\n"
@ -1436,9 +1419,6 @@ static int become_shutdown(
if (log_get_show_location())
command_line[pos++] = "--log-location";
if (log_get_show_time())
command_line[pos++] = "--log-time";
if (streq(shutdown_verb, "exit")) {
command_line[pos++] = "--exit-code";
command_line[pos++] = exit_code;

View File

@ -16,7 +16,6 @@
#LogTarget=journal-or-kmsg
#LogColor=yes
#LogLocation=no
#LogTime=no
#DumpCore=yes
#ShowStatus=yes
#CrashChangeVT=no

View File

@ -15,7 +15,6 @@
#LogTarget=console
#LogColor=yes
#LogLocation=no
#LogTime=no
#SystemCallArchitectures=
#TimerSlackNSec=
#StatusUnitFormat=@STATUS_UNIT_FORMAT_DEFAULT@

View File

@ -6,3 +6,6 @@
/* The entry point into the fuzzer */
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
/* https://docs.fuzzbuzz.io/developer-documentation/porting-targets-to-fuzzbuzz/libfuzzer-targets */
int FuzzerEntrypoint(const uint8_t *data, size_t size);

View File

@ -0,0 +1,5 @@
#include "fuzz.h"
int FuzzerEntrypoint(const uint8_t *data, size_t size) {
return LLVMFuzzerTestOneInput(data, size);
}

View File

@ -509,17 +509,14 @@ static void raw_pull_job_on_finished(PullJob *j) {
raw_pull_report_progress(i, RAW_FINALIZING);
if (i->raw_job->etag) {
/* Only make a read-only copy if ETag header is set. */
r = import_make_read_only_fd(i->raw_job->disk_fd);
if (r < 0)
goto finish;
r = import_make_read_only_fd(i->raw_job->disk_fd);
if (r < 0)
goto finish;
r = rename_noreplace(AT_FDCWD, i->temp_path, AT_FDCWD, i->final_path);
if (r < 0) {
log_error_errno(r, "Failed to rename raw file to %s: %m", i->final_path);
goto finish;
}
r = rename_noreplace(AT_FDCWD, i->temp_path, AT_FDCWD, i->final_path);
if (r < 0) {
log_error_errno(r, "Failed to rename raw file to %s: %m", i->final_path);
goto finish;
}
i->temp_path = mfree(i->temp_path);

View File

@ -64,9 +64,6 @@ struct sd_dhcp_lease {
struct in_addr *pop3_server;
size_t pop3_server_size;
struct in_addr *smtp_server;
size_t smtp_server_size;
struct sd_dhcp_route *static_route;
size_t static_route_size, static_route_allocated;

View File

@ -55,8 +55,8 @@ struct sd_dhcp_server {
char *timezone;
struct in_addr *ntp, *dns, *sip, *pop3_server, *smtp_server;
unsigned n_ntp, n_dns, n_sip, n_pop3_server, n_smtp_server;
struct in_addr *ntp, *dns, *sip, *pop3_server;
unsigned n_ntp, n_dns, n_sip, n_pop3_server;
OrderedHashmap *extra_options;
OrderedHashmap *vendor_options;

View File

@ -140,17 +140,6 @@ int sd_dhcp_lease_get_pop3_server(sd_dhcp_lease *lease, const struct in_addr **a
return (int) lease->pop3_server_size;
}
int sd_dhcp_lease_get_smtp_server(sd_dhcp_lease *lease, const struct in_addr **addr) {
assert_return(lease, -EINVAL);
assert_return(addr, -EINVAL);
if (lease->smtp_server_size <= 0)
return -ENODATA;
*addr = lease->smtp_server;
return (int) lease->smtp_server_size;
}
int sd_dhcp_lease_get_domainname(sd_dhcp_lease *lease, const char **domainname) {
assert_return(lease, -EINVAL);
assert_return(domainname, -EINVAL);
@ -302,7 +291,6 @@ static sd_dhcp_lease *dhcp_lease_free(sd_dhcp_lease *lease) {
free(lease->ntp);
free(lease->sip);
free(lease->pop3_server);
free(lease->smtp_server);
free(lease->static_route);
free(lease->client_id);
free(lease->vendor_specific);
@ -631,12 +619,6 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option, void
log_debug_errno(r, "Failed to parse POP3 server, ignoring: %m");
break;
case SD_DHCP_OPTION_SMTP_SERVER:
r = lease_parse_in_addrs(option, len, &lease->smtp_server, &lease->smtp_server_size);
if (r < 0)
log_debug_errno(r, "Failed to parse SMTP server, ignoring: %m");
break;
case SD_DHCP_OPTION_STATIC_ROUTE:
r = lease_parse_routes(option, len, &lease->static_route, &lease->static_route_size, &lease->static_route_allocated);
if (r < 0)
@ -1074,7 +1056,6 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) {
*ntp = NULL,
*sip = NULL,
*pop3_server = NULL,
*smtp_server = NULL,
*mtu = NULL,
*routes = NULL,
*domains = NULL,
@ -1105,7 +1086,6 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) {
"NTP", &ntp,
"SIP", &sip,
"POP3_SERVERS", &pop3_server,
"SMTP_SERVERS", &smtp_server,
"MTU", &mtu,
"DOMAINNAME", &lease->domainname,
"HOSTNAME", &lease->hostname,
@ -1226,14 +1206,6 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) {
lease->pop3_server_size = r;
}
if (smtp_server) {
r = deserialize_in_addrs(&lease->smtp_server, smtp_server);
if (r < 0)
log_debug_errno(r, "Failed to deserialize SMTP server %s, ignoring: %m", smtp_server);
else
lease->smtp_server_size = r;
}
if (mtu) {
r = safe_atou16(mtu, &lease->mtu);
if (r < 0)

View File

@ -141,7 +141,6 @@ static sd_dhcp_server *dhcp_server_free(sd_dhcp_server *server) {
free(server->ntp);
free(server->sip);
free(server->pop3_server);
free(server->smtp_server);
hashmap_free(server->leases_by_client_id);
@ -524,15 +523,6 @@ static int server_send_ack(sd_dhcp_server *server, DHCPRequest *req,
return r;
}
if (server->n_smtp_server > 0) {
r = dhcp_option_append(
&packet->dhcp, req->max_optlen, &offset, 0,
SD_DHCP_OPTION_SMTP_SERVER,
sizeof(struct in_addr) * server->n_smtp_server, server->smtp_server);
if (r < 0)
return r;
}
if (server->timezone) {
r = dhcp_option_append(
&packet->dhcp, req->max_optlen, &offset, 0,
@ -1226,31 +1216,6 @@ int sd_dhcp_server_set_pop3_server(sd_dhcp_server *server, const struct in_addr
return 1;
}
int sd_dhcp_server_set_smtp_server(sd_dhcp_server *server, const struct in_addr smtp_server[], unsigned n) {
assert_return(server, -EINVAL);
assert_return(smtp_server || n <= 0, -EINVAL);
if (server->n_smtp_server == n &&
memcmp(server->smtp_server, smtp_server, sizeof(struct in_addr) * n) == 0)
return 0;
if (n <= 0) {
server->smtp_server = mfree(server->smtp_server);
server->n_smtp_server = 0;
} else {
struct in_addr *c;
c = newdup(struct in_addr, smtp_server, n);
if (!c)
return -ENOMEM;
free_and_replace(server->smtp_server, c);
server->n_smtp_server = n;
}
return 1;
}
int sd_dhcp_server_set_emit_router(sd_dhcp_server *server, int enabled) {
assert_return(server, -EINVAL);

View File

@ -260,10 +260,6 @@ _public_ int sd_network_link_get_pop3_servers(int ifindex, char ***pop3) {
return network_link_get_strv(ifindex, "POP3_SERVERS", pop3);
}
_public_ int sd_network_link_get_smtp_servers(int ifindex, char ***ret) {
return network_link_get_strv(ifindex, "SMTP_SERVERS", ret);
}
_public_ int sd_network_link_get_dns_default_route(int ifindex) {
char path[STRLEN("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex) + 1];
_cleanup_free_ char *s = NULL;

View File

@ -1241,7 +1241,7 @@ static int link_status_one(
const LinkInfo *info) {
_cleanup_strv_free_ char **dns = NULL, **ntp = NULL, **sip = NULL, **search_domains = NULL, **route_domains = NULL,
**pop3_server = NULL, **smtp_server = NULL;
**pop3_server = NULL;
_cleanup_free_ char *setup_state = NULL, *operational_state = NULL, *tz = NULL;
_cleanup_free_ char *t = NULL, *network = NULL;
const char *driver = NULL, *path = NULL, *vendor = NULL, *model = NULL, *link = NULL;
@ -1269,7 +1269,6 @@ static int link_status_one(
(void) sd_network_link_get_ntp(info->ifindex, &ntp);
(void) sd_network_link_get_sip(info->ifindex, &sip);
(void) sd_network_link_get_pop3_servers(info->ifindex, &pop3_server);
(void) sd_network_link_get_smtp_servers(info->ifindex, &smtp_server);
if (info->sd_device) {
(void) sd_device_get_property_value(info->sd_device, "ID_NET_LINK_FILE", &link);
@ -1833,9 +1832,6 @@ static int link_status_one(
if (r < 0)
return r;
r = dump_list(table, "POP3 servers:", pop3_server);
if (r < 0)
return r;
r = dump_list(table, "SMTP servers:", smtp_server);
if (r < 0)
return r;
r = dump_ifindexes(table, "Carrier Bound To:", carrier_bound_to);

View File

@ -189,55 +189,6 @@ static int link_push_uplink_pop3_to_dhcp_server(Link *link, sd_dhcp_server *s) {
return sd_dhcp_server_set_pop3_server(s, addresses, n_addresses);
}
static int link_push_uplink_smtp_to_dhcp_server(Link *link, sd_dhcp_server *s) {
_cleanup_free_ struct in_addr *addresses = NULL;
size_t n_addresses = 0, n_allocated = 0;
char **a;
if (!link->network)
return 0;
log_link_debug(link, "Copying SMTP server information from link");
STRV_FOREACH(a, link->network->smtp) {
union in_addr_union ia;
/* Only look for IPv4 addresses */
if (in_addr_from_string(AF_INET, *a, &ia) <= 0)
continue;
/* Never propagate obviously borked data */
if (in4_addr_is_null(&ia.in) || in4_addr_is_localhost(&ia.in))
continue;
if (!GREEDY_REALLOC(addresses, n_allocated, n_addresses + 1))
return log_oom();
addresses[n_addresses++] = ia.in;
}
if (link->dhcp_lease) {
const struct in_addr *da = NULL;
int j, n;
n = sd_dhcp_lease_get_smtp_server(link->dhcp_lease, &da);
if (n > 0) {
if (!GREEDY_REALLOC(addresses, n_allocated, n_addresses + n))
return log_oom();
for (j = 0; j < n; j++)
if (in4_addr_is_non_local(&da[j]))
addresses[n_addresses++] = da[j];
}
}
if (n_addresses <= 0)
return 0;
return sd_dhcp_server_set_smtp_server(s, addresses, n_addresses);
}
static int link_push_uplink_sip_to_dhcp_server(Link *link, sd_dhcp_server *s) {
_cleanup_free_ struct in_addr *addresses = NULL;
size_t n_addresses = 0, n_allocated = 0;
@ -379,36 +330,21 @@ int dhcp4_server_configure(Link *link) {
log_link_warning_errno(link, r, "Failed to set SIP server for DHCP server, ignoring: %m");
}
if (link->network->n_dhcp_server_pop3 > 0)
r = sd_dhcp_server_set_pop3_server(link->dhcp_server, link->network->dhcp_server_pop3, link->network->n_dhcp_server_pop3);
else {
if (!acquired_uplink)
uplink = manager_find_uplink(link->manager, link);
if (link->network->n_dhcp_server_pop3 > 0)
r = sd_dhcp_server_set_pop3_server(link->dhcp_server, link->network->dhcp_server_pop3, link->network->n_dhcp_server_pop3);
else {
if (!acquired_uplink)
uplink = manager_find_uplink(link->manager, link);
if (!uplink) {
log_link_debug(link, "Not emitting POP3 server information on link, couldn't find suitable uplink.");
r = 0;
} else
r = link_push_uplink_pop3_to_dhcp_server(uplink, link->dhcp_server);
}
if (r < 0)
log_link_warning_errno(link, r, "Failed to set POP3 server for DHCP server, ignoring: %m");
if (link->network->n_dhcp_server_smtp > 0)
r = sd_dhcp_server_set_smtp_server(link->dhcp_server, link->network->dhcp_server_smtp, link->network->n_dhcp_server_smtp);
else {
if (!acquired_uplink)
uplink = manager_find_uplink(link->manager, link);
if (!uplink) {
log_link_debug(link, "Not emitting SMTP server information on link, couldn't find suitable uplink.");
r = 0;
} else
r = link_push_uplink_smtp_to_dhcp_server(uplink, link->dhcp_server);
}
if (r < 0)
log_link_warning_errno(link, r, "Failed to SMTP server for DHCP server, ignoring: %m");
if (!uplink) {
log_link_debug(link, "Not emitting POP3 server information on link, couldn't find suitable uplink.");
r = 0;
} else
r = link_push_uplink_pop3_to_dhcp_server(uplink, link->dhcp_server);
}
if (r < 0)
log_link_warning_errno(link, r, "Failed to set POP3 server for DHCP server, ignoring: %m");
r = sd_dhcp_server_set_emit_router(link->dhcp_server, link->network->dhcp_server_emit_router);
if (r < 0)
@ -614,8 +550,6 @@ int config_parse_dhcp_server_sip(
m[n->n_dhcp_server_sip++] = a.in;
n->dhcp_server_sip = m;
}
return 0;
}
int config_parse_dhcp_server_pop3_servers(
@ -668,60 +602,4 @@ int config_parse_dhcp_server_pop3_servers(
m[n->n_dhcp_server_pop3++] = a.in;
n->dhcp_server_pop3 = m;
}
return 0;
}
int config_parse_dhcp_server_smtp_servers(
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) {
Network *n = data;
const char *p = rvalue;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
for (;;) {
_cleanup_free_ char *w = NULL;
union in_addr_union a;
struct in_addr *m;
r = extract_first_word(&p, &w, NULL, 0);
if (r == -ENOMEM)
return log_oom();
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Failed to extract word, ignoring: %s", rvalue);
return 0;
}
if (r == 0)
return 0;
r = in_addr_from_string(AF_INET, w, &a);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Failed to parse SMTP server address '%s', ignoring: %m", w);
continue;
}
m = reallocarray(n->dhcp_server_smtp, n->n_dhcp_server_smtp + 1, sizeof(struct in_addr));
if (!m)
return log_oom();
m[n->n_dhcp_server_smtp++] = a.in;
n->dhcp_server_smtp = m;
}
return 0;
}

View File

@ -13,4 +13,3 @@ CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_dns);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_ntp);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_sip);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_pop3_servers);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_smtp_servers);

View File

@ -4106,12 +4106,6 @@ int link_save(Link *link) {
space = false;
fputstrv(f, link->network->pop3, NULL, &space);
fputc('\n', f);
fputs("SMTP_SERVERS=", f);
space = false;
fputstrv(f, link->network->smtp, NULL, &space);
if (link->dhcp_lease) {
const struct in_addr *addresses;
@ -4121,15 +4115,6 @@ int link_save(Link *link) {
space = true;
}
if (link->dhcp_lease) {
const struct in_addr *addresses;
r = sd_dhcp_lease_get_smtp_server(link->dhcp_lease, &addresses);
if (r > 0)
if (serialize_in_addrs(f, addresses, r, space, in4_addr_is_non_local) > 0)
space = true;
}
if (link->network->dhcp6_use_ntp && dhcp6_lease) {
struct in6_addr *in6_addrs;
char **hosts;

View File

@ -1490,7 +1490,7 @@ static int ordered_set_put_in4_addrv(OrderedSet *s,
static int manager_save(Manager *m) {
_cleanup_ordered_set_free_free_ OrderedSet *dns = NULL, *ntp = NULL, *sip = NULL, *pop3 = NULL,
*smtp = NULL, *search_domains = NULL, *route_domains = NULL;
*search_domains = NULL, *route_domains = NULL;
const char *operstate_str, *carrier_state_str, *address_state_str;
LinkOperationalState operstate = LINK_OPERSTATE_OFF;
LinkCarrierState carrier_state = LINK_CARRIER_STATE_OFF;
@ -1521,10 +1521,6 @@ static int manager_save(Manager *m) {
pop3 = ordered_set_new(&string_hash_ops);
if (!pop3)
return -ENOMEM;
smtp = ordered_set_new(&string_hash_ops);
if (!smtp)
return -ENOMEM;
search_domains = ordered_set_new(&dns_name_hash_ops);
@ -1602,6 +1598,7 @@ static int manager_save(Manager *m) {
return r;
}
r = sd_dhcp_lease_get_pop3_server(link->dhcp_lease, &addresses);
if (r > 0) {
r = ordered_set_put_in4_addrv(pop3, addresses, r, in4_addr_is_non_local);
@ -1610,14 +1607,6 @@ static int manager_save(Manager *m) {
} else if (r < 0 && r != -ENODATA)
return r;
r = sd_dhcp_lease_get_smtp_server(link->dhcp_lease, &addresses);
if (r > 0) {
r = ordered_set_put_in4_addrv(smtp, addresses, r, in4_addr_is_non_local);
if (r < 0)
return r;
} else if (r < 0 && r != -ENODATA)
return r;
if (link->network->dhcp_use_domains != DHCP_USE_DOMAINS_NO) {
const char *domainname;
char **domains = NULL;
@ -1670,7 +1659,6 @@ static int manager_save(Manager *m) {
ordered_set_print(f, "NTP=", ntp);
ordered_set_print(f, "SIP=", sip);
ordered_set_print(f, "POP3_SERVERS=", pop3);
ordered_set_print(f, "SMTP_SERVERS=", smtp);
ordered_set_print(f, "DOMAINS=", search_domains);
ordered_set_print(f, "ROUTE_DOMAINS=", route_domains);

View File

@ -208,7 +208,6 @@ DHCPServer.NTP, config_parse_dhcp_server_ntp,
DHCPServer.EmitSIP, config_parse_bool, 0, offsetof(Network, dhcp_server_emit_sip)
DHCPServer.SIP, config_parse_dhcp_server_sip, 0, 0
DHCPServer.POP3Servers, config_parse_dhcp_server_pop3_servers, 0, 0
DHCPServer.SMTPServers, config_parse_dhcp_server_smtp_servers, 0, 0
DHCPServer.EmitRouter, config_parse_bool, 0, offsetof(Network, dhcp_server_emit_router)
DHCPServer.EmitTimezone, config_parse_bool, 0, offsetof(Network, dhcp_server_emit_timezone)
DHCPServer.Timezone, config_parse_timezone, 0, offsetof(Network, dhcp_server_timezone)

View File

@ -652,7 +652,6 @@ static Network *network_free(Network *network) {
strv_free(network->ntp);
free(network->dns);
strv_free(network->sip);
strv_free(network->smtp);
ordered_set_free_free(network->search_domains);
ordered_set_free_free(network->route_domains);
strv_free(network->bind_carrier);

View File

@ -150,9 +150,6 @@ struct Network {
struct in_addr *dhcp_server_pop3;
unsigned n_dhcp_server_pop3;
struct in_addr *dhcp_server_smtp;
unsigned n_dhcp_server_smtp;
bool dhcp_server_emit_router;
bool dhcp_server_emit_timezone;
char *dhcp_server_timezone;
@ -303,7 +300,6 @@ struct Network {
char **ntp;
char **sip;
char **pop3;
char **smtp;
char **bind_carrier;
};

View File

@ -9,7 +9,6 @@
#include "group-record-nss.h"
#include "macro.h"
#include "nss-util.h"
#include "pthread-util.h"
#include "signal-util.h"
#include "strv.h"
#include "user-util.h"
@ -278,11 +277,10 @@ static enum nss_status nss_systemd_endent(GetentData *p) {
assert(p);
_cleanup_(pthread_mutex_unlock_assertp) pthread_mutex_t *_l = NULL;
_l = pthread_mutex_lock_assert(&p->mutex);
assert_se(pthread_mutex_lock(&p->mutex) == 0);
p->iterator = userdb_iterator_free(p->iterator);
p->by_membership = false;
assert_se(pthread_mutex_unlock(&p->mutex) == 0);
return NSS_STATUS_SUCCESS;
}
@ -296,41 +294,45 @@ enum nss_status _nss_systemd_endgrent(void) {
}
enum nss_status _nss_systemd_setpwent(int stayopen) {
enum nss_status ret;
PROTECT_ERRNO;
BLOCK_SIGNALS(NSS_SIGNALS_BLOCK);
if (userdb_nss_compat_is_enabled() <= 0)
return NSS_STATUS_NOTFOUND;
_cleanup_(pthread_mutex_unlock_assertp) pthread_mutex_t *_l = NULL;
int r;
_l = pthread_mutex_lock_assert(&getpwent_data.mutex);
assert_se(pthread_mutex_lock(&getpwent_data.mutex) == 0);
getpwent_data.iterator = userdb_iterator_free(getpwent_data.iterator);
getpwent_data.by_membership = false;
r = userdb_all(nss_glue_userdb_flags(), &getpwent_data.iterator);
return r < 0 ? NSS_STATUS_UNAVAIL : NSS_STATUS_SUCCESS;
ret = userdb_all(nss_glue_userdb_flags(), &getpwent_data.iterator) < 0 ?
NSS_STATUS_UNAVAIL : NSS_STATUS_SUCCESS;
assert_se(pthread_mutex_unlock(&getpwent_data.mutex) == 0);
return ret;
}
enum nss_status _nss_systemd_setgrent(int stayopen) {
enum nss_status ret;
PROTECT_ERRNO;
BLOCK_SIGNALS(NSS_SIGNALS_BLOCK);
if (userdb_nss_compat_is_enabled() <= 0)
return NSS_STATUS_NOTFOUND;
_cleanup_(pthread_mutex_unlock_assertp) pthread_mutex_t *_l = NULL;
int r;
_l = pthread_mutex_lock_assert(&getgrent_data.mutex);
assert_se(pthread_mutex_lock(&getgrent_data.mutex) == 0);
getgrent_data.iterator = userdb_iterator_free(getgrent_data.iterator);
getpwent_data.by_membership = false;
r = groupdb_all(nss_glue_userdb_flags(), &getgrent_data.iterator);
return r < 0 ? NSS_STATUS_UNAVAIL : NSS_STATUS_SUCCESS;
ret = groupdb_all(nss_glue_userdb_flags(), &getgrent_data.iterator) < 0 ?
NSS_STATUS_UNAVAIL : NSS_STATUS_SUCCESS;
assert_se(pthread_mutex_unlock(&getgrent_data.mutex) == 0);
return ret;
}
enum nss_status _nss_systemd_getpwent_r(
@ -339,6 +341,7 @@ enum nss_status _nss_systemd_getpwent_r(
int *errnop) {
_cleanup_(user_record_unrefp) UserRecord *ur = NULL;
enum nss_status ret;
int r;
PROTECT_ERRNO;
@ -356,33 +359,40 @@ enum nss_status _nss_systemd_getpwent_r(
if (!r)
return NSS_STATUS_NOTFOUND;
_cleanup_(pthread_mutex_unlock_assertp) pthread_mutex_t *_l = NULL;
_l = pthread_mutex_lock_assert(&getpwent_data.mutex);
assert_se(pthread_mutex_lock(&getpwent_data.mutex) == 0);
if (!getpwent_data.iterator) {
UNPROTECT_ERRNO;
*errnop = EHOSTDOWN;
return NSS_STATUS_UNAVAIL;
ret = NSS_STATUS_UNAVAIL;
goto finish;
}
r = userdb_iterator_get(getpwent_data.iterator, &ur);
if (r == -ESRCH)
return NSS_STATUS_NOTFOUND;
if (r == -ESRCH) {
ret = NSS_STATUS_NOTFOUND;
goto finish;
}
if (r < 0) {
UNPROTECT_ERRNO;
*errnop = -r;
return NSS_STATUS_UNAVAIL;
ret = NSS_STATUS_UNAVAIL;
goto finish;
}
r = nss_pack_user_record(ur, result, buffer, buflen);
if (r < 0) {
UNPROTECT_ERRNO;
*errnop = -r;
return NSS_STATUS_TRYAGAIN;
ret = NSS_STATUS_TRYAGAIN;
goto finish;
}
return NSS_STATUS_SUCCESS;
ret = NSS_STATUS_SUCCESS;
finish:
assert_se(pthread_mutex_unlock(&getpwent_data.mutex) == 0);
return ret;
}
enum nss_status _nss_systemd_getgrent_r(
@ -392,6 +402,7 @@ enum nss_status _nss_systemd_getgrent_r(
_cleanup_(group_record_unrefp) GroupRecord *gr = NULL;
_cleanup_free_ char **members = NULL;
enum nss_status ret;
int r;
PROTECT_ERRNO;
@ -409,20 +420,19 @@ enum nss_status _nss_systemd_getgrent_r(
if (!r)
return NSS_STATUS_UNAVAIL;
_cleanup_(pthread_mutex_unlock_assertp) pthread_mutex_t *_l = NULL;
_l = pthread_mutex_lock_assert(&getgrent_data.mutex);
assert_se(pthread_mutex_lock(&getgrent_data.mutex) == 0);
if (!getgrent_data.iterator) {
UNPROTECT_ERRNO;
*errnop = EHOSTDOWN;
return NSS_STATUS_UNAVAIL;
ret = NSS_STATUS_UNAVAIL;
goto finish;
}
if (!getgrent_data.by_membership) {
r = groupdb_iterator_get(getgrent_data.iterator, &gr);
if (r == -ESRCH) {
/* So we finished iterating native groups now. Let's now continue with iterating
/* So we finished iterating native groups now. let's now continue with iterating
* native memberships, and generate additional group entries for any groups
* referenced there that are defined in NSS only. This means for those groups there
* will be two or more entries generated during iteration, but this is apparently how
@ -434,20 +444,23 @@ enum nss_status _nss_systemd_getgrent_r(
if (r < 0) {
UNPROTECT_ERRNO;
*errnop = -r;
return NSS_STATUS_UNAVAIL;
ret = NSS_STATUS_UNAVAIL;
goto finish;
}
getgrent_data.by_membership = true;
} else if (r < 0) {
UNPROTECT_ERRNO;
*errnop = -r;
return NSS_STATUS_UNAVAIL;
ret = NSS_STATUS_UNAVAIL;
goto finish;
} else if (!STR_IN_SET(gr->group_name, root_group.gr_name, nobody_group.gr_name)) {
r = membershipdb_by_group_strv(gr->group_name, nss_glue_userdb_flags(), &members);
if (r < 0) {
UNPROTECT_ERRNO;
*errnop = -r;
return NSS_STATUS_UNAVAIL;
ret = NSS_STATUS_UNAVAIL;
goto finish;
}
}
}
@ -459,12 +472,15 @@ enum nss_status _nss_systemd_getgrent_r(
_cleanup_free_ char *user_name = NULL, *group_name = NULL;
r = membershipdb_iterator_get(getgrent_data.iterator, &user_name, &group_name);
if (r == -ESRCH)
return NSS_STATUS_NOTFOUND;
if (r == -ESRCH) {
ret = NSS_STATUS_NOTFOUND;
goto finish;
}
if (r < 0) {
UNPROTECT_ERRNO;
*errnop = -r;
return NSS_STATUS_UNAVAIL;
ret = NSS_STATUS_UNAVAIL;
goto finish;
}
if (STR_IN_SET(user_name, root_passwd.pw_name, nobody_passwd.pw_name))
@ -478,7 +494,8 @@ enum nss_status _nss_systemd_getgrent_r(
if (lock_fd < 0 && lock_fd != -EBUSY) {
UNPROTECT_ERRNO;
*errnop = -lock_fd;
return NSS_STATUS_UNAVAIL;
ret = NSS_STATUS_UNAVAIL;
goto finish;
}
}
@ -508,10 +525,15 @@ enum nss_status _nss_systemd_getgrent_r(
if (r < 0) {
UNPROTECT_ERRNO;
*errnop = -r;
return NSS_STATUS_TRYAGAIN;
ret = NSS_STATUS_TRYAGAIN;
goto finish;
}
return NSS_STATUS_SUCCESS;
ret = NSS_STATUS_SUCCESS;
finish:
assert_se(pthread_mutex_unlock(&getgrent_data.mutex) == 0);
return ret;
}
enum nss_status _nss_systemd_initgroups_dyn(

View File

@ -3,5 +3,3 @@
systemd_repart_sources = files('''
repart.c
'''.split())
test_repart_sh = find_program('test-repart.sh')

View File

@ -1,111 +0,0 @@
#!/usr/bin/env bash
set -ex
repart=$1
test -x $repart
D=$(mktemp --directory)
trap "rm -rf '$D'" EXIT INT QUIT PIPE
mkdir -p $D/definitions
truncate -s 1G $D/zzz
SEED=e2a40bf9-73f1-4278-9160-49c031e7aef8
$repart $D/zzz --empty=force --dry-run=no --seed=$SEED
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' > $D/empty
cmp $D/empty - <<EOF
label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: $D/zzz
unit: sectors
first-lba: 2048
last-lba: 2097118
EOF
cat >$D/definitions/root.conf <<EOF
[Partition]
Type=root
EOF
ln -s root.conf $D/definitions/root2.conf
cat >$D/definitions/home.conf <<EOF
[Partition]
Type=home
EOF
cat > $D/definitions/swap.conf <<EOF
[Partition]
Type=swap
SizeMaxBytes=64M
PaddingMinBytes=92M
EOF
$repart $D/zzz --dry-run=no --seed=$SEED --definitions=$D/definitions
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated
cmp $D/populated - <<EOF
label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: $D/zzz
unit: sectors
first-lba: 2048
last-lba: 2097118
$D/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=A6005774-F558-4330-A8E5-D6D2C01C01D6, name="home"
$D/zzz2 : start= 593904, size= 591856, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=CE9C76EB-A8F1-40FF-813C-11DCA6C0A55B, name="root-x86-64"
$D/zzz3 : start= 1185760, size= 591864, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=AC60A837-550C-43BD-B5C4-9CB73B884E79, name="root-x86-64-2"
$D/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=2AA78CDB-59C7-4173-AF11-C7453737A5D1, name="swap"
EOF
cat >$D/definitions/swap.conf <<EOF
[Partition]
Type=swap
SizeMaxBytes=64M
EOF
cat >$D/definitions/extra.conf <<EOF
[Partition]
Type=linux-generic
EOF
$repart $D/zzz --dry-run=no --seed=$SEED --definitions=$D/definitions
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated2
cmp $D/populated2 - <<EOF
label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: $D/zzz
unit: sectors
first-lba: 2048
last-lba: 2097118
$D/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=A6005774-F558-4330-A8E5-D6D2C01C01D6, name="home"
$D/zzz2 : start= 593904, size= 591856, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=CE9C76EB-A8F1-40FF-813C-11DCA6C0A55B, name="root-x86-64"
$D/zzz3 : start= 1185760, size= 591864, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=AC60A837-550C-43BD-B5C4-9CB73B884E79, name="root-x86-64-2"
$D/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=2AA78CDB-59C7-4173-AF11-C7453737A5D1, name="swap"
$D/zzz5 : start= 1908696, size= 188416, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=03477476-06AD-44E8-9EF4-BC2BD7771289, name="linux-generic"
EOF
truncate -s 2G $D/zzz
$repart $D/zzz --dry-run=no --seed=$SEED --definitions=$D/definitions
sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated3
cmp $D/populated3 - <<EOF
label: gpt
label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
device: $D/zzz
unit: sectors
first-lba: 2048
last-lba: 4194270
$D/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=A6005774-F558-4330-A8E5-D6D2C01C01D6, name="home"
$D/zzz2 : start= 593904, size= 591856, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=CE9C76EB-A8F1-40FF-813C-11DCA6C0A55B, name="root-x86-64"
$D/zzz3 : start= 1185760, size= 591864, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=AC60A837-550C-43BD-B5C4-9CB73B884E79, name="root-x86-64-2"
$D/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=2AA78CDB-59C7-4173-AF11-C7453737A5D1, name="swap"
$D/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=03477476-06AD-44E8-9EF4-BC2BD7771289, name="linux-generic"
EOF

View File

@ -92,6 +92,7 @@ static void test_packet_from_file(const char* filename, bool canonical) {
int main(int argc, char **argv) {
int i, N;
_cleanup_free_ char *pkts_glob = NULL;
_cleanup_globfree_ glob_t g = {};
char **fnames;
@ -101,8 +102,7 @@ int main(int argc, char **argv) {
N = argc - 1;
fnames = argv + 1;
} else {
_cleanup_free_ char *pkts_glob = NULL;
assert_se(get_testdata_dir("test-resolve/*.pkts", &pkts_glob) >= 0);
pkts_glob = path_join(get_testdata_dir(), "test-resolve/*.pkts");
assert_se(glob(pkts_glob, GLOB_NOSORT, NULL, &g) == 0);
N = g.gl_pathc;
fnames = g.gl_pathv;

View File

@ -58,25 +58,21 @@ static void load_testdata_env(void) {
setenv(*k, *v, 0);
}
int get_testdata_dir(const char *suffix, char **ret) {
const char *dir;
char *p;
const char* get_testdata_dir(void) {
const char *env;
load_testdata_env();
/* if the env var is set, use that */
dir = getenv("SYSTEMD_TEST_DATA");
if (!dir)
dir = SYSTEMD_TEST_DATA;
if (access(dir, F_OK) < 0)
return log_error_errno(errno, "ERROR: $SYSTEMD_TEST_DATA directory [%s] not accesible: %m", dir);
env = getenv("SYSTEMD_TEST_DATA");
if (!env)
env = SYSTEMD_TEST_DATA;
if (access(env, F_OK) < 0) {
fprintf(stderr, "ERROR: $SYSTEMD_TEST_DATA directory [%s] does not exist\n", env);
exit(EXIT_FAILURE);
}
p = path_join(dir, suffix);
if (!p)
return log_oom();
*ret = p;
return 0;
return env;
}
const char* get_catalog_dir(void) {

View File

@ -20,7 +20,7 @@ static inline bool manager_errno_skip_test(int r) {
char* setup_fake_runtime_dir(void);
int enter_cgroup_subroot(char **ret_cgroup);
int get_testdata_dir(const char *suffix, char **ret);
const char* get_testdata_dir(void);
const char* get_catalog_dir(void);
bool slow_tests_enabled(void);
void test_setup_logging(int level);

View File

@ -51,7 +51,6 @@ static int parse_argv(int argc, char *argv[]) {
ARG_LOG_TARGET,
ARG_LOG_COLOR,
ARG_LOG_LOCATION,
ARG_LOG_TIME,
ARG_EXIT_CODE,
ARG_TIMEOUT,
};
@ -61,7 +60,6 @@ static int parse_argv(int argc, char *argv[]) {
{ "log-target", required_argument, NULL, ARG_LOG_TARGET },
{ "log-color", optional_argument, NULL, ARG_LOG_COLOR },
{ "log-location", optional_argument, NULL, ARG_LOG_LOCATION },
{ "log-time", optional_argument, NULL, ARG_LOG_TIME },
{ "exit-code", required_argument, NULL, ARG_EXIT_CODE },
{ "timeout", required_argument, NULL, ARG_TIMEOUT },
{}
@ -112,17 +110,6 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_LOG_TIME:
if (optarg) {
r = log_show_time_from_string(optarg);
if (r < 0)
log_error_errno(r, "Failed to parse log time setting %s, ignoring: %m", optarg);
} else
log_show_time(true);
break;
case ARG_EXIT_CODE:
r = safe_atou8(optarg, &arg_exit_code);
if (r < 0)

View File

@ -83,7 +83,6 @@ enum {
SD_DHCP_OPTION_REBINDING_T2_TIME = 59,
SD_DHCP_OPTION_VENDOR_CLASS_IDENTIFIER = 60,
SD_DHCP_OPTION_CLIENT_IDENTIFIER = 61,
SD_DHCP_OPTION_SMTP_SERVER = 69,
SD_DHCP_OPTION_POP3_SERVER = 70,
SD_DHCP_OPTION_USER_CLASS = 77,
SD_DHCP_OPTION_FQDN = 81,

View File

@ -46,7 +46,6 @@ int sd_dhcp_lease_get_dns(sd_dhcp_lease *lease, const struct in_addr **addr);
int sd_dhcp_lease_get_ntp(sd_dhcp_lease *lease, const struct in_addr **addr);
int sd_dhcp_lease_get_sip(sd_dhcp_lease *lease, const struct in_addr **addr);
int sd_dhcp_lease_get_pop3_server(sd_dhcp_lease *lease, const struct in_addr **addr);
int sd_dhcp_lease_get_smtp_server(sd_dhcp_lease *lease, const struct in_addr **addr);
int sd_dhcp_lease_get_mtu(sd_dhcp_lease *lease, uint16_t *mtu);
int sd_dhcp_lease_get_domainname(sd_dhcp_lease *lease, const char **domainname);
int sd_dhcp_lease_get_search_domains(sd_dhcp_lease *lease, char ***domains);

View File

@ -51,7 +51,6 @@ int sd_dhcp_server_set_dns(sd_dhcp_server *server, const struct in_addr dns[], u
int sd_dhcp_server_set_ntp(sd_dhcp_server *server, const struct in_addr ntp[], unsigned n);
int sd_dhcp_server_set_sip(sd_dhcp_server *server, const struct in_addr sip[], unsigned n);
int sd_dhcp_server_set_pop3_server(sd_dhcp_server *server, const struct in_addr pop3_server[], unsigned n);
int sd_dhcp_server_set_smtp_server(sd_dhcp_server *server, const struct in_addr smtp_server[], unsigned n);
int sd_dhcp_server_set_emit_router(sd_dhcp_server *server, int enabled);
int sd_dhcp_server_add_option(sd_dhcp_server *server, sd_dhcp_option *v);

View File

@ -170,9 +170,6 @@ int sd_network_link_get_sip_servers(int ifindex, char ***sip);
/* Get the pop3 servers for a given link. */
int sd_network_link_get_pop3_servers(int ifindex, char ***pop3);
/* Get the SMTP servers for a given link. */
int sd_network_link_get_smtp_servers(int ifindex, char ***smtp);
/* Get whether this link shall be used as 'default route' for DNS queries */
int sd_network_link_get_dns_default_route(int ifindex);

View File

@ -1026,7 +1026,10 @@ tests += [
]
if cxx_cmd != ''
# test-bus-vtable-cc.cc is a symlink and symlinks get lost in containers on FuzzBuzz.
# The issue has been reported to the developers of FuzzBuzz and hopefully will be fixed soon.
# In the meantime, let's just skip the symlink there.
if cxx_cmd != '' and not want_fuzzbuzz
tests += [
[['src/libsystemd/sd-bus/test-bus-vtable-cc.cc'],
[],

View File

@ -48,9 +48,7 @@ int main(int argc, char *argv[]) {
if (r == -ENOMEDIUM)
return log_tests_skipped("cgroupfs not available");
_cleanup_free_ char *unit_dir = NULL;
assert_se(get_testdata_dir("units", &unit_dir) >= 0);
assert_se(set_unit_path(unit_dir) >= 0);
assert_se(set_unit_path(get_testdata_dir()) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = bpf_program_new(BPF_PROG_TYPE_CGROUP_SKB, &p);

View File

@ -38,9 +38,7 @@ static int test_cgroup_mask(void) {
return log_tests_skipped("cgroupfs not available");
/* Prepare the manager. */
_cleanup_free_ char *unit_dir = NULL;
assert_se(get_testdata_dir("units", &unit_dir) >= 0);
assert_se(set_unit_path(unit_dir) >= 0);
assert_se(set_unit_path(get_testdata_dir()) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
if (IN_SET(r, -EPERM, -EACCES)) {

View File

@ -22,9 +22,7 @@ static int test_default_memory_low(void) {
if (r == -ENOMEDIUM)
return log_tests_skipped("cgroupfs not available");
_cleanup_free_ char *unit_dir = NULL;
assert_se(get_testdata_dir("units", &unit_dir) >= 0);
assert_se(set_unit_path(unit_dir) >= 0);
assert_se(set_unit_path(get_testdata_dir()) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
if (IN_SET(r, -EPERM, -EACCES)) {

View File

@ -26,11 +26,8 @@ int main(int argc, char *argv[]) {
return log_tests_skipped("cgroupfs not available");
/* prepare the test */
_cleanup_free_ char *unit_dir = NULL;
assert_se(get_testdata_dir("units", &unit_dir) >= 0);
assert_se(set_unit_path(unit_dir) >= 0);
assert_se(set_unit_path(get_testdata_dir()) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
if (manager_errno_skip_test(r))
return log_tests_skipped_errno(r, "manager_new");

View File

@ -806,6 +806,7 @@ static int run_tests(UnitFileScope scope, const test_entry tests[], char **patte
int main(int argc, char *argv[]) {
_cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
_cleanup_free_ char *test_execute_path = NULL;
static const test_entry user_tests[] = {
entry(test_exec_basic),
@ -877,10 +878,9 @@ int main(int argc, char *argv[]) {
if (r == -ENOMEDIUM)
return log_tests_skipped("cgroupfs not available");
_cleanup_free_ char *unit_dir = NULL;
assert_se(get_testdata_dir("test-execute/", &unit_dir) >= 0);
assert_se(set_unit_path(unit_dir) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
test_execute_path = path_join(get_testdata_dir(), "test-execute");
assert_se(set_unit_path(test_execute_path) >= 0);
/* Unset VAR1, VAR2 and VAR3 which are used in the PassEnvironment test
* cases, otherwise (and if they are present in the environment),

View File

@ -444,20 +444,20 @@ static void test_write_string_file_verify(void) {
_cleanup_free_ char *buf = NULL, *buf2 = NULL;
int r;
assert_se(read_one_line_file("/proc/version", &buf) >= 0);
assert_se(read_one_line_file("/proc/cmdline", &buf) >= 0);
assert_se(buf2 = strjoin(buf, "\n"));
r = write_string_file("/proc/version", buf, 0);
r = write_string_file("/proc/cmdline", buf, 0);
assert_se(IN_SET(r, -EACCES, -EIO));
r = write_string_file("/proc/version", buf2, 0);
r = write_string_file("/proc/cmdline", buf2, 0);
assert_se(IN_SET(r, -EACCES, -EIO));
assert_se(write_string_file("/proc/version", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0);
assert_se(write_string_file("/proc/version", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0);
assert_se(write_string_file("/proc/cmdline", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0);
assert_se(write_string_file("/proc/cmdline", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0);
r = write_string_file("/proc/version", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE);
r = write_string_file("/proc/cmdline", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE);
assert_se(IN_SET(r, -EACCES, -EIO));
assert_se(write_string_file("/proc/version", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE) == 0);
assert_se(write_string_file("/proc/cmdline", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE) == 0);
}
static void test_load_env_file_pairs(void) {
@ -757,7 +757,7 @@ static void test_read_line3(void) {
_cleanup_free_ char *line = NULL;
int r;
f = fopen("/proc/uptime", "re");
f = fopen("/proc/cmdline", "re");
if (!f && IN_SET(errno, ENOENT, EPERM))
return;
assert_se(f);

View File

@ -25,7 +25,7 @@ static void test_basic_parsing(void) {
_cleanup_free_ char *journal_data_path = NULL;
int r;
assert_se(get_testdata_dir("journal-data/journal-1.txt", &journal_data_path) >= 0);
journal_data_path = path_join(get_testdata_dir(), "journal-data/journal-1.txt");
imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC);
assert_se(imp.fd >= 0);
@ -56,7 +56,7 @@ static void test_bad_input(void) {
_cleanup_free_ char *journal_data_path = NULL;
int r;
assert_se(get_testdata_dir("journal-data/journal-1.txt", &journal_data_path) >= 0);
journal_data_path = path_join(get_testdata_dir(), "journal-data/journal-2.txt");
imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC);
assert_se(imp.fd >= 0);

View File

@ -251,7 +251,7 @@ int main(int argc, char *argv[]) {
test_setup_logging(LOG_INFO);
assert_se(get_testdata_dir("test-path", &test_path) >= 0);
test_path = path_join(get_testdata_dir(), "test-path");
assert_se(set_unit_path(test_path) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());

View File

@ -25,11 +25,8 @@ int main(int argc, char *argv[]) {
return log_tests_skipped("cgroupfs not available");
/* prepare the test */
_cleanup_free_ char *unit_dir = NULL;
assert_se(get_testdata_dir("units", &unit_dir) >= 0);
assert_se(set_unit_path(unit_dir) >= 0);
assert_se(set_unit_path(get_testdata_dir()) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
if (manager_errno_skip_test(r))
return log_tests_skipped_errno(r, "manager_new");

View File

@ -674,7 +674,7 @@ static void test_strv_push_prepend(void) {
log_info("/* %s */", __func__);
assert_se(a = strv_new("foo", "bar", "three"));
a = strv_new("foo", "bar", "three");
assert_se(strv_push_prepend(&a, strdup("first")) >= 0);
assert_se(streq(a[0], "first"));

View File

@ -15,10 +15,8 @@ static void test_mount_points_list(const char *fname) {
log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
if (fname) {
assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
fname = testdata_fname;
}
if (fname)
fname = testdata_fname = path_join(get_testdata_dir(), fname);
LIST_HEAD_INIT(mp_list_head);
assert_se(mount_points_list_get(fname, &mp_list_head) >= 0);
@ -39,10 +37,8 @@ static void test_swap_list(const char *fname) {
log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps");
if (fname) {
assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
fname = testdata_fname;
}
if (fname)
fname = testdata_fname = path_join(get_testdata_dir(), fname);
LIST_HEAD_INIT(mp_list_head);
assert_se(swap_list_get(fname, &mp_list_head) >= 0);

View File

@ -20,10 +20,7 @@ int main(int argc, char *argv[]) {
if (r == -ENOMEDIUM)
return log_tests_skipped("cgroupfs not available");
_cleanup_free_ char *unit_dir = NULL;
assert_se(get_testdata_dir("units/", &unit_dir) >= 0);
assert_se(set_unit_path(unit_dir) >= 0);
assert_se(set_unit_path(get_testdata_dir()) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
assert_se(manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m) >= 0);

View File

@ -10,10 +10,10 @@ ninja: no work to do.
--x-- Running TEST-01-BASIC --x--
+ make -C TEST-01-BASIC BUILD_DIR=/home/zbyszek/src/systemd/build clean setup run
make: Entering directory '/home/zbyszek/src/systemd/test/TEST-01-BASIC'
TEST-01-BASIC CLEANUP: Basic systemd setup
TEST-01-BASIC SETUP: Basic systemd setup
TEST CLEANUP: Basic systemd setup
TEST SETUP: Basic systemd setup
...
TEST-01-BASIC RUN: Basic systemd setup [OK]
TEST RUN: Basic systemd setup [OK]
make: Leaving directory '/home/zbyszek/src/systemd/test/TEST-01-BASIC'
--x-- Result of TEST-01-BASIC: 0 --x--
--x-- Running TEST-02-CRYPTSETUP --x--

View File

@ -1,6 +1,9 @@
BUILD_DIR=$(shell ../../tools/find-build-dir.sh)
all setup run clean clean-again:
all setup run:
@basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@
clean clean-again:
@basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --clean
.PHONY: all setup run clean clean-again

View File

@ -1,25 +1,34 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="Basic systemd setup"
IMAGE_NAME="basic"
RUN_IN_UNPRIVILEGED_CONTAINER=${RUN_IN_UNPRIVILEGED_CONTAINER:-yes}
TEST_REQUIRE_INSTALL_TESTS=0
. $TEST_BASE_DIR/test-functions
test_create_image() {
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
# install tests manually so the test is functional even when -Dinstall-tests=false
mkdir -p $initdir/usr/lib/systemd/tests/testdata/units/
cp -v $(dirname $0)/../units/{testsuite-01,end}.service $initdir/usr/lib/systemd/tests/testdata/units/
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
After=multi-user.target
[Service]
ExecStart=/bin/sh -e -x -c 'systemctl --state=failed --no-legend --no-pager > /failed ; systemctl daemon-reload ; echo OK > /testok'
Type=oneshot
EOF
setup_testsuite
)
setup_nspawn_root
}
do_test "$@" 01
do_test "$@"

View File

@ -1,22 +1,21 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="cryptsetup systemd setup"
IMAGE_NAME="cryptsetup"
TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
check_result_qemu() {
ret=1
mount_initdir
mkdir -p $initdir
mount ${LOOPDEV}p1 $initdir
[[ -e $initdir/testok ]] && ret=0
[[ -f $initdir/failed ]] && cp -a $initdir/failed $TESTDIR
cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile
mount /dev/mapper/varcrypt $initdir/var
cp -a $initdir/var/log/journal $TESTDIR
rm -r $initdir/var/log/journal/*
_umount_dir $initdir/var
_umount_dir $initdir
umount $initdir/var
umount $initdir
cryptsetup luksClose /dev/mapper/varcrypt
[[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
ls -l $TESTDIR/journal/*/*.journal
@ -24,7 +23,8 @@ check_result_qemu() {
return $ret
}
test_create_image() {
test_setup() {
create_empty_image_rootdir
echo -n test >$TESTDIR/keyfile
cryptsetup -q luksFormat --pbkdf pbkdf2 --pbkdf-force-iterations 1000 ${LOOPDEV}p2 $TESTDIR/keyfile
@ -42,12 +42,25 @@ test_create_image() {
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
After=multi-user.target
[Service]
ExecStart=/bin/sh -x -c 'systemctl --state=failed --no-legend --no-pager > /failed ; echo OK > /testok'
Type=oneshot
EOF
setup_testsuite
install_dmevent
generate_module_dependencies
cat >$initdir/etc/crypttab <<EOF
$DM_NAME UUID=$ID_FS_UUID /etc/varkey
EOF
echo -n test >$initdir/etc/varkey
echo -n test > $initdir/etc/varkey
cat $initdir/etc/crypttab | ddebug
cat >>$initdir/etc/fstab <<EOF
@ -69,8 +82,8 @@ test_cleanup() {
}
test_setup_cleanup() {
cleanup_root_var || :
cleanup_initdir
cleanup_root_var
_test_setup_cleanup
}
do_test "$@" 02
do_test "$@"

View File

@ -5,4 +5,36 @@ TEST_NO_QEMU=1
. $TEST_BASE_DIR/test-functions
do_test "$@" 03
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
After=multi-user.target
[Service]
ExecStart=/test-jobs.sh
Type=oneshot
EOF
# copy the units used by this test
cp $TEST_BASE_DIR/{hello.service,sleep.service,hello-after-sleep.target,unstoppable.service} \
$initdir/etc/systemd/system
cp test-jobs.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"

View File

@ -4,4 +4,41 @@ TEST_DESCRIPTION="Journal-related tests"
. $TEST_BASE_DIR/test-functions
do_test "$@" 04
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/test-journal.sh
Type=oneshot
EOF
cat >$initdir/etc/systemd/system/forever-print-hola.service <<EOF
[Unit]
Description=ForeverPrintHola service
[Service]
Type=simple
ExecStart=/bin/sh -x -c 'while :; do printf "Hola\n" || touch /i-lose-my-logs; sleep 1; done'
EOF
cp test-journal.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"

View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -x
set -e
set -o pipefail
[[ "$(systemctl show -p DefaultLimitNOFILESoft)" = "DefaultLimitNOFILESoft=10000" ]]
[[ "$(systemctl show -p DefaultLimitNOFILE)" = "DefaultLimitNOFILE=16384" ]]
[[ "$(systemctl show -p LimitNOFILESoft testsuite.service)" = "LimitNOFILESoft=10000" ]]
[[ "$(systemctl show -p LimitNOFILE testsuite.service)" = "LimitNOFILE=16384" ]]
[[ "$(ulimit -n -S)" = "10000" ]]
[[ "$(ulimit -n -H)" = "16384" ]]
touch /testok

View File

@ -4,4 +4,37 @@ TEST_DESCRIPTION="Resource limits-related tests"
. $TEST_BASE_DIR/test-functions
do_test "$@" 05
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
cat >$initdir/etc/systemd/system.conf <<EOF
[Manager]
DefaultLimitNOFILE=10000:16384
EOF
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/test-rlimits.sh
Type=oneshot
EOF
cp test-rlimits.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"

View File

@ -3,12 +3,7 @@ set -x
set -e
set -o pipefail
echo 1 >/sys/fs/selinux/enforce || {
echo "Can't make selinux enforcing, skipping test"
touch /testok
exit
}
echo 1 >/sys/fs/selinux/enforce
runcon -t systemd_test_start_t systemctl start hola
runcon -t systemd_test_reload_t systemctl reload hola
runcon -t systemd_test_stop_t systemctl stop hola

View File

@ -1,7 +1,6 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="SELinux tests"
IMAGE_NAME="selinux"
TEST_NO_NSPAWN=1
# Requirements:
@ -16,16 +15,60 @@ test -f /usr/share/selinux/devel/include/system/systemd.if || exit 0
SETUP_SELINUX=yes
KERNEL_APPEND="$KERNEL_APPEND selinux=1 security=selinux"
test_create_image() {
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat <<EOF >$initdir/etc/systemd/system/testsuite.service
[Unit]
Description=Testsuite service
[Service]
ExecStart=/test-selinux-checks.sh
Type=oneshot
EOF
cat <<EOF >$initdir/etc/systemd/system/hola.service
[Service]
Type=oneshot
ExecStart=/bin/echo Start Hola
ExecReload=/bin/echo Reload Hola
ExecStop=/bin/echo Stop Hola
RemainAfterExit=yes
EOF
setup_testsuite
cat <<EOF >$initdir/etc/systemd/system/load-systemd-test-module.service
[Unit]
Description=Load systemd-test module
DefaultDependencies=no
Requires=local-fs.target
Conflicts=shutdown.target
After=local-fs.target
Before=sysinit.target shutdown.target autorelabel.service
ConditionSecurity=selinux
ConditionPathExists=|/.load-systemd-test-module
[Service]
ExecStart=/bin/sh -x -c 'echo 0 >/sys/fs/selinux/enforce && cd /systemd-test-module && make -f /usr/share/selinux/devel/Makefile load && rm /.load-systemd-test-module'
Type=oneshot
TimeoutSec=0
RemainAfterExit=yes
EOF
touch $initdir/.load-systemd-test-module
mkdir -p $initdir/etc/systemd/system/basic.target.wants
ln -fs load-systemd-test-module.service $initdir/etc/systemd/system/basic.target.wants/load-systemd-test-module.service
local _modules_dir=/var/lib/selinux
rm -rf $initdir/$_modules_dir
if ! cp -ar $_modules_dir $initdir/$_modules_dir; then
@ -44,10 +87,11 @@ test_create_image() {
mkdir $initdir/systemd-test-module
cp systemd_test.te $initdir/systemd-test-module
cp systemd_test.if $initdir/systemd-test-module
cp test-selinux-checks.sh $initdir
dracut_install -o sesearch
dracut_install runcon
dracut_install checkmodule semodule semodule_package m4 make /usr/libexec/selinux/hll/pp load_policy sefcontext_compile
)
}
do_test "$@" 06
do_test "$@"

View File

@ -7,4 +7,32 @@ TEST_NO_QEMU=1
NSPAWN_TIMEOUT=30
do_test "$@" 07
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/test-segfault.sh
Type=oneshot
EOF
cp test-segfault.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"

View File

@ -1,22 +1,70 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2730"
IMAGE_NAME="test08"
TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
QEMU_TIMEOUT=300
FSTYPE=ext4
test_create_image() {
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/sh -x -c 'mount -o remount,rw /dev/sda1 && echo OK > /testok; systemctl poweroff'
Type=oneshot
EOF
rm $initdir/etc/fstab
cat >$initdir/etc/systemd/system/-.mount <<EOF
[Unit]
Before=local-fs.target
[Mount]
What=/dev/sda1
Where=/
Type=ext4
Options=errors=remount-ro,noatime
[Install]
WantedBy=local-fs.target
Alias=root.mount
EOF
cat >$initdir/etc/systemd/system/systemd-remount-fs.service <<EOF
[Unit]
DefaultDependencies=no
Conflicts=shutdown.target
After=systemd-fsck-root.service
Before=local-fs-pre.target local-fs.target shutdown.target
Wants=local-fs-pre.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/systemctl reload /
EOF
setup_testsuite
)
ln -s /etc/systemd/system/-.mount $initdir/etc/systemd/system/root.mount
mkdir -p $initdir/etc/systemd/system/local-fs.target.wants
ln -s /etc/systemd/system/-.mount $initdir/etc/systemd/system/local-fs.target.wants/-.mount
mask_supporting_services
}
do_test "$@" 08
do_test "$@"

View File

@ -6,4 +6,32 @@ TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
QEMU_TIMEOUT=300
do_test "$@" 09
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<'EOF'
[Unit]
Description=Testsuite service
[Service]
Type=oneshot
ExecStart=/bin/sh -c '>/testok'
RemainAfterExit=yes
ExecStop=/bin/sh -c 'kill -SEGV $$$$'
TimeoutStopSec=270s
EOF
setup_testsuite
)
}
do_test "$@"

View File

@ -4,4 +4,45 @@ TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2467"
. $TEST_BASE_DIR/test-functions
do_test "$@" 10
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
dracut_install true rm socat
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<'EOF'
[Unit]
Description=Testsuite service
[Service]
Type=oneshot
ExecStart=/bin/sh -e -x -c 'rm -f /tmp/nonexistent; systemctl start test.socket; printf x > test.file; socat -t20 OPEN:test.file UNIX-CONNECT:/run/test.ctl; >/testok'
EOF
cat >$initdir/etc/systemd/system/test.socket <<'EOF'
[Socket]
ListenStream=/run/test.ctl
EOF
cat > $initdir/etc/systemd/system/test.service <<'EOF'
[Unit]
Requires=test.socket
ConditionPathExistsGlob=/tmp/nonexistent
[Service]
ExecStart=/bin/true
EOF
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"

View File

@ -5,4 +5,58 @@ TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
do_test "$@" 11
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
dracut_install false touch
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/test-fail-on-restart.sh
Type=oneshot
EOF
cat >$initdir/etc/systemd/system/fail-on-restart.service <<EOF
[Unit]
Description=Fail on restart
StartLimitIntervalSec=1m
StartLimitBurst=3
[Service]
Type=simple
ExecStart=/bin/false
Restart=always
EOF
cat >$initdir/test-fail-on-restart.sh <<'EOF'
#!/usr/bin/env bash
set -x
systemctl start fail-on-restart.service
active_state=$(systemctl show --property ActiveState fail-on-restart.service)
while [[ "$active_state" == "ActiveState=activating" || "$active_state" == "ActiveState=active" ]]; do
sleep 1
active_state=$(systemctl show --property ActiveState fail-on-restart.service)
done
systemctl is-failed fail-on-restart.service || exit 1
touch /testok
EOF
chmod 0755 $initdir/test-fail-on-restart.sh
setup_testsuite
)
}
do_test "$@"

View File

@ -5,4 +5,85 @@ TEST_NO_QEMU=1
. $TEST_BASE_DIR/test-functions
do_test "$@" 12
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
dracut_install cat mv stat nc
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
After=multi-user.target
[Service]
ExecStart=/test-socket-group.sh
Type=oneshot
EOF
cat >$initdir/test-socket-group.sh <<'EOF'
#!/usr/bin/env bash
set -x
set -e
set -o pipefail
U=/run/systemd/system/test.socket
cat <<'EOL' >$U
[Unit]
Description=Test socket
[Socket]
Accept=yes
ListenStream=/run/test.socket
SocketGroup=adm
SocketMode=0660
EOL
cat <<'EOL' > /run/systemd/system/test@.service
[Unit]
Description=Test service
[Service]
StandardInput=socket
ExecStart=/bin/sh -x -c cat
EOL
systemctl start test.socket
systemctl is-active test.socket
[[ "$(stat --format='%G' /run/test.socket)" == adm ]]
echo A | nc -w1 -U /run/test.socket
mv $U ${U}.disabled
systemctl daemon-reload
systemctl is-active test.socket
[[ "$(stat --format='%G' /run/test.socket)" == adm ]]
echo B | nc -w1 -U /run/test.socket && exit 1
mv ${U}.disabled $U
systemctl daemon-reload
systemctl is-active test.socket
echo C | nc -w1 -U /run/test.socket && exit 1
[[ "$(stat --format='%G' /run/test.socket)" == adm ]]
systemctl restart test.socket
systemctl is-active test.socket
echo D | nc -w1 -U /run/test.socket
[[ "$(stat --format='%G' /run/test.socket)" == adm ]]
touch /testok
EOF
chmod 0755 $initdir/test-socket-group.sh
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"

View File

@ -1 +0,0 @@
../TEST-01-BASIC/Makefile

View File

@ -0,0 +1,10 @@
BUILD_DIR=$(shell ../../tools/find-build-dir.sh)
all setup run:
@basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@
clean clean-again:
@basedir=../.. TEST_BASE_DIR=../ ./test.sh --clean
@rm -f has-overflow
.PHONY: all setup run clean clean-again

View File

@ -1,23 +1,193 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="systemd-nspawn smoke test"
IMAGE_NAME=nspawn
TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
test_create_image() {
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
dracut_install busybox chmod rmdir unshare ip sysctl
../create-busybox-container $initdir/nc-container
cp create-busybox-container $initdir/
./create-busybox-container $initdir/nc-container
initdir="$initdir/nc-container" dracut_install nc ip
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/test-nspawn.sh
Type=oneshot
EOF
cat >$initdir/test-nspawn.sh <<'EOF'
#!/usr/bin/env bash
set -x
set -e
set -u
set -o pipefail
export SYSTEMD_LOG_LEVEL=debug
# check cgroup-v2
is_v2_supported=no
mkdir -p /tmp/cgroup2
if mount -t cgroup2 cgroup2 /tmp/cgroup2; then
is_v2_supported=yes
umount /tmp/cgroup2
fi
rmdir /tmp/cgroup2
# check cgroup namespaces
is_cgns_supported=no
if [[ -f /proc/1/ns/cgroup ]]; then
is_cgns_supported=yes
fi
is_user_ns_supported=no
# On some systems (e.g. CentOS 7) the default limit for user namespaces
# is set to 0, which causes the following unshare syscall to fail, even
# with enabled user namespaces support. By setting this value explicitly
# we can ensure the user namespaces support to be detected correctly.
sysctl -w user.max_user_namespaces=10000
if unshare -U sh -c :; then
is_user_ns_supported=yes
fi
function check_bind_tmp_path {
# https://github.com/systemd/systemd/issues/4789
local _root="/var/lib/machines/bind-tmp-path"
/create-busybox-container "$_root"
>/tmp/bind
systemd-nspawn --register=no -D "$_root" --bind=/tmp/bind /bin/sh -c 'test -e /tmp/bind'
}
function check_norbind {
# https://github.com/systemd/systemd/issues/13170
local _root="/var/lib/machines/norbind-path"
mkdir -p /tmp/binddir/subdir
echo -n "outer" > /tmp/binddir/subdir/file
mount -t tmpfs tmpfs /tmp/binddir/subdir
echo -n "inner" > /tmp/binddir/subdir/file
/create-busybox-container "$_root"
systemd-nspawn --register=no -D "$_root" --bind=/tmp/binddir:/mnt:norbind /bin/sh -c 'CONTENT=$(cat /mnt/subdir/file); if [[ $CONTENT != "outer" ]]; then echo "*** unexpected content: $CONTENT"; return 1; fi'
}
function check_notification_socket {
# https://github.com/systemd/systemd/issues/4944
local _cmd='echo a | $(busybox which nc) -U -u -w 1 /run/systemd/nspawn/notify'
systemd-nspawn --register=no -D /nc-container /bin/sh -x -c "$_cmd"
systemd-nspawn --register=no -D /nc-container -U /bin/sh -x -c "$_cmd"
}
function run {
if [[ "$1" = "yes" && "$is_v2_supported" = "no" ]]; then
printf "Unified cgroup hierarchy is not supported. Skipping.\n" >&2
return 0
fi
if [[ "$2" = "yes" && "$is_cgns_supported" = "no" ]]; then
printf "CGroup namespaces are not supported. Skipping.\n" >&2
return 0
fi
local _root="/var/lib/machines/unified-$1-cgns-$2-api-vfs-writable-$3"
/create-busybox-container "$_root"
SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" -b
SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" --private-network -b
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" -U -b; then
[[ "$is_user_ns_supported" = "yes" && "$3" = "network" ]] && return 1
else
[[ "$is_user_ns_supported" = "no" && "$3" = "network" ]] && return 1
fi
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" --private-network -U -b; then
[[ "$is_user_ns_supported" = "yes" && "$3" = "yes" ]] && return 1
else
[[ "$is_user_ns_supported" = "no" && "$3" = "yes" ]] && return 1
fi
local _netns_opt="--network-namespace-path=/proc/self/ns/net"
# --network-namespace-path and network-related options cannot be used together
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-interface=lo -b; then
return 1
fi
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-macvlan=lo -b; then
return 1
fi
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-ipvlan=lo -b; then
return 1
fi
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-veth -b; then
return 1
fi
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-veth-extra=lo -b; then
return 1
fi
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-bridge=lo -b; then
return 1
fi
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --network-zone=zone -b; then
return 1
fi
# allow combination of --network-namespace-path and --private-network
if ! SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --private-network -b; then
return 1
fi
# test --network-namespace-path works with a network namespace created by "ip netns"
ip netns add nspawn_test
_netns_opt="--network-namespace-path=/run/netns/nspawn_test"
SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" /bin/ip a | grep -v -E '^1: lo.*UP'
local r=$?
ip netns del nspawn_test
if [ $r -ne 0 ]; then
return 1
fi
return 0
}
check_bind_tmp_path
check_norbind
check_notification_socket
for api_vfs_writable in yes no network; do
run no no $api_vfs_writable
run yes no $api_vfs_writable
run no yes $api_vfs_writable
run yes yes $api_vfs_writable
done
touch /testok
EOF
chmod 0755 $initdir/test-nspawn.sh
setup_testsuite
)
}
do_test "$@" 13
do_test "$@"

View File

@ -1,21 +1,78 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="/etc/machine-id testing"
IMAGE_NAME=badid
TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
test_create_image() {
test_setup() {
create_empty_image_rootdir
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
printf "556f48e837bc4424a710fa2e2c9d3e3c\ne3d\n" >$initdir/etc/machine-id
dracut_install mount cmp
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/sh -e -x -c '/test-machine-id-setup.sh; systemctl --state=failed --no-legend --no-pager > /failed ; echo OK > /testok'
Type=oneshot
EOF
cat >$initdir/test-machine-id-setup.sh <<'EOF'
#!/usr/bin/env bash
set -e
set -x
function setup_root {
local _root="$1"
mkdir -p "$_root"
mount -t tmpfs tmpfs "$_root"
mkdir -p "$_root/etc" "$_root/run"
}
function check {
printf "Expected\n"
cat "$1"
printf "\nGot\n"
cat "$2"
cmp "$1" "$2"
}
r="$(pwd)/overwrite-broken-machine-id"
setup_root "$r"
systemd-machine-id-setup --print --root "$r"
echo abc >>"$r/etc/machine-id"
id=$(systemd-machine-id-setup --print --root "$r")
echo $id >expected
check expected "$r/etc/machine-id"
r="$(pwd)/transient-machine-id"
setup_root "$r"
systemd-machine-id-setup --print --root "$r"
echo abc >>"$r/etc/machine-id"
mount -o remount,ro "$r"
mount -t tmpfs tmpfs "$r/run"
transient_id=$(systemd-machine-id-setup --print --root "$r")
mount -o remount,rw "$r"
commited_id=$(systemd-machine-id-setup --print --commit --root "$r")
[[ "$transient_id" = "$commited_id" ]]
check "$r/etc/machine-id" "$r/run/machine-id"
EOF
chmod +x $initdir/test-machine-id-setup.sh
setup_testsuite
)
}
do_test "$@" 14
do_test "$@"

View File

@ -7,12 +7,6 @@ _clear_service () {
rm -f /{etc,run,usr/lib}/systemd/system/$1.service
rm -fr /{etc,run,usr/lib}/systemd/system/$1.service.d
rm -fr /{etc,run,usr/lib}/systemd/system/$1.service.{wants,requires}
if [[ $1 == *@ ]]; then
systemctl stop $1*.service 2>/dev/null || :
rm -f /{etc,run,usr/lib}/systemd/system/$1*.service
rm -fr /{etc,run,usr/lib}/systemd/system/$1*.service.d
rm -fr /{etc,run,usr/lib}/systemd/system/$1*.service.{wants,requires}
fi
}
clear_services () {
@ -62,66 +56,65 @@ test_basic_dropins () {
echo "Testing basic dropins..."
echo "*** test a wants b wants c"
create_services test15-a test15-b test15-c
ln -s ../test15-b.service /etc/systemd/system/test15-a.service.wants/
ln -s ../test15-c.service /etc/systemd/system/test15-b.service.wants/
check_ok test15-a Wants test15-b.service
check_ok test15-b Wants test15-c.service
create_services a b c
ln -s ../b.service /etc/systemd/system/a.service.wants/
ln -s ../c.service /etc/systemd/system/b.service.wants/
check_ok a Wants b.service
check_ok b Wants c.service
echo "*** test a wants,requires b"
create_services test15-a test15-b test15-c
ln -s ../test15-b.service /etc/systemd/system/test15-a.service.wants/
ln -s ../test15-b.service /etc/systemd/system/test15-a.service.requires/
check_ok test15-a Wants test15-b.service
check_ok test15-a Requires test15-b.service
create_services a b c
ln -s ../b.service /etc/systemd/system/a.service.wants/
ln -s ../b.service /etc/systemd/system/a.service.requires/
check_ok a Wants b.service
check_ok a Requires b.service
echo "*** test a wants nonexistent"
create_service test15-a
ln -s ../nonexistent.service /etc/systemd/system/test15-a.service.wants/
check_ok test15-a Wants nonexistent.service
systemctl start test15-a
systemctl stop test15-a
create_service a
ln -s ../nonexistent.service /etc/systemd/system/a.service.wants/
check_ok a Wants nonexistent.service
systemctl start a
systemctl stop a
echo "*** test a requires nonexistent"
ln -sf ../nonexistent.service /etc/systemd/system/test15-a.service.requires/
ln -sf ../nonexistent.service /etc/systemd/system/a.service.requires/
systemctl daemon-reload
check_ok test15-a Requires nonexistent.service
check_ok a Requires nonexistent.service
# 'b' is already loaded when 'c' pulls it in via a dropin.
echo "*** test a,c require b"
create_services test15-a test15-b test15-c
ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.requires/
ln -sf ../test15-b.service /etc/systemd/system/test15-c.service.requires/
systemctl start test15-a
check_ok test15-c Requires test15-b.service
systemctl stop test15-a test15-b
create_services a b c
ln -sf ../b.service /etc/systemd/system/a.service.requires/
ln -sf ../b.service /etc/systemd/system/c.service.requires/
systemctl start a
check_ok c Requires b.service
systemctl stop a b
# 'b' is already loaded when 'c' pulls it in via an alias dropin.
echo "*** test a wants alias"
create_services test15-a test15-b test15-c
ln -sf test15-c.service /etc/systemd/system/test15-c1.service
ln -sf ../test15-c.service /etc/systemd/system/test15-a.service.wants/
ln -sf ../test15-c1.service /etc/systemd/system/test15-b.service.wants/
systemctl start test15-a
check_ok test15-a Wants test15-c.service
check_ok test15-b Wants test15-c.service
systemctl stop test15-a test15-c
create_services a b c
ln -sf c.service /etc/systemd/system/c1.service
ln -sf ../c.service /etc/systemd/system/a.service.wants/
ln -sf ../c1.service /etc/systemd/system/b.service.wants/
systemctl start a
check_ok a Wants c.service
check_ok b Wants c.service
systemctl stop a c
echo "*** test service.d/ top level drop-in"
create_services test15-a test15-b
check_ko test15-a ExecCondition "/bin/echo a"
check_ko test15-b ExecCondition "/bin/echo b"
create_services a b
check_ko a ExecCondition "/bin/echo a"
check_ko b ExecCondition "/bin/echo b"
mkdir -p /usr/lib/systemd/system/service.d
cat >/usr/lib/systemd/system/service.d/override.conf <<EOF
[Service]
ExecCondition=/bin/echo %n
EOF
systemctl daemon-reload
check_ok test15-a ExecCondition "/bin/echo test15-a"
check_ok test15-b ExecCondition "/bin/echo test15-b"
check_ok a ExecCondition "/bin/echo a"
check_ok b ExecCondition "/bin/echo b"
rm -rf /usr/lib/systemd/system/service.d
clear_services test15-a test15-b test15-c
clear_services a b c
}
test_hierarchical_dropins () {
@ -139,7 +132,6 @@ test_hierarchical_dropins () {
[Service]
ExecCondition=/bin/echo $dropin
" > /usr/lib/systemd/system/$dropin/override.conf
systemctl daemon-reload
check_ok a-b-c ExecCondition "/bin/echo $dropin"
done
for dropin in service.d a-.service.d a-b-.service.d a-b-c.service.d; do
@ -302,153 +294,153 @@ test_alias_dropins () {
echo "Testing alias dropins..."
echo "*** test a wants b1 alias of b"
create_services test15-a test15-b
ln -sf test15-b.service /etc/systemd/system/test15-b1.service
ln -sf ../test15-b1.service /etc/systemd/system/test15-a.service.wants/
check_ok test15-a Wants test15-b.service
systemctl start test15-a
systemctl --quiet is-active test15-b
systemctl stop test15-a test15-b
rm /etc/systemd/system/test15-b1.service
clear_services test15-a test15-b
create_services a b
ln -sf b.service /etc/systemd/system/b1.service
ln -sf ../b1.service /etc/systemd/system/a.service.wants/
check_ok a Wants b.service
systemctl start a
systemctl --quiet is-active b
systemctl stop a b
rm /etc/systemd/system/b1.service
clear_services a b
# Check that dependencies don't vary.
echo "*** test 2"
create_services test15-a test15-x test15-y
mkdir -p /etc/systemd/system/test15-a1.service.wants/
ln -sf test15-a.service /etc/systemd/system/test15-a1.service
ln -sf ../test15-x.service /etc/systemd/system/test15-a.service.wants/
ln -sf ../test15-y.service /etc/systemd/system/test15-a1.service.wants/
check_ok test15-a1 Wants test15-x.service # see [1]
check_ok test15-a1 Wants test15-y.service
systemctl start test15-a
check_ok test15-a1 Wants test15-x.service # see [2]
check_ok test15-a1 Wants test15-y.service
systemctl stop test15-a test15-x test15-y
rm /etc/systemd/system/test15-a1.service
create_services a x y
mkdir -p /etc/systemd/system/a1.service.wants/
ln -sf a.service /etc/systemd/system/a1.service
ln -sf ../x.service /etc/systemd/system/a.service.wants/
ln -sf ../y.service /etc/systemd/system/a1.service.wants/
check_ok a1 Wants x.service # see [1]
check_ok a1 Wants y.service
systemctl start a
check_ok a1 Wants x.service # see [2]
check_ok a1 Wants y.service
systemctl stop a x y
rm /etc/systemd/system/a1.service
clear_services test15-a test15-x test15-y
clear_services a x y
}
test_masked_dropins () {
echo "Testing masked dropins..."
create_services test15-a test15-b
create_services a b
# 'b' is masked for both deps
echo "*** test a wants,requires b is masked"
ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service
ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/test15-b.service
check_ko test15-a Wants test15-b.service
check_ko test15-a Requires test15-b.service
ln -sf /dev/null /etc/systemd/system/a.service.wants/b.service
ln -sf /dev/null /etc/systemd/system/a.service.requires/b.service
check_ko a Wants b.service
check_ko a Requires b.service
# 'a' wants 'b' and 'b' is masked at a lower level
echo "*** test a wants b, mask override"
ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.wants/test15-b.service
ln -sf /dev/null /usr/lib/systemd/system/test15-a.service.wants/test15-b.service
check_ok test15-a Wants test15-b.service
ln -sf ../b.service /etc/systemd/system/a.service.wants/b.service
ln -sf /dev/null /usr/lib/systemd/system/a.service.wants/b.service
check_ok a Wants b.service
# 'a' wants 'b' and 'b' is masked at a higher level
echo "*** test a wants b, mask"
ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service
ln -sf ../test15-b.service /usr/lib/systemd/system/test15-a.service.wants/test15-b.service
check_ko test15-a Wants test15-b.service
ln -sf /dev/null /etc/systemd/system/a.service.wants/b.service
ln -sf ../b.service /usr/lib/systemd/system/a.service.wants/b.service
check_ko a Wants b.service
# 'a' is masked but has an override config file
echo "*** test a is masked but has an override"
create_services test15-a test15-b
ln -sf /dev/null /etc/systemd/system/test15-a.service
cat >/usr/lib/systemd/system/test15-a.service.d/override.conf <<EOF
create_services a b
ln -sf /dev/null /etc/systemd/system/a.service
cat >/usr/lib/systemd/system/a.service.d/override.conf <<EOF
[Unit]
After=test15-b.service
After=b.service
EOF
check_ok test15-a UnitFileState masked
check_ok a UnitFileState masked
# 'b1' is an alias for 'b': masking 'b' dep should not influence 'b1' dep
echo "*** test a wants b, b1, and one is masked"
create_services test15-a test15-b
ln -sf test15-b.service /etc/systemd/system/test15-b1.service
ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service
ln -sf ../test15-b1.service /usr/lib/systemd/system/test15-a.service.wants/test15-b1.service
systemctl cat test15-a
systemctl show -p Wants,Requires test15-a
systemctl cat test15-b1
systemctl show -p Wants,Requires test15-b1
check_ok test15-a Wants test15-b.service
check_ko test15-a Wants test15-b1.service # the alias does not show up in the list of units
rm /etc/systemd/system/test15-b1.service
create_services a b
ln -sf b.service /etc/systemd/system/b1.service
ln -sf /dev/null /etc/systemd/system/a.service.wants/b.service
ln -sf ../b1.service /usr/lib/systemd/system/a.service.wants/b1.service
systemctl cat a
systemctl show -p Wants,Requires a
systemctl cat b1
systemctl show -p Wants,Requires b1
check_ok a Wants b.service
check_ko a Wants b1.service # the alias does not show up in the list of units
rm /etc/systemd/system/b1.service
# 'b1' is an alias for 'b': masking 'b1' should not influence 'b' dep
echo "*** test a wants b, alias dep is masked"
create_services test15-a test15-b
ln -sf test15-b.service /etc/systemd/system/test15-b1.service
ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b1.service
ln -sf ../test15-b.service /usr/lib/systemd/system/test15-a.service.wants/test15-b.service
check_ok test15-a Wants test15-b.service
check_ko test15-a Wants test15-b1.service # the alias does not show up in the list of units
rm /etc/systemd/system/test15-b1.service
create_services a b
ln -sf b.service /etc/systemd/system/b1.service
ln -sf /dev/null /etc/systemd/system/a.service.wants/b1.service
ln -sf ../b.service /usr/lib/systemd/system/a.service.wants/b.service
check_ok a Wants b.service
check_ko a Wants b1.service # the alias does not show up in the list of units
rm /etc/systemd/system/b1.service
# 'a' has Wants=b.service but also has a masking
# dropin 'b': 'b' should still be pulled in.
echo "*** test a wants b both ways"
create_services test15-a test15-b
ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service
cat >/usr/lib/systemd/system/test15-a.service.d/wants-b.conf<<EOF
create_services a b
ln -sf /dev/null /etc/systemd/system/a.service.wants/b.service
cat >/usr/lib/systemd/system/a.service.d/wants-b.conf<<EOF
[Unit]
Wants=test15-b.service
Wants=b.service
EOF
check_ok test15-a Wants test15-b.service
check_ok a Wants b.service
# mask a dropin that points to an nonexistent unit.
echo "*** test a wants nonexistent is masked"
create_services test15-a
ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/nonexistent.service
ln -sf ../nonexistent.service /usr/lib/systemd/system/test15-a.service.requires/
check_ko test15-a Requires nonexistent.service
create_services a
ln -sf /dev/null /etc/systemd/system/a.service.requires/nonexistent.service
ln -sf ../nonexistent.service /usr/lib/systemd/system/a.service.requires/
check_ko a Requires nonexistent.service
# 'b' is already loaded when 'c' pulls it in via a dropin but 'b' is
# masked at a higher level.
echo "*** test a wants b is masked"
create_services test15-a test15-b test15-c
ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.requires/
ln -sf ../test15-b.service /run/systemd/system/test15-c.service.requires/
ln -sf /dev/null /etc/systemd/system/test15-c.service.requires/test15-b.service
systemctl start test15-a
check_ko test15-c Requires test15-b.service
systemctl stop test15-a test15-b
create_services a b c
ln -sf ../b.service /etc/systemd/system/a.service.requires/
ln -sf ../b.service /run/systemd/system/c.service.requires/
ln -sf /dev/null /etc/systemd/system/c.service.requires/b.service
systemctl start a
check_ko c Requires b.service
systemctl stop a b
# 'b' is already loaded when 'c' pulls it in via a dropin but 'b' is
# masked at a lower level.
echo "*** test a requires b is masked"
create_services test15-a test15-b test15-c
ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.requires/
ln -sf ../test15-b.service /etc/systemd/system/test15-c.service.requires/
ln -sf /dev/null /run/systemd/system/test15-c.service.requires/test15-b.service
systemctl start test15-a
check_ok test15-c Requires test15-b.service
systemctl stop test15-a test15-b
create_services a b c
ln -sf ../b.service /etc/systemd/system/a.service.requires/
ln -sf ../b.service /etc/systemd/system/c.service.requires/
ln -sf /dev/null /run/systemd/system/c.service.requires/b.service
systemctl start a
check_ok c Requires b.service
systemctl stop a b
# 'a' requires 2 aliases of 'b' and one of them is a mask.
echo "*** test a requires alias of b, other alias masked"
create_services test15-a test15-b
ln -sf test15-b.service /etc/systemd/system/test15-b1.service
ln -sf test15-b.service /etc/systemd/system/test15-b2.service
ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/test15-b1.service
ln -sf ../test15-b1.service /run/systemd/system/test15-a.service.requires/
ln -sf ../test15-b2.service /usr/lib/systemd/system/test15-a.service.requires/
check_ok test15-a Requires test15-b
create_services a b
ln -sf b.service /etc/systemd/system/b1.service
ln -sf b.service /etc/systemd/system/b2.service
ln -sf /dev/null /etc/systemd/system/a.service.requires/b1.service
ln -sf ../b1.service /run/systemd/system/a.service.requires/
ln -sf ../b2.service /usr/lib/systemd/system/a.service.requires/
check_ok a Requires b
# Same as above but now 'b' is masked.
echo "*** test a requires alias of b, b dep masked"
create_services test15-a test15-b
ln -sf test15-b.service /etc/systemd/system/test15-b1.service
ln -sf test15-b.service /etc/systemd/system/test15-b2.service
ln -sf ../test15-b1.service /run/systemd/system/test15-a.service.requires/
ln -sf ../test15-b2.service /usr/lib/systemd/system/test15-a.service.requires/
ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/test15-b.service
check_ok test15-a Requires test15-b
create_services a b
ln -sf b.service /etc/systemd/system/b1.service
ln -sf b.service /etc/systemd/system/b2.service
ln -sf ../b1.service /run/systemd/system/a.service.requires/
ln -sf ../b2.service /usr/lib/systemd/system/a.service.requires/
ln -sf /dev/null /etc/systemd/system/a.service.requires/b.service
check_ok a Requires b
clear_services test15-a test15-b
clear_services a b
}
test_invalid_dropins () {

View File

@ -5,4 +5,18 @@ TEST_NO_QEMU=1
. $TEST_BASE_DIR/test-functions
do_test "$@" 15
test_setup() {
# create the basic filesystem layout
setup_basic_environment
mask_supporting_services
# import the test scripts in the rootfs and plug them in systemd
cp testsuite.service $initdir/etc/systemd/system/
cp test-dropin.sh $initdir/
setup_testsuite
# create dedicated rootfs for nspawn (located in $TESTDIR/nspawn-root)
setup_nspawn_root
}
do_test "$@"

View File

@ -0,0 +1,6 @@
[Unit]
Description=Testsuite service
[Service]
ExecStart=/test-dropin.sh
Type=oneshot

View File

@ -19,7 +19,7 @@ function wait_for()
if [[ ! -f /${service}.${result} ]]
then
journalctl -u ${service/_/-}.service >> "${TL}"
journalctl -u testsuite-${service/_/-}.service >> "${TL}"
fi
}

View File

@ -4,15 +4,23 @@ set -e
set -o pipefail
# sleep interval (seconds)
: ${sleep_interval:=1}
sleep_interval=1
# extend_timeout_interval second(s)
: ${extend_timeout_interval:=1}
extend_timeout_interval=1
# number of sleep_intervals before READY=1
: ${start_intervals:=10}
start_intervals=10
# number of sleep_intervals before exiting
: ${stop_intervals:=10}
stop_intervals=10
# run intervals, number of sleep_intervals to run
: ${run_intervals:=7}
run_intervals=7
# service name
SERVICE=unknown
while [ $# -gt 0 ];
do
eval ${1%=*}=${1#*=}
shift
done
# We convert to usec
extend_timeout_interval=$(( $extend_timeout_interval * 1000000 ))

View File

@ -6,4 +6,30 @@ TEST_NO_QEMU=1
. $TEST_BASE_DIR/test-functions
do_test "$@" 16
test_setup() {
create_empty_image
# Create what will eventually be our root filesystem onto an overlay
(
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
for s in success-all success-start success-stop success-runtime \
fail-start fail-stop fail-runtime
do
cp testsuite-${s}.service ${initdir}/etc/systemd/system
done
cp testsuite.service ${initdir}/etc/systemd/system
cp extend_timeout_test_service.sh ${initdir}/
cp assess.sh ${initdir}/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"

View File

@ -1,12 +1,13 @@
[Unit]
Description=Testsuite: Fail Runtime (EXTEND_TIMEOUT_USEC Didn't occur in sufficient time after RuntimeSecMax.)
[Service]
# EXTEND_TIMEOUT_USEC on runtime start (0) and 7 seconds after. Systemd will expect one at 7+5 (extend_timeout_interval)
# seconds this won't happen until 7 + 7 (sleep interval) seconds. Therefore timeout at 12 seconds.
Type=notify
TimeoutStartSec=4
TimeoutStopSec=4
RuntimeMaxSec=10
Environment=SERVICE=fail_runtime extend_timeout_interval=5 sleep_interval=7 start_intervals=0 run_intervals=2 stop_intervals=0
ExecStart=/usr/lib/systemd/tests/testdata/testsuite-16.units/extend-timeout.sh
ExecStart=/extend_timeout_test_service.sh SERVICE=fail_runtime extend_timeout_interval=5 sleep_interval=7 start_intervals=0 run_intervals=2 stop_intervals=0

View File

@ -1,3 +1,4 @@
[Unit]
Description=Testsuite: Fail Start (EXTEND_TIMEOUT_USEC Didn't occur in sufficient time after TimeoutStartSec.)
@ -9,5 +10,4 @@ Type=notify
TimeoutStartSec=10
TimeoutStopSec=4
RuntimeMaxSec=4
Environment=SERVICE=fail_start extend_timeout_interval=5 sleep_interval=7 start_intervals=2 run_intervals=0 stop_intervals=0
ExecStart=/usr/lib/systemd/tests/testdata/testsuite-16.units/extend-timeout.sh
ExecStart=/extend_timeout_test_service.sh SERVICE=fail_start extend_timeout_interval=5 sleep_interval=7 start_intervals=2 run_intervals=0 stop_intervals=0

View File

@ -1,15 +1,16 @@
[Unit]
Description=Testsuite: Fail Stop (EXTEND_TIMEOUT_USEC Didn't occur in sufficient time after TimeoutStopSec.)
[Service]
# EXTEND_TIMEOUT_USEC on stop (0) and 7 seconds after. Systemd will expect one at 7+5 (extend_timeout_interval)
# seconds this won't happen until 7 + 7 (sleep interval) seconds. Therefore timeout at 12 seconds.
Type=notify
TimeoutStartSec=4
TimeoutStopSec=10
RuntimeMaxSec=4
Environment=SERVICE=fail_stop extend_timeout_interval=5 sleep_interval=7 start_intervals=0 run_intervals=0 stop_intervals=2
ExecStart=/usr/lib/systemd/tests/testdata/testsuite-16.units/extend-timeout.sh
ExecStart=/extend_timeout_test_service.sh SERVICE=fail_stop extend_timeout_interval=5 sleep_interval=7 start_intervals=0 run_intervals=0 stop_intervals=2
# Due to 6041a7ee2c1bbff6301082f192fc1b0882400d42 SIGTERM isn't sent as the service shuts down with STOPPING=1
# This file makes the test assess.sh quicker by notifing it that this test has finished.
ExecStopPost=/bin/bash -c '[[ $SERVICE_RESULT == timeout && $EXIT_CODE == killed ]] && touch /fail_runtime.terminated'

View File

@ -1,3 +1,4 @@
[Unit]
Description=Testsuite: EXTEND_TIMEOUT_USEC Success - extend timeout on all services
@ -10,5 +11,4 @@ Type=notify
TimeoutStartSec=4
TimeoutStopSec=4
RuntimeMaxSec=4
Environment=SERVICE=success_all extend_timeout_interval=4 sleep_interval=2 start_intervals=3 run_intervals=3 stop_intervals=3
ExecStart=/usr/lib/systemd/tests/testdata/testsuite-16.units/extend-timeout.sh
ExecStart=/extend_timeout_test_service.sh SERVICE=success_all extend_timeout_interval=4 sleep_interval=2 start_intervals=3 run_intervals=3 stop_intervals=3

View File

@ -1,3 +1,4 @@
[Unit]
Description=Testsuite: Success Runtime (EXTEND_TIMEOUT_USEC > WATCHDOG_USEC however < RuntimeMaxSec)
@ -9,5 +10,4 @@ Type=notify
TimeoutStartSec=4
TimeoutStopSec=4
RuntimeMaxSec=8
Environment=SERVICE=success_runtime extend_timeout_interval=4 sleep_interval=6 start_intervals=0 run_intervals=1 stop_intervals=0
ExecStart=/usr/lib/systemd/tests/testdata/testsuite-16.units/extend-timeout.sh
ExecStart=/extend_timeout_test_service.sh SERVICE=success_runtime extend_timeout_interval=4 sleep_interval=6 start_intervals=0 run_intervals=1 stop_intervals=0

View File

@ -1,12 +1,13 @@
[Unit]
Description=Testsuite: Success Start (EXTEND_TIMEOUT_USEC > WATCHDOG_USEC however < TimeoutStartSec)
[Service]
# EXTEND_TIMEOUT_USEC=4 second interval once at startup, but sleep 6 seconds.
# Therefore startup is 6 seconds and < TimeoutStartSec so still successful.
Type=notify
TimeoutStartSec=8
TimeoutStopSec=4
RuntimeMaxSec=4
Environment=SERVICE=success_start extend_timeout_interval=4 sleep_interval=6 start_intervals=1 run_intervals=0 stop_intervals=0
ExecStart=/usr/lib/systemd/tests/testdata/testsuite-16.units/extend-timeout.sh
ExecStart=/extend_timeout_test_service.sh SERVICE=success_start extend_timeout_interval=4 sleep_interval=6 start_intervals=1 run_intervals=0 stop_intervals=0

View File

@ -1,12 +1,13 @@
[Unit]
Description=Testsuite: Success Stop (EXTEND_TIMEOUT_USEC > WATCHDOG_USEC however < TimeoutStopSec)
[Service]
# EXTEND_TIMEOUT_USEC=4 seconds once during shutdown, but sleep for 6 seconds.
# Therefore stop time is 6 seconds and < TimeoutStopSec so still successful.
Type=notify
TimeoutStartSec=4
TimeoutStopSec=8
RuntimeMaxSec=4
Environment=SERVICE=success_stop extend_timeout_interval=4 sleep_interval=6 start_intervals=0 run_intervals=0 stop_intervals=1
ExecStart=/usr/lib/systemd/tests/testdata/testsuite-16.units/extend-timeout.sh
ExecStart=/extend_timeout_test_service.sh SERVICE=success_stop extend_timeout_interval=4 sleep_interval=6 start_intervals=0 run_intervals=0 stop_intervals=1

View File

@ -0,0 +1,18 @@
[Unit]
Description=Testsuite: Assess all other testsuite-*.services worked as expected
Wants=testsuite-success-all.service
Wants=testsuite-success-start.service
Wants=testsuite-success-runtime.service
Wants=testsuite-success-stop.service
Wants=testsuite-fail-start.service
Wants=testsuite-fail-stop.service
Wants=testsuite-fail-runtime.service
StopWhenUnneeded=yes
[Service]
Type=simple
TimeoutStartSec=infinity
ExecStartPre=/assess.sh
ExecStart=/bin/true

View File

@ -6,4 +6,29 @@ TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
QEMU_TIMEOUT=300
do_test "$@" 17
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/bash -x /testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
}
do_test "$@"

View File

@ -69,6 +69,6 @@ while : ; do
sleep .5
done
echo OK >/testok
echo OK > /testok
exit 0

View File

@ -5,4 +5,31 @@ TEST_DESCRIPTION="FailureAction= operation"
. $TEST_BASE_DIR/test-functions
QEMU_TIMEOUT=600
do_test "$@" 18
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/bash -x /testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
setup_nspawn_root
}
do_test "$@"

View File

@ -7,4 +7,29 @@ TEST_NO_NSPAWN=1
QEMU_TIMEOUT=600
UNIFIED_CGROUP_HIERARCHY=yes
do_test "$@" 19
test_setup() {
create_empty_image_rootdir
(
LOG_LEVEL=5
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
setup_basic_environment
mask_supporting_services
# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
[Unit]
Description=Testsuite service
[Service]
ExecStart=/bin/bash -x /testsuite.sh
Type=oneshot
EOF
cp testsuite.sh $initdir/
setup_testsuite
)
}
do_test "$@"

Some files were not shown because too many files have changed in this diff Show More