File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -109,20 +109,28 @@ int cmd_cd(struct tokens *tokens){
109
109
So what have I found?
110
110
FIXME: program corrupts it own files
111
111
FIXME: '>' creates executable files
112
- FIXME: '<' not even works
113
112
FIXME: core fault
113
+ FIXME: '<' after using stops work of the shell
114
114
*/
115
115
int shell_exec (struct tokens * tokens ){
116
116
/* path processed by detpath and then we could use it */
117
117
char * path = detpath (tokens_get_token (tokens , 0 ));
118
118
char * * args = args_proc (path , tokens );
119
+
120
+ if (!path || !args ) return -1 ;
119
121
122
+ int saved_stdout = dup (1 );
123
+ int saved_stdin = dup (0 );
120
124
pid_t cpid ;
121
125
int status ;
122
126
cpid = fork ();
123
127
/* cpid > 0 - parent process, cpid == 0 - child process, cpid < 0 - error */
124
128
if (cpid > 0 ) {
125
129
wait (& status );
130
+ fflush (stdout );
131
+ fflush (stdin );
132
+ dup2 (saved_stdout , 1 );
133
+ dup2 (saved_stdin , 0 );
126
134
} else if (cpid == 0 ){
127
135
/* executes program according to path and given arguments */
128
136
execv (path , args );
@@ -180,6 +188,8 @@ int redirection(char *path, int stream){
180
188
5. If it absent we lookup on the PATH environment variables.
181
189
*/
182
190
char * detpath (char * ppath ){
191
+ if (ppath == NULL )
192
+ return NULL ;
183
193
/* ppath is absolute path */
184
194
if (* ppath == '/' )
185
195
return ppath ;
You can’t perform that action at this time.
0 commit comments