linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: BUG (non-kernel), can hurt developers.
@ 2003-11-28 21:21 Andries.Brouwer
  2003-11-28 21:38 ` Chris Friesen
  0 siblings, 1 reply; 14+ messages in thread
From: Andries.Brouwer @ 2003-11-28 21:21 UTC (permalink / raw)
  To: Andries.Brouwer, cfriesen; +Cc: linux-kernel, root, szepe, torvalds

> You may also want to mention the SUS async-safe list as well,
> since there are some additional functions there.

Are you sure?
Which? In which SUS version?

^ permalink raw reply	[flat|nested] 14+ messages in thread
* Re: BUG (non-kernel), can hurt developers.
@ 2003-11-28 10:29 Andries.Brouwer
  2003-11-28 17:22 ` Chris Friesen
  0 siblings, 1 reply; 14+ messages in thread
From: Andries.Brouwer @ 2003-11-28 10:29 UTC (permalink / raw)
  To: szepe, torvalds; +Cc: Andries.Brouwer, linux-kernel, root

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2113 bytes --]

> I believe it would be very useful to have this information included
> in the standard Linux signal(2) manpage.

OK. You might have included a patch. I made it say

       The  effects  of this call in a multi-threaded process are
       unspecified.

       The routine handler must be very careful, since processing
       elsewhere  was  interrupted at some arbitrary point. POSIX
       has the concept of "safe function".  If  a  signal  inter­
       rupts  an  unsafe  function,  and  handler calls an unsafe
       function, then the behavior is undefined.  Safe  functions
       are listed explicitly in the various standards.  The POSIX
       1003.1-2003 list is

       _Exit()  _exit()  abort()  accept()  access()  aio_error()
       aio_return()  aio_suspend()  alarm()  bind() cfgetispeed()
       cfgetospeed() cfsetispeed() cfsetospeed() chdir()  chmod()
       chown()  clock_gettime()  close()  connect() creat() dup()
       dup2() execle() execve() fchmod() fchown() fcntl()  fdata­
       sync()  fork()  fpathconf()  fstat()  fsync()  ftruncate()
       getegid()  geteuid()  getgid()  getgroups()  getpeername()
       getpgrp()  getpid()  getppid()  getsockname() getsockopt()
       getuid() kill() link() listen()  lseek()  lstat()  mkdir()
       mkfifo()   open()   pathconf()   pause()   pipe()   poll()
       posix_trace_event() pselect()  raise()  read()  readlink()
       recv()  recvfrom()  recvmsg()  rename()  rmdir()  select()
       sem_post() send() sendmsg()  sendto()  setgid()  setpgid()
       setsid()   setsockopt()  setuid()  shutdown()  sigaction()
       sigaddset() sigdelset() sigemptyset() sigfillset()  sigis­
       member() sleep() signal() sigpause() sigpending() sigproc­
       mask() sigqueue() sigset() sigsuspend()  socket()  socket­
       pair()   stat()  symlink()  sysconf()  tcdrain()  tcflow()
       tcflush()  tcgetattr()  tcgetpgrp()  tcsendbreak()   tcse­
       tattr()  tcsetpgrp()  time() timer_getoverrun() timer_get­
       time() timer_settime() times()  umask()  uname()  unlink()
       utime() wait() waitpid() write().

Andries

^ permalink raw reply	[flat|nested] 14+ messages in thread
* BUG (non-kernel), can hurt developers.
@ 2003-11-26 16:54 Richard B. Johnson
  2003-11-26 17:21 ` YOSHIFUJI Hideaki / 吉藤英明
  2003-11-26 18:29 ` Linus Torvalds
  0 siblings, 2 replies; 14+ messages in thread
From: Richard B. Johnson @ 2003-11-26 16:54 UTC (permalink / raw)
  To: Linux kernel


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.



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2003-11-28 21:39 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-28 21:21 BUG (non-kernel), can hurt developers Andries.Brouwer
2003-11-28 21:38 ` Chris Friesen
  -- strict thread matches above, loose matches on Subject: below --
2003-11-28 10:29 Andries.Brouwer
2003-11-28 17:22 ` Chris Friesen
2003-11-26 16:54 Richard B. Johnson
2003-11-26 17:21 ` 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

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).