1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-19 22:50:17 +03:00

core: Log in more scenarios about which process initiated an operation

Exit/Reboot/Poweroff and similar operations are invasive enough that
logging about who initiated them is very useful to debug issues.

(cherry picked from commit acb0f501f4291efce82bcf89d4ad92b6a895f4fa)
This commit is contained in:
Daan De Meyer 2024-10-08 16:28:25 +02:00
parent 31e38b55b2
commit 814be7116d

View File

@ -1671,6 +1671,8 @@ static int method_exit(sd_bus_message *message, void *userdata, sd_bus_error *er
if (r < 0)
return r;
log_caller(message, m, "Exit");
/* Exit() (in contrast to SetExitCode()) is actually allowed even if
* we are running on the host. It will fall back on reboot() in
* systemd-shutdown if it cannot do the exit() because it isn't a
@ -1695,6 +1697,8 @@ static int method_reboot(sd_bus_message *message, void *userdata, sd_bus_error *
return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED,
"Reboot is only supported for system managers.");
log_caller(message, m, "Reboot");
m->objective = MANAGER_REBOOT;
return sd_bus_reply_method_return(message, NULL);
@ -1737,6 +1741,8 @@ static int method_soft_reboot(sd_bus_message *message, void *userdata, sd_bus_er
return -ENOMEM;
}
log_caller(message, m, "Soft reboot");
free_and_replace(m->switch_root, rt);
m->objective = MANAGER_SOFT_REBOOT;
@ -1757,6 +1763,8 @@ static int method_poweroff(sd_bus_message *message, void *userdata, sd_bus_error
return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED,
"Powering off is only supported for system managers.");
log_caller(message, m, "Poweroff");
m->objective = MANAGER_POWEROFF;
return sd_bus_reply_method_return(message, NULL);
@ -1776,6 +1784,8 @@ static int method_halt(sd_bus_message *message, void *userdata, sd_bus_error *er
return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED,
"Halt is only supported for system managers.");
log_caller(message, m, "Halt");
m->objective = MANAGER_HALT;
return sd_bus_reply_method_return(message, NULL);
@ -1795,6 +1805,8 @@ static int method_kexec(sd_bus_message *message, void *userdata, sd_bus_error *e
return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED,
"KExec is only supported for system managers.");
log_caller(message, m, "Kexec");
m->objective = MANAGER_KEXEC;
return sd_bus_reply_method_return(message, NULL);