| 130 | #define EXECCMD_PIPE_WRITE 1 |
| 131 | |
| 132 | void exec_cmd |
| 133 | ( |
| 134 | string const * command, |
| 135 | ExecCmdCallback func, |
| 136 | void * closure, |
| 137 | LIST * shell |
| 138 | ) |
| 139 | { |
| 140 | int const slot = get_free_cmdtab_slot(); |
| 141 | int out[ 2 ]; |
| 142 | int err[ 2 ]; |
| 143 | int len; |
| 144 | char const * argv[ MAXARGC + 1 ]; /* +1 for NULL */ |
| 145 | |
| 146 | /* Initialize default shell. */ |
| 147 | static LIST * default_shell; |
| 148 | if ( !default_shell ) |
| 149 | default_shell = list_push_back( list_new( |
| 150 | object_new( "/bin/sh" ) ), |
| 151 | object_new( "-c" ) ); |
| 152 | |
| 153 | if ( list_empty( shell ) ) |
| 154 | shell = default_shell; |
| 155 | |
| 156 | /* Forumulate argv. If shell was defined, be prepared for % and ! subs. |
| 157 | * Otherwise, use stock /bin/sh. |
| 158 | */ |
| 159 | argv_from_shell( argv, shell, command->value, slot ); |
| 160 | |
| 161 | if ( DEBUG_EXECCMD ) |
| 162 | { |
| 163 | int i; |
| 164 | printf( "Using shell: " ); |
| 165 | list_print( shell ); |
| 166 | printf( "\n" ); |
| 167 | for ( i = 0; argv[ i ]; ++i ) |
| 168 | printf( " argv[%d] = '%s'\n", i, argv[ i ] ); |
| 169 | } |
| 170 | |
| 171 | /* Create pipes for collecting child output. */ |
| 172 | if ( pipe( out ) < 0 || ( globs.pipe_action && pipe( err ) < 0 ) ) |
| 173 | { |
| 174 | perror( "pipe" ); |
| 175 | exit( EXITBAD ); |
| 176 | } |
| 177 | |
| 178 | /* Initialize old_time only once. */ |
| 179 | if ( !old_time_initialized ) |
| 180 | { |
| 181 | times( &old_time ); |
| 182 | old_time_initialized = 1; |
| 183 | } |
| 184 | |
| 185 | /* Start the command */ |
| 186 | |
| 187 | timestamp_current( &cmdtab[ slot ].start_dt ); |
| 188 | |
| 189 | if ( 0 < globs.timeout ) |
nothing calls this directly
no test coverage detected