1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

Merge pull request #7997 from poettering/systemctl-is-active-fix

systemctl is-active fix
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-01-26 01:48:34 +03:00 committed by GitHub
commit 463a9e9c42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 50 deletions

View File

@ -877,10 +877,6 @@ Sun 2017-02-26 20:57:49 EST 2h 3min left Sun 2017-02-26 11:56:36 EST 6h ago
non-zero otherwise. Unless <option>--quiet</option> is
specified, this will also print the current unit state to
standard output.</para>
<para>Unlike <command>status</command> or <command>show</command> commands, this does not
load units. So, when a specified unit is an alias of another unit and is not loaded,
then this outputs "inactive", even if the aliased unit is active.</para>
</listitem>
</varlistentry>
<varlistentry>
@ -893,10 +889,6 @@ Sun 2017-02-26 20:57:49 EST 2h 3min left Sun 2017-02-26 11:56:36 EST 6h ago
non-zero otherwise. Unless <option>--quiet</option> is
specified, this will also print the current unit state to
standard output.</para>
<para>Unlike <command>status</command> or <command>show</command> commands, this does not
load units. So, when a specified unit is an alias of another unit and is not loaded,
then this outputs "inactive", even if the aliased unit is failed.</para>
</listitem>
</varlistentry>
<varlistentry>
@ -995,9 +987,6 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
are always exposed as properties ending in the <literal>…USec</literal> suffix even if a matching
configuration options end in <literal>…Sec</literal>, because microseconds is the normalized time unit used
by the system and service manager.</para>
<para>As similar to <command>status</command> command, systemd implicitly loads units as necessary.
See also <command>status</command> command for the detail.</para>
</listitem>
</varlistentry>
<varlistentry>

View File

@ -2650,55 +2650,32 @@ static int unit_find_paths(
static int get_state_one_unit(sd_bus *bus, const char *name, UnitActiveState *active_state) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_free_ char *buf = NULL;
_cleanup_free_ char *buf = NULL, *path = NULL;
UnitActiveState state;
const char *path;
int r;
assert(name);
assert(active_state);
/* We don't use unit_dbus_path_from_name() directly since we don't want to load the unit unnecessarily, if it
* isn't loaded. */
r = sd_bus_call_method(
path = unit_dbus_path_from_name(name);
if (!path)
return log_oom();
r = sd_bus_get_property_string(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"GetUnit",
path,
"org.freedesktop.systemd1.Unit",
"ActiveState",
&error,
&reply,
"s", name);
if (r < 0) {
if (!sd_bus_error_has_name(&error, BUS_ERROR_NO_SUCH_UNIT))
return log_error_errno(r, "Failed to retrieve unit: %s", bus_error_message(&error, r));
&buf);
if (r < 0)
return log_error_errno(r, "Failed to retrieve unit state: %s", bus_error_message(&error, r));
/* The unit is currently not loaded, hence say it's "inactive", since all units that aren't loaded are
* considered inactive. */
state = UNIT_INACTIVE;
} else {
r = sd_bus_message_read(reply, "o", &path);
if (r < 0)
return bus_log_parse_error(r);
r = sd_bus_get_property_string(
bus,
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Unit",
"ActiveState",
&error,
&buf);
if (r < 0)
return log_error_errno(r, "Failed to retrieve unit state: %s", bus_error_message(&error, r));
state = unit_active_state_from_string(buf);
if (state == _UNIT_ACTIVE_STATE_INVALID) {
log_error("Invalid unit state '%s' for: %s", buf, name);
return -EINVAL;
}
state = unit_active_state_from_string(buf);
if (state == _UNIT_ACTIVE_STATE_INVALID) {
log_error("Invalid unit state '%s' for: %s", buf, name);
return -EINVAL;
}
*active_state = state;