From b81bbe5355b97d0d7dbe8796afd39bf284696063 Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Tue, 21 Jul 2015 17:26:28 +0200 Subject: core: small refactor of job completion logging Joins three log_struct() calls into one. --- src/core/job.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) (limited to 'src/core/job.c') diff --git a/src/core/job.c b/src/core/job.c index 0f0fe1994a..03ef1d5891 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -705,6 +705,7 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) { static void job_log_status_message(Unit *u, JobType t, JobResult result) { const char *format; char buf[LINE_MAX]; + sd_id128_t mid; assert(u); assert(t >= 0); @@ -724,38 +725,27 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) { snprintf(buf, sizeof(buf), format, unit_description(u)); REENABLE_WARNING; - if (t == JOB_START) { - sd_id128_t mid; - + if (t == JOB_START) mid = result == JOB_DONE ? SD_MESSAGE_UNIT_STARTED : SD_MESSAGE_UNIT_FAILED; - log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR, - LOG_MESSAGE_ID(mid), - LOG_UNIT_ID(u), - LOG_MESSAGE("%s", buf), - "RESULT=%s", job_result_to_string(result), - NULL); - - } else if (t == JOB_STOP || t == JOB_RESTART) - log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR, - LOG_MESSAGE_ID(SD_MESSAGE_UNIT_STOPPED), - LOG_UNIT_ID(u), - LOG_MESSAGE("%s", buf), - "RESULT=%s", job_result_to_string(result), - NULL); - + else if (t == JOB_STOP || t == JOB_RESTART) + mid = SD_MESSAGE_UNIT_STOPPED; else if (t == JOB_RELOAD) - log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR, - LOG_MESSAGE_ID(SD_MESSAGE_UNIT_RELOADED), - LOG_UNIT_ID(u), - LOG_MESSAGE("%s", buf), - "RESULT=%s", job_result_to_string(result), - NULL); - else + mid = SD_MESSAGE_UNIT_RELOADED; + else { log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR, LOG_UNIT_ID(u), LOG_MESSAGE("%s", buf), "RESULT=%s", job_result_to_string(result), NULL); + return; + } + + log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR, + LOG_MESSAGE_ID(mid), + LOG_UNIT_ID(u), + LOG_MESSAGE("%s", buf), + "RESULT=%s", job_result_to_string(result), + NULL); } static void job_emit_status_message(Unit *u, JobType t, JobResult result) { -- cgit v1.2.3-54-g00ecf