7 #undef USE_DYNAMIC_LOADING
12 #include <sys/cygwin.h>
16 * pp_system() implemented via spawn()
17 * - more efficient and useful when embedding Perl in non-Cygwin apps
18 * - code mostly borrowed from djgpp.c
21 do_spawnvp (const char *path, const char * const *argv)
24 Sigsave_t ihand,qhand;
25 int childpid, result, status;
27 rsignal_save(SIGINT, (Sighandler_t) SIG_IGN, &ihand);
28 rsignal_save(SIGQUIT, (Sighandler_t) SIG_IGN, &qhand);
29 childpid = spawnvp(_P_NOWAIT,path,argv);
33 Perl_warner(aTHX_ packWARN(WARN_EXEC),"Can't spawn \"%s\": %s",
34 path,Strerror (errno));
37 result = wait4pid(childpid, &status, 0);
38 } while (result == -1 && errno == EINTR);
42 (void)rsignal_restore(SIGINT, &ihand);
43 (void)rsignal_restore(SIGQUIT, &qhand);
48 do_aspawn (SV *really, void **mark, void **sp)
52 char **a,*tmps,**argv;
57 a=argv=(char**) alloca ((sp-mark+3)*sizeof (char*));
61 *a++ = SvPVx((SV *)*mark, n_a);
66 if (argv[0][0] != '/' && argv[0][0] != '\\'
67 && !(argv[0][0] && argv[0][1] == ':'
68 && (argv[0][2] == '/' || argv[0][2] != '\\'))
69 ) /* will swawnvp use PATH? */
70 TAINT_ENV(); /* testing IFS here is overkill, probably */
72 if (really && *(tmps = SvPV(really, n_a)))
73 rc=do_spawnvp (tmps,(const char * const *)argv);
75 rc=do_spawnvp (argv[0],(const char *const *)argv);
84 char **a,*s,*metachars = "$&*(){}[]'\";\\?>|<~`\n";
85 const char *command[4];
87 while (*cmd && isSPACE(*cmd))
90 if (strnEQ (cmd,"/bin/sh",7) && isSPACE (cmd[7]))
93 /* save an extra exec if possible */
94 /* see if there are shell metacharacters in it */
95 if (strstr (cmd,"..."))
97 if (*cmd=='.' && isSPACE (cmd[1]))
99 if (strnEQ (cmd,"exec",4) && isSPACE (cmd[4]))
101 for (s=cmd; *s && isALPHA (*s); s++) ; /* catch VAR=val gizmo */
106 if (strchr (metachars,*s))
108 if (*s=='\n' && s[1]=='\0')
119 return do_spawnvp("sh",command);
122 Newx (PL_Argv,(s-cmd)/2+2,char*);
123 PL_Cmd=savepvn (cmd,s-cmd);
125 for (s=PL_Cmd; *s;) {
126 while (*s && isSPACE (*s)) s++;
129 while (*s && !isSPACE (*s)) s++;
137 return do_spawnvp(PL_Argv[0],(const char * const *)PL_Argv);
140 /* 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
159 XS(XS_Cygwin_pid_to_winpid)
166 Perl_croak(aTHX_ "Usage: Cygwin::pid_to_winpid(pid)");
168 pid = (pid_t)SvIV(ST(0));
170 if ((RETVAL = cygwin_internal(CW_CYGWIN_PID_TO_WINPID, pid)) > 0) {
171 XSprePUSH; PUSHi((IV)RETVAL);
177 XS(XS_Cygwin_winpid_to_pid)
184 Perl_croak(aTHX_ "Usage: Cygwin::winpid_to_pid(pid)");
186 pid = (pid_t)SvIV(ST(0));
188 if ((RETVAL = cygwin32_winpid_to_pid(pid)) > 0) {
189 XSprePUSH; PUSHi((IV)RETVAL);
199 char *file = __FILE__;
203 newXS("Cwd::cwd", Cygwin_cwd, file);
204 newXS("Cygwin::winpid_to_pid", XS_Cygwin_winpid_to_pid, file);
205 newXS("Cygwin::pid_to_winpid", XS_Cygwin_pid_to_winpid, file);
207 if ((cv = get_cv("Win32CORE::bootstrap", 0))) {
210 (void)call_sv((SV *)cv, G_EVAL|G_DISCARD|G_VOID);