@@ -120,7 +120,9 @@ async fn main() -> ExitCode {
120
120
if !cli. allow_multiple {
121
121
match get_current_pid ( ) {
122
122
Ok ( current_pid) => {
123
- allow_multiple_running_check ( current_pid, cli. kill_old , page. clone ( ) ) . await ;
123
+ if let Some ( exit_code) = allow_multiple_running_check ( current_pid, cli. kill_old , page. clone ( ) ) . await {
124
+ return exit_code;
125
+ }
124
126
} ,
125
127
Err ( err) => warn ! ( %err, "Failed to get pid" ) ,
126
128
}
@@ -226,6 +228,7 @@ fn parse_url_page(url: Option<&str>) -> Result<Option<String>, ExitCode> {
226
228
}
227
229
228
230
#[ cfg( target_os = "linux" ) ]
231
+ #[ must_use]
229
232
async fn allow_multiple_running_check (
230
233
current_pid : sysinfo:: Pid ,
231
234
kill_old : bool ,
@@ -287,6 +290,7 @@ async fn allow_multiple_running_check(
287
290
}
288
291
289
292
#[ cfg( target_os = "macos" ) ]
293
+ #[ must_use]
290
294
async fn allow_multiple_running_check (
291
295
current_pid : sysinfo:: Pid ,
292
296
kill_old : bool ,
@@ -297,14 +301,7 @@ async fn allow_multiple_running_check(
297
301
let app_process_name = OsString :: from ( APP_PROCESS_NAME ) ;
298
302
let system = System :: new_with_specifics ( RefreshKind :: new ( ) . with_processes ( ProcessRefreshKind :: new ( ) ) ) ;
299
303
let processes = system. processes_by_name ( & app_process_name) ;
300
-
301
- cfg_if:: cfg_if! {
302
- if #[ cfg( unix) ] {
303
- let current_user_id = Some ( nix:: unistd:: getuid( ) . as_raw( ) ) ;
304
- } else {
305
- let current_user_id = None ;
306
- }
307
- } ;
304
+ let current_uid = nix:: unistd:: getuid ( ) . as_raw ( ) ;
308
305
309
306
for process in processes {
310
307
let pid = process. pid ( ) ;
@@ -347,12 +344,8 @@ async fn allow_multiple_running_check(
347
344
}
348
345
} ;
349
346
350
- match ( process. user_id ( ) . map ( |uid| uid as & u32 ) , current_user_id. as_ref ( ) ) {
351
- ( Some ( uid) , Some ( current_uid) ) if uid == current_uid => {
352
- on_match. await ;
353
- return Some ( ExitCode :: SUCCESS ) ;
354
- } ,
355
- ( _, None ) => {
347
+ match process. user_id ( ) . map ( |uid| uid as & u32 ) {
348
+ Some ( & uid) if uid == current_uid => {
356
349
on_match. await ;
357
350
return Some ( ExitCode :: SUCCESS ) ;
358
351
} ,
0 commit comments