This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: signals and _REENT
- From: Jeff Johnston <jjohnstn at redhat dot com>
- To: Freddie Chopin <freddie_chopin at op dot pl>
- Cc: newlib at sourceware dot org
- Date: Thu, 26 Feb 2015 14:39:31 -0500 (EST)
- Subject: Re: signals and _REENT
- Authentication-results: sourceware.org; auth=none
- References: <54E8FC58 dot 1060503 at op dot pl> <20150224133049 dot GH437 at calimero dot vinschen dot de> <820331943 dot 24407010 dot 1424801251193 dot JavaMail dot zimbra at redhat dot com> <54ECE7F2 dot 60909 at op dot pl> <53234661 dot 25550941 dot 1424885653210 dot JavaMail dot zimbra at redhat dot com>
Here is patch as mentioned. Did I miss anything?
-- Jeff J.
----- Original Message -----
From: "Jeff Johnston" <jjohnstn@redhat.com>
To: "Freddie Chopin" <freddie_chopin@op.pl>
Cc: newlib@sourceware.org
Sent: Wednesday, February 25, 2015 12:34:13 PM
Subject: Re: signals and _REENT
Agreed. I will post a patch.
----- Original Message -----
From: "Freddie Chopin" <freddie_chopin@op.pl>
To: newlib@sourceware.org
Sent: Tuesday, February 24, 2015 4:06:58 PM
Subject: Re: signals and _REENT
On 02/24/2015 07:07 PM, Jeff Johnston wrote:
> These functions set errno for the caller when an error has occurred.
> This would mean a user would have to check the global errno value (not using
> the dynamic reentrancy errno macro) which in turn could be changed by
> another thread making similar calls and therefore unreliable.
If errno is the only reason for using _REENT instead of _GLOBAL_REENT
then this can be easily solved. The functions may still get pointer to
current _REENT (for errno), but signal actions should be taken/set with
_GLOBAL_REENT.
Regards,
FCh
Index: signal.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/signal/signal.c,v
retrieving revision 1.6
diff -u -p -r1.6 signal.c
--- signal.c 31 Oct 2007 22:22:31 -0000 1.6
+++ signal.c 26 Feb 2015 19:36:27 -0000
@@ -105,14 +105,14 @@ _DEFUN (_init_signal_r, (ptr),
{
int i;
- if (ptr->_sig_func == NULL)
+ if (_GLOBAL_REENT->_sig_func == NULL)
{
- ptr->_sig_func = (_sig_func_ptr *)_malloc_r (ptr, sizeof (_sig_func_ptr) * NSIG);
- if (ptr->_sig_func == NULL)
+ _GLOBAL_REENT->_sig_func = (_sig_func_ptr *)_malloc_r (ptr, sizeof (_sig_func_ptr) * NSIG);
+ if (_GLOBAL_REENT->_sig_func == NULL)
return -1;
for (i = 0; i < NSIG; i++)
- ptr->_sig_func[i] = SIG_DFL;
+ _GLOBAL_REENT->_sig_func[i] = SIG_DFL;
}
return 0;
@@ -132,11 +132,11 @@ _DEFUN (_signal_r, (ptr, sig, func),
return SIG_ERR;
}
- if (ptr->_sig_func == NULL && _init_signal_r (ptr) != 0)
+ if (_GLOBAL_REENT->_sig_func == NULL && _init_signal_r (ptr) != 0)
return SIG_ERR;
- old_func = ptr->_sig_func[sig];
- ptr->_sig_func[sig] = func;
+ old_func = _GLOBAL_REENT->_sig_func[sig];
+ _GLOBAL_REENT->_sig_func[sig] = func;
return old_func;
}
@@ -154,10 +154,10 @@ _DEFUN (_raise_r, (ptr, sig),
return -1;
}
- if (ptr->_sig_func == NULL)
+ if (_GLOBAL_REENT->_sig_func == NULL)
func = SIG_DFL;
else
- func = ptr->_sig_func[sig];
+ func = _GLOBAL_REENT->_sig_func[sig];
if (func == SIG_DFL)
return _kill_r (ptr, _getpid_r (ptr), sig);
@@ -170,7 +170,7 @@ _DEFUN (_raise_r, (ptr, sig),
}
else
{
- ptr->_sig_func[sig] = SIG_DFL;
+ _GLOBAL_REENT->_sig_func[sig] = SIG_DFL;
func (sig);
return 0;
}
@@ -188,10 +188,10 @@ _DEFUN (__sigtramp_r, (ptr, sig),
return -1;
}
- if (ptr->_sig_func == NULL && _init_signal_r (ptr) != 0)
+ if (_GLOBAL_REENT->_sig_func == NULL && _init_signal_r (ptr) != 0)
return -1;
- func = ptr->_sig_func[sig];
+ func = _GLOBAL_REENT->_sig_func[sig];
if (func == SIG_DFL)
return 1;
else if (func == SIG_ERR)
@@ -200,7 +200,7 @@ _DEFUN (__sigtramp_r, (ptr, sig),
return 3;
else
{
- ptr->_sig_func[sig] = SIG_DFL;
+ _GLOBAL_REENT->_sig_func[sig] = SIG_DFL;
func (sig);
return 0;
}