Changeset 2294 in kBuild
- Timestamp:
- Feb 28, 2009 8:33:26 AM (16 years ago)
- Location:
- trunk/src/kash
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/main.c
r2292 r2294 134 134 return 2; 135 135 shthread_set_shell(psh); 136 return shell_main(psh, argc, argv);136 return shell_main(psh, argc, psh->argptr); 137 137 } 138 138 -
trunk/src/kash/shfile.c
r2293 r2294 381 381 if (getcwd(buf, sizeof(buf))) 382 382 { 383 pfdtab->cwd = s trdup(buf);383 pfdtab->cwd = sh_strdup(NULL, buf); 384 384 if (!inherit) 385 385 { … … 466 466 467 467 shmtx_enter(&pfdtab->mtx, &tmp); 468 TRACE2((NULL, "shfile_fork_win:\n")); 468 469 469 470 i = pfdtab->size; … … 473 474 { 474 475 HANDLE hFile = (HANDLE)pfdtab->tab[i].native; 475 DWORD fFlag = set || !pfdtab->tab[i].cloexec ? HANDLE_FLAG_INHERIT : 0; 476 DWORD fFlag = (set || !pfdtab->tab[i].cloexec) 477 ? HANDLE_FLAG_INHERIT : 0; 478 if (set) 479 TRACE2((NULL, " #%d: native=%#x flags=%#x cloexec=%d fFlag=%#x\n", 480 i, pfdtab->tab[i].flags, hFile, pfdtab->tab[i].cloexec, fFlag)); 481 476 482 if (!SetHandleInformation(hFile, HANDLE_FLAG_INHERIT, fFlag)) 477 483 { … … 613 619 int shfile_pipe(shfdtab *pfdtab, int fds[2]) 614 620 { 615 #ifdef SH_PURE_STUB_MODE 616 return -1; 621 int rc; 622 int s; 623 #ifdef SHFILE_IN_USE 624 # if K_OS == K_OS_WINDOWS 625 HANDLE hRead = INVALID_HANDLE_VALUE; 626 HANDLE hWrite = INVALID_HANDLE_VALUE; 627 SECURITY_ATTRIBUTES SecurityAttributes; 628 629 SecurityAttributes.nLength = sizeof(SecurityAttributes); 630 SecurityAttributes.lpSecurityDescriptor = NULL; 631 SecurityAttributes.bInheritHandle = TRUE; 632 633 if (!CreatePipe(&hRead, &hWrite, &SecurityAttributes, 4096)) 634 { 635 fds[0] = shfile_insert(pfdtab, (intptr_t)hRead, O_RDONLY, -1, "shfile_pipe"); 636 if (fds[0] != -1) 637 { 638 fds[1] = shfile_insert(pfdtab, (intptr_t)hWrite, O_WRONLY, -1, "shfile_pipe"); 639 if (fds[1] != -1) 640 rc = 0; 641 } 642 643 # else 644 int native_fds[2]; 645 if (!pipe(native_fds)) 646 { 647 fds[1] = -1; 648 fds[0] = shfile_insert(pfdtab, native_fds[0], O_RDONLY, -1, "shfile_pipe"); 649 if (fds[0] != -1) 650 { 651 fds[1] = shfile_insert(pfdtab, native_fds[1], O_WRONLY, -1, "shfile_pipe"); 652 if (fds[1] != -1) 653 rc = 0; 654 } 655 # endif 656 s = errno; 657 if (fds[1] == -1) 658 { 659 if (fds[0] != -1) 660 { 661 shmtxtmp tmp; 662 shmtx_enter(&pfdtab->mtx, &tmp); 663 rc = fds[0]; 664 pfdtab->tab[rc].fd = -1; 665 pfdtab->tab[rc].flags = 0; 666 pfdtab->tab[rc].native = -1; 667 shmtx_leave(&pfdtab->mtx, &tmp); 668 } 669 670 # if K_OS == K_OS_WINDOWS 671 CloseHandle(hRead); 672 CloseHandle(hWrite); 673 # else 674 close(native_fds[0]); 675 close(native_fds[1]); 676 # endif 677 fds[0] = fds[1] = -1; 678 errno = s; 679 rc = -1; 680 } 681 } 682 683 #elif defined(SH_PURE_STUB_MODE) 684 rc = -1; 685 errno = ENOSYS; 617 686 618 687 #elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE) 619 688 # ifdef _MSC_VER 620 return _pipe(fds, PIPE_BUF, O_BINARY); 621 # else 622 return pipe(fds); 623 # endif 624 625 #else 626 #endif 689 rc = _pipe(fds, PIPE_BUF, O_BINARY); 690 # else 691 rc = pipe(fds); 692 # endif 693 #endif 694 695 TRACE2((NULL, "shfile_pipe() -> %d{%d,%d} [%d]\n", rc, fds[0], fds[1], errno)); 696 return rc; 627 697 } 628 698 -
trunk/src/kash/shforkA-win.asm
r2293 r2294 107 107 mov [rax - 10h], r10 108 108 mov [rax - 18h], r11 109 int3 109 110 cmp rax, r10 110 111 jb .below -
trunk/src/kash/shinstance.c
r2293 r2294 181 181 182 182 /** 183 * Clones a n environment vector.183 * Clones a string vector like enviorn or argv. 184 184 * 185 185 * @returns 0 on success, -1 and errno on failure. 186 * @param psh The shell to associate the allocations with. 186 187 * @param dstp Where to store the clone. 187 188 * @param src The vector to be cloned. 188 189 */ 189 static int sh_ env_clone(char ***dstp, char **src)190 static int sh_clone_string_vector(shinstance *psh, char ***dstp, char **src) 190 191 { 191 192 char **dst; … … 198 199 199 200 /* alloc clone array. */ 200 *dstp = dst = sh_malloc( NULL, sizeof(*dst) * items + 1);201 *dstp = dst = sh_malloc(psh, sizeof(*dst) * items + 1); 201 202 if (!dst) 202 203 return -1; … … 206 207 while (items-- > 0) 207 208 { 208 dst[items] = sh_strdup( NULL, src[items]);209 dst[items] = sh_strdup(psh, src[items]); 209 210 if (!dst[items]) 210 211 { 211 212 /* allocation error, clean up. */ 212 213 while (dst[++items]) 213 sh_free( NULL, dst[items]);214 sh_free( NULL, dst);214 sh_free(psh, dst[items]); 215 sh_free(psh, dst); 215 216 errno = ENOMEM; 216 217 return -1; … … 246 247 247 248 /* Call the basic initializers. */ 248 if ( !sh_env_clone(&psh->shenviron, envp) 249 if ( !sh_clone_string_vector(psh, &psh->shenviron, envp) 250 && !sh_clone_string_vector(psh, &psh->argptr, argv) 249 251 && !shfile_init(&psh->fdtab, inherit ? &inherit->fdtab : NULL)) 250 252 { … … 916 918 #elif K_OS == K_OS_WINDOWS //&& defined(SH_FORKED_MODE) 917 919 pid = shfork_do_it(psh); 920 # ifdef DEBUG 921 if (!pid) 922 opentrace(psh); 923 # endif 918 924 919 925 #elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE) … … 928 934 929 935 #endif 936 937 /* child: update the pid */ 938 if (!pid) 939 # ifdef _MSC_VER 940 psh->pid = _getpid(); 941 # else 942 psh->pid = getpid(); 943 # endif 930 944 931 945 TRACE2((psh, "sh_fork -> %d [%d]\n", pid, errno)); -
trunk/src/kash/var.c
r2290 r2294 255 255 vp->next = *vpp; 256 256 *vpp = vp; 257 vp->text = s trdup(ip->text);257 vp->text = sh_strdup(psh, ip->text); 258 258 vp->flags = ip->flags; 259 259 vp->func = ip->func; … … 265 265 psh->vps1.next = *vpp; 266 266 *vpp = &psh->vps1; 267 psh->vps1.text = s trdup(sh_geteuid(psh) ? "PS1=$ " : "PS1=# ");267 psh->vps1.text = sh_strdup(psh, sh_geteuid(psh) ? "PS1=$ " : "PS1=# "); 268 268 psh->vps1.flags = VSTRFIXED|VTEXTFIXED; 269 269 }
Note:
See TracChangeset
for help on using the changeset viewer.