diff options
author | 2006-12-09 08:04:28 +1000 | |
---|---|---|
committer | 2006-12-09 08:04:28 +1000 | |
commit | 23759e6eca3e25700ea9c944a225709e3f4231c5 (patch) | |
tree | cbf8cfb0ac4daafe20bf3f77083abb7a969e6e83 /exec.c | |
parent | 1d3465698fb9f0d8e198daa8dd874a328bd1171b (diff) |
colon-command support
Shells such as bash, sh, tcsh, and ksh each support a "colon command" that causes the script to be
evaluated as a bourne script. In the case of bash and sh, this command is a no-op. For others,
it means the script has sh syntax.
To suppor this in fish, I've added code to launch_process that checks for a ':' as the first
character of p->actual_cmd. If it is a colon, the process descriptor is modified to call
/bin/sh, which should exist on any POSIX system.
darcs-hash:20061208220428-5830d-6bde4f1a3e8100296a60c21f9e47988e20688a77.gz
Diffstat (limited to 'exec.c')
-rw-r--r-- | exec.c | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -447,7 +447,38 @@ static int setup_child_process( job_t *j, process_t *p ) static void launch_process( process_t *p ) { // debug( 1, L"exec '%ls'", p->argv[0] ); - + + /* check for a ":\n", and run system() if so */ + + FILE* f = wfopen(p->actual_cmd, "r"); + if (f != NULL) + { + char begin[1] = {0}; + fread(begin, 1, 1, f); + if (begin[0] == ':') + { + int count = 0; + int i = 1; + int j = 2; + while( p->argv[count] != 0 ) + count++; + wchar_t **res = malloc( sizeof(wchar_t*)*(count+2)); + res[0] = L"/bin/sh"; + res[1] = p->actual_cmd; + while( p->argv[i] != 0 ) + { + res[j] = p->argv[i]; + i++; + j++; + } + res[j] = NULL; + free(p->argv); + p->argv = res; + p->actual_cmd = L"/bin/sh"; + } + + } + execve ( wcs2str(p->actual_cmd), wcsv2strv( (const wchar_t **) p->argv), env_export_arr( 0 ) ); |