- Timestamp:
- Sep 9, 2012, 6:06:32 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/shfile.c
r2647 r2650 570 570 { 571 571 #ifdef SHFILE_IN_USE 572 /* Get CWD with unix slashes. */ 572 573 char buf[SHFILE_MAX_PATH]; 573 574 if (getcwd(buf, sizeof(buf))) 574 575 { 576 # if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2 577 char *pszSlash = strchr(buf, '\\'); 578 while (pszSlash) 579 { 580 *pszSlash = '/'; 581 pszSlash = strchr(pszSlash + 1, '\\'); 582 } 583 # endif 584 575 585 pfdtab->cwd = sh_strdup(NULL, buf); 576 586 if (!inherit) … … 764 774 765 775 /** 776 * Changes the inheritability of a file descriptro, taking console handles into 777 * account. 778 * 779 * @note This MAY change the native handle for the entry. 780 * 781 * @returns The native handle. 782 * @param pfd The file descriptor to change. 783 * @param set If set, make child processes inherit the handle, if clear 784 * make them not inherit it. 785 */ 786 static HANDLE shfile_set_inherit_win(shfile *pfd, int set) 787 { 788 HANDLE hFile = (HANDLE)pfd->native; 789 if (!SetHandleInformation(hFile, HANDLE_FLAG_INHERIT, set ? HANDLE_FLAG_INHERIT : 0)) 790 { 791 /* SetHandleInformation doesn't work for console handles, 792 so we have to duplicate the handle to change the 793 inheritability. */ 794 DWORD err = GetLastError(); 795 if ( err == ERROR_INVALID_PARAMETER 796 && DuplicateHandle(GetCurrentProcess(), 797 hFile, 798 GetCurrentProcess(), 799 &hFile, 800 0, 801 set ? TRUE : FALSE /* bInheritHandle */, 802 DUPLICATE_SAME_ACCESS)) 803 { 804 TRACE2((NULL, "shfile_set_inherit_win: %p -> %p (set=%d)\n", pfd->native, hFile, set)); 805 if (!CloseHandle((HANDLE)pfd->native)) 806 assert(0); 807 pfd->native = (intptr_t)hFile; 808 } 809 else 810 { 811 err = GetLastError(); 812 assert(0); 813 hFile = (HANDLE)pfd->native; 814 } 815 } 816 return hFile; 817 } 818 819 /** 766 820 * Helper for shfork. 767 821 * … … 775 829 shmtxtmp tmp; 776 830 unsigned i; 777 DWORD fFlag = set ? HANDLE_FLAG_INHERIT : 0;778 831 779 832 shmtx_enter(&pfdtab->mtx, &tmp); … … 785 838 if (pfdtab->tab[i].fd == i) 786 839 { 787 HANDLE hFile = (HANDLE)pfdtab->tab[i].native;840 shfile_set_inherit_win(&pfdtab->tab[i], set); 788 841 if (set) 789 842 TRACE2((NULL, " #%d: native=%#x oflags=%#x shflags=%#x\n", 790 i, hFile, pfdtab->tab[i].oflags, pfdtab->tab[i].shflags)); 791 if (!SetHandleInformation(hFile, HANDLE_FLAG_INHERIT, fFlag)) 792 { 793 #if 0 /* Seems to happen for console handles, ignore it. */ 794 DWORD err = GetLastError(); 795 assert(0); 796 #endif 797 } 843 i, pfdtab->tab[i].native, pfdtab->tab[i].oflags, pfdtab->tab[i].shflags)); 798 844 } 799 845 } … … 861 907 && !(pfdtab->tab[i].shflags & SHFILE_FLAGS_CLOSE_ON_EXEC)) 862 908 { 863 HANDLE hFile = (HANDLE)pfdtab->tab[i].native;909 HANDLE hFile = shfile_set_inherit_win(&pfdtab->tab[i], 1); 864 910 TRACE2((NULL, " #%d: native=%#x oflags=%#x shflags=%#x\n", 865 911 i, hFile, pfdtab->tab[i].oflags, pfdtab->tab[i].shflags)); 866 867 if (!SetHandleInformation(hFile, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT))868 {869 #if 0 /* Seems to fail for console handles, ignore. */870 DWORD err = GetLastError();871 assert(0);872 #endif873 }874 912 paf[i] = FOPEN; 875 913 if (pfdtab->tab[i].oflags & _O_APPEND) … … 914 952 if ( pfdtab->tab[i].fd == i 915 953 && !(pfdtab->tab[i].shflags & SHFILE_FLAGS_CLOSE_ON_EXEC)) 916 { 917 HANDLE hFile = (HANDLE)pfdtab->tab[i].native; 918 if (!SetHandleInformation(hFile, HANDLE_FLAG_INHERIT, 0)) 919 { 920 DWORD err = GetLastError(); 921 assert(0); 922 } 923 } 954 shfile_set_inherit_win(&pfdtab->tab[i], 0); 924 955 } 925 956 pvRet = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.