Changeset 3438 for trunk/src/kash/shinstance.c
- Timestamp:
- Sep 9, 2020, 10:01:39 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/shinstance.c
r3437 r3438 40 40 #include "shinstance.h" 41 41 42 #include "alias.h" 43 #include "memalloc.h" 44 #include "shell.h" 45 #include "trap.h" 46 42 47 #if K_OS == K_OS_WINDOWS 43 48 # include <Windows.h> 49 # ifdef SH_FORKED_MODE 44 50 extern pid_t shfork_do(shinstance *psh); /* shforkA-win.asm */ 51 # endif 45 52 #endif 46 53 … … 174 181 static void sh_destroy(shinstance *psh) 175 182 { 183 /** @todo finish this... */ 176 184 memset(psh, 0, sizeof(*psh)); 177 185 sh_free(NULL, psh); … … 221 229 222 230 /** 223 * Creates a root shell instance. 224 * 225 * @param inherit The shell to inherit from. If NULL inherit from environment and such. 226 * @param argc The argument count. 231 * Creates a shell instance, caller must link it. 232 * 233 * @param inherit The shell to inherit from, or NULL if root. 227 234 * @param argv The argument vector. 228 235 * @param envp The environment vector. 236 * @param parentfdtab File table to inherit from, NULL if root. 229 237 * 230 238 * @returns pointer to root shell on success, NULL on failure. 231 239 */ 232 s hinstance *sh_create_root_shell(shinstance *inherit, int argc, char **argv, char **envp)240 static shinstance *sh_create_shell_common(char **argv, char **envp, shfdtab *parentfdtab) 233 241 { 234 242 shinstance *psh; 235 int i;236 243 237 244 /* … … 241 248 if (psh) 242 249 { 243 /* Init it enough for sh_destroy() to not get upset */244 250 /* Init it enough for sh_destroy() to not get upset: */ 251 /* ... */ 245 252 246 253 /* Call the basic initializers. */ 247 254 if ( !sh_clone_string_vector(psh, &psh->shenviron, envp) 248 && !sh_clone_string_vector(psh, &psh->argptr, argv) 249 && !shfile_init(&psh->fdtab, inherit ? &inherit->fdtab : NULL)) 250 { 251 /* the special stuff. */ 252 #ifdef _MSC_VER 253 psh->pid = _getpid(); 255 && !sh_clone_string_vector(psh, &psh->orgargv, argv) 256 && !shfile_init(&psh->fdtab, parentfdtab)) 257 { 258 unsigned i; 259 260 /* 261 * The special stuff. 262 */ 263 #ifdef _MSC_VER 264 psh->pgid = psh->pid = _getpid(); 254 265 #else 255 266 psh->pid = getpid(); 256 #endif 267 psh->pgid = getpgid(); 268 #endif 269 257 270 /*sh_sigemptyset(&psh->sigrestartset);*/ 258 for (i = 0; i < NSIG; i++)271 for (i = 0; i < K_ELEMENTS(psh->sigactions); i++) 259 272 psh->sigactions[i].sh_handler = SH_SIG_UNK; 260 if (inherit)261 psh->sigmask = psh->sigmask;262 else263 {264 273 #if defined(_MSC_VER) 265 sh_sigemptyset(&psh->sigmask); 266 #else 267 sigprocmask(SIG_SETMASK, NULL, &psh->sigmask); 268 #endif 269 } 274 sh_sigemptyset(&psh->sigmask); 275 #else 276 sigprocmask(SIG_SETMASK, NULL, &psh->sigmask); 277 #endif 278 279 /* 280 * State initialization. 281 */ 282 /* cd.c */ 283 psh->getpwd_first = 1; 284 285 /* exec */ 286 psh->builtinloc = -1; 270 287 271 288 /* memalloc.c */ … … 303 320 /* show.c */ 304 321 psh->tracefd = -1; 305 306 /* link it. */307 sh_int_link(psh);308 322 return psh; 309 323 } … … 313 327 return NULL; 314 328 } 329 330 /** 331 * Creates the root shell instance. 332 * 333 * @param argv The argument vector. 334 * @param envp The environment vector. 335 * 336 * @returns pointer to root shell on success, NULL on failure. 337 */ 338 shinstance *sh_create_root_shell(char **argv, char **envp) 339 { 340 shinstance *psh = sh_create_shell_common(argv, envp, NULL /*parentfdtab*/); 341 if (psh) 342 { 343 sh_int_link(psh); 344 return psh; 345 } 346 return NULL; 347 } 348 349 #ifndef SH_FORKED_MODE 350 351 /** 352 * Does the inherting from the parent shell instance. 353 */ 354 static void sh_inherit_from_parent(shinstance *psh, shinstance *inherit) 355 { 356 /* 357 * Do the rest of the inheriting. 358 */ 359 psh->parent = inherit; 360 psh->pgid = inherit->pgid; 361 362 psh->sigmask = psh->sigmask; 363 /** @todo sigactions? */ 364 /// @todo suppressint? 365 366 /* alises: */ 367 subshellinitalias(psh, inherit); 368 369 /* cd.c */ 370 psh->getpwd_first = inherit->getpwd_first; 371 if (inherit->curdir) 372 psh->curdir = savestr(psh, inherit->curdir); 373 if (inherit->prevdir) 374 psh->prevdir = savestr(psh, inherit->prevdir); 375 376 /* eval.h */ 377 /* psh->commandname - see subshellinitoptions */ 378 psh->exitstatus = inherit->exitstatus; /// @todo ?? 379 psh->back_exitstatus = inherit->back_exitstatus; /// @todo ?? 380 psh->funcnest = inherit->funcnest; 381 psh->evalskip = inherit->evalskip; /// @todo ?? 382 psh->skipcount = inherit->skipcount; /// @todo ?? 383 384 /* exec.c */ 385 subshellinitexec(psh, inherit); 386 387 /* input.h/input.c - only for the parser and anyway forkchild calls closescript(). */ 388 389 /* jobs.h - should backgndpid be -1 in subshells? */ 390 391 /* jobs.c - */ 392 psh->jobctl = inherit->jobctl; /// @todo ?? 393 psh->initialpgrp = inherit->initialpgrp; 394 psh->ttyfd = inherit->ttyfd; 395 /** @todo copy jobtab so the 'jobs' command can be run in a subshell. 396 * Better, make it follow the parent chain and skip the copying. Will 397 * require some kind of job locking. */ 398 399 /* mail.c - nothing (for now at least) */ 400 401 /* main.h */ 402 psh->rootpid = inherit->rootpid; 403 psh->psh_rootshell = inherit->psh_rootshell; 404 405 /* memalloc.h / memalloc.c - nothing. */ 406 407 /* myhistedit.h */ /** @todo copy history? Do we need to care? */ 408 409 /* output.h */ /** @todo not sure this is possible/relevant for subshells */ 410 psh->output.fd = inherit->output.fd; 411 psh->errout.fd = inherit->errout.fd; 412 if (inherit->out1 == &inherit->memout) 413 psh->out1 = &psh->memout; 414 if (inherit->out2 == &inherit->memout) 415 psh->out2 = &psh->memout; 416 417 /* options.h */ 418 subshellinitoptions(psh, inherit); 419 420 /* parse.h/parse.c */ 421 psh->whichprompt = inherit->whichprompt; 422 /* tokpushback, doprompt and needprompt shouldn't really matter, parsecmd resets thems. */ 423 /* The rest are internal to the parser, as I see them, and can be ignored. */ 424 425 /* redir.c - we shouldn't sub-shell with redirlist as non-NULL, I think. */ 426 assert(inherit->redirlist == NULL); 427 assert(inherit->fd0_redirected == 0); /* (follows from redirlist == NULL) */ 428 429 /* show.c */ 430 psh->tracefd = inherit->tracefd; 431 432 /* trap.h / trap.c */ /** @todo we don't carry pendingsigs to the subshell, right? */ 433 subshellinittrap(psh, inherit); 434 435 /* var.h */ 436 subshellinitvar(psh, inherit); 437 } 438 439 /** 440 * Creates a child shell instance. 441 * 442 * @param inherit The shell to inherit from. 443 * 444 * @returns pointer to root shell on success, NULL on failure. 445 */ 446 shinstance *sh_create_child_shell(shinstance *inherit) 447 { 448 shinstance *psh = sh_create_shell_common(inherit->orgargv, inherit->shenviron, &inherit->fdtab); 449 if (psh) 450 { 451 /* Fake a pid for the child: */ 452 static unsigned volatile s_cShells = 0; 453 int const iSubShell = ++s_cShells; 454 psh->pid = SHPID_MAKE(SHPID_GET_PID(inherit->pid), iSubShell); 455 456 sh_inherit_from_parent(psh, inherit); 457 458 /* link it */ 459 sh_int_link(psh); 460 return psh; 461 } 462 return NULL; 463 } 464 465 #endif /* !SH_FORKED_MODE */ 315 466 316 467 /** getenv() */ … … 777 928 } 778 929 779 int sh_kill(shinstance *psh, pid_tpid, int signo)930 int sh_kill(shinstance *psh, shpid pid, int signo) 780 931 { 781 932 shinstance *pshDst; … … 793 944 if (pshDst->pid == pid) 794 945 { 795 TRACE2((psh, "sh_kill(% d, %d): pshDst=%p\n", pid, signo, pshDst));946 TRACE2((psh, "sh_kill(%" SHPID_PRI ", %d): pshDst=%p\n", pid, signo, pshDst)); 796 947 sh_sig_do_signal(psh, pshDst, signo, 1 /* locked */); 797 948 … … 807 958 * Some other process, call kill where possible 808 959 */ 809 #if defined(SH_FORKED_MODE) 810 # ifdef _MSC_VER 960 #ifdef _MSC_VER 811 961 errno = ENOSYS; 812 962 rc = -1; 813 # else963 #elif defined(SH_FORKED_MODE) 814 964 /* fprintf(stderr, "kill(%d, %d)\n", pid, signo);*/ 815 965 rc = kill(pid, signo); 816 # endif 817 818 #else 966 #else 967 # error "PORT ME?" 819 968 #endif 820 969 … … 823 972 } 824 973 825 int sh_killpg(shinstance *psh, pid_t pgid, int signo) 826 { 974 int sh_killpg(shinstance *psh, shpid pgid, int signo) 975 { 976 shinstance *pshDst; 977 shmtxtmp tmp; 827 978 int rc; 828 979 829 #if defined(SH_FORKED_MODE) 830 # ifdef _MSC_VER 980 /* 981 * Self or any of the subshells? 982 */ 983 shmtx_enter(&g_sh_mtx, &tmp); 984 985 pshDst = g_sh_tail; 986 while (pshDst != NULL) 987 { 988 if (pshDst->pgid == pgid) 989 { 990 TRACE2((psh, "sh_killpg(%" SHPID_PRI ", %d): pshDst=%p\n", pgid, signo, pshDst)); 991 sh_sig_do_signal(psh, pshDst, signo, 1 /* locked */); 992 993 shmtx_leave(&g_sh_mtx, &tmp); 994 return 0; 995 } 996 pshDst = pshDst->prev; 997 } 998 999 shmtx_leave(&g_sh_mtx, &tmp); 1000 1001 #ifdef _MSC_VER 831 1002 errno = ENOSYS; 832 1003 rc = -1; 833 # else1004 #elif defined(SH_FORKED_MODE) 834 1005 //fprintf(stderr, "killpg(%d, %d)\n", pgid, signo); 835 1006 rc = killpg(pgid, signo); 836 # endif 837 838 #else 839 #endif 840 841 TRACE2((psh, "sh_killpg(%d, %d) -> %d [%d]\n", pgid, signo, rc, errno)); 1007 #else 1008 # error "PORTME?" 1009 #endif 1010 1011 TRACE2((psh, "sh_killpg(%" SHPID_PRI ", %d) -> %d [%d]\n", pgid, signo, rc, errno)); 842 1012 (void)psh; 843 1013 return rc; … … 846 1016 clock_t sh_times(shinstance *psh, shtms *tmsp) 847 1017 { 848 #if defined(SH_FORKED_MODE) 849 (void)psh; 850 # ifdef _MSC_VER 1018 #ifdef _MSC_VER 851 1019 errno = ENOSYS; 852 1020 return (clock_t)-1; 853 # else 1021 #elif defined(SH_FORKED_MODE) 1022 (void)psh; 854 1023 return times(tmsp); 855 # endif 856 857 #else 1024 #else 1025 # error "PORTME" 858 1026 #endif 859 1027 } … … 873 1041 * @returns 0 on success, on failure -1 and errno set to ENOMEM. 874 1042 * 875 * @param psh The shell instance. 876 * @param pid The child pid. 877 * @param hChild Windows child handle. 1043 * @param psh The shell instance. 1044 * @param pid The child pid. 1045 * @param hChild Windows child handle. 1046 * @param fProcess Set if process, clear if thread. 878 1047 */ 879 int sh_add_child(shinstance *psh, pid_t pid, void *hChild)1048 int sh_add_child(shinstance *psh, shpid pid, void *hChild, KBOOL fProcess) 880 1049 { 881 1050 /* get a free table entry. */ … … 898 1067 psh->children[i].hChild = hChild; 899 1068 #endif 900 (void)hChild; 1069 #ifndef SH_FORKED_MODE 1070 psh->children[i].fProcess = fProcess; 1071 #endif 1072 (void)hChild; (void)fProcess; 901 1073 return 0; 902 1074 } 1075 1076 #ifdef SH_FORKED_MODE 903 1077 904 1078 pid_t sh_fork(shinstance *psh) … … 938 1112 } 939 1113 1114 #else /* !SH_FORKED_MODE */ 1115 1116 # ifdef _MSC_VER 1117 /** Thread wrapper procedure. */ 1118 static unsigned __stdcall sh_thread_wrapper(void *user) 1119 { 1120 shinstance *psh = (shinstance *)user; 1121 int iExit; 1122 1123 /* Update the TID and PID (racing sh_thread_start) */ 1124 DWORD tid = GetCurrentThreadId(); 1125 shpid pid = GetCurrentProcessId(); 1126 1127 pid = SHPID_MAKE(pid, tid); 1128 psh->pid = pid; 1129 psh->tid = tid; 1130 1131 /* Set the TLS entry before we try TRACE or TRACE2. */ 1132 shthread_set_shell(psh); 1133 1134 TRACE2((psh, "sh_thread_wrapper: enter\n")); 1135 iExit = psh->thread(psh, psh->threadarg); 1136 /** @todo do shell cleanup. */ 1137 TRACE2((psh, "sh_thread_wrapper: quits - iExit=%d\n", iExit)); 1138 1139 _endthreadex(iExit); 1140 return iExit; 1141 } 1142 # else 1143 # error "PORTME" 1144 # endif 1145 1146 /** 1147 * Starts a sub-shell thread. 1148 */ 1149 shpid sh_thread_start(shinstance *pshparent, shinstance *pshchild, int (*thread)(shinstance *, void *), void *arg) 1150 { 1151 # ifdef _MSC_VER 1152 unsigned tid = 0; 1153 uintptr_t hThread; 1154 shpid pid; 1155 1156 pshchild->thread = thread; 1157 pshchild->threadarg = arg; 1158 hThread = _beginthreadex(NULL /*security*/, 0 /*stack_size*/, sh_thread_wrapper, pshchild, 0 /*initflags*/, &tid); 1159 if (hThread == -1) 1160 return -errno; 1161 1162 pid = SHPID_MAKE(SHPID_GET_PID(pshparent->pid), tid); 1163 pshchild->pid = pid; 1164 pshchild->tid = tid; 1165 1166 if (sh_add_child(pshparent, pid, (void *)hThread, K_FALSE) != 0) { 1167 return -ENOMEM; 1168 } 1169 return pid; 1170 1171 # else 1172 # error "PORTME" 1173 # endif 1174 } 1175 1176 #endif /* !SH_FORKED_MODE */ 1177 940 1178 /** waitpid() */ 941 pid_t sh_waitpid(shinstance *psh, pid_tpid, int *statusp, int flags)942 { 943 pid_tpidret;1179 shpid sh_waitpid(shinstance *psh, shpid pid, int *statusp, int flags) 1180 { 1181 shpid pidret; 944 1182 #if K_OS == K_OS_WINDOWS //&& defined(SH_FORKED_MODE) 945 1183 DWORD dwRet; … … 1015 1253 { 1016 1254 DWORD dwExitCode = 127; 1255 #ifndef SH_FORKED_MODE 1256 if (psh->children[i].fProcess ? GetExitCodeProcess(hChild, &dwExitCode) : GetExitCodeThread(hChild, &dwExitCode)) 1257 #else 1017 1258 if (GetExitCodeProcess(hChild, &dwExitCode)) 1259 #endif 1018 1260 { 1019 1261 pidret = psh->children[i].pid; … … 1046 1288 #endif 1047 1289 1048 TRACE2((psh, "waitpid(% d, %p, %#x) -> %d[%d] *statusp=%#x (rc=%d)\n", pid, statusp, flags,1290 TRACE2((psh, "waitpid(%" SHPID_PRI ", %p, %#x) -> %" SHPID_PRI " [%d] *statusp=%#x (rc=%d)\n", pid, statusp, flags, 1049 1291 pidret, errno, *statusp, WEXITSTATUS(*statusp))); 1050 1292 (void)psh; … … 1282 1524 uid_t sh_getuid(shinstance *psh) 1283 1525 { 1284 #if defined(SH_FORKED_MODE) 1285 # ifdef _MSC_VER 1526 #ifdef _MSC_VER 1286 1527 uid_t uid = 0; 1287 # 1528 #else 1288 1529 uid_t uid = getuid(); 1289 # endif1290 1291 #else1292 1530 #endif 1293 1531 … … 1299 1537 uid_t sh_geteuid(shinstance *psh) 1300 1538 { 1301 #if defined(SH_FORKED_MODE) 1302 # ifdef _MSC_VER 1539 #ifdef _MSC_VER 1303 1540 uid_t euid = 0; 1304 # 1541 #else 1305 1542 uid_t euid = geteuid(); 1306 # endif1307 1308 #else1309 1543 #endif 1310 1544 … … 1316 1550 gid_t sh_getgid(shinstance *psh) 1317 1551 { 1318 #if defined(SH_FORKED_MODE) 1319 # ifdef _MSC_VER 1552 #ifdef _MSC_VER 1320 1553 gid_t gid = 0; 1321 # 1554 #else 1322 1555 gid_t gid = getgid(); 1323 # endif1324 1325 #else1326 1556 #endif 1327 1557 … … 1333 1563 gid_t sh_getegid(shinstance *psh) 1334 1564 { 1335 #if defined(SH_FORKED_MODE) 1336 # ifdef _MSC_VER 1565 #ifdef _MSC_VER 1337 1566 gid_t egid = 0; 1338 # 1567 #else 1339 1568 gid_t egid = getegid(); 1340 # endif1341 1342 #else1343 1569 #endif 1344 1570 … … 1348 1574 } 1349 1575 1350 pid_t sh_getpid(shinstance *psh) 1351 { 1352 pid_t pid; 1353 1354 #if defined(SH_FORKED_MODE) 1355 # ifdef _MSC_VER 1356 pid = _getpid(); 1357 # else 1358 pid = getpid(); 1359 # endif 1360 #else 1361 #endif 1362 1576 shpid sh_getpid(shinstance *psh) 1577 { 1578 return psh->pid; 1579 } 1580 1581 shpid sh_getpgrp(shinstance *psh) 1582 { 1583 shpid pgid = psh->pgid; 1584 #ifndef _MSC_VER 1585 assert(pgid == getpgrp()); 1586 #endif 1587 1588 TRACE2((psh, "sh_getpgrp() -> %" SHPID_PRI " [%d]\n", pgid, errno)); 1589 return pgid; 1590 } 1591 1592 /** 1593 * @param pid Should always be zero, i.e. referring to the current shell 1594 * process. 1595 */ 1596 shpid sh_getpgid(shinstance *psh, shpid pid) 1597 { 1598 shpid pgid; 1599 if (pid == 0 || psh->pid == pid) 1600 { 1601 shpid pgid = psh->pgid; 1602 #ifndef _MSC_VER 1603 assert(pgid == getpgrp()); 1604 #endif 1605 } 1606 else 1607 { 1608 assert(0); 1609 errno = ESRCH; 1610 pgid = -1; 1611 } 1612 1613 TRACE2((psh, "sh_getpgid(%" SHPID_PRI ") -> %" SHPID_PRI " [%d]\n", pid, pgid, errno)); 1614 return pgid; 1615 } 1616 1617 /** 1618 * 1619 * @param pid The pid to modify. This is always 0, except when forkparent 1620 * calls to group a newly created child. Though, we might 1621 * almost safely ignore it in that case as the child will also 1622 * perform the operation. 1623 * @param pgid The process group to assign @a pid to. 1624 */ 1625 int sh_setpgid(shinstance *psh, shpid pid, shpid pgid) 1626 { 1627 #if defined(SH_FORKED_MODE) && !defined(_MSC_VER) 1628 int rc = setpgid(pid, pgid); 1629 TRACE2((psh, "sh_setpgid(%" SHPID_PRI ", %" SHPID_PRI ") -> %d [%d]\n", pid, pgid, rc, errno)); 1363 1630 (void)psh; 1364 return pid; 1365 } 1366 1367 pid_t sh_getpgrp(shinstance *psh) 1368 { 1369 #if defined(SH_FORKED_MODE) 1370 # ifdef _MSC_VER 1371 pid_t pgrp = _getpid(); 1372 # else 1373 pid_t pgrp = getpgrp(); 1374 # endif 1375 1376 #else 1377 #endif 1378 1379 TRACE2((psh, "sh_getpgrp() -> %d [%d]\n", pgrp, errno)); 1631 #else 1632 int rc = 0; 1633 if (pid == 0 || psh->pid == pid) 1634 { 1635 TRACE2((psh, "sh_setpgid(self,): %" SHPID_PRI " -> %" SHPID_PRI "\n", psh->pgid, pgid)); 1636 psh->pgid = pgid; 1637 } 1638 else 1639 { 1640 /** @todo fixme */ 1641 rc = -1; 1642 errno = ENOSYS; 1643 } 1644 #endif 1645 return rc; 1646 } 1647 1648 shpid sh_tcgetpgrp(shinstance *psh, int fd) 1649 { 1650 shpid pgrp; 1651 1652 #ifdef _MSC_VER 1653 pgrp = -1; 1654 errno = ENOSYS; 1655 #elif defined(SH_FORKED_MODE) 1656 pgrp = tcgetpgrp(fd); 1657 #else 1658 # error "PORT ME" 1659 #endif 1660 1661 TRACE2((psh, "sh_tcgetpgrp(%d) -> %" SHPID_PRI " [%d]\n", fd, pgrp, errno)); 1380 1662 (void)psh; 1381 1663 return pgrp; 1382 1664 } 1383 1665 1384 pid_t sh_getpgid(shinstance *psh, pid_t pid) 1385 { 1386 #if defined(SH_FORKED_MODE) 1387 # ifdef _MSC_VER 1388 pid_t pgid = pid; 1389 # else 1390 pid_t pgid = getpgid(pid); 1391 # endif 1392 1393 #else 1394 #endif 1395 1396 TRACE2((psh, "sh_getpgid(%d) -> %d [%d]\n", pid, pgid, errno)); 1666 int sh_tcsetpgrp(shinstance *psh, int fd, shpid pgrp) 1667 { 1668 int rc; 1669 TRACE2((psh, "sh_tcsetpgrp(%d, %" SHPID_PRI ")\n", fd, pgrp)); 1670 1671 #ifdef _MSC_VER 1672 rc = -1; 1673 errno = ENOSYS; 1674 #elif defined(SH_FORKED_MODE) 1675 rc = tcsetpgrp(fd, pgrp); 1676 #else 1677 # error "PORT ME" 1678 #endif 1679 1680 TRACE2((psh, "sh_tcsetpgrp(%d, %" SHPID_PRI ") -> %d [%d]\n", fd, pgrp, rc, errno)); 1397 1681 (void)psh; 1398 return pgid; 1399 } 1400 1401 int sh_setpgid(shinstance *psh, pid_t pid, pid_t pgid) 1402 { 1403 #if defined(SH_FORKED_MODE) 1404 # ifdef _MSC_VER 1682 return rc; 1683 } 1684 1685 int sh_getrlimit(shinstance *psh, int resid, shrlimit *limp) 1686 { 1687 #ifdef _MSC_VER 1405 1688 int rc = -1; 1406 1689 errno = ENOSYS; 1407 # else 1408 int rc = setpgid(pid, pgid); 1409 # endif 1410 1411 #else 1412 #endif 1413 1414 TRACE2((psh, "sh_setpgid(%d, %d) -> %d [%d]\n", pid, pgid, rc, errno)); 1415 (void)psh; 1416 return rc; 1417 } 1418 1419 pid_t sh_tcgetpgrp(shinstance *psh, int fd) 1420 { 1421 pid_t pgrp; 1422 1423 #if defined(SH_FORKED_MODE) 1424 # ifdef _MSC_VER 1425 pgrp = -1; 1426 errno = ENOSYS; 1427 # else 1428 pgrp = tcgetpgrp(fd); 1429 # endif 1430 1431 #else 1432 #endif 1433 1434 TRACE2((psh, "sh_tcgetpgrp(%d) -> %d [%d]\n", fd, pgrp, errno)); 1435 (void)psh; 1436 return pgrp; 1437 } 1438 1439 int sh_tcsetpgrp(shinstance *psh, int fd, pid_t pgrp) 1440 { 1441 int rc; 1442 TRACE2((psh, "sh_tcsetpgrp(%d, %d)\n", fd, pgrp)); 1443 1444 #if defined(SH_FORKED_MODE) 1445 # ifdef _MSC_VER 1446 rc = -1; 1447 errno = ENOSYS; 1448 # else 1449 rc = tcsetpgrp(fd, pgrp); 1450 # endif 1451 1452 #else 1453 #endif 1454 1455 TRACE2((psh, "sh_tcsetpgrp(%d, %d) -> %d [%d]\n", fd, pgrp, rc, errno)); 1456 (void)psh; 1457 return rc; 1458 } 1459 1460 int sh_getrlimit(shinstance *psh, int resid, shrlimit *limp) 1461 { 1462 #if defined(SH_FORKED_MODE) 1463 # ifdef _MSC_VER 1464 int rc = -1; 1465 errno = ENOSYS; 1466 # else 1690 #elif defined(SH_FORKED_MODE) 1467 1691 int rc = getrlimit(resid, limp); 1468 # endif 1469 1470 #else 1692 #else 1693 # error "PORT ME" 1471 1694 /* returned the stored limit */ 1472 1695 #endif … … 1480 1703 int sh_setrlimit(shinstance *psh, int resid, const shrlimit *limp) 1481 1704 { 1482 #if defined(SH_FORKED_MODE) 1483 # ifdef _MSC_VER 1705 #ifdef _MSC_VER 1484 1706 int rc = -1; 1485 1707 errno = ENOSYS; 1486 # else1708 #elif defined(SH_FORKED_MODE) 1487 1709 int rc = setrlimit(resid, limp); 1488 # endif 1489 1490 #else 1710 #else 1711 # error "PORT ME" 1491 1712 /* if max(shell) < limp; then setrlimit; fi 1492 1713 if success; then store limit for later retrival and maxing. */
Note:
See TracChangeset
for help on using the changeset viewer.