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;
1111use uzers:: os:: unix:: UserExt ;
1212
1313fn 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 ( ) ?;
2015
2116 users
2217 . as_array ( )
@@ -39,6 +34,25 @@ fn loginctl_users() -> Result<Vec<String>> {
3934 . context ( "error parsing users" )
4035}
4136
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+
4256struct UidChange {
4357 uid : Uid ,
4458 euid : Uid ,
You can’t perform that action at this time.
0 commit comments