Changeset 3435 in kBuild
- Timestamp:
- Sep 2, 2020 8:30:54 PM (4 years ago)
- Location:
- trunk/src/kash
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/eval.c
r3434 r3435 773 773 * evalcommand_out, evalcommand_parent, evalcommand_doit, evalcommand_child 774 774 */ 775 /*int vforked = 0; */775 /*int vforked = 0; - obsolete */ 776 776 777 777 /* Both child and parent exits thru here. */ … … 983 983 trputs(psh, "normal command: "); trargs(psh, args->argv); 984 984 #endif 985 clearredir(psh, psh->vforked); 986 redirect(psh, cmd->ncmd.redirect, psh->vforked ? REDIR_VFORK : 0); 987 if (!psh->vforked) 988 for (sp = args->varlist.list ; sp ; sp = sp->next) 989 setvareq(psh, sp->text, VEXPORT|VSTACK); 985 clearredir(psh); 986 redirect(psh, cmd->ncmd.redirect, 0); 987 for (sp = args->varlist.list ; sp ; sp = sp->next) 988 setvareq(psh, sp->text, VEXPORT|VSTACK); 990 989 envp = environment(psh); 991 shellexec(psh, args->argv, envp, args->path, args->cmdentry.u.index , psh->vforked);990 shellexec(psh, args->argv, envp, args->path, args->cmdentry.u.index); 992 991 break; 993 992 } … … 1014 1013 const char *path = pathval(psh); 1015 1014 1016 psh->vforked = 0;1017 1015 /* First expand the arguments. */ 1018 1016 TRACE((psh, "evalcommand(0x%lx, %d) called\n", (long)cmd, flags)); … … 1153 1151 1154 1152 if (flags & EV_BACKCMD) { 1155 if (!psh->vforked) { 1156 FORCEINTON; 1157 } 1153 FORCEINTON; 1158 1154 shfile_close(&psh->fdtab, pip[0]); 1159 1155 if (pip[1] != 1) { … … 1304 1300 for (sp = psh->cmdenviron; sp; sp = sp->next) 1305 1301 setvareq(psh, sp->text, VEXPORT|VSTACK); 1306 shellexec(psh, argv + 1, environment(psh), pathval(psh), 0 , 0);1302 shellexec(psh, argv + 1, environment(psh), pathval(psh), 0); 1307 1303 } 1308 1304 return 0; -
trunk/src/kash/exec.c
r3057 r3435 99 99 100 100 101 STATIC void tryexec(shinstance *, char *, char **, char **, int , int);101 STATIC void tryexec(shinstance *, char *, char **, char **, int); 102 102 STATIC void execinterp(shinstance *, char **, char **); 103 103 STATIC void printentry(shinstance *, struct tblentry *, int); … … 118 118 119 119 SH_NORETURN_1 void 120 shellexec(shinstance *psh, char **argv, char **envp, const char *path, int idx , int vforked)120 shellexec(shinstance *psh, char **argv, char **envp, const char *path, int idx) 121 121 { 122 122 char *cmdname; … … 144 144 cmdname = stalloc(psh, argv0len + 5); 145 145 strcpy(cmdname, argv0); 146 tryexec(psh, cmdname, argv, envp, vforked,has_ext);146 tryexec(psh, cmdname, argv, envp, has_ext); 147 147 TRACE((psh, "shellexec: cmdname=%s\n", cmdname)); 148 148 stunalloc(psh, cmdname); … … 165 165 while ((cmdname = padvance(psh, &path, argv0)) != NULL) { 166 166 if (--idx < 0 && psh->pathopt == NULL) { 167 tryexec(psh, cmdname, argv, envp, vforked,has_ext);167 tryexec(psh, cmdname, argv, envp, has_ext); 168 168 if (errno != ENOENT && errno != ENOTDIR) 169 169 e = errno; … … 185 185 break; 186 186 } 187 TRACE((psh, "shellexec failed for '%s', errno %d, vforked %d,suppressint %d\n",188 argv[0], e, vforked,psh->suppressint ));187 TRACE((psh, "shellexec failed for '%s', errno %d, suppressint %d\n", 188 argv[0], e, psh->suppressint )); 189 189 exerror(psh, EXEXEC, "%s: %s", argv[0], errmsg(psh, e, E_EXEC)); 190 190 /* NOTREACHED */ … … 193 193 194 194 STATIC void 195 tryexec(shinstance *psh, char *cmd, char **argv, char **envp, int vforked, inthas_ext)195 tryexec(shinstance *psh, char *cmd, char **argv, char **envp, int has_ext) 196 196 { 197 197 int e; … … 220 220 e = errno; 221 221 if (e == ENOEXEC) { 222 if (vforked) {223 /* We are currently vfork(2)ed, so raise an224 * exception, and evalcommand will try again225 * with a normal fork(2).226 */227 exraise(psh, EXSHELLPROC);228 }229 222 initshellproc(psh); 230 223 setinputfile(psh, cmd, 0); … … 347 340 /* nothing*/; 348 341 TRACE((psh, "hash bang '%s'\n", new[0])); 349 shellexec(psh, new, envp, pathval(psh), 0 , 0);342 shellexec(psh, new, envp, pathval(psh), 0); 350 343 /* NOTREACHED */ 351 344 } -
trunk/src/kash/exec.h
r2415 r3435 71 71 #endif 72 72 73 SH_NORETURN_1 void shellexec(struct shinstance *, char **, char **, const char *, int , int) SH_NORETURN_2;73 SH_NORETURN_1 void shellexec(struct shinstance *, char **, char **, const char *, int) SH_NORETURN_2; 74 74 char *padvance(struct shinstance *, const char **, const char *); 75 75 int hashcmd(struct shinstance *, int, char **); -
trunk/src/kash/generated/init.c
r2652 r3435 276 276 /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/redir.c: */ 277 277 { 278 clearredir(psh , 0);278 clearredir(psh); 279 279 } 280 280 … … 283 283 char *sm; 284 284 285 clear_traps(psh , 0);285 clear_traps(psh); 286 286 for (sm = psh->sigmode ; sm < psh->sigmode + NSIG ; sm++) { 287 287 if (*sm == S_IGN) -
trunk/src/kash/input.c
r3065 r3435 565 565 566 566 void 567 closescript(shinstance *psh, int vforked) 568 { 569 if (vforked) 570 return; 567 closescript(shinstance *psh) 568 { 571 569 popallfiles(psh); 572 570 if (psh->parsefile->fd > 0) { -
trunk/src/kash/input.h
r1233 r3435 58 58 void popfile(struct shinstance *); 59 59 void popallfiles(struct shinstance *); 60 void closescript(struct shinstance * , int);60 void closescript(struct shinstance *); 61 61 62 62 #define pgetc_macro(psh) (--(psh)->parsenleft >= 0? *(psh)->parsenextc++ : preadbuffer(psh)) -
trunk/src/kash/jobs.c
r3434 r3435 86 86 #ifdef KASH_USE_FORKSHELL2 87 87 static int forkparent(shinstance *psh, struct job *jp, union node *n, int mode, pid_t pid); 88 static void forkchild(shinstance *psh, struct job *jp, union node *n, int mode , int vforked);88 static void forkchild(shinstance *psh, struct job *jp, union node *n, int mode); 89 89 #endif 90 90 … … 149 149 } while (0); 150 150 151 setsignal(psh, SIGTSTP , 0);152 setsignal(psh, SIGTTOU , 0);153 setsignal(psh, SIGTTIN , 0);151 setsignal(psh, SIGTSTP); 152 setsignal(psh, SIGTTOU); 153 setsignal(psh, SIGTTIN); 154 154 if (sh_getpgid(psh, 0) != psh->rootpid && sh_setpgid(psh, 0, psh->rootpid) == -1) 155 155 error(psh, "Cannot set process group (%s) at %d", … … 167 167 shfile_close(&psh->fdtab, psh->ttyfd); 168 168 psh->ttyfd = -1; 169 setsignal(psh, SIGTSTP , 0);170 setsignal(psh, SIGTTOU , 0);171 setsignal(psh, SIGTTIN , 0);169 setsignal(psh, SIGTSTP); 170 setsignal(psh, SIGTTOU); 171 setsignal(psh, SIGTTIN); 172 172 } 173 173 psh->jobctl = on; … … 798 798 return -1; /* won't get here */ 799 799 case 0: 800 forkchild(psh, jp, n, mode , 0);800 forkchild(psh, jp, n, mode); 801 801 return 0; 802 802 default: … … 817 817 /* child */ 818 818 (void)arglen; 819 forkchild(psh, jp, n, mode , 0);819 forkchild(psh, jp, n, mode); 820 820 sh_exit(psh, child(psh, nchild, argp)); 821 821 return 0; … … 866 866 #endif 867 867 void 868 forkchild(shinstance *psh, struct job *jp, union node *n, int mode , int vforked)868 forkchild(shinstance *psh, struct job *jp, union node *n, int mode) 869 869 { 870 870 int wasroot; … … 875 875 wasroot = psh->rootshell; 876 876 TRACE((psh, "Child shell %d\n", sh_getpid(psh))); 877 if (!vforked) 878 psh->rootshell = 0; 879 880 closescript(psh, vforked); 881 clear_traps(psh, vforked); 882 #if JOBS 883 if (!vforked) 884 psh->jobctl = 0; /* do job control only in root shell */ 877 psh->rootshell = 0; 878 879 closescript(psh); 880 clear_traps(psh); 881 #if JOBS 882 psh->jobctl = 0; /* do job control only in root shell */ 885 883 if (wasroot && mode != FORK_NOJOB && mflag(psh)) { 886 884 if (jp == NULL || jp->nprocs == 0) … … 896 894 sh_strerror(psh, errno), __LINE__); 897 895 } 898 setsignal(psh, SIGTSTP , vforked);899 setsignal(psh, SIGTTOU , vforked);896 setsignal(psh, SIGTSTP); 897 setsignal(psh, SIGTTOU); 900 898 } else if (mode == FORK_BG) { 901 ignoresig(psh, SIGINT , vforked);902 ignoresig(psh, SIGQUIT , vforked);899 ignoresig(psh, SIGINT); 900 ignoresig(psh, SIGQUIT); 903 901 if ((jp == NULL || jp->nprocs == 0) && 904 902 ! fd0_redirected_p(psh)) { … … 910 908 #else 911 909 if (mode == FORK_BG) { 912 ignoresig(psh, SIGINT , vforked);913 ignoresig(psh, SIGQUIT , vforked);910 ignoresig(psh, SIGINT); 911 ignoresig(psh, SIGQUIT); 914 912 if ((jp == NULL || jp->nprocs == 0) && 915 913 ! fd0_redirected_p(psh)) { … … 921 919 #endif 922 920 if (wasroot && iflag(psh)) { 923 setsignal(psh, SIGINT, vforked); 924 setsignal(psh, SIGQUIT, vforked); 925 setsignal(psh, SIGTERM, vforked); 926 } 927 928 if (!vforked) 929 psh->jobs_invalid = 1; 921 setsignal(psh, SIGINT); 922 setsignal(psh, SIGQUIT); 923 setsignal(psh, SIGTERM); 924 } 925 926 psh->jobs_invalid = 1; 930 927 } 931 928 -
trunk/src/kash/jobs.h
r3434 r3435 101 101 #else 102 102 int forkshell(struct shinstance *, struct job *, union node *, int); 103 void forkchild(struct shinstance *, struct job *, union node *, int , int);103 void forkchild(struct shinstance *, struct job *, union node *, int); 104 104 int forkparent(struct shinstance *, struct job *, union node *, int, pid_t); 105 105 #endif -
trunk/src/kash/main.c
r2457 r3435 241 241 242 242 for (i = 0; i < SIGSSIZE; i++) 243 setsignal(psh, sigs[i] , 0);243 setsignal(psh, sigs[i]); 244 244 } 245 245 -
trunk/src/kash/redir.c
r3433 r3435 114 114 memory[1] = flags & REDIR_BACKQ; 115 115 if (flags & REDIR_PUSH) { 116 /* We don't have to worry about REDIR_VFORK here, as117 * flags & REDIR_PUSH is never true if REDIR_VFORK is set.118 */119 116 sv = ckmalloc(psh, sizeof (struct redirtab)); 120 117 for (i = 0 ; i < 10 ; i++) … … 174 171 char *fname; 175 172 int f; 176 int oflags = O_WRONLY|O_CREAT|O_TRUNC , eflags;173 int oflags = O_WRONLY|O_CREAT|O_TRUNC; 177 174 178 175 /* … … 186 183 case NFROM: 187 184 fname = redir->nfile.expfname; 188 if (flags & REDIR_VFORK) 189 eflags = O_NONBLOCK; 190 else 191 eflags = 0; 192 if ((f = shfile_open(&psh->fdtab, fname, O_RDONLY|eflags, 0)) < 0) 185 if ((f = shfile_open(&psh->fdtab, fname, O_RDONLY, 0)) < 0) 193 186 goto eopen; 194 if (eflags)195 (void)shfile_fcntl(&psh->fdtab, f, F_SETFL, shfile_fcntl(&psh->fdtab, f, F_GETFL, 0) & ~eflags);196 187 break; 197 188 case NFROMTO: … … 365 356 366 357 SHELLPROC { 367 clearredir(psh , 0);358 clearredir(psh); 368 359 } 369 360 … … 381 372 382 373 void 383 clearredir(shinstance *psh , int vforked)374 clearredir(shinstance *psh) 384 375 { 385 376 struct redirtab *rp; … … 391 382 shfile_close(&psh->fdtab, rp->renamed[i]); 392 383 } 393 if (!vforked) 394 rp->renamed[i] = EMPTY; 384 rp->renamed[i] = EMPTY; 395 385 } 396 386 } -
trunk/src/kash/redir.h
r2424 r3435 38 38 #define REDIR_PUSH 01 /* save previous values of file descriptors */ 39 39 #define REDIR_BACKQ 02 /* save the command output in memory */ 40 #define REDIR_VFORK 04 /* running under vfork(2), be careful */40 //#define REDIR_VFORK 04 /* running under vfork(2), be careful */ 41 41 42 42 union node; … … 44 44 void popredir(struct shinstance *); 45 45 int fd0_redirected_p(struct shinstance *); 46 void clearredir(struct shinstance * , int);46 void clearredir(struct shinstance *); 47 47 int copyfd(struct shinstance *, int, int); 48 48 int movefd(struct shinstance *, int, int); -
trunk/src/kash/shinstance.h
r3434 r3435 178 178 int skipcount; /**< number of levels to skip */ 179 179 int loopnest; /**< current loop nesting level */ 180 181 /* eval.c */182 int vforked; /** @todo remove this */183 180 184 181 /* expand.c */ -
trunk/src/kash/trap.c
r3409 r3435 187 187 188 188 if (signo != 0) 189 setsignal(psh, signo , 0);189 setsignal(psh, signo); 190 190 INTON; 191 191 ap++; … … 203 203 204 204 void 205 clear_traps(shinstance *psh , int vforked)205 clear_traps(shinstance *psh) 206 206 { 207 207 char **tp; … … 210 210 if (*tp && **tp) { /* trap not NULL or SIG_IGN */ 211 211 INTOFF; 212 if (!vforked) { 213 ckfree(psh, *tp); 214 *tp = NULL; 215 } 212 ckfree(psh, *tp); 213 *tp = NULL; 216 214 if (tp != &psh->trap[0]) 217 setsignal(psh, (int)(tp - psh->trap) , vforked);215 setsignal(psh, (int)(tp - psh->trap)); 218 216 INTON; 219 217 } … … 229 227 230 228 void 231 setsignal(shinstance *psh, int signo , int vforked)229 setsignal(shinstance *psh, int signo) 232 230 { 233 231 int action; … … 241 239 else 242 240 action = S_IGN; 243 if (psh->rootshell && !vforked &&action == S_DFL) {241 if (psh->rootshell && action == S_DFL) { 244 242 switch (signo) { 245 243 case SIGINT: … … 298 296 case S_IGN: sigact = SH_SIG_IGN; break; 299 297 } 300 if (!vforked) 301 *t = action; 298 *t = action; 302 299 sh_siginterrupt(psh, signo, 1); 303 300 sh_signal(psh, signo, sigact); … … 323 320 324 321 void 325 ignoresig(shinstance *psh, int signo , int vforked)322 ignoresig(shinstance *psh, int signo) 326 323 { 327 324 if (psh->sigmode[signo - 1] != S_IGN && psh->sigmode[signo - 1] != S_HARD_IGN) { 328 325 sh_signal(psh, signo, SH_SIG_IGN); 329 326 } 330 if (!vforked) 331 psh->sigmode[signo - 1] = S_HARD_IGN; 327 psh->sigmode[signo - 1] = S_HARD_IGN; 332 328 } 333 329 … … 340 336 char *sm; 341 337 342 clear_traps(psh , 0);338 clear_traps(psh); 343 339 for (sm = psh->sigmode ; sm < psh->sigmode + NSIG ; sm++) { 344 340 if (*sm == S_IGN) … … 409 405 if (on == is_interactive) 410 406 return; 411 setsignal(psh, SIGINT , 0);412 setsignal(psh, SIGQUIT , 0);413 setsignal(psh, SIGTERM , 0);407 setsignal(psh, SIGINT); 408 setsignal(psh, SIGQUIT); 409 setsignal(psh, SIGTERM); 414 410 is_interactive = on; 415 411 } -
trunk/src/kash/trap.h
r2298 r3435 38 38 39 39 int trapcmd(struct shinstance *, int, char **); 40 void clear_traps(struct shinstance * , int);41 void setsignal(struct shinstance *, int , int);42 void ignoresig(struct shinstance *, int , int);40 void clear_traps(struct shinstance *); 41 void setsignal(struct shinstance *, int); 42 void ignoresig(struct shinstance *, int); 43 43 void onsig(struct shinstance *, int); 44 44 void dotrap(struct shinstance *);
Note:
See TracChangeset
for help on using the changeset viewer.