File tree Expand file tree Collapse file tree 1 file changed +20
-6
lines changed
system-reinstall-bootc/src Expand file tree Collapse file tree 1 file changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,7 @@ use std::process::Command;
11
11
use uzers:: os:: unix:: UserExt ;
12
12
13
13
fn loginctl_users ( ) -> Result < Vec < String > > {
14
- let users: Value = Command :: new ( "loginctl" )
15
- . arg ( "list-sessions" )
16
- . arg ( "--output" )
17
- . arg ( "json" )
18
- . run_and_parse_json ( )
19
- . context ( "loginctl failed" ) ?;
14
+ let users = loginctl_run_compat ( ) ?;
20
15
21
16
users
22
17
. as_array ( )
@@ -39,6 +34,25 @@ fn loginctl_users() -> Result<Vec<String>> {
39
34
. context ( "error parsing users" )
40
35
}
41
36
37
+ /// Run `loginctl` with some compatibility maneuvers to get JSON output
38
+ fn loginctl_run_compat ( ) -> Result < Value > {
39
+ let mut command = Command :: new ( "loginctl" ) ;
40
+ command. arg ( "list-sessions" ) . arg ( "--output" ) . arg ( "json" ) ;
41
+ let output = command. run_get_output ( ) . context ( "running loginctl" ) ?;
42
+ let users: Value = match serde_json:: from_reader ( output) {
43
+ Ok ( users) => users,
44
+ // Failing to parse means loginctl is not outputting JSON despite `--output`
45
+ // (https://github.com/systemd/systemd/issues/15275), we need to use the `--json` flag
46
+ Err ( _err) => Command :: new ( "loginctl" )
47
+ . arg ( "list-sessions" )
48
+ . arg ( "--json" )
49
+ . arg ( "short" )
50
+ . run_and_parse_json ( )
51
+ . context ( "running loginctl" ) ?,
52
+ } ;
53
+ Ok ( users)
54
+ }
55
+
42
56
struct UidChange {
43
57
uid : Uid ,
44
58
euid : Uid ,
You can’t perform that action at this time.
0 commit comments