From: Lennart Poettering Date: Wed, 28 Nov 2018 19:05:49 +0000 (+0100) Subject: swap: flush out state when activating a unit, not when deactivating it X-Git-Tag: v240~112^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=31135818e41fb7d779da3a74e4ff50df6a20f2fd;p=thirdparty%2Fsystemd.git swap: flush out state when activating a unit, not when deactivating it This is similar to the previous commit which did the same change for mount units. --- diff --git a/src/core/swap.c b/src/core/swap.c index 90207a48fa6..bbcf886458b 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -813,6 +813,14 @@ fail: swap_enter_dead_or_active(s, SWAP_FAILURE_RESOURCES); } +static void swap_cycle_clear(Swap *s) { + assert(s); + + s->result = SWAP_SUCCESS; + exec_command_reset_status_array(s->exec_command, _SWAP_EXEC_COMMAND_MAX); + UNIT(s)->reset_accounting = true; +} + static int swap_start(Unit *u) { Swap *s = SWAP(u), *other; int r; @@ -852,11 +860,7 @@ static int swap_start(Unit *u) { if (r < 0) return r; - s->result = SWAP_SUCCESS; - exec_command_reset_status_array(s->exec_command, _SWAP_EXEC_COMMAND_MAX); - - u->reset_accounting = true; - + swap_cycle_clear(s); swap_enter_activating(s); return 1; } @@ -1183,7 +1187,8 @@ static int swap_dispatch_io(sd_event_source *source, int fd, uint32_t revents, v case SWAP_DEAD: case SWAP_FAILED: - (void) unit_acquire_invocation_id(UNIT(swap)); + (void) unit_acquire_invocation_id(u); + swap_cycle_clear(swap); swap_enter_active(swap, SWAP_SUCCESS); break;