diff options
author | Larry Wall <lwall@netlabs.com> | 1993-10-07 23:00:00 +0000 |
---|---|---|
committer | Larry Wall <lwall@netlabs.com> | 1993-10-07 23:00:00 +0000 |
commit | 79072805bf63abe5b5978b5928ab00d360ea3e7f (patch) | |
tree | 96688fcd69f9c8d2110e93c350b4d0025eaf240d /do/exec | |
parent | e334a159a5616cab575044bafaf68f75b7bb3a16 (diff) | |
download | perl-79072805bf63abe5b5978b5928ab00d360ea3e7f.tar.gz |
perl 5.0 alpha 2perl-5a2
[editor's note: from history.perl.org. The sparc executables
originally included in the distribution are not in this commit.]
Diffstat (limited to 'do/exec')
-rw-r--r-- | do/exec | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/do/exec b/do/exec new file mode 100644 index 0000000000..5aee9a2f93 --- /dev/null +++ b/do/exec @@ -0,0 +1,77 @@ +bool +do_exec(cmd) +char *cmd; +{ + register char **a; + register char *s; + char flags[10]; + + /* save an extra exec if possible */ + +#ifdef CSH + if (strnEQ(cmd,cshname,cshlen) && strnEQ(cmd+cshlen," -c",3)) { + strcpy(flags,"-c"); + s = cmd+cshlen+3; + if (*s == 'f') { + s++; + strcat(flags,"f"); + } + if (*s == ' ') + s++; + if (*s++ == '\'') { + char *ncmd = s; + + while (*s) + s++; + if (s[-1] == '\n') + *--s = '\0'; + if (s[-1] == '\'') { + *--s = '\0'; + execl(cshname,"csh", flags,ncmd,(char*)0); + *s = '\''; + return FALSE; + } + } + } +#endif /* CSH */ + + /* see if there are shell metacharacters in it */ + + /*SUPPRESS 530*/ + for (s = cmd; *s && isALPHA(*s); s++) ; /* catch VAR=val gizmo */ + if (*s == '=') + goto doshell; + for (s = cmd; *s; s++) { + if (*s != ' ' && !isALPHA(*s) && index("$&*(){}[]'\";\\|?<>~`\n",*s)) { + if (*s == '\n' && !s[1]) { + *s = '\0'; + break; + } + doshell: + execl("/bin/sh","sh","-c",cmd,(char*)0); + return FALSE; + } + } + New(402,Argv, (s - cmd) / 2 + 2, char*); + Cmd = nsavestr(cmd, s-cmd); + a = Argv; + for (s = Cmd; *s;) { + while (*s && isSPACE(*s)) s++; + if (*s) + *(a++) = s; + while (*s && !isSPACE(*s)) s++; + if (*s) + *s++ = '\0'; + } + *a = Nullch; + if (Argv[0]) { + execvp(Argv[0],Argv); + if (errno == ENOEXEC) { /* for system V NIH syndrome */ + do_execfree(); + goto doshell; + } + } + do_execfree(); + return FALSE; +} + |