Changeset 3444 in kBuild
- Timestamp:
- Sep 10, 2020 2:08:18 PM (5 years ago)
- Location:
- trunk/src/kash
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/shfile.c
r3439 r3444 240 240 if (fdMin >= SHFILE_MAX) 241 241 { 242 TRACE2((NULL, "shfile_insert: fdMin=%d is out of bounds; native=%p\n", fdMin, native)); 243 shfile_native_close(native, oflags); 242 244 errno = EMFILE; 243 245 return -1; … … 247 249 { 248 250 int e = errno; 251 TRACE2((NULL, "shfile_insert: F_SETFD failed %d; native=%p\n", e, native)); 249 252 close((int)native); 250 253 errno = e; … … 277 280 pfdtab->tab[fd].shflags = shflags; 278 281 pfdtab->tab[fd].native = native; 282 TRACE2((NULL, "shfile_insert: #%d: native=%p oflags=%#x shflags=%#x\n", fd, native, oflags, shflags)); 279 283 } 280 284 else … … 847 851 else 848 852 { 849 # ifdef SH_FORKED_MODE 853 # if K_OS == K_OS_WINDOWS 854 # ifdef SH_FORKED_MODE 850 855 KBOOL const cox = !!(src->shflags & SHFILE_FLAGS_CLOSE_ON_EXEC); 851 # else 852 KBOOL const cox = !!(src->shflags & SHFILE_FLAGS_CLOSE_ON_EXEC); /// @todo K_TRUE 856 # else 857 KBOOL const cox = K_TRUE; 858 # endif 853 859 # endif 854 860 *dst = *src; … … 859 865 (HANDLE *)&dst->native, 860 866 0, 861 cox ? FALSE : TRUE /* bInheritHandle */,867 FALSE /* bInheritHandle */, 862 868 DUPLICATE_SAME_ACCESS)) 863 869 TRACE2((NULL, "shfile_init: %d (%#x, %#x) %p (was %p)\n", … … 1054 1060 * @returns Pointer to CRT data if prepare is 1, NULL if prepare is 0. 1055 1061 * @param pfdtab The file descriptor table. 1056 * @param prepare Which call, 1 if before and 0 if after.1062 * @param prepare Which call, 1 if before, 0 if after and success, -1 if after on failure. 1057 1063 * @param sizep Where to store the size of the returned data. 1058 1064 * @param hndls Where to store the three standard handles. … … 1074 1080 count--; 1075 1081 1076 if (prepare )1082 if (prepare > 0) 1077 1083 { 1078 1084 size_t cbData = sizeof(int) + count * (1 + sizeof(HANDLE)); … … 1127 1133 else 1128 1134 { 1135 shfile *file = pfdtab->tab; 1129 1136 assert(!hndls); 1130 1137 assert(!sizep); 1131 1138 i = count; 1132 while (i-- > 0) 1133 { 1134 if ( pfdtab->tab[i].fd == i 1135 && !(pfdtab->tab[i].shflags & SHFILE_FLAGS_CLOSE_ON_EXEC)) 1136 shfile_set_inherit_win(&pfdtab->tab[i], 0); 1137 } 1139 if (prepare == 0) 1140 for (i = 0; i < count; i++, file++) 1141 { 1142 if ( file->fd == i 1143 && !(file->shflags & SHFILE_FLAGS_TRACE)) 1144 { 1145 shfile_native_close(file->native, file->oflags); 1146 1147 file->fd = -1; 1148 file->oflags = 0; 1149 file->shflags = 0; 1150 file->native = -1; 1151 } 1152 } 1153 else 1154 for (i = 0; i < count; i++, file++) 1155 if ( file->fd == i 1156 && !(file->shflags & SHFILE_FLAGS_CLOSE_ON_EXEC)) 1157 shfile_set_inherit_win(file, 0); 1138 1158 pvRet = NULL; 1139 1159 } … … 1945 1965 1946 1966 TRACE2((NULL, "shfile_cloexec(%d, %d) -> %d [%d]\n", fd, closeit, rc, errno)); 1967 return rc; 1968 } 1969 1970 /** 1971 * Sets the SHFILE_FLAGS_TRACE flag. 1972 */ 1973 int shfile_set_trace(shfdtab *pfdtab, int fd) 1974 { 1975 int rc; 1976 #ifdef SHFILE_IN_USE 1977 shmtxtmp tmp; 1978 shfile *file = shfile_get(pfdtab, fd, &tmp); 1979 if (file) 1980 { 1981 file->shflags |= SHFILE_FLAGS_TRACE; 1982 shfile_put(pfdtab, file, &tmp); 1983 rc = 0; 1984 } 1985 else 1986 rc = -1; 1987 #else 1988 rc = 0; 1989 #endif 1990 1991 TRACE2((NULL, "shfile_set_trace(%d) -> %d\n", fd, rc)); 1947 1992 return rc; 1948 1993 } -
trunk/src/kash/shfile.h
r3439 r3444 112 112 */ 113 113 #define SHFILE_FLAGS_CLOSE_ON_EXEC 0x0001 114 #define SHFILE_FLAGS_TRACE 0x0002 /**< The 'trace' file, keep open after execve. */ 114 115 #define SHFILE_FLAGS_TYPE_MASK 0x00f0 115 116 #define SHFILE_FLAGS_FILE 0x0000 … … 154 155 int shfile_isatty(shfdtab *, int); 155 156 int shfile_cloexec(shfdtab *, int, int); 157 int shfile_set_trace(shfdtab *, int); 156 158 int shfile_ioctl(shfdtab *, int, unsigned long, void *); 157 159 #if defined(_MSC_VER) || defined(__OS2__) -
trunk/src/kash/shinstance.c
r3442 r3444 44 44 #include "error.h" 45 45 #include "memalloc.h" 46 #include "redir.h" 46 47 #include "shell.h" 47 48 #include "trap.h" … … 1841 1842 &ProcInfo); 1842 1843 1843 shfile_exec_win(&psh->fdtab, 0 /* done*/, NULL, NULL);1844 shfile_exec_win(&psh->fdtab, rc ? 0 /* done */ : -1 /* done but failed */, NULL, NULL); 1844 1845 #ifndef SH_FORKED_MODE 1845 1846 shmtx_leave(&g_sh_exec_mtx, &tmp); -
trunk/src/kash/show.c
r3438 r3444 522 522 } 523 523 shfile_cloexec(&psh->fdtab, psh->tracefd, 1 /* close it */); 524 shfile_set_trace(&psh->fdtab, psh->tracefd); 524 525 } 525 526 if (psh->tracefd == -1) {
Note:
See TracChangeset
for help on using the changeset viewer.