File tree Expand file tree Collapse file tree 3 files changed +15
-20
lines changed Expand file tree Collapse file tree 3 files changed +15
-20
lines changed Original file line number Diff line number Diff line change @@ -168,7 +168,7 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
168168
169169 #[ cfg( target_os = "openbsd" ) ]
170170 {
171- let upsecs = get_uptime ( None ) ;
171+ let upsecs = get_uptime ( None ) ? ;
172172 if upsecs >= 0 {
173173 print_uptime ( Some ( upsecs) ) ?;
174174 } else {
Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ pub fn get_uptime(_boot_time: Option<time_t>) -> UResult<i64> {
7575
7676 Ok ( uptime)
7777 } else {
78- Err ( UptimeError :: SystemUptime )
78+ Err ( UptimeError :: SystemUptime ) ?
7979 }
8080}
8181
@@ -213,27 +213,23 @@ pub fn get_nusers() -> usize {
213213pub fn get_nusers ( file : & str ) -> usize {
214214 use utmp_classic:: { UtmpEntry , parse_from_path} ;
215215
216- let mut nusers = 0 ;
217-
218216 let entries = match parse_from_path ( file) {
219- Some ( e) => e,
220- None => return 0 ,
217+ Ok ( e) => e,
218+ Err ( _ ) => return 0 ,
221219 } ;
222220
223- for entry in entries {
224- if let UtmpEntry :: UTMP {
225- line : _,
226- user,
227- host : _,
228- time : _,
229- } = entry
230- {
231- if !user. is_empty ( ) {
232- nusers += 1 ;
233- }
234- }
221+ if entries. is_empty ( ) {
222+ return 0 ;
235223 }
236- nusers
224+
225+ // Count entries that have a non-empty user field
226+ entries
227+ . iter ( )
228+ . filter_map ( |entry| match entry {
229+ UtmpEntry :: UTMP { user, .. } if !user. is_empty ( ) => Some ( ( ) ) ,
230+ _ => None ,
231+ } )
232+ . count ( )
237233}
238234
239235/// Get the number of users currently logged in
Original file line number Diff line number Diff line change 66// spell-checker:ignore bincode serde utmp runlevel testusr testx
77#![ allow( clippy:: cast_possible_wrap, clippy:: unreadable_literal) ]
88
9- #[ cfg( not( target_os = "openbsd" ) ) ]
109use uutests:: at_and_ucmd;
1110use uutests:: util:: TestScenario ;
1211use uutests:: { new_ucmd, util_name} ;
You can’t perform that action at this time.
0 commit comments