7 #undef USE_DYNAMIC_LOADING
12 #include <sys/cygwin.h>
15 * pp_system() implemented via spawn()
16 * - more efficient and useful when embedding Perl in non-Cygwin apps
17 * - code mostly borrowed from djgpp.c
20 do_spawnvp (const char *path, const char * const *argv)
23 Sigsave_t ihand,qhand;
24 int childpid, result, status;
26 rsignal_save(SIGINT, (Sighandler_t) SIG_IGN, &ihand);
27 rsignal_save(SIGQUIT, (Sighandler_t) SIG_IGN, &qhand);
28 childpid = spawnvp(_P_NOWAIT,path,argv);
32 Perl_warner(aTHX_ packWARN(WARN_EXEC),"Can't spawn \"%s\": %s",
33 path,Strerror (errno));
36 result = wait4pid(childpid, &status, 0);
37 } while (result == -1 && errno == EINTR);
41 (void)rsignal_restore(SIGINT, &ihand);
42 (void)rsignal_restore(SIGQUIT, &qhand);
47 do_aspawn (SV *really, void **mark, void **sp)
51 char **a,*tmps,**argv;
56 a=argv=(char**) alloca ((sp-mark+3)*sizeof (char*));
60 *a++ = SvPVx(*mark, n_a);
65 if (argv[0][0] != '/' && argv[0][0] != '\\'
66 && !(argv[0][0] && argv[0][1] == ':'
67 && (argv[0][2] == '/' || argv[0][2] != '\\'))
68 ) /* will swawnvp use PATH? */
69 TAINT_ENV(); /* testing IFS here is overkill, probably */
71 if (really && *(tmps = SvPV(really, n_a)))
72 rc=do_spawnvp (tmps,(const char * const *)argv);
74 rc=do_spawnvp (argv[0],(const char *const *)argv);
83 char **a,*s,*metachars = "$&*(){}[]'\";\\?>|<~`\n";
84 const char *command[4];
86 while (*cmd && isSPACE(*cmd))
89 if (strnEQ (cmd,"/bin/sh",7) && isSPACE (cmd[7]))
92 /* save an extra exec if possible */
93 /* see if there are shell metacharacters in it */
94 if (strstr (cmd,"..."))
96 if (*cmd=='.' && isSPACE (cmd[1]))
98 if (strnEQ (cmd,"exec",4) && isSPACE (cmd[4]))
100 for (s=cmd; *s && isALPHA (*s); s++) ; /* catch VAR=val gizmo */
105 if (strchr (metachars,*s))
107 if (*s=='\n' && s[1]=='\0')
118 return do_spawnvp("sh",command);
121 Newx (PL_Argv,(s-cmd)/2+2,char*);
122 PL_Cmd=savepvn (cmd,s-cmd);
124 for (s=PL_Cmd; *s;) {
125 while (*s && isSPACE (*s)) s++;
128 while (*s && !isSPACE (*s)) s++;
136 return do_spawnvp(PL_Argv[0],(const char * const *)PL_Argv);
139 /* see also Cwd.pm */
147 Perl_croak(aTHX_ "Usage: Cwd::cwd()");
148 if((cwd = getcwd(NULL, -1))) {
149 ST(0) = sv_2mortal(newSVpv(cwd, 0));
151 #ifndef INCOMPLETE_TAINTS
160 XS(XS_Cygwin_pid_to_winpid)
167 Perl_croak(aTHX_ "Usage: Cygwin::pid_to_winpid(pid)");
169 pid = (pid_t)SvIV(ST(0));
171 if ((RETVAL = cygwin_internal(CW_CYGWIN_PID_TO_WINPID, pid)) > 0) {
172 XSprePUSH; PUSHi((IV)RETVAL);
179 XS(XS_Cygwin_winpid_to_pid)
186 Perl_croak(aTHX_ "Usage: Cygwin::winpid_to_pid(pid)");
188 pid = (pid_t)SvIV(ST(0));
190 if ((RETVAL = cygwin32_winpid_to_pid(pid)) > 0) {
191 XSprePUSH; PUSHi((IV)RETVAL);
201 char *file = __FILE__;
204 newXS("Cwd::cwd", Cygwin_cwd, file);
205 newXS("Cygwin::winpid_to_pid", XS_Cygwin_winpid_to_pid, file);
206 newXS("Cygwin::pid_to_winpid", XS_Cygwin_pid_to_winpid, file);