Incorrect cv_wait_sig() return values?
Hi, I recently noticed that cv_wait_sig() will return -1 rather than EINTR when a SIGINT is delivered. This is in contrast to CONDVAR(9) which states: <...> cv_wait_sig() and cv_timedwait_sig() return prematurely with a value of EINTR or ERESTART if a signal is caught <...> To demonstrate the problem outside my out-of-tree driver, I took the skeleton driver from http://www.captain.at/programming/freebsd/ and added the following function, invoked at module load: static struct mtx m; static struct cv c; static void cv_test(void) { int rc; mtx_init(&m, "skel_m", MTX_DEF, MTX_DEF); cv_init(&c, "skel_c"); mtx_lock(&m); rc = cv_wait_sig(&c, &m); mtx_unlock(&m); printf("cv_wait_sig returned %d\n", rc); cv_destroy(&c); mtx_destroy(&m); } I load the module, and I ^C kldload after a few seconds to break out of the cv_wait_sig(), which results in this output on console: Skeleton KLD loaded. cv_wait_sig returned -1 Am I doing something wrong, or are condvars broken? I've tried to track this down with dtrace, but failed.. Thanks, Drew ___ freebsd-current@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"
Re: Incorrect cv_wait_sig() return values?
On Wed, Aug 04, 2010 at 10:36:24AM -0400, Andrew Gallatin wrote: > Hi, > > I recently noticed that cv_wait_sig() will return -1 > rather than EINTR when a SIGINT is delivered. This is > in contrast to CONDVAR(9) which states: > > <...> > cv_wait_sig() and cv_timedwait_sig() return prematurely with a > value of EINTR or ERESTART if a signal is caught > <...> > > To demonstrate the problem outside my out-of-tree driver, I > took the skeleton driver from > http://www.captain.at/programming/freebsd/ > and added the following function, invoked at module > load: > > static struct mtx m; > static struct cv c; > > static void > cv_test(void) > { > int rc; > > mtx_init(&m, "skel_m", MTX_DEF, MTX_DEF); > cv_init(&c, "skel_c"); > mtx_lock(&m); > rc = cv_wait_sig(&c, &m); > mtx_unlock(&m); > printf("cv_wait_sig returned %d\n", rc); > cv_destroy(&c); > mtx_destroy(&m); > } > > > I load the module, and I ^C kldload after a few seconds > to break out of the cv_wait_sig(), which results in this > output on console: > > Skeleton KLD loaded. > cv_wait_sig returned -1 > > Am I doing something wrong, or are condvars broken? > I've tried to track this down with dtrace, but failed.. What version of the system do you use ? I cannot confirm this on the HEAD from several hours ago with the following test module. On the SIGINT I get `4' printed, which is EINTR. #include #include #include #include #include #include #include static struct mtx m; static struct cv c; static void cv_test(void) { int rc; mtx_init(&m, "skel_m", MTX_DEF, MTX_DEF); cv_init(&c, "skel_c"); mtx_lock(&m); rc = cv_wait_sig(&c, &m); mtx_unlock(&m); printf("cv_wait_sig returned %d\n", rc); cv_destroy(&c); mtx_destroy(&m); } static int test_load(module_t mod, int cmd, void *arg) { switch (cmd) { case MOD_LOAD: cv_test(); break; } return (0); } static moduledata_t test_module = { "test", &test_load, NULL }; DECLARE_MODULE(test, test_module, SI_SUB_KLD, SI_ORDER_FIRST); MODULE_VERSION(test, 1); pgpz2cxfxk5ZS.pgp Description: PGP signature
Re: Incorrect cv_wait_sig() return values?
On Wed, Aug 04, 2010 at 06:46:04PM +0300, Kostik Belousov wrote: > On Wed, Aug 04, 2010 at 10:36:24AM -0400, Andrew Gallatin wrote: > > Hi, > > > > I recently noticed that cv_wait_sig() will return -1 > > rather than EINTR when a SIGINT is delivered. This is > > in contrast to CONDVAR(9) which states: > > > > <...> > > cv_wait_sig() and cv_timedwait_sig() return prematurely with a > > value of EINTR or ERESTART if a signal is caught > > <...> > > > > To demonstrate the problem outside my out-of-tree driver, I > > took the skeleton driver from > > http://www.captain.at/programming/freebsd/ > > and added the following function, invoked at module > > load: > > > > static struct mtx m; > > static struct cv c; > > > > static void > > cv_test(void) > > { > > int rc; > > > > mtx_init(&m, "skel_m", MTX_DEF, MTX_DEF); > > cv_init(&c, "skel_c"); > > mtx_lock(&m); > > rc = cv_wait_sig(&c, &m); > > mtx_unlock(&m); > > printf("cv_wait_sig returned %d\n", rc); > > cv_destroy(&c); > > mtx_destroy(&m); > > } > > > > > > I load the module, and I ^C kldload after a few seconds > > to break out of the cv_wait_sig(), which results in this > > output on console: > > > > Skeleton KLD loaded. > > cv_wait_sig returned -1 > > > > Am I doing something wrong, or are condvars broken? > > I've tried to track this down with dtrace, but failed.. > > What version of the system do you use ? I cannot confirm this on > the HEAD from several hours ago with the following test module. > On the SIGINT I get `4' printed, which is EINTR. BTW, -1 is ERESTART, so if you have SIGINT catched with SA_RESTART flag in the process that initiated kldload(2) syscall, then -1 is the right return code for cv_wait_sig. pgp9l3SKbjafV.pgp Description: PGP signature
Re: Incorrect cv_wait_sig() return values?
Kostik Belousov wrote: BTW, -1 is ERESTART, so if you have SIGINT catched with SA_RESTART flag in the process that initiated kldload(2) syscall, then -1 is the right return code for cv_wait_sig. Ah, makes sense. I hadn't considered that a BSD kernel error could be negative. I should have actually looked at errno.h. Sorry for the noise, and thanks for the explanation. Drew ___ freebsd-current@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"