linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Richard B. Johnson" <root@chaos.analogic.com>
To: Linux kernel <linux-kernel@vger.kernel.org>
Subject: BUG (non-kernel), can hurt developers.
Date: Wed, 26 Nov 2003 11:54:56 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.53.0311261153050.10929@chaos> (raw)


Note  to hackers. Even though this is a lib-c bug, be
aware that many versions of the 'C' runtime library
have a rand() function that can (read will) segfault
in threads or signals.

		glibc-2.1.3
		libc.so.6

Are two culprits. This "little" problem just took me
a week to find. Rand() was used as a source of test
data in a system diagnostic. The diagnostic kept blowing
up. The following code tests for the problem.

//-----------------
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/time.h>

static int spare;
static int inside;
void handler(int unused)
{
    struct itimerval it;
    inside++;
    spare = rand();
    it.it_interval.tv_sec = 0L;
    it.it_interval.tv_usec = 0L;
    it.it_value.tv_sec = 0L;
    it.it_value.tv_usec = 1L;
    (void)signal(SIGALRM, handler);
    setitimer(ITIMER_REAL, &it, &it);
    inside--;
}
void bad(int sig)
{
    char *where;
    if(inside)
      where = "inside";
    else
      where = "outside";
   fprintf(stderr, "Failed %s handler on %d\n", where, spare);
   exit(EXIT_FAILURE);
}
int main(void);
int main()
{
    (void)signal(SIGSEGV, bad);
    handler(0);
    for(;;)
        (void)rand();
    return 0;
}
//---------------------


Run this for a few minutes.

Script started on Wed Nov 26 11:50:23 2003
$ gcc -Wall -o xxx -O2 xxx.c
$ ./xxx
Failed inside handler on 1735818301
$ ./xxx
Failed inside handler on 129960814
$ ./xxx
Failed inside handler on 1999426653
$ exit
exit
Script done on Wed Nov 26 11:50:52 2003


Cheers,
Dick Johnson
Penguin : Linux version 2.4.22 on an i686 machine (797.90 BogoMips).
            Note 96.31% of all statistics are fiction.



             reply	other threads:[~2003-11-26 16:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-26 16:54 Richard B. Johnson [this message]
2003-11-26 17:21 ` BUG (non-kernel), can hurt developers YOSHIFUJI Hideaki / 吉藤英明
2003-11-26 18:29 ` Linus Torvalds
2003-11-26 18:55   ` Richard B. Johnson
2003-11-26 19:33     ` Jamie Lokier
2003-11-26 20:17       ` Richard B. Johnson
2003-11-26 20:42         ` Jamie Lokier
2003-11-26 18:59   ` YOSHIFUJI Hideaki / 吉藤英明
2003-11-27 20:41   ` Mikulas Patocka
2003-11-28  7:18   ` Tomas Szepe
2003-11-28 10:29 Andries.Brouwer
2003-11-28 17:22 ` Chris Friesen
2003-11-28 21:21 Andries.Brouwer
2003-11-28 21:38 ` Chris Friesen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.53.0311261153050.10929@chaos \
    --to=root@chaos.analogic.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).