chiark / gitweb /
core: log USER_UNIT instead of UNIT if in user session
authorMirco Tischler <mt-ml@gmx.de>
Thu, 17 Jan 2013 17:55:06 +0000 (18:55 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 18 Jan 2013 16:14:00 +0000 (11:14 -0500)
src/core/execute.c
src/core/job.c
src/core/mount.c
src/core/service.c
src/core/unit.c
src/core/unit.h

index 9718e43a707e4920ffcb276c95c936d9f1ba9ed2..65a10af3b0793cc4bfe4f96734e4fadc456dc34b 100644 (file)
@@ -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);
index 31ab11880ef0fa1a52b4d4c6a9c628c6d8a56928..e381ea2b69d21d389ce53cb19d0587b253392ede 100644 (file)
@@ -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'.",
index 25bc7e197a12a066bded44d829aa0aeee505b474..18ce73b4386852a544eae78aad2c458dbc2b1460 100644 (file)
@@ -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);
 }
index 9e46dbae9478b7aab8177018c395da2e8cd3f68e..bc41617bf7ec518493627b6d8611062ec3cfb7bb 100644 (file)
@@ -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);
index d26f6e456c1dcfb5a451b2a495eee0357e561059..83359e126b52a88318a103c7bd30ed888da81be0 100644 (file)
@@ -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);
                 }
index d1ecae74acf76e6c0dd243b9864748a03f7d6348..23cd9ef459812e1208311da0cd8babd89eb235cb 100644 (file)
@@ -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__)