Ignore:
Timestamp:
Sep 9, 2020, 10:01:39 PM (5 years ago)
Author:
bird
Message:

kash: Hammering on threaded mode.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/shinstance.c

    r3437 r3438  
    4040#include "shinstance.h"
    4141
     42#include "alias.h"
     43#include "memalloc.h"
     44#include "shell.h"
     45#include "trap.h"
     46
    4247#if K_OS == K_OS_WINDOWS
    4348# include <Windows.h>
     49# ifdef SH_FORKED_MODE
    4450extern pid_t shfork_do(shinstance *psh); /* shforkA-win.asm */
     51# endif
    4552#endif
    4653
     
    174181static void sh_destroy(shinstance *psh)
    175182{
     183/** @todo finish this...   */
    176184    memset(psh, 0, sizeof(*psh));
    177185    sh_free(NULL, psh);
     
    221229
    222230/**
    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.
    227234 * @param   argv        The argument vector.
    228235 * @param   envp        The environment vector.
     236 * @param   parentfdtab File table to inherit from, NULL if root.
    229237 *
    230238 * @returns pointer to root shell on success, NULL on failure.
    231239 */
    232 shinstance *sh_create_root_shell(shinstance *inherit, int argc, char **argv, char **envp)
     240static shinstance *sh_create_shell_common(char **argv, char **envp, shfdtab *parentfdtab)
    233241{
    234242    shinstance *psh;
    235     int i;
    236243
    237244    /*
     
    241248    if (psh)
    242249    {
    243         /* Init it enough for sh_destroy() to not get upset */
    244           /* ... */
     250        /* Init it enough for sh_destroy() to not get upset: */
     251        /* ... */
    245252
    246253        /* Call the basic initializers. */
    247254        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();
    254265#else
    255266            psh->pid = getpid();
    256 #endif
     267            psh->pgid = getpgid();
     268#endif
     269
    257270            /*sh_sigemptyset(&psh->sigrestartset);*/
    258             for (i = 0; i < NSIG; i++)
     271            for (i = 0; i < K_ELEMENTS(psh->sigactions); i++)
    259272                psh->sigactions[i].sh_handler = SH_SIG_UNK;
    260             if (inherit)
    261                 psh->sigmask = psh->sigmask;
    262             else
    263             {
    264273#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;
    270287
    271288            /* memalloc.c */
     
    303320            /* show.c */
    304321            psh->tracefd = -1;
    305 
    306             /* link it. */
    307             sh_int_link(psh);
    308322            return psh;
    309323        }
     
    313327    return NULL;
    314328}
     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 */
     338shinstance *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 */
     354static 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 */
     446shinstance *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 */
    315466
    316467/** getenv() */
     
    777928}
    778929
    779 int sh_kill(shinstance *psh, pid_t pid, int signo)
     930int sh_kill(shinstance *psh, shpid pid, int signo)
    780931{
    781932    shinstance *pshDst;
     
    793944        if (pshDst->pid == pid)
    794945        {
    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));
    796947            sh_sig_do_signal(psh, pshDst, signo, 1 /* locked */);
    797948
     
    807958     * Some other process, call kill where possible
    808959     */
    809 #if defined(SH_FORKED_MODE)
    810 # ifdef _MSC_VER
     960#ifdef _MSC_VER
    811961    errno = ENOSYS;
    812962    rc = -1;
    813 # else
     963#elif defined(SH_FORKED_MODE)
    814964/*    fprintf(stderr, "kill(%d, %d)\n", pid, signo);*/
    815965    rc = kill(pid, signo);
    816 # endif
    817 
    818 #else
     966#else
     967# error "PORT ME?"
    819968#endif
    820969
     
    823972}
    824973
    825 int sh_killpg(shinstance *psh, pid_t pgid, int signo)
    826 {
     974int sh_killpg(shinstance *psh, shpid pgid, int signo)
     975{
     976    shinstance *pshDst;
     977    shmtxtmp tmp;
    827978    int rc;
    828979
    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
    8311002    errno = ENOSYS;
    8321003    rc = -1;
    833 # else
     1004#elif defined(SH_FORKED_MODE)
    8341005    //fprintf(stderr, "killpg(%d, %d)\n", pgid, signo);
    8351006    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));
    8421012    (void)psh;
    8431013    return rc;
     
    8461016clock_t sh_times(shinstance *psh, shtms *tmsp)
    8471017{
    848 #if defined(SH_FORKED_MODE)
    849     (void)psh;
    850 # ifdef _MSC_VER
     1018#ifdef _MSC_VER
    8511019    errno = ENOSYS;
    8521020    return (clock_t)-1;
    853 # else
     1021#elif defined(SH_FORKED_MODE)
     1022    (void)psh;
    8541023    return times(tmsp);
    855 # endif
    856 
    857 #else
     1024#else
     1025# error "PORTME"
    8581026#endif
    8591027}
     
    8731041 * @returns 0 on success, on failure -1 and errno set to ENOMEM.
    8741042 *
    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.
    8781047 */
    879 int sh_add_child(shinstance *psh, pid_t pid, void *hChild)
     1048int sh_add_child(shinstance *psh, shpid pid, void *hChild, KBOOL fProcess)
    8801049{
    8811050    /* get a free table entry. */
     
    8981067    psh->children[i].hChild = hChild;
    8991068#endif
    900     (void)hChild;
     1069#ifndef SH_FORKED_MODE
     1070    psh->children[i].fProcess = fProcess;
     1071#endif
     1072    (void)hChild; (void)fProcess;
    9011073    return 0;
    9021074}
     1075
     1076#ifdef SH_FORKED_MODE
    9031077
    9041078pid_t sh_fork(shinstance *psh)
     
    9381112}
    9391113
     1114#else  /* !SH_FORKED_MODE */
     1115
     1116# ifdef _MSC_VER
     1117/** Thread wrapper procedure. */
     1118static 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 */
     1149shpid 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
    9401178/** waitpid() */
    941 pid_t sh_waitpid(shinstance *psh, pid_t pid, int *statusp, int flags)
    942 {
    943     pid_t pidret;
     1179shpid sh_waitpid(shinstance *psh, shpid pid, int *statusp, int flags)
     1180{
     1181    shpid  pidret;
    9441182#if K_OS == K_OS_WINDOWS //&& defined(SH_FORKED_MODE)
    9451183    DWORD   dwRet;
     
    10151253        {
    10161254            DWORD dwExitCode = 127;
     1255#ifndef SH_FORKED_MODE
     1256            if (psh->children[i].fProcess ? GetExitCodeProcess(hChild, &dwExitCode) : GetExitCodeThread(hChild, &dwExitCode))
     1257#else
    10171258            if (GetExitCodeProcess(hChild, &dwExitCode))
     1259#endif
    10181260            {
    10191261                pidret = psh->children[i].pid;
     
    10461288#endif
    10471289
    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,
    10491291            pidret, errno, *statusp, WEXITSTATUS(*statusp)));
    10501292    (void)psh;
     
    12821524uid_t sh_getuid(shinstance *psh)
    12831525{
    1284 #if defined(SH_FORKED_MODE)
    1285 # ifdef _MSC_VER
     1526#ifdef _MSC_VER
    12861527    uid_t uid = 0;
    1287 # else
     1528#else
    12881529    uid_t uid = getuid();
    1289 # endif
    1290 
    1291 #else
    12921530#endif
    12931531
     
    12991537uid_t sh_geteuid(shinstance *psh)
    13001538{
    1301 #if defined(SH_FORKED_MODE)
    1302 # ifdef _MSC_VER
     1539#ifdef _MSC_VER
    13031540    uid_t euid = 0;
    1304 # else
     1541#else
    13051542    uid_t euid = geteuid();
    1306 # endif
    1307 
    1308 #else
    13091543#endif
    13101544
     
    13161550gid_t sh_getgid(shinstance *psh)
    13171551{
    1318 #if defined(SH_FORKED_MODE)
    1319 # ifdef _MSC_VER
     1552#ifdef _MSC_VER
    13201553    gid_t gid = 0;
    1321 # else
     1554#else
    13221555    gid_t gid = getgid();
    1323 # endif
    1324 
    1325 #else
    13261556#endif
    13271557
     
    13331563gid_t sh_getegid(shinstance *psh)
    13341564{
    1335 #if defined(SH_FORKED_MODE)
    1336 # ifdef _MSC_VER
     1565#ifdef _MSC_VER
    13371566    gid_t egid = 0;
    1338 # else
     1567#else
    13391568    gid_t egid = getegid();
    1340 # endif
    1341 
    1342 #else
    13431569#endif
    13441570
     
    13481574}
    13491575
    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 
     1576shpid sh_getpid(shinstance *psh)
     1577{
     1578    return psh->pid;
     1579}
     1580
     1581shpid 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 */
     1596shpid 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 */
     1625int 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));
    13631630    (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
     1648shpid 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));
    13801662    (void)psh;
    13811663    return pgrp;
    13821664}
    13831665
    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));
     1666int 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));
    13971681    (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
     1685int sh_getrlimit(shinstance *psh, int resid, shrlimit *limp)
     1686{
     1687#ifdef _MSC_VER
    14051688    int rc = -1;
    14061689    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)
    14671691    int rc = getrlimit(resid, limp);
    1468 # endif
    1469 
    1470 #else
     1692#else
     1693# error "PORT ME"
    14711694    /* returned the stored limit */
    14721695#endif
     
    14801703int sh_setrlimit(shinstance *psh, int resid, const shrlimit *limp)
    14811704{
    1482 #if defined(SH_FORKED_MODE)
    1483 # ifdef _MSC_VER
     1705#ifdef _MSC_VER
    14841706    int rc = -1;
    14851707    errno = ENOSYS;
    1486 # else
     1708#elif defined(SH_FORKED_MODE)
    14871709    int rc = setrlimit(resid, limp);
    1488 # endif
    1489 
    1490 #else
     1710#else
     1711# error "PORT ME"
    14911712    /* if max(shell) < limp; then setrlimit; fi
    14921713       if success; then store limit for later retrival and maxing. */
Note: See TracChangeset for help on using the changeset viewer.