mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 17:51:22 +03:00
core: log USER_UNIT instead of UNIT if in user session
This commit is contained in:
parent
ef1673d169
commit
bbc9006e6b
@ -1024,8 +1024,8 @@ int exec_spawn(ExecCommand *command,
|
||||
|
||||
r = exec_context_load_environment(context, &files_env);
|
||||
if (r < 0) {
|
||||
log_struct(LOG_ERR,
|
||||
"UNIT=%s", unit_id,
|
||||
log_struct_unit(LOG_ERR,
|
||||
unit_id,
|
||||
"MESSAGE=Failed to load environment files: %s", strerror(-r),
|
||||
"ERRNO=%d", -r,
|
||||
NULL);
|
||||
@ -1039,8 +1039,8 @@ int exec_spawn(ExecCommand *command,
|
||||
if (!line)
|
||||
return log_oom();
|
||||
|
||||
log_struct(LOG_DEBUG,
|
||||
"UNIT=%s", unit_id,
|
||||
log_struct_unit(LOG_DEBUG,
|
||||
unit_id,
|
||||
"MESSAGE=About to execute %s", line,
|
||||
NULL);
|
||||
free(line);
|
||||
@ -1512,8 +1512,8 @@ int exec_spawn(ExecCommand *command,
|
||||
_exit(r);
|
||||
}
|
||||
|
||||
log_struct(LOG_DEBUG,
|
||||
"UNIT=%s", unit_id,
|
||||
log_struct_unit(LOG_DEBUG,
|
||||
unit_id,
|
||||
"MESSAGE=Forked %s as %lu",
|
||||
command->path, (unsigned long) pid,
|
||||
NULL);
|
||||
|
@ -713,25 +713,25 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
|
||||
sd_id128_t mid;
|
||||
|
||||
mid = result == JOB_DONE ? SD_MESSAGE_UNIT_STARTED : SD_MESSAGE_UNIT_FAILED;
|
||||
log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR,
|
||||
log_struct_unit(result == JOB_DONE ? LOG_INFO : LOG_ERR,
|
||||
u->id,
|
||||
MESSAGE_ID(mid),
|
||||
"UNIT=%s", u->id,
|
||||
"RESULT=%s", job_result_to_string(result),
|
||||
"MESSAGE=%s", buf,
|
||||
NULL);
|
||||
|
||||
} else if (t == JOB_STOP)
|
||||
log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR,
|
||||
log_struct_unit(result == JOB_DONE ? LOG_INFO : LOG_ERR,
|
||||
u->id,
|
||||
MESSAGE_ID(SD_MESSAGE_UNIT_STOPPED),
|
||||
"UNIT=%s", u->id,
|
||||
"RESULT=%s", job_result_to_string(result),
|
||||
"MESSAGE=%s", buf,
|
||||
NULL);
|
||||
|
||||
else if (t == JOB_RELOAD)
|
||||
log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR,
|
||||
log_struct_unit(result == JOB_DONE ? LOG_INFO : LOG_ERR,
|
||||
u->id,
|
||||
MESSAGE_ID(SD_MESSAGE_UNIT_RELOADED),
|
||||
"UNIT=%s", u->id,
|
||||
"RESULT=%s", job_result_to_string(result),
|
||||
"MESSAGE=%s", buf,
|
||||
NULL);
|
||||
@ -818,8 +818,8 @@ int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) {
|
||||
* this context. And JOB_FAILURE is already handled by the
|
||||
* unit itself. */
|
||||
if (result == JOB_TIMEOUT || result == JOB_DEPENDENCY) {
|
||||
log_struct(LOG_NOTICE,
|
||||
"UNIT=%s", u->id,
|
||||
log_struct_unit(LOG_NOTICE,
|
||||
u->id,
|
||||
"JOB_TYPE=%s", job_type_to_string(t),
|
||||
"JOB_RESULT=%s", job_result_to_string(result),
|
||||
"Job %s/%s failed with result '%s'.",
|
||||
|
@ -955,11 +955,11 @@ fail:
|
||||
void warn_if_dir_nonempty(const char *unit, const char* where) {
|
||||
if (dir_is_empty(where) > 0)
|
||||
return;
|
||||
log_struct(LOG_NOTICE,
|
||||
log_struct_unit(LOG_NOTICE,
|
||||
unit,
|
||||
"MESSAGE=%s: Directory %s to mount over is not empty, mounting anyway.",
|
||||
unit, where,
|
||||
"WHERE=%s", where,
|
||||
"_SYSTEMD_UNIT=%s", unit,
|
||||
MESSAGE_ID(SD_MESSAGE_OVERMOUNTING),
|
||||
NULL);
|
||||
}
|
||||
|
@ -2939,13 +2939,13 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
||||
f = SERVICE_SUCCESS;
|
||||
}
|
||||
|
||||
log_struct(f == SERVICE_SUCCESS ? LOG_DEBUG : LOG_NOTICE,
|
||||
log_struct_unit(f == SERVICE_SUCCESS ? LOG_DEBUG : LOG_NOTICE,
|
||||
u->id,
|
||||
"MESSAGE=%s: main process exited, code=%s, status=%i/%s",
|
||||
u->id, sigchld_code_to_string(code), status,
|
||||
strna(code == CLD_EXITED
|
||||
? exit_status_to_string(status, EXIT_STATUS_FULL)
|
||||
: signal_to_string(status)),
|
||||
"UNIT=%s", u->id,
|
||||
"EXIT_CODE=%s", sigchld_code_to_string(code),
|
||||
"EXIT_STATUS=%i", status,
|
||||
NULL);
|
||||
|
@ -1022,9 +1022,9 @@ static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
|
||||
t == JOB_STOP ? SD_MESSAGE_UNIT_STOPPING :
|
||||
SD_MESSAGE_UNIT_RELOADING;
|
||||
|
||||
log_struct(LOG_INFO,
|
||||
log_struct_unit(LOG_INFO,
|
||||
u->id,
|
||||
MESSAGE_ID(mid),
|
||||
"UNIT=%s", u->id,
|
||||
"MESSAGE=%s", buf,
|
||||
NULL);
|
||||
}
|
||||
@ -1438,9 +1438,9 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
|
||||
check_unneeded_dependencies(u);
|
||||
|
||||
if (ns != os && ns == UNIT_FAILED) {
|
||||
log_struct(LOG_NOTICE,
|
||||
log_struct_unit(LOG_NOTICE,
|
||||
u->id,
|
||||
"MESSAGE=Unit %s entered failed state", u->id,
|
||||
"UNIT=%s", u->id,
|
||||
NULL);
|
||||
unit_trigger_on_failure(u);
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef struct Unit Unit;
|
||||
typedef struct UnitVTable UnitVTable;
|
||||
@ -556,9 +557,11 @@ UnitActiveState unit_active_state_from_string(const char *s);
|
||||
const char *unit_dependency_to_string(UnitDependency i);
|
||||
UnitDependency unit_dependency_from_string(const char *s);
|
||||
|
||||
#define log_full_unit(level, unit, ...) log_meta_object(level, __FILE__, __LINE__, __func__, "UNIT=", unit, __VA_ARGS__)
|
||||
#define log_full_unit(level, unit, ...) log_meta_object(level, __FILE__, __LINE__, __func__, getpid() == 1 ? "UNIT=" : "USER_UNIT=", unit, __VA_ARGS__)
|
||||
#define log_debug_unit(unit, ...) log_full_unit(LOG_DEBUG, unit, __VA_ARGS__)
|
||||
#define log_info_unit(unit, ...) log_full_unit(LOG_INFO, unit, __VA_ARGS__)
|
||||
#define log_notice_unit(unit, ...) log_full_unit(LOG_NOTICE, unit, __VA_ARGS__)
|
||||
#define log_warning_unit(unit, ...) log_full_unit(LOG_WARNING, unit, __VA_ARGS__)
|
||||
#define log_error_unit(unit, ...) log_full_unit(LOG_ERR, unit, __VA_ARGS__)
|
||||
|
||||
#define log_struct_unit(level, unit, ...) log_struct(level, getpid() == 1 ? "UNIT=%s" : "USER_UNIT=%s", unit, __VA_ARGS__)
|
||||
|
Loading…
Reference in New Issue
Block a user