Skip to content

Commit 48a051c

Browse files
committed
ssh-agent: exit 0 from SIGTERM under systemd socket-activation
When the ssh-agent service is configured to be launched under systemd socket-activation, the user can inspect the status of the agent with something like: systemctl --user status ssh-agent.service If the user does: systemctl --user stop ssh-agent.service it causes the `systemd --user` supervisor to send a SIGTERM to the agent, which terminates while leaving the systemd-managed socket in place. That's good, and as expected. (If the user wants to close the socket, they can do "systemctl --user stop ssh-agent.socket" instead) But because ssh-agent exits with code 2 in response to a SIGTERM, the supervisor marks the service as "failed", even though the state of the supervised service is exactly the same as during session startup (not running, ready to launch when a client connects to the socket). This change makes ssh-agent exit cleanly (code 0) in response to a SIGTERM when launched under socket activation. This aligns the systemd supervisor's understanding of the state of supervised ssh-agent with reality. Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
1 parent 849c2fd commit 48a051c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ssh-agent.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2238,6 +2238,7 @@ main(int ac, char **av)
22382238
size_t npfd = 0;
22392239
u_int maxfds;
22402240
sigset_t nsigset, osigset;
2241+
int socket_activated = 0;
22412242

22422243
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
22432244
sanitise_stdfd();
@@ -2389,6 +2390,7 @@ main(int ac, char **av)
23892390
fatal("bad LISTEN_PID: %d vs pid %d", pid, getpid());
23902391
debug("using socket activation on fd=3");
23912392
sock = 3;
2393+
socket_activated = 1;
23922394
}
23932395

23942396
/* Otherwise, create private directory for agent socket */
@@ -2522,7 +2524,7 @@ main(int ac, char **av)
25222524
sigprocmask(SIG_BLOCK, &nsigset, &osigset);
25232525
if (signalled_exit != 0) {
25242526
logit("exiting on signal %d", (int)signalled_exit);
2525-
cleanup_exit(2);
2527+
cleanup_exit((signalled_exit == SIGTERM && socket_activated) ? 0 : 2);
25262528
}
25272529
if (signalled_keydrop) {
25282530
logit("signal %d received; removing all keys",

0 commit comments

Comments
 (0)