From bc52801034e9e33d7aab0cb64c84f64cd9d4c035 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 10 May 2023 03:22:16 +0900 Subject: tree-wide: drop _pure_ attribute from non-pure functions Prompted by #27595. Follow-ups for 6723c28f36ea566faf61d3610012cd89f95ee4a0. --- src/basic/hash-funcs.h | 2 +- src/core/job.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/basic/hash-funcs.h b/src/basic/hash-funcs.h index c14302ec72..be64289252 100644 --- a/src/basic/hash-funcs.h +++ b/src/basic/hash-funcs.h @@ -102,7 +102,7 @@ extern const struct hash_ops uint64_hash_ops; /* On some archs dev_t is 32bit, and on others 64bit. And sometimes it's 64bit on 32bit archs, and sometimes 32bit on * 64bit archs. Yuck! */ #if SIZEOF_DEV_T != 8 -void devt_hash_func(const dev_t *p, struct siphash *state) _pure_; +void devt_hash_func(const dev_t *p, struct siphash *state); #else #define devt_hash_func uint64_hash_func #endif diff --git a/src/core/job.h b/src/core/job.h index df35e2a5b6..dcb5c7fff6 100644 --- a/src/core/job.h +++ b/src/core/job.h @@ -220,7 +220,7 @@ char *job_dbus_path(Job *j); void job_shutdown_magic(Job *j); -int job_get_timeout(Job *j, usec_t *timeout) _pure_; +int job_get_timeout(Job *j, usec_t *timeout); bool job_may_gc(Job *j); void job_add_to_gc_queue(Job *j); -- cgit v1.2.1 From fcd7e0b7edf57d8de1de35bcef26c22ecd62b256 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 10 May 2023 03:25:37 +0900 Subject: core: several cleanups for job_get_timeout() - add missing assertion, - rename the argument for storing result, - always initialize result on success. --- src/core/job.c | 10 +++++++--- src/core/job.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/job.c b/src/core/job.c index 24f407ad83..f87b0f7c74 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -1404,11 +1404,13 @@ void job_shutdown_magic(Job *j) { (void) asynchronous_sync(NULL); } -int job_get_timeout(Job *j, usec_t *timeout) { +int job_get_timeout(Job *j, usec_t *ret) { usec_t x = USEC_INFINITY, y = USEC_INFINITY; Unit *u = ASSERT_PTR(ASSERT_PTR(j)->unit); int r; + assert(ret); + if (j->timer_event_source) { r = sd_event_source_get_time(j->timer_event_source, &x); if (r < 0) @@ -1421,10 +1423,12 @@ int job_get_timeout(Job *j, usec_t *timeout) { return r; } - if (x == USEC_INFINITY && y == USEC_INFINITY) + if (x == USEC_INFINITY && y == USEC_INFINITY) { + *ret = 0; return 0; + } - *timeout = MIN(x, y); + *ret = MIN(x, y); return 1; } diff --git a/src/core/job.h b/src/core/job.h index dcb5c7fff6..f3e0b93fed 100644 --- a/src/core/job.h +++ b/src/core/job.h @@ -220,7 +220,7 @@ char *job_dbus_path(Job *j); void job_shutdown_magic(Job *j); -int job_get_timeout(Job *j, usec_t *timeout); +int job_get_timeout(Job *j, usec_t *ret); bool job_may_gc(Job *j); void job_add_to_gc_queue(Job *j); -- cgit v1.2.1 From 735f0645db13d18f1ea37f046343ae0c3ec36987 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 10 May 2023 03:31:11 +0900 Subject: core: drop unused argument --- src/core/transaction.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/core/transaction.c b/src/core/transaction.c index 997839c553..625a873c32 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -308,13 +308,11 @@ static void transaction_drop_redundant(Transaction *tr) { } while (again); } -_pure_ static bool unit_matters_to_anchor(Unit *u, Job *job) { - assert(u); +_pure_ static bool job_matters_to_anchor(Job *job) { assert(job); assert(!job->transaction_prev); - /* Checks whether at least one of the jobs for this unit - * matters to the anchor. */ + /* Checks whether at least one of the jobs for this transaction matters to the anchor. */ LIST_FOREACH(transaction, j, job) if (j->matters_to_anchor) @@ -382,7 +380,7 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi if (strv_push_pair(&array, k->unit->id, (char*) job_type_to_string(k->type)) < 0) log_oom(); - if (!delete && hashmap_get(tr->jobs, k->unit) && !unit_matters_to_anchor(k->unit, k)) + if (!delete && hashmap_get(tr->jobs, k->unit) && !job_matters_to_anchor(k)) /* Ok, we can drop this one, so let's do so. */ delete = k; -- cgit v1.2.1 From 6112c86139c6fefb1e669d337531b26b8fce0ae8 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 10 May 2023 03:33:46 +0900 Subject: core: replace hashmap_get() with hashmap_contains() where appropriate --- src/core/transaction.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/transaction.c b/src/core/transaction.c index 625a873c32..c3d6ffccc1 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -380,7 +380,7 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi if (strv_push_pair(&array, k->unit->id, (char*) job_type_to_string(k->type)) < 0) log_oom(); - if (!delete && hashmap_get(tr->jobs, k->unit) && !job_matters_to_anchor(k)) + if (!delete && hashmap_contains(tr->jobs, k->unit) && !job_matters_to_anchor(k)) /* Ok, we can drop this one, so let's do so. */ delete = k; @@ -629,7 +629,7 @@ static int transaction_apply( if (j->unit->ignore_on_isolate) continue; - if (hashmap_get(tr->jobs, j->unit)) + if (hashmap_contains(tr->jobs, j->unit)) continue; /* Not invalidating recursively. Avoids triggering @@ -1110,7 +1110,7 @@ static bool shall_stop_on_isolate(Transaction *tr, Unit *u) { return false; /* Is there already something listed for this? */ - if (hashmap_get(tr->jobs, u)) + if (hashmap_contains(tr->jobs, u)) return false; return true; @@ -1170,7 +1170,7 @@ int transaction_add_triggering_jobs(Transaction *tr, Unit *u) { continue; /* Is there already something listed for this? */ - if (hashmap_get(tr->jobs, trigger)) + if (hashmap_contains(tr->jobs, trigger)) continue; r = transaction_add_job_and_dependencies(tr, JOB_STOP, trigger, tr->anchor_job, true, false, false, false, NULL); -- cgit v1.2.1