mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
Merge pull request #31659 from YHNdnzj/freezer-followup
Freezer trivial follow-up
This commit is contained in:
commit
12adbb6dc7
@ -42,9 +42,6 @@
|
|||||||
#define DEFAULT_START_LIMIT_INTERVAL (10*USEC_PER_SEC)
|
#define DEFAULT_START_LIMIT_INTERVAL (10*USEC_PER_SEC)
|
||||||
#define DEFAULT_START_LIMIT_BURST 5
|
#define DEFAULT_START_LIMIT_BURST 5
|
||||||
|
|
||||||
/* Wait for 1.5 seconds at maximum for freeze operation */
|
|
||||||
#define FREEZE_TIMEOUT (1500 * USEC_PER_MSEC)
|
|
||||||
|
|
||||||
/* The default time after which exit-on-idle services exit. This
|
/* The default time after which exit-on-idle services exit. This
|
||||||
* should be kept lower than the watchdog timeout, because otherwise
|
* should be kept lower than the watchdog timeout, because otherwise
|
||||||
* the watchdog pings will keep the loop busy. */
|
* the watchdog pings will keep the loop busy. */
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#include "cgroup-setup.h"
|
#include "cgroup-setup.h"
|
||||||
#include "cgroup-util.h"
|
#include "cgroup-util.h"
|
||||||
#include "condition.h"
|
#include "condition.h"
|
||||||
#include "constants.h"
|
|
||||||
#include "coredump-util.h"
|
#include "coredump-util.h"
|
||||||
#include "cpu-set-util.h"
|
#include "cpu-set-util.h"
|
||||||
#include "dissect-image.h"
|
#include "dissect-image.h"
|
||||||
@ -2939,6 +2938,9 @@ int bus_service_manager_reload(sd_bus *bus) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Wait for 1.5 seconds at maximum for freeze operation */
|
||||||
|
#define FREEZE_BUS_CALL_TIMEOUT (1500 * USEC_PER_MSEC)
|
||||||
|
|
||||||
int unit_freezer_new(const char *name, UnitFreezer *ret) {
|
int unit_freezer_new(const char *name, UnitFreezer *ret) {
|
||||||
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
||||||
_cleanup_free_ char *namedup = NULL;
|
_cleanup_free_ char *namedup = NULL;
|
||||||
@ -2955,7 +2957,7 @@ int unit_freezer_new(const char *name, UnitFreezer *ret) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_debug_errno(r, "Failed to open connection to systemd: %m");
|
return log_debug_errno(r, "Failed to open connection to systemd: %m");
|
||||||
|
|
||||||
(void) sd_bus_set_method_call_timeout(bus, FREEZE_TIMEOUT);
|
(void) sd_bus_set_method_call_timeout(bus, FREEZE_BUS_CALL_TIMEOUT);
|
||||||
|
|
||||||
*ret = (UnitFreezer) {
|
*ret = (UnitFreezer) {
|
||||||
.name = TAKE_PTR(namedup),
|
.name = TAKE_PTR(namedup),
|
||||||
@ -2964,31 +2966,6 @@ int unit_freezer_new(const char *name, UnitFreezer *ret) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int unit_freezer_action(bool freeze, UnitFreezer *f) {
|
|
||||||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(f);
|
|
||||||
assert(f->bus);
|
|
||||||
assert(f->name);
|
|
||||||
|
|
||||||
r = bus_call_method(f->bus, bus_systemd_mgr, freeze ? "FreezeUnit" : "ThawUnit",
|
|
||||||
&error, NULL, "s", f->name);
|
|
||||||
if (r < 0)
|
|
||||||
return log_debug_errno(r, "Failed to %s unit %s: %s", freeze ? "freeze" : "thaw",
|
|
||||||
f->name, bus_error_message(&error, r));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int unit_freezer_freeze(UnitFreezer *f) {
|
|
||||||
return unit_freezer_action(true, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
int unit_freezer_thaw(UnitFreezer *f) {
|
|
||||||
return unit_freezer_action(false, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void unit_freezer_done(UnitFreezer *f) {
|
void unit_freezer_done(UnitFreezer *f) {
|
||||||
assert(f);
|
assert(f);
|
||||||
|
|
||||||
@ -2996,6 +2973,35 @@ void unit_freezer_done(UnitFreezer *f) {
|
|||||||
f->bus = sd_bus_flush_close_unref(f->bus);
|
f->bus = sd_bus_flush_close_unref(f->bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int unit_freezer_action(UnitFreezer *f, bool freeze) {
|
||||||
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(f);
|
||||||
|
assert(f->name);
|
||||||
|
assert(f->bus);
|
||||||
|
|
||||||
|
r = bus_call_method(f->bus, bus_systemd_mgr,
|
||||||
|
freeze ? "FreezeUnit" : "ThawUnit",
|
||||||
|
&error,
|
||||||
|
/* reply = */ NULL,
|
||||||
|
"s",
|
||||||
|
f->name);
|
||||||
|
if (r < 0)
|
||||||
|
return log_debug_errno(r, "Failed to %s unit %s: %s",
|
||||||
|
freeze ? "freeze" : "thaw", f->name, bus_error_message(&error, r));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int unit_freezer_freeze(UnitFreezer *f) {
|
||||||
|
return unit_freezer_action(f, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
int unit_freezer_thaw(UnitFreezer *f) {
|
||||||
|
return unit_freezer_action(f, false);
|
||||||
|
}
|
||||||
|
|
||||||
int unit_freezer_new_freeze(const char *name, UnitFreezer *ret) {
|
int unit_freezer_new_freeze(const char *name, UnitFreezer *ret) {
|
||||||
_cleanup_(unit_freezer_done) UnitFreezer f = {};
|
_cleanup_(unit_freezer_done) UnitFreezer f = {};
|
||||||
int r;
|
int r;
|
||||||
|
@ -42,13 +42,11 @@ typedef struct UnitFreezer {
|
|||||||
} UnitFreezer;
|
} UnitFreezer;
|
||||||
|
|
||||||
int unit_freezer_new(const char *name, UnitFreezer *ret);
|
int unit_freezer_new(const char *name, UnitFreezer *ret);
|
||||||
|
void unit_freezer_done(UnitFreezer *f);
|
||||||
|
|
||||||
int unit_freezer_freeze(UnitFreezer *freezer);
|
int unit_freezer_freeze(UnitFreezer *f);
|
||||||
|
int unit_freezer_thaw(UnitFreezer *f);
|
||||||
int unit_freezer_thaw(UnitFreezer *freezer);
|
|
||||||
|
|
||||||
void unit_freezer_done(UnitFreezer *freezer);
|
|
||||||
|
|
||||||
int unit_freezer_new_freeze(const char *name, UnitFreezer *ret);
|
int unit_freezer_new_freeze(const char *name, UnitFreezer *ret);
|
||||||
|
|
||||||
void unit_freezer_done_thaw(UnitFreezer *freezer);
|
void unit_freezer_done_thaw(UnitFreezer *f);
|
||||||
|
@ -606,7 +606,7 @@ static int run(int argc, char *argv[]) {
|
|||||||
} else
|
} else
|
||||||
log_notice("User sessions remain unfrozen on explicit request "
|
log_notice("User sessions remain unfrozen on explicit request "
|
||||||
"($SYSTEMD_SLEEP_FREEZE_USER_SESSIONS is set to false). This is not recommended, "
|
"($SYSTEMD_SLEEP_FREEZE_USER_SESSIONS is set to false). This is not recommended, "
|
||||||
"and might result in unexpected behavior, particularly in sysupend-then-hibernate "
|
"and might result in unexpected behavior, particularly in suspend-then-hibernate "
|
||||||
"operations or setups with encrypted home directories.");
|
"operations or setups with encrypted home directories.");
|
||||||
|
|
||||||
switch (arg_operation) {
|
switch (arg_operation) {
|
||||||
|
Loading…
Reference in New Issue
Block a user