Compare commits

...

3 Commits

Author SHA1 Message Date
Petr Menšík 1dc5672376
Merge b8675eef92 into 49fd31df58 2024-10-18 10:50:30 +05:30
Petr Menšík b8675eef92 Cancel re-link to uplink if it is missing
In case target file would be missing as well, symlinking to it won't
help. Just log it and finish.
2024-03-05 21:38:12 +01:00
Petr Menšík 844b2e9588 Configure no-stub fallback on resolved shutdown
When stub listener is disabled, stub-resolv.conf is made symlink to
resolv.conf. That contains valid servers obtained from the system. Do
the same action on systemd-resolved shutdown, where stub listener
becomes unavailable. If /etc/resolv.conf is linked to stub-resolv.conf,
avoid breaking network resolution on temporary resolved shutdown.
It gets fixed on (re)start again. Ignore return code, used only for
logging.
2024-03-05 21:20:24 +01:00
3 changed files with 25 additions and 9 deletions

View File

@ -323,6 +323,25 @@ static int write_stub_resolv_conf_contents(FILE *f, OrderedSet *dns, OrderedSet
return fflush_and_check(f);
}
void manager_symlink_stub_to_uplink_resolv_conf(void) {
_cleanup_free_ char *fname = NULL;
int r;
if (access(PRIVATE_UPLINK_RESOLV_CONF, R_OK) != 0) {
log_debug("Uplink %s is missing.", PRIVATE_UPLINK_RESOLV_CONF);
return;
}
r = path_extract_filename(PRIVATE_UPLINK_RESOLV_CONF, &fname);
if (r < 0) {
log_warning_errno(r, "Failed to extract filename from path '" PRIVATE_UPLINK_RESOLV_CONF "', ignoring: %m");
return;
}
r = symlink_atomic_label(fname, PRIVATE_STUB_RESOLV_CONF);
if (r < 0)
log_warning_errno(r, "Failed to symlink %s, ignoring: %m", PRIVATE_STUB_RESOLV_CONF);
}
int manager_write_resolv_conf(Manager *m) {
_cleanup_ordered_set_free_ OrderedSet *dns = NULL, *domains = NULL;
_cleanup_(unlink_and_freep) char *temp_path_uplink = NULL, *temp_path_stub = NULL;
@ -369,16 +388,9 @@ int manager_write_resolv_conf(Manager *m) {
log_warning_errno(r, "Failed to move new %s into place, ignoring: %m", PRIVATE_STUB_RESOLV_CONF);
temp_path_stub = mfree(temp_path_stub); /* free the string explicitly, so that we don't unlink anymore */
} else {
_cleanup_free_ char *fname = NULL;
r = path_extract_filename(PRIVATE_UPLINK_RESOLV_CONF, &fname);
if (r < 0)
return log_warning_errno(r, "Failed to extract filename from path '" PRIVATE_UPLINK_RESOLV_CONF "', ignoring: %m");
} else
manager_symlink_stub_to_uplink_resolv_conf();
r = symlink_atomic_label(fname, PRIVATE_STUB_RESOLV_CONF);
if (r < 0)
log_warning_errno(r, "Failed to symlink %s, ignoring: %m", PRIVATE_STUB_RESOLV_CONF);
}
r = conservative_rename(temp_path_uplink, PRIVATE_UPLINK_RESOLV_CONF);
if (r < 0)

View File

@ -6,6 +6,7 @@
int manager_check_resolv_conf(const Manager *m);
int manager_read_resolv_conf(Manager *m);
int manager_write_resolv_conf(Manager *m);
void manager_symlink_stub_to_uplink_resolv_conf(void);
typedef enum ResolvConfMode {
RESOLV_CONF_UPLINK,

View File

@ -91,6 +91,9 @@ static int run(int argc, char *argv[]) {
if (r < 0)
return log_error_errno(r, "Event loop failed: %m");
/* send queries on shutdown to other servers */
manager_symlink_stub_to_uplink_resolv_conf();
return 0;
}