Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #1089
| From | Markus Elfring <Markus.Elfring@web.de> |
|---|---|
| Newsgroups | comp.programming.threads, comp.unix.programmer |
| Subject | Safe accesses of global arrays in signal handlers? |
| Date | 2012-09-25 08:01 +0200 |
| Message-ID | <accvmcFog2gU1@mid.individual.net> (permalink) |
Cross-posted to 2 groups.
Hello,
A secure programming guideline contains the following information.
https://www.securecoding.cert.org/confluence/display/seccode/SIG31-C.+Do+not+access+or+modify+shared+objects+in+signal+handlers
:
'Accessing or modifying shared objects in signal handlers can result in race
conditions that can leave data in an inconsistent state. The exception to this
rule is the ability to read and write to variables of volatile sig_atomic_t.
...
It is important to note that the behavior of a program that accesses an object
of any other type from a signal handler is undefined.'
I interpret this description in the way that there are risks for the portable
use of a shared variable which has got a data type like "array" within a signal
handler.
http://en.wikipedia.org/wiki/Array_data_type
Source code example:
pthread_mutex_t my_lock = PTHREAD_MUTEX_INITIALIZER;
struct my_element my_list[MY_ARRAY_SIZE];
void my_status_log(int number)
{
int result = pthread_mutex_lock(&my_lock);
if (result) exit(result);
if ( my_list[number - 1].catched
&& printf("Signal %d was received.", number) < 22)
perror("printf");
result = pthread_mutex_unlock(&my_lock);
if (result) exit(result);
}
static void my_signal_handler(int number)
{
struct my_data * pointer = my_list[number - 1].context;
if (!pointer) return;
my_list[number - 1].catched = 1;
/* Call more functions eventually ... */
}
I would appreciate your advices for the clarification of the involved
implementation details. Would you like to suggest any solutions for such an use
case?
Regards,
Markus
Back to comp.programming.threads | Previous | Next — Next in thread | Find similar
Safe accesses of global arrays in signal handlers? Markus Elfring <Markus.Elfring@web.de> - 2012-09-25 08:01 +0200
Re: Safe accesses of global arrays in signal handlers? Nobody <nobody@nowhere.com> - 2012-09-25 12:15 +0100
Re: Safe accesses of global arrays in signal handlers? Markus Elfring <Markus.Elfring@web.de> - 2012-09-27 11:20 +0200
Re: Safe accesses of global arrays in signal handlers? Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-09-27 13:23 +0100
Re: Safe accesses of global arrays in signal handlers? Markus Elfring <Markus.Elfring@web.de> - 2012-09-28 13:25 +0200
Re: Safe accesses of global arrays in signal handlers? Nobody <nobody@nowhere.com> - 2012-09-27 13:35 +0100
Re: Safe accesses of global arrays in signal handlers? Markus Elfring <Markus.Elfring@web.de> - 2012-09-28 13:48 +0200
Re: Safe accesses of global arrays in signal handlers? Johann Klammer <klammerj@NOSPAM.a1.net> - 2012-09-28 18:34 +0200
Re: Safe accesses of global arrays in signal handlers? scott@slp53.sl.home (Scott Lurndal) - 2012-09-28 17:54 +0000
Re: Safe accesses of global arrays in signal handlers? Nobody <nobody@nowhere.com> - 2012-09-28 18:26 +0100
Re: Safe accesses of global arrays in signal handlers? Markus Elfring <Markus.Elfring@web.de> - 2012-09-29 13:44 +0200
Re: Safe accesses of global arrays in signal handlers? Nobody <nobody@nowhere.com> - 2012-09-29 20:37 +0100
Re: Safe accesses of global arrays in signal handlers? William Ahern <william@wilbur.25thandClement.com> - 2012-09-29 17:31 -0700
Signal handlers writing into pipes Markus Elfring <Markus.Elfring@web.de> - 2012-09-30 13:21 +0200
Re: Safe accesses of global arrays in signal handlers? Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-10-01 18:04 +0100
Signal handlers writing into pipes Markus Elfring <Markus.Elfring@web.de> - 2012-10-03 16:36 +0200
Re: Signal handlers writing into pipes Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-10-03 17:07 +0100
Re: Safe accesses of global arrays in signal handlers? Markus Elfring <Markus.Elfring@web.de> - 2012-09-30 13:12 +0200
Re: Safe accesses of global arrays in signal handlers? Nobody <nobody@nowhere.com> - 2012-09-30 20:46 +0100
Re: Safe accesses of global arrays in signal handlers? Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2012-09-28 13:39 +0100
Re: Safe accesses of global arrays in signal handlers? Markus Elfring <Markus.Elfring@web.de> - 2012-09-29 13:15 +0200
Re: Safe accesses of global arrays in signal handlers? William Ahern <william@wilbur.25thandClement.com> - 2012-09-29 17:42 -0700
Re: Safe accesses of global arrays in signal handlers? Markus Elfring <Markus.Elfring@web.de> - 2012-09-30 14:04 +0200
Re: Safe accesses of global arrays in signal handlers? Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-09-25 13:27 +0100
csiph-web