@@ -19,30 +19,16 @@ use rustix::{
19
19
20
20
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
21
21
pub fn grant_root ( global_mnt : bool ) -> Result < ( ) > {
22
- const KERNEL_SU_OPTION : u32 = 0xDEAD_BEEF ;
23
- const CMD_GRANT_ROOT : u64 = 0 ;
24
-
25
- let mut result: u32 = 0 ;
26
- unsafe {
27
- #[ allow( clippy:: cast_possible_wrap) ]
28
- libc:: prctl (
29
- KERNEL_SU_OPTION as i32 , // supposed to overflow
30
- CMD_GRANT_ROOT ,
31
- 0 ,
32
- 0 ,
33
- std:: ptr:: addr_of_mut!( result) . cast :: < libc:: c_void > ( ) ,
34
- ) ;
35
- }
22
+ rustix:: process:: ksu_grant_root ( ) ?;
36
23
37
- anyhow:: ensure!( result == KERNEL_SU_OPTION , "grant root failed" ) ;
38
- let mut command = std:: process:: Command :: new ( "sh" ) ;
24
+ let mut command = Command :: new ( "sh" ) ;
39
25
let command = unsafe {
40
26
command. pre_exec ( move || {
41
27
if global_mnt {
42
28
let _ = utils:: switch_mnt_ns ( 1 ) ;
43
29
let _ = utils:: unshare_mnt_ns ( ) ;
44
30
}
45
- std :: result :: Result :: Ok ( ( ) )
31
+ Result :: Ok ( ( ) )
46
32
} )
47
33
} ;
48
34
// add /data/adb/ksu/bin to PATH
@@ -64,7 +50,7 @@ fn print_usage(program: &str, opts: Options) {
64
50
fn set_identity ( uid : u32 , gid : u32 , groups : & [ u32 ] ) {
65
51
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
66
52
{
67
- rustix:: process :: set_groups (
53
+ rustix:: thread :: set_thread_groups (
68
54
groups
69
55
. iter ( )
70
56
. map ( |g| unsafe { Gid :: from_raw ( * g) } )
@@ -89,7 +75,7 @@ pub fn root_shell() -> Result<()> {
89
75
// we are root now, this was set in kernel!
90
76
91
77
use anyhow:: anyhow;
92
- let env_args: Vec < String > = std :: env:: args ( ) . collect ( ) ;
78
+ let env_args: Vec < String > = env:: args ( ) . collect ( ) ;
93
79
let program = env_args[ 0 ] . clone ( ) ;
94
80
let args = env_args
95
81
. iter ( )
@@ -154,7 +140,7 @@ pub fn root_shell() -> Result<()> {
154
140
. collect :: < Vec < String > > ( ) ;
155
141
156
142
let matches = match opts. parse ( & args[ 1 ..] ) {
157
- std :: result :: Result :: Ok ( m) => m,
143
+ Result :: Ok ( m) => m,
158
144
Err ( f) => {
159
145
println ! ( "{f}" ) ;
160
146
print_usage ( & program, opts) ;
@@ -282,7 +268,7 @@ pub fn root_shell() -> Result<()> {
282
268
283
269
set_identity ( uid, gid, & groups) ;
284
270
285
- std :: result :: Result :: Ok ( ( ) )
271
+ Result :: Ok ( ( ) )
286
272
} )
287
273
} ;
288
274
0 commit comments