summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/basic/fs-util.c29
-rw-r--r--src/basic/fs-util.h2
-rw-r--r--src/basic/strv.c12
-rw-r--r--src/basic/strv.h4
-rw-r--r--src/journal/journal-verify.c15
-rw-r--r--src/journal/journalctl.c48
-rw-r--r--src/libsystemd/sd-bus/bus-match.c3
-rw-r--r--src/resolve/resolved-manager.c5
-rw-r--r--src/systemctl/systemctl.c50
-rw-r--r--src/test/test-fs-util.c46
-rw-r--r--src/test/test-path-util.c2
-rw-r--r--src/test/test-strv.c11
12 files changed, 196 insertions, 31 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index e24e7036f7..f0c6f3265e 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -38,6 +38,7 @@
#include "mkdir.h"
#include "parse-util.h"
#include "path-util.h"
+#include "stat-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
@@ -495,6 +496,34 @@ int get_files_in_directory(const char *path, char ***list) {
return n;
}
+int var_tmp(char **ret) {
+ const char *tmp_dir = NULL;
+ const char *env_tmp_dir = NULL;
+ char *c = NULL;
+ int r;
+
+ assert(ret);
+
+ env_tmp_dir = getenv("TMPDIR");
+ if (env_tmp_dir != NULL) {
+ r = is_dir(env_tmp_dir, true);
+ if (r < 0 && r != -ENOENT)
+ return r;
+ if (r > 0)
+ tmp_dir = env_tmp_dir;
+ }
+
+ if (!tmp_dir)
+ tmp_dir = "/var/tmp";
+
+ c = strdup(tmp_dir);
+ if (!c)
+ return -ENOMEM;
+ *ret = c;
+
+ return 0;
+}
+
int inotify_add_watch_fd(int fd, int what, uint32_t mask) {
char path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1];
int r;
diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h
index 517b599d6f..075e5942b1 100644
--- a/src/basic/fs-util.h
+++ b/src/basic/fs-util.h
@@ -61,6 +61,8 @@ int mkfifo_atomic(const char *path, mode_t mode);
int get_files_in_directory(const char *path, char ***list);
+int var_tmp(char **ret);
+
#define INOTIFY_EVENT_MAX (sizeof(struct inotify_event) + NAME_MAX + 1)
#define FOREACH_INOTIFY_EVENT(e, buffer, sz) \
diff --git a/src/basic/strv.c b/src/basic/strv.c
index 578a9c1005..53298268f4 100644
--- a/src/basic/strv.c
+++ b/src/basic/strv.c
@@ -139,16 +139,16 @@ char **strv_new_ap(const char *x, va_list ap) {
va_list aq;
/* As a special trick we ignore all listed strings that equal
- * (const char*) -1. This is supposed to be used with the
+ * STRV_IGNORE. This is supposed to be used with the
* STRV_IFNOTNULL() macro to include possibly NULL strings in
* the string list. */
if (x) {
- n = x == (const char*) -1 ? 0 : 1;
+ n = x == STRV_IGNORE ? 0 : 1;
va_copy(aq, ap);
while ((s = va_arg(aq, const char*))) {
- if (s == (const char*) -1)
+ if (s == STRV_IGNORE)
continue;
n++;
@@ -162,7 +162,7 @@ char **strv_new_ap(const char *x, va_list ap) {
return NULL;
if (x) {
- if (x != (const char*) -1) {
+ if (x != STRV_IGNORE) {
a[i] = strdup(x);
if (!a[i])
goto fail;
@@ -171,7 +171,7 @@ char **strv_new_ap(const char *x, va_list ap) {
while ((s = va_arg(ap, const char*))) {
- if (s == (const char*) -1)
+ if (s == STRV_IGNORE)
continue;
a[i] = strdup(s);
@@ -834,7 +834,7 @@ bool strv_fnmatch(char* const* patterns, const char *s, int flags) {
char* const* p;
STRV_FOREACH(p, patterns)
- if (fnmatch(*p, s, 0) == 0)
+ if (fnmatch(*p, s, flags) == 0)
return true;
return false;
diff --git a/src/basic/strv.h b/src/basic/strv.h
index f61bbb5386..683ce83a2a 100644
--- a/src/basic/strv.h
+++ b/src/basic/strv.h
@@ -69,8 +69,10 @@ bool strv_equal(char **a, char **b);
char **strv_new(const char *x, ...) _sentinel_;
char **strv_new_ap(const char *x, va_list ap);
+#define STRV_IGNORE ((const char *) -1)
+
static inline const char* STRV_IFNOTNULL(const char *x) {
- return x ? x : (const char *) -1;
+ return x ? x : STRV_IGNORE;
}
static inline bool strv_isempty(char * const *l) {
diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c
index a37316b8f9..f61f158e8a 100644
--- a/src/journal/journal-verify.c
+++ b/src/journal/journal-verify.c
@@ -26,6 +26,7 @@
#include "compress.h"
#include "fd-util.h"
#include "fileio.h"
+#include "fs-util.h"
#include "journal-authenticate.h"
#include "journal-def.h"
#include "journal-file.h"
@@ -825,6 +826,8 @@ int journal_file_verify(
int data_fd = -1, entry_fd = -1, entry_array_fd = -1;
unsigned i;
bool found_last = false;
+ _cleanup_free_ char *tmp_dir = NULL;
+
#ifdef HAVE_GCRYPT
uint64_t last_tag = 0;
#endif
@@ -843,19 +846,25 @@ int journal_file_verify(
} else if (f->seal)
return -ENOKEY;
- data_fd = open_tmpfile_unlinkable("/var/tmp", O_RDWR | O_CLOEXEC);
+ r = var_tmp(&tmp_dir);
+ if (r < 0) {
+ log_error_errno(r, "Failed to determine temporary directory: %m");
+ goto fail;
+ }
+
+ data_fd = open_tmpfile_unlinkable(tmp_dir, O_RDWR | O_CLOEXEC);
if (data_fd < 0) {
r = log_error_errno(data_fd, "Failed to create data file: %m");
goto fail;
}
- entry_fd = open_tmpfile_unlinkable("/var/tmp", O_RDWR | O_CLOEXEC);
+ entry_fd = open_tmpfile_unlinkable(tmp_dir, O_RDWR | O_CLOEXEC);
if (entry_fd < 0) {
r = log_error_errno(entry_fd, "Failed to create entry file: %m");
goto fail;
}
- entry_array_fd = open_tmpfile_unlinkable("/var/tmp", O_RDWR | O_CLOEXEC);
+ entry_array_fd = open_tmpfile_unlinkable(tmp_dir, O_RDWR | O_CLOEXEC);
if (entry_array_fd < 0) {
r = log_error_errno(entry_array_fd,
"Failed to create entry array file: %m");
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 8e4897831b..4cc0c2b6c2 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -348,6 +348,7 @@ static int parse_argv(int argc, char *argv[]) {
ARG_NO_FULL,
ARG_NO_TAIL,
ARG_NEW_ID128,
+ ARG_THIS_BOOT,
ARG_LIST_BOOTS,
ARG_USER,
ARG_SYSTEM,
@@ -392,9 +393,9 @@ static int parse_argv(int argc, char *argv[]) {
{ "new-id128", no_argument, NULL, ARG_NEW_ID128 },
{ "quiet", no_argument, NULL, 'q' },
{ "merge", no_argument, NULL, 'm' },
+ { "this-boot", no_argument, NULL, ARG_THIS_BOOT }, /* deprecated */
{ "boot", optional_argument, NULL, 'b' },
{ "list-boots", no_argument, NULL, ARG_LIST_BOOTS },
- { "this-boot", optional_argument, NULL, 'b' }, /* deprecated */
{ "dmesg", no_argument, NULL, 'k' },
{ "system", no_argument, NULL, ARG_SYSTEM },
{ "user", no_argument, NULL, ARG_USER },
@@ -544,6 +545,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_merge = true;
break;
+ case ARG_THIS_BOOT:
+ arg_boot = true;
+ break;
+
case 'b':
arg_boot = true;
@@ -868,8 +873,8 @@ static int parse_argv(int argc, char *argv[]) {
return -EINVAL;
}
- if ((arg_boot || arg_action == ACTION_LIST_BOOTS) && (arg_file || arg_directory || arg_merge)) {
- log_error("Using --boot or --list-boots with --file, --directory or --merge is not supported.");
+ if ((arg_boot || arg_action == ACTION_LIST_BOOTS) && arg_merge) {
+ log_error("Using --boot or --list-boots with --merge is not supported.");
return -EINVAL;
}
@@ -1102,13 +1107,13 @@ static int discover_next_boot(sd_journal *j,
static int get_boots(
sd_journal *j,
BootId **boots,
- sd_id128_t *query_ref_boot,
- int ref_boot_offset) {
+ sd_id128_t *boot_id,
+ int offset) {
bool skip_once;
int r, count = 0;
BootId *head = NULL, *tail = NULL;
- const bool advance_older = query_ref_boot && ref_boot_offset <= 0;
+ const bool advance_older = boot_id && offset <= 0;
sd_id128_t previous_boot_id;
assert(j);
@@ -1116,19 +1121,19 @@ static int get_boots(
/* Adjust for the asymmetry that offset 0 is
* the last (and current) boot, while 1 is considered the
* (chronological) first boot in the journal. */
- skip_once = query_ref_boot && sd_id128_is_null(*query_ref_boot) && ref_boot_offset < 0;
+ skip_once = boot_id && sd_id128_is_null(*boot_id) && offset <= 0;
/* Advance to the earliest/latest occurrence of our reference
* boot ID (taking our lookup direction into account), so that
* discover_next_boot() can do its job.
* If no reference is given, the journal head/tail will do,
* they're "virtual" boots after all. */
- if (query_ref_boot && !sd_id128_is_null(*query_ref_boot)) {
+ if (boot_id && !sd_id128_is_null(*boot_id)) {
char match[9+32+1] = "_BOOT_ID=";
sd_journal_flush_matches(j);
- sd_id128_to_string(*query_ref_boot, match + 9);
+ sd_id128_to_string(*boot_id, match + 9);
r = sd_journal_add_match(j, match, sizeof(match) - 1);
if (r < 0)
return r;
@@ -1148,7 +1153,7 @@ static int get_boots(
return r;
else if (r == 0)
goto finish;
- else if (ref_boot_offset == 0) {
+ else if (offset == 0) {
count = 1;
goto finish;
}
@@ -1187,14 +1192,14 @@ static int get_boots(
previous_boot_id = current->id;
- if (query_ref_boot) {
+ if (boot_id) {
if (!skip_once)
- ref_boot_offset += advance_older ? 1 : -1;
+ offset += advance_older ? 1 : -1;
skip_once = false;
- if (ref_boot_offset == 0) {
+ if (offset == 0) {
count = 1;
- *query_ref_boot = current->id;
+ *boot_id = current->id;
break;
}
} else {
@@ -1250,7 +1255,7 @@ static int list_boots(sd_journal *j) {
static int add_boot(sd_journal *j) {
char match[9+32+1] = "_BOOT_ID=";
- sd_id128_t ref_boot_id;
+ sd_id128_t boot_id;
int r;
assert(j);
@@ -1258,11 +1263,16 @@ static int add_boot(sd_journal *j) {
if (!arg_boot)
return 0;
- if (arg_boot_offset == 0 && sd_id128_equal(arg_boot_id, SD_ID128_NULL))
+ /* Take a shortcut and use the current boot_id, which we can do very quickly.
+ * We can do this only when we logs are coming from the current machine,
+ * so take the slow path if log location is specified. */
+ if (arg_boot_offset == 0 && sd_id128_equal(arg_boot_id, SD_ID128_NULL) &&
+ !arg_directory && !arg_file)
+
return add_match_this_boot(j, arg_machine);
- ref_boot_id = arg_boot_id;
- r = get_boots(j, NULL, &ref_boot_id, arg_boot_offset);
+ boot_id = arg_boot_id;
+ r = get_boots(j, NULL, &boot_id, arg_boot_offset);
assert(r <= 1);
if (r <= 0) {
const char *reason = (r == 0) ? "No such boot ID in journal" : strerror(-r);
@@ -1277,7 +1287,7 @@ static int add_boot(sd_journal *j) {
return r == 0 ? -ENODATA : r;
}
- sd_id128_to_string(ref_boot_id, match + 9);
+ sd_id128_to_string(boot_id, match + 9);
r = sd_journal_add_match(j, match, sizeof(match) - 1);
if (r < 0)
diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c
index 397baf6f33..db01f21135 100644
--- a/src/libsystemd/sd-bus/bus-match.c
+++ b/src/libsystemd/sd-bus/bus-match.c
@@ -429,6 +429,9 @@ int bus_match_run(
r = bus_match_run(bus, c, m);
if (r != 0)
return r;
+
+ if (bus && bus->match_callbacks_modified)
+ return 0;
}
}
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index add463b6a9..92ade820ac 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -1200,6 +1200,11 @@ int manager_compile_dns_servers(Manager *m, OrderedSet **dns) {
return 0;
}
+/* filter_route is a tri-state:
+ * < 0: no filtering
+ * = 0 or false: return only domains which should be used for searching
+ * > 0 or true: return only domains which are for routing only
+ */
int manager_compile_search_domains(Manager *m, OrderedSet **domains, int filter_route) {
DnsSearchDomain *d;
Iterator i;
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index c0b285b58f..b575437bcb 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4367,7 +4367,7 @@ static int print_property(const char *name, sd_bus_message *m, const char *conte
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(m, "(sb)", &path, &ignore)) > 0)
- print_prop("EnvironmentFile", "%s (ignore_errors=%s)\n", path, yes_no(ignore));
+ print_prop("EnvironmentFile", "%s (ignore_errors=%s)", path, yes_no(ignore));
if (r < 0)
return bus_log_parse_error(r);
@@ -5605,6 +5605,46 @@ static int mangle_names(char **original_names, char ***mangled_names) {
return 0;
}
+static int unit_exists(const char *unit) {
+ _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL, *m = NULL;
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_free_ char *path = NULL;
+ static const struct bus_properties_map property_map[] = {
+ { "LoadState", "s", NULL, offsetof(UnitStatusInfo, load_state) },
+ { "ActiveState", "s", NULL, offsetof(UnitStatusInfo, active_state)},
+ {},
+ };
+ UnitStatusInfo info = {};
+ sd_bus *bus;
+ int r;
+
+ path = unit_dbus_path_from_name(unit);
+ if (!path)
+ return log_oom();
+
+ r = acquire_bus(BUS_MANAGER, &bus);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_call_method(
+ bus,
+ "org.freedesktop.systemd1",
+ path,
+ "org.freedesktop.DBus.Properties",
+ "GetAll",
+ &error,
+ &reply,
+ "s", "");
+ if (r < 0)
+ return log_error_errno(r, "Failed to get properties: %s", bus_error_message(&error, r));
+
+ r = bus_message_map_all_properties(reply, property_map, &info);
+ if (r < 0)
+ return log_error_errno(r, "Failed to map properties: %s", bus_error_message(&error, r));
+
+ return !streq_ptr(info.load_state, "not-found") || !streq_ptr(info.active_state, "inactive");
+}
+
static int enable_unit(int argc, char *argv[], void *userdata) {
_cleanup_strv_free_ char **names = NULL;
const char *verb = argv[0];
@@ -5666,6 +5706,14 @@ static int enable_unit(int argc, char *argv[], void *userdata) {
const char *method;
sd_bus *bus;
+ if (STR_IN_SET(verb, "mask", "unmask")) {
+ r = unit_exists(*names);
+ if (r < 0)
+ return r;
+ if (r == 0)
+ log_notice("Unit %s does not exist, proceeding anyway.", *names);
+ }
+
r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0)
return r;
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c
index 6db2c2b6f1..e0c040f39b 100644
--- a/src/test/test-fs-util.c
+++ b/src/test/test-fs-util.c
@@ -82,10 +82,56 @@ static void test_get_files_in_directory(void) {
assert_se(get_files_in_directory(".", NULL) >= 0);
}
+static void test_var_tmp(void) {
+ char *tmp_dir = NULL;
+ char *tmpdir_backup = NULL;
+ const char *default_var_tmp = NULL;
+ const char *var_name;
+ bool do_overwrite = true;
+
+ default_var_tmp = "/var/tmp";
+ var_name = "TMPDIR";
+
+ if (getenv(var_name) != NULL) {
+ tmpdir_backup = strdup(getenv(var_name));
+ assert_se(tmpdir_backup != NULL);
+ }
+
+ unsetenv(var_name);
+
+ var_tmp(&tmp_dir);
+ assert_se(!strcmp(tmp_dir, default_var_tmp));
+
+ free(tmp_dir);
+
+ setenv(var_name, "/tmp", do_overwrite);
+ assert_se(!strcmp(getenv(var_name), "/tmp"));
+
+ var_tmp(&tmp_dir);
+ assert_se(!strcmp(tmp_dir, "/tmp"));
+
+ free(tmp_dir);
+
+ setenv(var_name, "/88_does_not_exist_88", do_overwrite);
+ assert_se(!strcmp(getenv(var_name), "/88_does_not_exist_88"));
+
+ var_tmp(&tmp_dir);
+ assert_se(!strcmp(tmp_dir, default_var_tmp));
+
+ free(tmp_dir);
+
+ if (tmpdir_backup != NULL) {
+ setenv(var_name, tmpdir_backup, do_overwrite);
+ assert_se(!strcmp(getenv(var_name), tmpdir_backup));
+ free(tmpdir_backup);
+ }
+}
+
int main(int argc, char *argv[]) {
test_unlink_noerrno();
test_readlink_and_make_absolute();
test_get_files_in_directory();
+ test_var_tmp();
return 0;
}
diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c
index b53324b5e6..6094d4c3e5 100644
--- a/src/test/test-path-util.c
+++ b/src/test/test-path-util.c
@@ -114,7 +114,7 @@ static void test_find_binary(const char *self) {
assert_se(find_binary(self, &p) == 0);
puts(p);
- assert_se(endswith(p, "/test-path-util"));
+ assert_se(endswith(p, "/lt-test-path-util"));
assert_se(path_is_absolute(p));
free(p);
diff --git a/src/test/test-strv.c b/src/test/test-strv.c
index fc01dcfaf1..cf5887d258 100644
--- a/src/test/test-strv.c
+++ b/src/test/test-strv.c
@@ -685,6 +685,16 @@ static void test_foreach_string(void) {
assert_se(streq(x, "zzz"));
}
+static void test_strv_fnmatch(void) {
+ _cleanup_free_ char **v = NULL;
+
+ assert_se(!strv_fnmatch(STRV_MAKE_EMPTY, "a", 0));
+
+ v = strv_new("*\\*", NULL);
+ assert_se(!strv_fnmatch(v, "\\", 0));
+ assert_se(strv_fnmatch(v, "\\", FNM_NOESCAPE));
+}
+
int main(int argc, char *argv[]) {
test_specifier_printf();
test_strv_foreach();
@@ -750,6 +760,7 @@ int main(int argc, char *argv[]) {
test_strv_make_nulstr();
test_foreach_string();
+ test_strv_fnmatch();
return 0;
}