mirror of
https://github.com/systemd/systemd.git
synced 2026-08-08 09:01:02 +00:00
logind: log peer ID when shutdown is called
The io.systemd.Manager.{PowerOff,SoftReboot,Halt,Kexec} manager
varlink and bus methods log the peer ID when calling shutdown.
The logind code is missing this, so this commit adds a similar
logging now. The code is quite similar to the one in existing in
src/core/manager.c but its hard to share code so this adds a bit
of duplication.
This commit is contained in:
@@ -2310,6 +2310,13 @@ static int method_do_shutdown_or_sleep(
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
{
|
||||
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
|
||||
|
||||
(void) bus_query_sender_pidref(message, &pidref);
|
||||
log_shutdown_caller(&pidref, handle_action_to_string(a->handle));
|
||||
}
|
||||
|
||||
if (m->delayed_action)
|
||||
return sd_bus_error_setf(error, BUS_ERROR_OPERATION_IN_PROGRESS,
|
||||
"Action %s already in progress, refusing requested %s operation.",
|
||||
|
||||
@@ -8,8 +8,11 @@
|
||||
|
||||
#include "bus-common-errors.h"
|
||||
#include "bus-polkit.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "format-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "hashmap.h"
|
||||
#include "log.h"
|
||||
#include "login-util.h"
|
||||
#include "logind.h"
|
||||
#include "logind-dbus.h"
|
||||
@@ -17,6 +20,8 @@
|
||||
#include "logind-session.h"
|
||||
#include "logind-shutdown.h"
|
||||
#include "logind-user.h"
|
||||
#include "pidref.h"
|
||||
#include "process-util.h"
|
||||
#include "user-record.h"
|
||||
|
||||
int manager_have_multiple_sessions(
|
||||
@@ -37,6 +42,24 @@ int manager_have_multiple_sessions(
|
||||
return false;
|
||||
}
|
||||
|
||||
void log_shutdown_caller(const PidRef *caller, const char *method) {
|
||||
_cleanup_free_ char *comm = NULL, *unit = NULL;
|
||||
|
||||
assert(method);
|
||||
|
||||
if (!pidref_is_set(caller)) {
|
||||
return log_notice("%s requested from unknown client PID...", method);
|
||||
}
|
||||
|
||||
(void) pidref_get_comm(caller, &comm);
|
||||
(void) cg_pidref_get_unit(caller, &unit);
|
||||
|
||||
log_notice("%s requested from client PID " PID_FMT "%s%s%s%s%s%s...",
|
||||
method, caller->pid,
|
||||
comm ? " ('" : "", strempty(comm), comm ? "')" : "",
|
||||
unit ? " (unit " : "", strempty(unit), unit ? ")" : "");
|
||||
}
|
||||
|
||||
int manager_verify_shutdown_creds(
|
||||
Manager *m,
|
||||
sd_bus_message *message,
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
int manager_have_multiple_sessions(Manager *m, uid_t uid);
|
||||
|
||||
void log_shutdown_caller(const PidRef *caller, const char *method);
|
||||
|
||||
/* manager_verify_shutdown_creds() takes *either* a "message" or "link" depending on if it is used
|
||||
* to validate a D-Bus or Varlink shutdown request. When varlink is used the sd_bus_error *error
|
||||
* must be NULL */
|
||||
|
||||
@@ -385,6 +385,13 @@ static int manager_do_shutdown_action(sd_varlink *link, sd_json_variant *paramet
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
{
|
||||
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
|
||||
|
||||
(void) varlink_get_peer_pidref(link, &pidref);
|
||||
log_shutdown_caller(&pidref, handle_action_to_string(action));
|
||||
}
|
||||
|
||||
if (m->delayed_action)
|
||||
return sd_varlink_error(link, "io.systemd.Shutdown.AlreadyInProgress", /* parameters= */ NULL);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user