1
1
//SPDX-FileCopyrightText: 2022 Ryuichi Ueda ryuichiueda@gmail.com
2
2
//SPDX-License-Identifier: BSD-3-Clause
3
3
4
- use crate :: { ShellCore , Feeder } ;
4
+ use crate :: { ShellCore , Feeder , proc_ctrl } ;
5
5
use crate :: error:: exec:: ExecError ;
6
6
use crate :: error:: parse:: ParseError ;
7
7
use super :: { Command , Pipe , Redirect } ;
@@ -10,12 +10,7 @@ use crate::elements::substitution::Substitution;
10
10
use crate :: elements:: word:: Word ;
11
11
use crate :: utils;
12
12
use crate :: utils:: exit;
13
- use nix:: unistd;
14
- use std:: ffi:: CString ;
15
- use std:: process;
16
-
17
13
use nix:: unistd:: Pid ;
18
- use nix:: errno:: Errno ;
19
14
20
15
#[ derive( Debug , Default , Clone ) ]
21
16
pub struct SimpleCommand {
@@ -65,7 +60,7 @@ impl Command for SimpleCommand {
65
60
if ! core. run_function ( & mut self . args )
66
61
&& ! core. run_builtin ( & mut self . args ) {
67
62
self . set_environment_variables ( core) ?;
68
- Self :: exec_external_command ( & mut self . args )
63
+ proc_ctrl :: exec_command ( & mut self . args )
69
64
}
70
65
71
66
core. db . pop_local ( ) ;
@@ -84,25 +79,6 @@ impl Command for SimpleCommand {
84
79
}
85
80
86
81
impl SimpleCommand {
87
- fn exec_external_command ( args : & mut [ String ] ) -> ! {
88
- let cargs = Self :: to_cargs ( args) ;
89
- match unistd:: execvp ( & cargs[ 0 ] , & cargs) {
90
- Err ( Errno :: EACCES ) => {
91
- println ! ( "sush: {}: Permission denied" , & args[ 0 ] ) ;
92
- process:: exit ( 126 )
93
- } ,
94
- Err ( Errno :: ENOENT ) => {
95
- println ! ( "{}: command not found" , & args[ 0 ] ) ;
96
- process:: exit ( 127 )
97
- } ,
98
- Err ( err) => {
99
- println ! ( "Failed to execute. {:?}" , err) ;
100
- process:: exit ( 127 )
101
- }
102
- _ => panic ! ( "SUSH INTERNAL ERROR (never come here)" )
103
- }
104
- }
105
-
106
82
fn set_local_params ( & mut self , core : & mut ShellCore ) -> Result < ( ) , ExecError > {
107
83
let layer = Some ( core. db . get_layer_num ( ) - 1 ) ;
108
84
for s in self . substitutions . iter_mut ( ) {
@@ -119,12 +95,6 @@ impl SimpleCommand {
119
95
Ok ( ( ) )
120
96
}
121
97
122
- fn to_cargs ( args : & mut [ String ] ) -> Vec < CString > {
123
- args. iter ( )
124
- . map ( |a| CString :: new ( a. to_string ( ) ) . unwrap ( ) )
125
- . collect ( )
126
- }
127
-
128
98
pub fn eat_substitution ( & mut self , feeder : & mut Feeder , core : & mut ShellCore )
129
99
-> Result < bool , ParseError > {
130
100
if let Some ( s) = Substitution :: parse ( feeder, core) ? {
0 commit comments