Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V255 stable batch #386

Merged
merged 5 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 40 additions & 29 deletions src/core/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static const UnitActiveState state_translation_table[_MOUNT_STATE_MAX] = {

static int mount_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata);
static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata);
static void mount_enter_dead(Mount *m, MountResult f);
static void mount_enter_dead(Mount *m, MountResult f, bool flush_result);
static void mount_enter_mounted(Mount *m, MountResult f);
static void mount_cycle_clear(Mount *m);
static int mount_process_proc_self_mountinfo(Manager *m);
Expand Down Expand Up @@ -846,7 +846,7 @@ static void mount_catchup(Unit *u) {
break;
case MOUNT_MOUNTED:
assert(!pidref_is_set(&m->control_pid));
mount_enter_dead(m, MOUNT_SUCCESS);
mount_enter_dead(m, MOUNT_SUCCESS, /* flush_result = */ false);
break;
default:
break;
Expand Down Expand Up @@ -952,10 +952,10 @@ static int mount_spawn(Mount *m, ExecCommand *c, PidRef *ret_pid) {
return 0;
}

static void mount_enter_dead(Mount *m, MountResult f) {
static void mount_enter_dead(Mount *m, MountResult f, bool flush_result) {
assert(m);

if (m->result == MOUNT_SUCCESS)
if (m->result == MOUNT_SUCCESS || flush_result)
m->result = f;

unit_log_result(UNIT(m), m->result == MOUNT_SUCCESS, mount_result_to_string(m->result));
Expand Down Expand Up @@ -983,17 +983,20 @@ static void mount_enter_mounted(Mount *m, MountResult f) {
mount_set_state(m, MOUNT_MOUNTED);
}

static void mount_enter_dead_or_mounted(Mount *m, MountResult f) {
static void mount_enter_dead_or_mounted(Mount *m, MountResult f, bool flush_result) {
assert(m);

/* Enter DEAD or MOUNTED state, depending on what the kernel currently says about the mount point. We use this
* whenever we executed an operation, so that our internal state reflects what the kernel says again, after all
* ultimately we just mirror the kernel's internal state on this. */
/* Enter DEAD or MOUNTED state, depending on what the kernel currently says about the mount point.
* We use this whenever we executed an operation, so that our internal state reflects what
* the kernel says again, after all ultimately we just mirror the kernel's internal state on this.
*
* Note that flush_result only applies to mount_enter_dead(), since that's when the result gets
* turned into unit end state. */

if (m->from_proc_self_mountinfo)
mount_enter_mounted(m, f);
else
mount_enter_dead(m, f);
mount_enter_dead(m, f, flush_result);
}

static int state_to_kill_operation(MountState state) {
Expand Down Expand Up @@ -1049,12 +1052,12 @@ static void mount_enter_signal(Mount *m, MountState state, MountResult f) {
else if (state == MOUNT_UNMOUNTING_SIGTERM && m->kill_context.send_sigkill)
mount_enter_signal(m, MOUNT_UNMOUNTING_SIGKILL, MOUNT_SUCCESS);
else
mount_enter_dead_or_mounted(m, MOUNT_SUCCESS);
mount_enter_dead_or_mounted(m, MOUNT_SUCCESS, /* flush_result = */ false);

return;

fail:
mount_enter_dead_or_mounted(m, MOUNT_FAILURE_RESOURCES);
mount_enter_dead_or_mounted(m, MOUNT_FAILURE_RESOURCES, /* flush_result = */ false);
}

static int mount_set_umount_command(Mount *m, ExecCommand *c) {
Expand Down Expand Up @@ -1116,7 +1119,7 @@ static void mount_enter_unmounting(Mount *m) {
return;

fail:
mount_enter_dead_or_mounted(m, MOUNT_FAILURE_RESOURCES);
mount_enter_dead_or_mounted(m, MOUNT_FAILURE_RESOURCES, /* flush_result = */ false);
}

static int mount_set_mount_command(Mount *m, ExecCommand *c, const MountParameters *p) {
Expand Down Expand Up @@ -1232,7 +1235,7 @@ static void mount_enter_mounting(Mount *m) {
return;

fail:
mount_enter_dead_or_mounted(m, MOUNT_FAILURE_RESOURCES);
mount_enter_dead_or_mounted(m, MOUNT_FAILURE_RESOURCES, /* flush_result = */ false);
}

static void mount_set_reload_result(Mount *m, MountResult result) {
Expand Down Expand Up @@ -1298,7 +1301,7 @@ static void mount_enter_remounting(Mount *m) {

fail:
mount_set_reload_result(m, MOUNT_FAILURE_RESOURCES);
mount_enter_dead_or_mounted(m, MOUNT_SUCCESS);
mount_enter_dead_or_mounted(m, MOUNT_SUCCESS, /* flush_result = */ false);
}

static void mount_cycle_clear(Mount *m) {
Expand Down Expand Up @@ -1472,8 +1475,8 @@ static int mount_deserialize_item(Unit *u, const char *key, const char *value, F

} else if (streq(key, "control-pid")) {

pidref_done(&m->control_pid);
(void) deserialize_pidref(fds, value, &m->control_pid);
if (!pidref_is_set(&m->control_pid))
(void) deserialize_pidref(fds, value, &m->control_pid);

} else if (streq(key, "control-command")) {
MountExecCommand id;
Expand Down Expand Up @@ -1587,7 +1590,7 @@ static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
log_unit_warning(UNIT(m), "Mount process finished, but there is no mount.");
f = MOUNT_FAILURE_PROTOCOL;
}
mount_enter_dead(m, f);
mount_enter_dead(m, f, /* flush_result = */ false);
break;

case MOUNT_MOUNTING_DONE:
Expand All @@ -1597,7 +1600,7 @@ static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
case MOUNT_REMOUNTING:
case MOUNT_REMOUNTING_SIGTERM:
case MOUNT_REMOUNTING_SIGKILL:
mount_enter_dead_or_mounted(m, MOUNT_SUCCESS);
mount_enter_dead_or_mounted(m, MOUNT_SUCCESS, /* flush_result = */ false);
break;

case MOUNT_UNMOUNTING:
Expand All @@ -1618,22 +1621,27 @@ static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
/* Hmm, umount process spawned by us failed, but the mount disappeared anyway?
* Maybe someone else is trying to unmount at the same time. */
log_unit_notice(u, "Mount disappeared even though umount process failed, continuing.");
mount_enter_dead(m, MOUNT_SUCCESS);
mount_enter_dead(m, MOUNT_SUCCESS, /* flush_result = */ true);
} else
mount_enter_dead_or_mounted(m, f);
/* At this point, either the unmount succeeded or unexpected error occurred. We usually
* remember the first error in 'result', but here let's update that forcibly, since
* there could previous failed attempts yet we only care about the most recent
* attempt. IOW, if we eventually managed to unmount the stuff, don't enter failed
* end state. */
mount_enter_dead_or_mounted(m, f, /* flush_result = */ true);

break;

case MOUNT_UNMOUNTING_SIGTERM:
case MOUNT_UNMOUNTING_SIGKILL:
mount_enter_dead_or_mounted(m, f);
mount_enter_dead_or_mounted(m, f, /* flush_result = */ false);
break;

case MOUNT_CLEANING:
if (m->clean_result == MOUNT_SUCCESS)
m->clean_result = f;

mount_enter_dead(m, MOUNT_SUCCESS);
mount_enter_dead(m, MOUNT_SUCCESS, /* flush_result = */ false);
break;

default:
Expand Down Expand Up @@ -1672,15 +1680,15 @@ static int mount_dispatch_timer(sd_event_source *source, usec_t usec, void *user
mount_enter_signal(m, MOUNT_REMOUNTING_SIGKILL, MOUNT_SUCCESS);
} else {
log_unit_warning(UNIT(m), "Remounting timed out. Skipping SIGKILL. Ignoring.");
mount_enter_dead_or_mounted(m, MOUNT_SUCCESS);
mount_enter_dead_or_mounted(m, MOUNT_SUCCESS, /* flush_result = */ false);
}
break;

case MOUNT_REMOUNTING_SIGKILL:
mount_set_reload_result(m, MOUNT_FAILURE_TIMEOUT);

log_unit_warning(UNIT(m), "Mount process still around after SIGKILL. Ignoring.");
mount_enter_dead_or_mounted(m, MOUNT_SUCCESS);
mount_enter_dead_or_mounted(m, MOUNT_SUCCESS, /* flush_result = */ false);
break;

case MOUNT_UNMOUNTING:
Expand All @@ -1694,13 +1702,13 @@ static int mount_dispatch_timer(sd_event_source *source, usec_t usec, void *user
mount_enter_signal(m, MOUNT_UNMOUNTING_SIGKILL, MOUNT_FAILURE_TIMEOUT);
} else {
log_unit_warning(UNIT(m), "Mount process timed out. Skipping SIGKILL. Ignoring.");
mount_enter_dead_or_mounted(m, MOUNT_FAILURE_TIMEOUT);
mount_enter_dead_or_mounted(m, MOUNT_FAILURE_TIMEOUT, /* flush_result = */ false);
}
break;

case MOUNT_UNMOUNTING_SIGKILL:
log_unit_warning(UNIT(m), "Mount process still around after SIGKILL. Ignoring.");
mount_enter_dead_or_mounted(m, MOUNT_FAILURE_TIMEOUT);
mount_enter_dead_or_mounted(m, MOUNT_FAILURE_TIMEOUT, /* flush_result = */ false);
break;

case MOUNT_CLEANING:
Expand Down Expand Up @@ -2161,8 +2169,11 @@ static int mount_process_proc_self_mountinfo(Manager *m) {
switch (mount->state) {

case MOUNT_MOUNTED:
/* This has just been unmounted by somebody else, follow the state change. */
mount_enter_dead(mount, MOUNT_SUCCESS);
/* This has just been unmounted by somebody else, follow the state change.
* Also explicitly override the result (see the comment in mount_sigchld_event()),
* but more aggressively here since the state change is extrinsic. */
mount_cycle_clear(mount);
mount_enter_dead(mount, MOUNT_SUCCESS, /* flush_result = */ true);
break;

case MOUNT_MOUNTING_DONE:
Expand Down Expand Up @@ -2334,7 +2345,7 @@ static int mount_can_start(Unit *u) {

r = unit_test_start_limit(u);
if (r < 0) {
mount_enter_dead(m, MOUNT_FAILURE_START_LIMIT_HIT);
mount_enter_dead(m, MOUNT_FAILURE_START_LIMIT_HIT, /* flush_result = */ false);
return r;
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ static int scope_deserialize_item(Unit *u, const char *key, const char *value, F
} else if (streq(key, "pids")) {
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;

/* We don't check if we already received the pid before here because unit_watch_pidref()
* does this check internally and discards the new pidref if we already received it before. */
if (deserialize_pidref(fds, value, &pidref) >= 0) {
r = unit_watch_pidref(u, &pidref, /* exclusive= */ false);
if (r < 0)
Expand Down
6 changes: 3 additions & 3 deletions src/core/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -3174,14 +3174,14 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
s->reload_result = f;

} else if (streq(key, "control-pid")) {
pidref_done(&s->control_pid);

(void) deserialize_pidref(fds, value, &s->control_pid);
if (!pidref_is_set(&s->control_pid))
(void) deserialize_pidref(fds, value, &s->control_pid);

} else if (streq(key, "main-pid")) {
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;

if (deserialize_pidref(fds, value, &pidref) >= 0)
if (!pidref_is_set(&s->main_pid) && deserialize_pidref(fds, value, &pidref) >= 0)
(void) service_set_main_pidref(s, &pidref);

} else if (streq(key, "main-pid-known")) {
Expand Down
5 changes: 3 additions & 2 deletions src/core/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -2634,8 +2634,9 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value,
else
s->n_refused += k;
} else if (streq(key, "control-pid")) {
pidref_done(&s->control_pid);
(void) deserialize_pidref(fds, value, &s->control_pid);

if (!pidref_is_set(&s->control_pid))
(void) deserialize_pidref(fds, value, &s->control_pid);

} else if (streq(key, "control-command")) {
SocketExecCommand id;
Expand Down
4 changes: 2 additions & 2 deletions src/core/swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -989,8 +989,8 @@ static int swap_deserialize_item(Unit *u, const char *key, const char *value, FD
s->result = f;
} else if (streq(key, "control-pid")) {

pidref_done(&s->control_pid);
(void) deserialize_pidref(fds, value, &s->control_pid);
if (!pidref_is_set(&s->control_pid))
(void) deserialize_pidref(fds, value, &s->control_pid);

} else if (streq(key, "control-command")) {
SwapExecCommand id;
Expand Down
22 changes: 2 additions & 20 deletions src/journal-remote/journal-remote-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,24 +535,6 @@ static int dispatch_http_event(sd_event_source *event,
**********************************************************************
**********************************************************************/

static int setup_signals(RemoteServer *s) {
int r;

assert(s);

assert_se(sigprocmask_many(SIG_SETMASK, NULL, SIGINT, SIGTERM, -1) >= 0);

r = sd_event_add_signal(s->events, &s->sigterm_event, SIGTERM, NULL, s);
if (r < 0)
return r;

r = sd_event_add_signal(s->events, &s->sigint_event, SIGINT, NULL, s);
if (r < 0)
return r;

return 0;
}

static int setup_raw_socket(RemoteServer *s, const char *address) {
int fd;

Expand Down Expand Up @@ -580,9 +562,9 @@ static int create_remoteserver(
if (r < 0)
return r;

r = setup_signals(s);
r = sd_event_set_signal_exit(s->events, true);
if (r < 0)
return log_error_errno(r, "Failed to set up signals: %m");
return log_error_errno(r, "Failed to install SIGINT/SIGTERM handlers: %m");

n = sd_listen_fds(true);
if (n < 0)
Expand Down
2 changes: 0 additions & 2 deletions src/journal-remote/journal-remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,6 @@ void journal_remote_server_destroy(RemoteServer *s) {
writer_unref(s->_single_writer);
hashmap_free(s->writers);

sd_event_source_unref(s->sigterm_event);
sd_event_source_unref(s->sigint_event);
sd_event_source_unref(s->listen_event);
sd_event_unref(s->events);

Expand Down
2 changes: 1 addition & 1 deletion src/journal-remote/journal-remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct RemoteServer {
size_t active;

sd_event *events;
sd_event_source *sigterm_event, *sigint_event, *listen_event;
sd_event_source *listen_event;

Hashmap *writers;
Writer *_single_writer;
Expand Down
38 changes: 2 additions & 36 deletions src/journal-remote/journal-upload.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,38 +380,6 @@ static int open_file_for_upload(Uploader *u, const char *filename) {
return r;
}

static int dispatch_sigterm(sd_event_source *event,
const struct signalfd_siginfo *si,
void *userdata) {
Uploader *u = ASSERT_PTR(userdata);

log_received_signal(LOG_INFO, si);

close_fd_input(u);
close_journal_input(u);

sd_event_exit(u->events, 0);
return 0;
}

static int setup_signals(Uploader *u) {
int r;

assert(u);

assert_se(sigprocmask_many(SIG_SETMASK, NULL, SIGINT, SIGTERM, -1) >= 0);

r = sd_event_add_signal(u->events, &u->sigterm_event, SIGTERM, dispatch_sigterm, u);
if (r < 0)
return r;

r = sd_event_add_signal(u->events, &u->sigint_event, SIGINT, dispatch_sigterm, u);
if (r < 0)
return r;

return 0;
}

static int setup_uploader(Uploader *u, const char *url, const char *state_file) {
int r;
const char *host, *proto = "";
Expand Down Expand Up @@ -451,9 +419,9 @@ static int setup_uploader(Uploader *u, const char *url, const char *state_file)
if (r < 0)
return log_error_errno(r, "sd_event_default failed: %m");

r = setup_signals(u);
r = sd_event_set_signal_exit(u->events, true);
if (r < 0)
return log_error_errno(r, "Failed to set up signals: %m");
return log_error_errno(r, "Failed to install SIGINT/SIGTERM handlers: %m");

(void) sd_watchdog_enabled(false, &u->watchdog_usec);

Expand All @@ -477,8 +445,6 @@ static void destroy_uploader(Uploader *u) {
close_fd_input(u);
close_journal_input(u);

sd_event_source_unref(u->sigterm_event);
sd_event_source_unref(u->sigint_event);
sd_event_unref(u->events);
}

Expand Down
1 change: 0 additions & 1 deletion src/journal-remote/journal-upload.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ typedef enum {

typedef struct Uploader {
sd_event *events;
sd_event_source *sigint_event, *sigterm_event;

char *url;
CURL *easy;
Expand Down
Loading
Loading