head 1.7; access; symbols pkgsrc-2026Q1:1.7.0.126 pkgsrc-2026Q1-base:1.7 pkgsrc-2025Q4:1.7.0.124 pkgsrc-2025Q4-base:1.7 pkgsrc-2025Q3:1.7.0.122 pkgsrc-2025Q3-base:1.7 pkgsrc-2025Q2:1.7.0.120 pkgsrc-2025Q2-base:1.7 pkgsrc-2025Q1:1.7.0.118 pkgsrc-2025Q1-base:1.7 pkgsrc-2024Q4:1.7.0.116 pkgsrc-2024Q4-base:1.7 pkgsrc-2024Q3:1.7.0.114 pkgsrc-2024Q3-base:1.7 pkgsrc-2024Q2:1.7.0.112 pkgsrc-2024Q2-base:1.7 pkgsrc-2024Q1:1.7.0.110 pkgsrc-2024Q1-base:1.7 pkgsrc-2023Q4:1.7.0.108 pkgsrc-2023Q4-base:1.7 pkgsrc-2023Q3:1.7.0.106 pkgsrc-2023Q3-base:1.7 pkgsrc-2023Q2:1.7.0.104 pkgsrc-2023Q2-base:1.7 pkgsrc-2023Q1:1.7.0.102 pkgsrc-2023Q1-base:1.7 pkgsrc-2022Q4:1.7.0.100 pkgsrc-2022Q4-base:1.7 pkgsrc-2022Q3:1.7.0.98 pkgsrc-2022Q3-base:1.7 pkgsrc-2022Q2:1.7.0.96 pkgsrc-2022Q2-base:1.7 pkgsrc-2022Q1:1.7.0.94 pkgsrc-2022Q1-base:1.7 pkgsrc-2021Q4:1.7.0.92 pkgsrc-2021Q4-base:1.7 pkgsrc-2021Q3:1.7.0.90 pkgsrc-2021Q3-base:1.7 pkgsrc-2021Q2:1.7.0.88 pkgsrc-2021Q2-base:1.7 pkgsrc-2021Q1:1.7.0.86 pkgsrc-2021Q1-base:1.7 pkgsrc-2020Q4:1.7.0.84 pkgsrc-2020Q4-base:1.7 pkgsrc-2020Q3:1.7.0.82 pkgsrc-2020Q3-base:1.7 pkgsrc-2020Q2:1.7.0.78 pkgsrc-2020Q2-base:1.7 pkgsrc-2020Q1:1.7.0.58 pkgsrc-2020Q1-base:1.7 pkgsrc-2019Q4:1.7.0.80 pkgsrc-2019Q4-base:1.7 pkgsrc-2019Q3:1.7.0.76 pkgsrc-2019Q3-base:1.7 pkgsrc-2019Q2:1.7.0.74 pkgsrc-2019Q2-base:1.7 pkgsrc-2019Q1:1.7.0.72 pkgsrc-2019Q1-base:1.7 pkgsrc-2018Q4:1.7.0.70 pkgsrc-2018Q4-base:1.7 pkgsrc-2018Q3:1.7.0.68 pkgsrc-2018Q3-base:1.7 pkgsrc-2018Q2:1.7.0.66 pkgsrc-2018Q2-base:1.7 pkgsrc-2018Q1:1.7.0.64 pkgsrc-2018Q1-base:1.7 pkgsrc-2017Q4:1.7.0.62 pkgsrc-2017Q4-base:1.7 pkgsrc-2017Q3:1.7.0.60 pkgsrc-2017Q3-base:1.7 pkgsrc-2017Q2:1.7.0.56 pkgsrc-2017Q2-base:1.7 pkgsrc-2017Q1:1.7.0.54 pkgsrc-2017Q1-base:1.7 pkgsrc-2016Q4:1.7.0.52 pkgsrc-2016Q4-base:1.7 pkgsrc-2016Q3:1.7.0.50 pkgsrc-2016Q3-base:1.7 pkgsrc-2016Q2:1.7.0.48 pkgsrc-2016Q2-base:1.7 pkgsrc-2016Q1:1.7.0.46 pkgsrc-2016Q1-base:1.7 pkgsrc-2015Q4:1.7.0.44 pkgsrc-2015Q4-base:1.7 pkgsrc-2015Q3:1.7.0.42 pkgsrc-2015Q3-base:1.7 pkgsrc-2015Q2:1.7.0.40 pkgsrc-2015Q2-base:1.7 pkgsrc-2015Q1:1.7.0.38 pkgsrc-2015Q1-base:1.7 pkgsrc-2014Q4:1.7.0.36 pkgsrc-2014Q4-base:1.7 pkgsrc-2014Q3:1.7.0.34 pkgsrc-2014Q3-base:1.7 pkgsrc-2014Q2:1.7.0.32 pkgsrc-2014Q2-base:1.7 pkgsrc-2014Q1:1.7.0.30 pkgsrc-2014Q1-base:1.7 pkgsrc-2013Q4:1.7.0.28 pkgsrc-2013Q4-base:1.7 pkgsrc-2013Q3:1.7.0.26 pkgsrc-2013Q3-base:1.7 pkgsrc-2013Q2:1.7.0.24 pkgsrc-2013Q2-base:1.7 pkgsrc-2013Q1:1.7.0.22 pkgsrc-2013Q1-base:1.7 pkgsrc-2012Q4:1.7.0.20 pkgsrc-2012Q4-base:1.7 pkgsrc-2012Q3:1.7.0.18 pkgsrc-2012Q3-base:1.7 pkgsrc-2012Q2:1.7.0.16 pkgsrc-2012Q2-base:1.7 pkgsrc-2012Q1:1.7.0.14 pkgsrc-2012Q1-base:1.7 pkgsrc-2011Q4:1.7.0.12 pkgsrc-2011Q4-base:1.7 pkgsrc-2011Q3:1.7.0.10 pkgsrc-2011Q3-base:1.7 pkgsrc-2011Q2:1.7.0.8 pkgsrc-2011Q2-base:1.7 pkgsrc-2011Q1:1.7.0.6 pkgsrc-2011Q1-base:1.7 pkgsrc-2010Q4:1.7.0.4 pkgsrc-2010Q4-base:1.7 pkgsrc-2010Q3:1.7.0.2 pkgsrc-2010Q3-base:1.7 pkgsrc-2010Q2:1.6.0.32 pkgsrc-2010Q2-base:1.6 pkgsrc-2010Q1:1.6.0.30 pkgsrc-2010Q1-base:1.6 pkgsrc-2009Q4:1.6.0.28 pkgsrc-2009Q4-base:1.6 pkgsrc-2009Q3:1.6.0.26 pkgsrc-2009Q3-base:1.6 pkgsrc-2009Q2:1.6.0.24 pkgsrc-2009Q2-base:1.6 pkgsrc-2009Q1:1.6.0.22 pkgsrc-2009Q1-base:1.6 pkgsrc-2008Q4:1.6.0.20 pkgsrc-2008Q4-base:1.6 pkgsrc-2008Q3:1.6.0.18 pkgsrc-2008Q3-base:1.6 cube-native-xorg:1.6.0.16 cube-native-xorg-base:1.6 pkgsrc-2008Q2:1.6.0.14 pkgsrc-2008Q2-base:1.6 cwrapper:1.6.0.12 pkgsrc-2008Q1:1.6.0.10 pkgsrc-2008Q1-base:1.6 pkgsrc-2007Q4:1.6.0.8 pkgsrc-2007Q4-base:1.6 pkgsrc-2007Q3:1.6.0.6 pkgsrc-2007Q3-base:1.6 pkgsrc-2007Q2:1.6.0.4 pkgsrc-2007Q2-base:1.6 pkgsrc-2007Q1:1.6.0.2 pkgsrc-2007Q1-base:1.6 pkgsrc-2006Q4:1.5.0.26 pkgsrc-2006Q4-base:1.5 pkgsrc-2006Q3:1.5.0.24 pkgsrc-2006Q3-base:1.5 pkgsrc-2006Q2:1.5.0.22 pkgsrc-2006Q2-base:1.5 pkgsrc-2006Q1:1.5.0.20 pkgsrc-2006Q1-base:1.5 pkgsrc-2005Q4:1.5.0.18 pkgsrc-2005Q4-base:1.5 pkgsrc-2005Q3:1.5.0.16 pkgsrc-2005Q3-base:1.5 pkgsrc-2005Q2:1.5.0.14 pkgsrc-2005Q2-base:1.5 pkgsrc-2005Q1:1.5.0.12 pkgsrc-2005Q1-base:1.5 pkgsrc-2004Q4:1.5.0.10 pkgsrc-2004Q4-base:1.5 pkgsrc-2004Q3:1.5.0.8 pkgsrc-2004Q3-base:1.5 pkgsrc-2004Q2:1.5.0.6 pkgsrc-2004Q2-base:1.5 pkgsrc-2004Q1:1.5.0.4 pkgsrc-2004Q1-base:1.5 pkgsrc-2003Q4:1.5.0.2 pkgsrc-2003Q4-base:1.5 netbsd-1-6-1:1.4.0.2 netbsd-1-6-1-base:1.4 netbsd-1-6:1.1.0.8 netbsd-1-6-RELEASE-base:1.1 pkgviews:1.1.0.4 pkgviews-base:1.1 buildlink2:1.1.0.2 buildlink2-base:1.1 netbsd-1-5-PATCH003:1.1; locks; strict; comment @# @; 1.7 date 2010.08.06.19.21.27; author drochner; state Exp; branches; next 1.6; 1.6 date 2007.02.18.11.40.10; author wiz; state Exp; branches; next 1.5; 1.5 date 2003.05.02.11.49.48; author wiz; state Exp; branches; next 1.4; 1.4 date 2002.11.26.21.42.49; author skrll; state Exp; branches; next 1.3; 1.3 date 2002.10.23.10.04.16; author drochner; state Exp; branches; next 1.2; 1.2 date 2002.10.14.11.49.55; author skrll; state Exp; branches; next 1.1; 1.1 date 2001.05.14.20.21.19; author skrll; state Exp; branches; next ; desc @@ 1.7 log @deal with connect(2) returning EINPROGRESS/EALREADY/EISCONN on non-blocking sockets (allowed by POSIX, but apparently not done usually on other OSes) bump PKGREVISION @ text @$NetBSD$ --- pth_high.c.orig 2006-06-08 17:54:03.000000000 +0000 +++ pth_high.c @@@@ -184,6 +184,35 @@@@ int pth_sigwait_ev(const sigset_t *set, return 0; } +#ifdef HAVE_SYS_RESOURCE_H +/* Pth variant of wait4(2) */ +pid_t pth_wait4(pid_t wpid, int *status, int options, struct rusage *rusage) +{ + pth_event_t ev; + static pth_key_t ev_key = PTH_KEY_INIT; + pid_t pid; + + pth_debug2("pth_wait4: called from thread \"%s\"", pth_current->name); + + for (;;) { + /* do a non-blocking poll for the pid */ + while ( (pid = pth_sc(wait4)(wpid, status, options|WNOHANG, rusage)) < 0 + && errno == EINTR) ; + + /* if pid was found or caller requested a polling return immediately */ + if (pid == -1 || pid > 0 || (pid == 0 && (options & WNOHANG))) + break; + + /* else wait a little bit */ + ev = pth_event(PTH_EVENT_TIME|PTH_MODE_STATIC, &ev_key, pth_timeout(0,250000)); + pth_wait(ev); + } + + pth_debug2("pth_wait4: leave to thread \"%s\"", pth_current->name); + return pid; +} +#endif + /* Pth variant of waitpid(2) */ pid_t pth_waitpid(pid_t wpid, int *status, int options) { @@@@ -334,9 +363,9 @@@@ int pth_select_ev(int nfd, fd_set *rfds, } } /* POSIX.1-2001/SUSv3 compliance */ - if (rfds != NULL) FD_ZERO(rfds); - if (wfds != NULL) FD_ZERO(wfds); - if (efds != NULL) FD_ZERO(efds); + if (rfds != NULL) pth_util_fd_zero(nfd, rfds); + if (wfds != NULL) pth_util_fd_zero(nfd, wfds); + if (efds != NULL) pth_util_fd_zero(nfd, efds); return 0; } @@@@ -349,17 +378,17 @@@@ int pth_select_ev(int nfd, fd_set *rfds, delay.tv_usec = 0; rtmp = NULL; if (rfds != NULL) { - memcpy(&rspare, rfds, sizeof(fd_set)); + pth_util_fd_copy(nfd, &rspare, rfds); rtmp = &rspare; } wtmp = NULL; if (wfds != NULL) { - memcpy(&wspare, wfds, sizeof(fd_set)); + pth_util_fd_copy(nfd, &wspare, wfds); wtmp = &wspare; } etmp = NULL; if (efds != NULL) { - memcpy(&espare, efds, sizeof(fd_set)); + pth_util_fd_copy(nfd, &espare, efds); etmp = &espare; } while ((rc = pth_sc(select)(nfd, rtmp, wtmp, etmp, &delay)) < 0 @@@@ -374,11 +403,11 @@@@ int pth_select_ev(int nfd, fd_set *rfds, && pth_time_cmp(timeout, PTH_TIME_ZERO) == 0)) { /* pass-through immediate success */ if (rfds != NULL) - memcpy(rfds, &rspare, sizeof(fd_set)); + pth_util_fd_copy(nfd, rfds, &rspare); if (wfds != NULL) - memcpy(wfds, &wspare, sizeof(fd_set)); + pth_util_fd_copy(nfd, wfds, &wspare); if (efds != NULL) - memcpy(efds, &espare, sizeof(fd_set)); + pth_util_fd_copy(nfd, efds, &espare); return rc; } @@@@ -411,9 +440,9 @@@@ int pth_select_ev(int nfd, fd_set *rfds, && pth_event_status(ev_timeout) == PTH_STATUS_OCCURRED) { selected = TRUE; /* POSIX.1-2001/SUSv3 compliance */ - if (rfds != NULL) FD_ZERO(rfds); - if (wfds != NULL) FD_ZERO(wfds); - if (efds != NULL) FD_ZERO(efds); + if (rfds != NULL) pth_util_fd_zero(nfd, rfds); + if (wfds != NULL) pth_util_fd_zero(nfd, wfds); + if (efds != NULL) pth_util_fd_zero(nfd, efds); rc = 0; } if (ev_extra != NULL && !selected) @@@@ -601,6 +630,7 @@@@ int pth_connect_ev(int s, const struct s int rv, err; socklen_t errlen; int fdmode; + int notfirsttry = 0; pth_implicit_init(); pth_debug2("pth_connect_ev: enter from thread \"%s\"", pth_current->name); @@@@ -615,8 +645,11 @@@@ int pth_connect_ev(int s, const struct s /* try to connect */ while ( (rv = pth_sc(connect)(s, (struct sockaddr *)addr, addrlen)) == -1 - && errno == EINTR) + && (errno == EINTR || errno == EINPROGRESS || errno == EALREADY)) + notfirsttry = 1; ; + if (rv == -1 && errno == EISCONN && notfirsttry) + rv = 0; /* restore filedescriptor mode */ pth_shield { pth_fdmode(s, fdmode); } @@@@ -624,6 +657,13 @@@@ int pth_connect_ev(int s, const struct s /* if it is still on progress wait until socket is really writeable */ if (rv == -1 && errno == EINPROGRESS && fdmode != PTH_FDMODE_NONBLOCK) { if ((ev = pth_event(PTH_EVENT_FD|PTH_UNTIL_FD_WRITEABLE|PTH_MODE_STATIC, &ev_key, s)) == NULL) + /* + * This will fail if the fd is > FD_SETSIZE so pass the error back to the + * caller. + */ + if (ev == NULL) { + return pth_error(-1, errno); + } return pth_error(-1, errno); if (ev_extra != NULL) pth_event_concat(ev, ev_extra, NULL); @ 1.6 log @Update to 2.0.7: Changes between 2.0.6 and 2.0.7 (22-Nov-2005 to 08-Jun-2006) *) Let AC_CHECK_PTH use "pth-config --libs --all" instead of just "pth-config --libs" to allow it to work under platforms like Solaris where additional libraries are required. [Ralf S. Engelschall] Changes between 2.0.5 and 2.0.6 (05-Oct-2005 to 22-Nov-2005) *) Add a missing "break" in pth_attr.c:pth_attr_ctrl(). [Stefan Schippers ] *) Return an error if pth_kill() is called before pth_init(). [Martin Kraemer ] Changes between 2.0.3 and 2.0.4 (03-Dec-2004 to 18-Feb-2005) *) Fix internal determination of maximum number in a size_t in the string formatter engine. [Ralf S. Engelschall] *) Add quotes around function names for AC_DEFUN in pth.m4 to avoid warnings about "underquoted definitions". [Stephane Loeuillet ] *) Do not insist on writing to the source directory on "make install" in order to more closely follow GNU standards. [Bruno Haible ] *) Remove "*.bak" and "*~" files under "make distclean" instead of "make clean". [Bruno Haible ] Changes between 2.0.2 and 2.0.3 (12-Sep-2004 to 03-Dec-2004) *) Resurrect the old "make striptease" command by fixing the configure run-time in the stripped down source tree and fixing the list of source files. [Ralf S. Engelschall] *) The pth_uctx_save() and pth_uctx_restore() API functions unfortunately were broken by design because they are C _functions_. This leads to one more deadly nesting on the run-time stack which effectively caused the pth_mctx_restore() in pth_uctx_restore() to return to the end of pth_uctx_save() but then the control flow unfortunately returns to the pth_uctx_restore() caller instead of the pth_uctx_save() caller because the call to pth_uctx_restore() had already overwritten the run-time stack position where the original return address for the pth_uctx_save() call was stored. The only workaround would be to #define pth_uctx_save() and pth_uctx_restore() as C _macros_, but this then would require that lots of the GNU Pth internals from pth_mctx.c would have to be exported in the GNU Pth API (which in turn is not acceptable). So, the only consequence is to remove the two functions again from the GNU Pth API. [Ralf S. Engelschall, Stefan Brantschen ] *) Enhance internal pth_mctx_save() if getcontext(3) is used for the machine context saving by better emulating the setjmp(3) style return code semantics. [Ralf S. Engelschall] *) Do not break in pth_msgport_find() if a message port was created with a NULL name. [Ralf S. Engelschall] *) Better error checking in pth_key_xxx() functions. [Ralf S. Engelschall] *) Added PTH_CTRL_FAVOURNEW control which allows the user to disable the favouring of new threads on scheduling to get more strict priority based scheduling behavior. [Ralf S. Engelschall, Vinu V ] Changes between 2.0.1 and 2.0.2 (13-Jul-2004 to 12-Sep-2004) *) Added hard syscall wrappers for send(2) and recv(2). [NetBSD pkgsrc patches] *) Internally handle errors returned from pth_event() in order to pass them upstream to the caller in pth_high.c functions. [Ralf S. Engelschall, NetBSD pkgsrc patches] *) Fix syscall wrapper for sendto(2). [NetBSD pkgsrc patches] *) Use "(char *)NULL" instead of plain "NULL" in last argument to execl(2) to avoid GCC 3.5's "warning: missing sentinel in function call". [Ralf S. Engelschall] *) Workaround Autoconf/m4 problems in pth.m4 by using "m4_define" instead of just "define" and no using m4_undefine at all. [Dr. Andreas Mueller ] *) Avoid side-effects by defining _XOPEN_SOURCE only temporarily for inclusion of instead of permanently. [Graham Nash ] *) Workaround GCC 2.x and 3.5 (3.4 worked fine) macro parsing behaviour by using a pre-declared function pointer type "typedef int (*pth_event_func_t)(void *);" instead of using an inlined "int (*)(void *)". [Ralf S. Engelschall, Robert Anderson ] *) Fixed prototype for pthread_attr_setschedparam(3) from to use a "const struct sched_param *" argument. [Rafael Ávila de Espíndola ] Changes between 2.0.0 and 2.0.1 (17-Feb-2003 to 13-Jul-2004) *) Fix handling/casting of "int (*)(void *)" callback functions. [Ralf S. Engelschall] *) Resolve symbol conflict in pth_string.c between pow10/round and GCC builtins. [Ralf S. Engelschall] *) Use GCC 3.3 option "-fno-strict-aliasing" (if available) under Autoconf option "--enable-debug" because mainly pth_mctx.c contains important and correct pointer casting constructs which are not acceptable in "strict aliasing" for GCC. [Ralf S. Engelschall] *) Fixed implementation so that --enable-pthread now correctly implies --enable-syscall-soft. [Steve Alstrin , Ralf S. Engelschall] *) Replace some 0 by more politically correct NULL in pth_string.c [Ralf S. Engelschall] @ text @d1 1 a1 1 $NetBSD: patch-ac,v 1.5 2003/05/02 11:49:48 wiz Exp $ d103 22 a124 1 @@@@ -624,6 +653,13 @@@@ int pth_connect_ev(int s, const struct s @ 1.5 log @Update to 2.0.0, supplied by skrll@@netbsd. Changes: *) Make pth_poll(3) more compliant to POSIX.1-2001/SUSv3 poll(2). *) Make pth_select(3) more compliant to POSIX.1-2001/SUSv3 select(2). *) Replaced pth_event_occurred() with pth_event_status(). *) Add Autoconf option --with-fdsetsize=NUM for enlarging FD_SETSIZE. *) Added thread attribute PTH_ATTR_DISPATCHES. *) Added sub-API pth_uctx_* for user-space context switching. *) Add a Pth variant of the new POSIX pselect(2) function. *) Internally cleaned up the error handling macros. *) Added POSIX-compliant sanity checks for bad fds. *) Added pth_nanosleep() function. *) Allow a NULL name for pth_msgport_create() *) Completely rewrote the "hard syscall mapping". *) Added support to pth_poll(3) for POLLD{RD,WR}{NORM,BAND}. *) Fixed a long-standing termination bug in pth_exit(3). *) Upgraded to Autoconf 2.57, Shtool 1.6.2 and Libtool 1.4.3. *) Add optional support for OSSP ex based exception handling. @ text @d1 1 a1 1 $NetBSD$ d3 1 a3 1 --- pth_high.c.orig Wed Jan 1 15:45:06 2003 d5 1 a5 1 @@@@ -180,6 +180,35 @@@@ int pth_sigwait_ev(const sigset_t *set, d41 1 a41 1 @@@@ -330,9 +359,9 @@@@ int pth_select_ev(int nfd, fd_set *rfds, d54 1 a54 1 @@@@ -345,17 +374,17 @@@@ int pth_select_ev(int nfd, fd_set *rfds, d75 1 a75 1 @@@@ -370,11 +399,11 @@@@ int pth_select_ev(int nfd, fd_set *rfds, d90 1 a90 1 @@@@ -407,9 +436,9 @@@@ int pth_select_ev(int nfd, fd_set *rfds, d103 1 a103 1 @@@@ -620,6 +649,13 @@@@ int pth_connect_ev(int s, const struct s d106 1 a106 1 ev = pth_event(PTH_EVENT_FD|PTH_UNTIL_FD_WRITEABLE|PTH_MODE_STATIC, &ev_key, s); d114 1 a116 1 pth_wait(ev); @ 1.4 log @Improve error handling. Patches backported from pth -current. PKGREVISION++ This fixes PR 19162 from Ingolf Steinbach. @ text @d3 1 a3 1 --- pth_high.c.orig Sun Jan 27 13:14:36 2002 d5 1 a5 44 @@@@ -35,6 +35,42 @@@@ #include "pth_p.h" +/* Pth variant of nanosleep(2) */ +int pth_nanosleep(const struct timespec *rqtp, struct timespec *rmtp) +{ + pth_time_t until; + pth_time_t offset; + pth_time_t now; + pth_event_t ev; + static pth_key_t ev_key = PTH_KEY_INIT; + + if (rqtp == NULL) { + return_errno(-1, EFAULT); + } + + /* short-circuit */ + if (rqtp->tv_sec == 0 && rqtp->tv_nsec == 0) + return 0; + + /* calculate asleep time */ + offset = pth_time((long)rqtp->tv_sec, (long)(rqtp->tv_nsec / 1000)); + pth_time_set(&until, PTH_TIME_NOW); + pth_time_add(&until, &offset); + + /* and let thread sleep until this time is elapsed */ + ev = pth_event(PTH_EVENT_TIME|PTH_MODE_STATIC, &ev_key, until); + pth_wait(ev); + + if (rmtp != NULL) { + pth_time_set(&now, PTH_TIME_NOW); + pth_time_sub(&until, &now); + rmtp->tv_sec = until.tv_sec; + rmtp->tv_nsec = until.tv_usec * 1000; + } + + return 0; +} + /* Pth variant of usleep(3) */ int pth_usleep(unsigned int usec) { @@@@ -141,8 +177,43 @@@@ int pth_sigwait_ev(const sigset_t *set, d21 1 a21 1 + while ( (pid = pth_sc(wait4)(wpid, status, options|WNOHANG, rusage)) < 0 d36 1 d39 1 a39 9 -pid_t pth_waitpid(pid_t wpid, int *status, int options) +pid_t pth_waitpid(pid_t wpid, int *status, int options) +{ + return pth_wait4(wpid, status, options, 0); +} + +#else +/* Pth variant of wait4(2) */ +pid_t pth_waitpid(pid_t wpid, int *status, int options) d41 1 a41 50 pth_event_t ev; static pth_key_t ev_key = PTH_KEY_INIT; @@@@ -167,6 +238,8 @@@@ pid_t pth_waitpid(pid_t wpid, int *statu pth_debug2("pth_waitpid: leave to thread \"%s\"", pth_current->name); return pid; } +#endif + /* Pth variant of system(3) */ int pth_system(const char *cmd) @@@@ -195,7 +268,7 @@@@ int pth_system(const char *cmd) /* block SIGCHLD signal */ sigemptyset(&ss_block); sigaddset(&ss_block, SIGCHLD); - sigprocmask(SIG_BLOCK, &ss_block, &ss_old); + pth_sc(sigprocmask)(SIG_BLOCK, &ss_block, &ss_old); /* fork the current process */ pstat = -1; @@@@ -207,7 +280,7 @@@@ int pth_system(const char *cmd) /* restore original signal dispositions and execute the command */ sigaction(SIGINT, &sa_int, NULL); sigaction(SIGQUIT, &sa_quit, NULL); - sigprocmask(SIG_SETMASK, &ss_old, NULL); + pth_sc(sigprocmask)(SIG_SETMASK, &ss_old, NULL); /* stop the Pth scheduling */ pth_scheduler_kill(); @@@@ -227,7 +300,7 @@@@ int pth_system(const char *cmd) /* restore original signal dispositions and execute the command */ sigaction(SIGINT, &sa_int, NULL); sigaction(SIGQUIT, &sa_quit, NULL); - sigprocmask(SIG_SETMASK, &ss_old, NULL); + pth_sc(sigprocmask)(SIG_SETMASK, &ss_old, NULL); /* return error or child process result code */ return (pid == -1 ? -1 : pstat); @@@@ -258,6 +331,9 @@@@ int pth_select_ev(int nfd, fd_set *rfds, pth_implicit_init(); pth_debug2("pth_select_ev: called from thread \"%s\"", pth_current->name); + if (nfd < 0 || nfd > FD_SETSIZE) + return_errno(-1, EINVAL); + /* first deal with the special situation of a plain microsecond delay */ if (nfd == 0 && rfds == NULL && wfds == NULL && efds == NULL && timeout != NULL) { if (timeout->tv_sec < 0 || timeout->tv_usec < 0) @@@@ -280,10 +356,11 @@@@ int pth_select_ev(int nfd, fd_set *rfds, return_errno(-1, EINTR); d44 1 a44 2 + /* POSIX compliance */ d54 1 a54 2 @@@@ -295,36 +372,42 @@@@ int pth_select_ev(int nfd, fd_set *rfds, delay.tv_sec = 0; a56 1 + d58 1 a58 1 - rspare = *rfds; d64 1 a64 1 - wspare = *wfds; d70 1 a70 1 - espare = *efds; d74 6 a79 11 while ((rc = pth_sc(select)(nfd, rtmp, wtmp, etmp, &delay)) < 0 && errno == EINTR) ; + if (rc < 0) + return_errno(-1, errno); if (rc > 0) { - if (rfds != NULL) - *rfds = rspare; - if (wfds != NULL) - *wfds = wspare; - if (efds != NULL) - *efds = espare; + if (rfds != NULL) { d81 2 a82 2 + } + if (wfds != NULL) { d84 2 a85 2 + } + if (efds != NULL) { a86 1 + } a88 29 if (rc == 0 && timeout != NULL) { if (pth_time_cmp(timeout, PTH_TIME_ZERO) == 0) { /* POSIX compliance */ - if (rfds != NULL) FD_ZERO(rfds); - if (wfds != NULL) FD_ZERO(wfds); - if (efds != NULL) FD_ZERO(efds); + if (rfds != NULL) pth_util_fd_zero(nfd, rfds); + if (wfds != NULL) pth_util_fd_zero(nfd, wfds); + if (efds != NULL) pth_util_fd_zero(nfd, efds); return 0; } } @@@@ -350,10 +433,9 @@@@ int pth_select_ev(int nfd, fd_set *rfds, pth_event_isolate(ev_timeout); if (pth_event_occurred(ev_timeout)) { selected = TRUE; - /* POSIX compliance */ - if (rfds != NULL) FD_ZERO(rfds); - if (wfds != NULL) FD_ZERO(wfds); - if (efds != NULL) FD_ZERO(efds); + if (rfds != NULL) pth_util_fd_zero(nfd, rfds); + if (wfds != NULL) pth_util_fd_zero(nfd, wfds); + if (efds != NULL) pth_util_fd_zero(nfd, efds); rc = 0; } } @@@@ -362,7 +444,7 @@@@ int pth_select_ev(int nfd, fd_set *rfds, return rc; } d90 11 a100 48 -/* Pth variant of select(2) */ +/* Pth variant of poll(2) */ int pth_poll(struct pollfd *pfd, nfds_t nfd, int timeout) { return pth_poll_ev(pfd, nfd, timeout, NULL); @@@@ -373,7 +455,7 @@@@ int pth_poll(struct pollfd *pfd, nfds_t INTERNALLY THE SCHEDULER IS ONLY select(2) BASED!! */ int pth_poll_ev(struct pollfd *pfd, nfds_t nfd, int timeout, pth_event_t ev_extra) { - fd_set rfds, wfds, efds; + fd_set rfds, wfds, efds, cfds; struct timeval tv, *ptv; int maxfd, rc, ok; unsigned int i; @@@@ -410,58 +492,64 @@@@ int pth_poll_ev(struct pollfd *pfd, nfds FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&efds); + FD_ZERO(&cfds); for(i = 0; i < nfd; i++) { - if (!pth_util_fd_valid(pfd[i].fd)) - return_errno(-1, EBADF); - if (pfd[i].events & POLLIN) - FD_SET(pfd[i].fd, &rfds); - if (pfd[i].events & POLLOUT) - FD_SET(pfd[i].fd, &wfds); - if (pfd[i].events & POLLPRI) - FD_SET(pfd[i].fd, &efds); - if (pfd[i].fd >= maxfd && (pfd[i].events & (POLLIN|POLLOUT|POLLPRI))) - maxfd = pfd[i].fd; + if (fcntl(pfd[i].fd, F_GETFL) == -1 && errno == EBADF) { + FD_SET(pfd[i].fd, &cfds); + } else { + if (pfd[i].events & POLLIN) + FD_SET(pfd[i].fd, &rfds); + if (pfd[i].events & POLLOUT) + FD_SET(pfd[i].fd, &wfds); + if (pfd[i].events & POLLPRI) + FD_SET(pfd[i].fd, &efds); + if (pfd[i].fd >= maxfd && (pfd[i].events & (POLLIN|POLLOUT|POLLPRI))) + maxfd = pfd[i].fd; + } + } + if (maxfd != -1) { + /* examine fd sets */ + rc = pth_select_ev(maxfd+1, &rfds, &wfds, &efds, ptv, ev_extra); + if (rc < 0) + return rc; d102 2 a103 86 - if (maxfd == -1) - return_errno(-1, EINVAL); - - /* examine fd sets */ - rc = pth_select_ev(maxfd+1, &rfds, &wfds, &efds, ptv, ev_extra); /* establish results */ - if (rc > 0) { - rc = 0; - for (i = 0; i < nfd; i++) { - ok = 0; - pfd[i].revents = 0; - if (pfd[i].fd < 0) { - pfd[i].revents |= POLLNVAL; - continue; - } - if (FD_ISSET(pfd[i].fd, &rfds)) { - pfd[i].revents |= POLLIN; - ok++; - /* support for POLLHUP */ - if (recv(pfd[i].fd, data, 64, MSG_PEEK) == -1) { - if ( errno == ESHUTDOWN || errno == ECONNRESET - || errno == ECONNABORTED || errno == ENETRESET) { - pfd[i].revents &= ~(POLLIN); - pfd[i].revents |= POLLHUP; - ok--; - } + rc = 0; + for (i = 0; i < nfd; i++) { + ok = 0; + pfd[i].revents = 0; + if (FD_ISSET(pfd[i].fd, &cfds)) { + pfd[i].revents |= POLLNVAL; + if (pfd[i].fd >= 0) + rc++; + continue; + } + if (maxfd == -1) + continue; + if (FD_ISSET(pfd[i].fd, &rfds)) { + pfd[i].revents |= POLLIN; + ok++; + /* support for POLLHUP */ + if (recv(pfd[i].fd, data, 64, MSG_PEEK) == -1) { + if ( errno == ESHUTDOWN || errno == ECONNRESET + || errno == ECONNABORTED || errno == ENETRESET) { + pfd[i].revents &= ~(POLLIN); + pfd[i].revents |= POLLHUP; + ok--; } } - if (FD_ISSET(pfd[i].fd, &wfds)) { - pfd[i].revents |= POLLOUT; - ok++; - } - if (FD_ISSET(pfd[i].fd, &efds)) { - pfd[i].revents |= POLLPRI; - ok++; - } - if (ok) - rc++; } + if (FD_ISSET(pfd[i].fd, &wfds)) { + pfd[i].revents |= POLLOUT; + ok++; + } + if (FD_ISSET(pfd[i].fd, &efds)) { + pfd[i].revents |= POLLPRI; + ok++; + } + if (ok) + rc++; } return rc; } @@@@ -485,7 +573,8 @@@@ int pth_connect_ev(int s, const struct s pth_debug2("pth_connect_ev: enter from thread \"%s\"", pth_current->name); /* force filedescriptor into non-blocking mode */ - fdmode = pth_fdmode(s, PTH_FDMODE_NONBLOCK); + if ((fdmode = pth_fdmode(s, PTH_FDMODE_NONBLOCK)) == PTH_FDMODE_ERROR) + return_errno(-1, EBADF); /* try to connect */ while ( (rv = pth_sc(connect)(s, (struct sockaddr *)addr, addrlen)) == -1 @@@@ -498,6 +587,13 @@@@ int pth_connect_ev(int s, const struct s d112 1 a112 1 + return_errno(-1, errno); a116 106 @@@@ -536,7 +632,8 @@@@ int pth_accept_ev(int s, struct sockaddr pth_debug2("pth_accept_ev: enter from thread \"%s\"", pth_current->name); /* force filedescriptor into non-blocking mode */ - fdmode = pth_fdmode(s, PTH_FDMODE_NONBLOCK); + if ((fdmode = pth_fdmode(s, PTH_FDMODE_NONBLOCK)) == PTH_FDMODE_ERROR) + return_errno(-1, EBADF); /* poll socket via accept */ ev = NULL; @@@@ -585,6 +682,7 @@@@ ssize_t pth_read_ev(int fd, void *buf, s pth_event_t ev; static pth_key_t ev_key = PTH_KEY_INIT; fd_set fds; + int fdmode; int n; pth_implicit_init(); @@@@ -594,8 +692,12 @@@@ ssize_t pth_read_ev(int fd, void *buf, s if (nbytes == 0) return 0; + /* check mode of filedescriptor */ + if ((fdmode = pth_fdmode(fd, PTH_FDMODE_POLL)) == PTH_FDMODE_ERROR) + return_errno(-1, EBADF); + /* poll filedescriptor if not already in non-blocking operation */ - if (pth_fdmode(fd, PTH_FDMODE_POLL) == PTH_FDMODE_BLOCK) { + if (fdmode == PTH_FDMODE_BLOCK) { /* now directly poll filedescriptor for readability to avoid unneccessary (and resource consuming because of context @@@@ -662,7 +764,8 @@@@ ssize_t pth_write_ev(int fd, const void return 0; /* force filedescriptor into non-blocking mode */ - fdmode = pth_fdmode(fd, PTH_FDMODE_NONBLOCK); + if ((fdmode = pth_fdmode(fd, PTH_FDMODE_NONBLOCK)) == PTH_FDMODE_ERROR) + return_errno(-1, EBADF); /* poll filedescriptor if not already in non-blocking operation */ if (fdmode != PTH_FDMODE_NONBLOCK) { @@@@ -749,6 +852,7 @@@@ ssize_t pth_readv_ev(int fd, const struc pth_event_t ev; static pth_key_t ev_key = PTH_KEY_INIT; fd_set fds; + int fdmode; int n; pth_implicit_init(); @@@@ -758,8 +862,12 @@@@ ssize_t pth_readv_ev(int fd, const struc if (iovcnt <= 0 || iovcnt > UIO_MAXIOV) return_errno(-1, EINVAL); + /* check mode of filedescriptor */ + if ((fdmode = pth_fdmode(fd, PTH_FDMODE_POLL)) == PTH_FDMODE_ERROR) + return_errno(-1, EBADF); + /* poll filedescriptor if not already in non-blocking operation */ - if (pth_fdmode(fd, PTH_FDMODE_POLL) == PTH_FDMODE_BLOCK) { + if (fdmode == PTH_FDMODE_BLOCK) { /* first directly poll filedescriptor for readability to avoid unneccessary (and resource consuming because of context @@@@ -881,7 +989,8 @@@@ ssize_t pth_writev_ev(int fd, const stru return_errno(-1, EINVAL); /* force filedescriptor into non-blocking mode */ - fdmode = pth_fdmode(fd, PTH_FDMODE_NONBLOCK); + if ((fdmode = pth_fdmode(fd, PTH_FDMODE_NONBLOCK)) == PTH_FDMODE_ERROR) + return_errno(-1, EBADF); /* poll filedescriptor if not already in non-blocking operation */ if (fdmode != PTH_FDMODE_NONBLOCK) { @@@@ -1176,6 +1285,7 @@@@ ssize_t pth_recvfrom_ev(int fd, void *bu pth_event_t ev; static pth_key_t ev_key = PTH_KEY_INIT; fd_set fds; + int fdmode; int n; pth_implicit_init(); @@@@ -1185,8 +1295,12 @@@@ ssize_t pth_recvfrom_ev(int fd, void *bu if (nbytes == 0) return 0; + /* check mode of filedescriptor */ + if ((fdmode = pth_fdmode(fd, PTH_FDMODE_POLL)) == PTH_FDMODE_ERROR) + return_errno(-1, EBADF); + /* poll filedescriptor if not already in non-blocking operation */ - if (pth_fdmode(fd, PTH_FDMODE_POLL) == PTH_FDMODE_BLOCK) { + if (fdmode == PTH_FDMODE_BLOCK) { /* now directly poll filedescriptor for readability to avoid unneccessary (and resource consuming because of context @@@@ -1265,7 +1379,8 @@@@ ssize_t pth_sendto_ev(int fd, const void return 0; /* force filedescriptor into non-blocking mode */ - fdmode = pth_fdmode(fd, PTH_FDMODE_NONBLOCK); + if ((fdmode = pth_fdmode(fd, PTH_FDMODE_NONBLOCK)) == PTH_FDMODE_ERROR) + return_errno(-1, EBADF); /* poll filedescriptor if not already in non-blocking operation */ if (fdmode != PTH_FDMODE_NONBLOCK) { @ 1.3 log @fix botch in a fd_set boundary check which broke uses of select(0,0,0,0,&to) as finegrained delay @ text @d3 2 a4 2 --- pth_high.c.orig Sun Jan 27 14:14:36 2002 +++ pth_high.c Wed Oct 23 11:38:37 2002 d48 1 a48 1 @@@@ -141,8 +177,43 @@@@ d93 1 a93 1 @@@@ -167,6 +238,8 @@@@ d102 1 a102 1 @@@@ -195,7 +268,7 @@@@ d111 1 a111 1 @@@@ -207,7 +280,7 @@@@ d120 1 a120 1 @@@@ -227,7 +300,7 @@@@ d129 1 a129 1 @@@@ -258,6 +331,9 @@@@ d139 1 a139 1 @@@@ -280,10 +356,11 @@@@ d154 1 a154 1 @@@@ -295,36 +372,42 @@@@ d209 1 a209 1 @@@@ -350,10 +433,9 @@@@ d223 1 a223 1 @@@@ -362,7 +444,7 @@@@ d232 1 a232 1 @@@@ -373,7 +455,7 @@@@ d241 1 a241 1 @@@@ -410,58 +492,64 @@@@ d351 11 a361 1 @@@@ -498,6 +586,13 @@@@ d375 106 @ 1.2 log @Various updates and fixes that I've collected recently: * Provide nanosleep(2) and usleep(3) wrappers. * Make sure sigprocmask syscalls are used in pth_system. * "Fix" FD_SET handling in the select(2) wrapper so that mismatches between pth FD_SETSIZE and user program FD_SETSIZE don't cause problems. * Update poll(2) wrapper to be more poll(2) like - in particular never return EINVAL for bad file descriptors Thanks to Matthias Drochner for this. * Improve error handling in connect(2) wrapper so that we don't confuse the scheduler. This fixes pkg/17944 from Christian Biere (ChristianBiere at gmx dot de) * Introduce autoconf handling of the value of FD_SETSIZE used by pth. If we have to hard code a value we might as well make it easy to change and make the inclusion of pth.h or pthread.h by a program that re-defines FD_SETSIZE an error. Inspired by pkg/17944. * Fix a compiler warning that I introduced a little while ago. * Disable --enable-syscall-hard for non-NetBSD platforms and for pre-1.6/m68k. Make a note of the PRs that need fixing. This closes pkg/18236 from Klaus Heinz (k dot heinz dot sep dot zwei at onlinehome dot de) The FD_SETSIZE problems would be handled better if pth was changed to use poll(2), and not select(2), internally. @ text @d3 2 a4 2 --- pth_high.c.orig Sun Jan 27 13:14:36 2002 +++ pth_high.c d48 1 a48 1 @@@@ -141,8 +177,43 @@@@ int pth_sigwait_ev(const sigset_t *set, d93 1 a93 1 @@@@ -167,6 +238,8 @@@@ pid_t pth_waitpid(pid_t wpid, int *statu d102 1 a102 1 @@@@ -195,7 +268,7 @@@@ int pth_system(const char *cmd) d111 1 a111 1 @@@@ -207,7 +280,7 @@@@ int pth_system(const char *cmd) d120 1 a120 1 @@@@ -227,7 +300,7 @@@@ int pth_system(const char *cmd) d129 1 a129 1 @@@@ -258,6 +331,9 @@@@ int pth_select_ev(int nfd, fd_set *rfds, d133 1 a133 1 + if (!pth_util_fd_valid(nfd-1)) d139 1 a139 1 @@@@ -280,10 +356,11 @@@@ int pth_select_ev(int nfd, fd_set *rfds, d154 1 a154 1 @@@@ -295,36 +372,42 @@@@ int pth_select_ev(int nfd, fd_set *rfds, d209 1 a209 1 @@@@ -350,10 +433,9 @@@@ int pth_select_ev(int nfd, fd_set *rfds, d223 1 a223 1 @@@@ -362,7 +444,7 @@@@ int pth_select_ev(int nfd, fd_set *rfds, d232 1 a232 1 @@@@ -373,7 +455,7 @@@@ int pth_poll(struct pollfd *pfd, nfds_t d241 1 a241 1 @@@@ -410,58 +492,64 @@@@ int pth_poll_ev(struct pollfd *pfd, nfds d351 1 a351 1 @@@@ -498,6 +586,13 @@@@ int pth_connect_ev(int s, const struct s @ 1.1 log @When --enable-syscall-hard is specified actually provide wrappers for all the syscalls that are documented as having wrappers. The ones missing were wait4 and sigprocmask. Patches have been sent to package maintainer. @ text @d3 1 a3 1 --- pth_high.c.orig Sat Mar 24 14:49:58 2001 d5 44 a48 1 @@@@ -141,8 +141,43 @@@@ d93 1 a93 1 @@@@ -167,6 +202,8 @@@@ d102 263 @