From: Evgeny Vereshchagin Date: Sun, 31 Jan 2016 13:26:09 +0000 (+0000) Subject: core: refactoring: add job_type_to_access_method X-Git-Tag: v231~696^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=94bd732348535de399f8f003e3a1cbc8a81ab839;p=platform%2Fupstream%2Fsystemd.git core: refactoring: add job_type_to_access_method remove duplication --- diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 9862f6e..7c7b50b 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -460,8 +460,8 @@ int bus_unit_method_start_generic( r = mac_selinux_unit_access_check( u, message, - (job_type == JOB_START || job_type == JOB_RESTART || job_type == JOB_TRY_RESTART) ? "start" : - job_type == JOB_STOP ? "stop" : "reload", error); + job_type_to_access_method(job_type), + error); if (r < 0) return r; @@ -995,8 +995,8 @@ int bus_unit_queue_job( r = mac_selinux_unit_access_check( u, message, - (type == JOB_START || type == JOB_RESTART || type == JOB_TRY_RESTART) ? "start" : - type == JOB_STOP ? "stop" : "reload", error); + job_type_to_access_method(type), + error); if (r < 0) return r; diff --git a/src/core/job.c b/src/core/job.c index 4e111ff..d8fdf1b 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -1240,3 +1240,15 @@ static const char* const job_result_table[_JOB_RESULT_MAX] = { }; DEFINE_STRING_TABLE_LOOKUP(job_result, JobResult); + +const char* job_type_to_access_method(JobType t) { + assert(t >= 0); + assert(t < _JOB_TYPE_MAX); + + if (IN_SET(t, JOB_START, JOB_RESTART, JOB_TRY_RESTART)) + return "start"; + else if (t == JOB_STOP) + return "stop"; + else + return "reload"; +} diff --git a/src/core/job.h b/src/core/job.h index 52866fd..bbf5471 100644 --- a/src/core/job.h +++ b/src/core/job.h @@ -240,3 +240,5 @@ const char* job_result_to_string(JobResult t) _const_; JobResult job_result_from_string(const char *s) _pure_; int job_get_timeout(Job *j, uint64_t *timeout) _pure_; + +const char* job_type_to_access_method(JobType t);