| 171 | #define EXECCMD_PIPE_WRITE 1 |
| 172 | |
| 173 | void exec_cmd |
| 174 | ( |
| 175 | string const * command, |
| 176 | int flags, |
| 177 | ExecCmdCallback func, |
| 178 | void * closure, |
| 179 | LIST * shell |
| 180 | ) |
| 181 | { |
| 182 | struct sigaction ignore, saveintr, savequit; |
| 183 | sigset_t chldmask, savemask; |
| 184 | |
| 185 | int const slot = get_free_cmdtab_slot(); |
| 186 | int out[ 2 ]; |
| 187 | int err[ 2 ]; |
| 188 | char const * argv[ MAXARGC + 1 ]; /* +1 for NULL */ |
| 189 | |
| 190 | /* Initialize default shell. */ |
| 191 | static LIST * default_shell; |
| 192 | if ( !default_shell ) |
| 193 | default_shell = list_push_back( list_new( |
| 194 | object_new( "/bin/sh" ) ), |
| 195 | object_new( "-c" ) ); |
| 196 | |
| 197 | if ( list_empty( shell ) ) |
| 198 | shell = default_shell; |
| 199 | |
| 200 | /* Forumulate argv. If shell was defined, be prepared for % and ! subs. |
| 201 | * Otherwise, use stock /bin/sh. |
| 202 | */ |
| 203 | argv_from_shell( argv, shell, command->value, slot ); |
| 204 | |
| 205 | if ( DEBUG_EXECCMD ) |
| 206 | { |
| 207 | int i; |
| 208 | out_printf( "Using shell: " ); |
| 209 | list_print( shell ); |
| 210 | out_printf( "\n" ); |
| 211 | for ( i = 0; argv[ i ]; ++i ) |
| 212 | out_printf( " argv[%d] = '%s'\n", i, argv[ i ] ); |
| 213 | } |
| 214 | |
| 215 | /* Create pipes for collecting child output. */ |
| 216 | if ( pipe( out ) < 0 || ( globs.pipe_action && pipe( err ) < 0 ) ) |
| 217 | { |
| 218 | perror( "pipe" ); |
| 219 | exit( EXITBAD ); |
| 220 | } |
| 221 | |
| 222 | /* Start the command */ |
| 223 | |
| 224 | timestamp_current( &cmdtab[ slot ].start_dt ); |
| 225 | |
| 226 | if ( 0 < globs.timeout ) |
| 227 | { |
| 228 | /* Handle hung processes by manually tracking elapsed time and signal |
| 229 | * process when time limit expires. |
| 230 | */ |
nothing calls this directly
no test coverage detected