I have compile a dummy program. I have attached it.
All is normal, excep for it generates a segmentation fault.
The program wait for SIGUSR1, cause by SIGALRM, and then call time( NULL
) and fails
in ctime.
Any idea ?
There is some probes:
bash-2.03# ctime
Segmentation fault
bash-2.03# gdb ctime
GNU gdb 4.18
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you
are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for
details.
This GDB was configured as "i386-suse-linux-gnu"...
(gdb) run
Starting program: /TRASH/BUGS/CTIME/ctime
warning: Cannot determine thread signal number; GDB may report spurious
signals.
Program received signal SIGSEGV, Segmentation fault.
0x0 in ?? ()
(gdb) bt
#0 0x0 in ?? ()
#1 0x40079954 in _IO_init (fp=0x80514c8, flags=0) at genops.c:556
#2 0x40074881 in _IO_new_fopen (filename=0x4010d5d1 "/etc/localtime",
mode=0x4010d642 "r") at iofopen.c:49
#3 0x400ade12 in __tzfile_read (file=0x4010d5d1 "/etc/localtime",
extra=0, extrap=0x0) at tzfile.c:149
#4 0x400acd13 in tzset_internal (always=-72548352) at tzset.c:172
#5 0x400adb8b in __tz_convert (timer=0xbffff698, use_localtime=1,
tp=0x4011a240) at tzset.c:582
#6 0x400a9d92 in localtime (t=0xbffff698) at localtime.c:43
#7 0x400a9c69 in ctime (t=0xbffff698) at ctime.c:32
#8 0x8049a02 in Tarea_A () at ctime-bug.c:52
#9 0x8049b0b in main () at ctime-bug.c:97
(gdb) q
The program is running. Exit anyway? (y or n) y
bash-2.03# strace ctime
execve("./ctime", ["ctime"], [/* 46 vars */]) = 0
brk(0) = 0x80514a8
open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or
directory)
open("/opt/kde/lib/i686/mmx/libc.so.6", O_RDONLY) = -1 ENOENT (No such
file or directory)
stat("/opt/kde/lib/i686/mmx", 0xbffff1d8) = -1 ENOENT (No such file or
directory)
open("/opt/kde/lib/i686/libc.so.6", O_RDONLY) = -1 ENOENT (No such file
or directory)
stat("/opt/kde/lib/i686", 0xbffff1d8) = -1 ENOENT (No such file or
directory)
open("/opt/kde/lib/mmx/libc.so.6", O_RDONLY) = -1 ENOENT (No such file
or directory)
stat("/opt/kde/lib/mmx", 0xbffff1d8) = -1 ENOENT (No such file or
directory)
open("/opt/kde/lib/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or
directory)
stat("/opt/kde/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=41117, ...}) = 0
mmap(NULL, 41117, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40015000
close(3) = 0
open("/lib/libc.so.6", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=4223971, ...}) = 0
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\200\204"...,
4096) = 4096
mmap(NULL, 1025596, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x40020000
mprotect(0x40113000, 30268, PROT_NONE) = 0
mmap(0x40113000, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3,
0xf2000) = 0x40113000
mmap(0x40117000, 13884, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40117000
close(3) = 0
mprotect(0x40020000, 995328, PROT_READ|PROT_WRITE) = 0
mprotect(0x40020000, 995328, PROT_READ|PROT_EXEC) = 0
munmap(0x40015000, 41117) = 0
personality(PER_LINUX) = 0
getpid() = 642
getpid() = 642
rt_sigaction(SIGUSR1, {0x804a490, [], SA_RESTART|0x4000000}, NULL, 8) =
0
rt_sigaction(SIGUSR2, {0x804a520, [], 0x4000000}, NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [USR1], NULL, 8) = 0
rt_sigaction(SIGALRM, {0x804996c, ~[INT QUIT ILL TRAP ABRT BUS FPE KILL
USR1 SEGV USR2 PIPE ALRM TERM STKFLT CHLD CONT STOP TSTP TTIN TTOU URG
XCPU XFSZ VTALRM PROF WINCH IO PWR UNUSED RT_0 RT_1 RT_2 RT_3 RT_4 RT_6
RT_7 RT_8 RT_9 RT_12], SA_RESTART|SA_NOMASK|0x4000000}, NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [ALRM], NULL, 8) = 0
setitimer(ITIMER_REAL, {it_interval={10, 0}, it_value={1, 0}}, NULL) = 0
rt_sigaction(SIG_0, {0x804a490, ~[], 0x4000000}, {0x280005, [HUP INT
QUIT BUS STKFLT UNUSED RT_3 RT_4 RT_6 RT_8 RT_11 RT_13 RT_17 RT_18],
0x2}, 8) = -1 EINVAL (Invalid argument)
rt_sigaction(SIGALRM, {0x804a490, ~[], 0x4000000}, {0x804996c, ~[INT
QUIT ILL TRAP ABRT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT
CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH IO PWR
UNUSED RT_0 RT_1 RT_2 RT_3 RT_4 RT_6 RT_7 RT_8 RT_9 RT_12],
SA_RESTART|SA_NOMASK|0x4000000}, 8) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [USR1 ALRM], 8) = 0
rt_sigsuspend(~[USR2 ALRM] <unfinished ...>
--- SIGALRM (Alarm clock) ---
<... rt_sigsuspend resumed> ) = -1 EINTR (Interrupted system
call)
sigreturn() = ? (mask now [USR1 ALRM])
rt_sigaction(SIG_0, {0x33d, [HUP ILL ABRT BUS FPE USR1 RT_1 RT_2 RT_4
RT_5 RT_6 RT_11], 0x4000000}, NULL, 8) = -1 EINVAL (Invalid argument)
rt_sigaction(SIGALRM, {0x804996c, ~[INT QUIT ILL TRAP ABRT BUS FPE KILL
USR1 SEGV USR2 PIPE ALRM TERM STKFLT CHLD CONT STOP TSTP TTIN TTOU URG
XCPU XFSZ VTALRM PROF WINCH IO PWR UNUSED RT_0 RT_1 RT_2 RT_3 RT_4 RT_6
RT_7 RT_8 RT_9 RT_12], SA_RESTART|SA_NOMASK|0x4000000}, NULL, 8) = 0
time(NULL) = 961444363
brk(0) = 0x80514a8
brk(0x80514d0) = 0x80514d0
brk(0x8052000) = 0x8052000
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++
bash-2.03#
[
ctime-bug.c 2K ]
// gcc -D_REENTRANT -DPOSIX_C_SOURCE=4 -D_POSIX_PTHREAD_SEMANTICS ciclico3.c -o ciclico -lpthread -lposix4 -g
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <signal.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
const numero_de_ciclos = 2 ;
#define CLOCK_REALTIME ITIMER_REAL
void timer_create( int , struct sigevent * , time_t * ) ;
static struct itimerval timerdata ;
static time_t timer_id ;
int redirect_signal ;
void alarm_signal ( int s )
{
kill( getpid( ) , redirect_signal ) ;
{
struct sigaction new_signal ;
redirect_signal = event -> sigev_signo ;
new_signal.sa_handler = alarm_signal ;
new_signal.sa_flags = SA_RESTART | SA_NODEFER ;
sigaction( SIGALRM , &new_signal , NULL ) ;
{
setitimer( CLOCK_REALTIME , timerdata , NULL ) ;
{
time_t reloj ;
reloj = time( NULL ) ;
ctime( &reloj ) ;
printf( "Tarea A %s\n" , ctime( &reloj ) ) ;
sleep( 3 ) ;
{
printf( "SEGNALLL \n" ) ;
// signal( SIGUSR1 , signal_handler ) ;
{
struct sigevent event ;
int i = 0 ;
sigset_t set ;
int received_sig ;
struct sigaction new_signal ;
/* crear el temporizador */
event.sigev_notify = SIGEV_SIGNAL ;
event.sigev_signo = SIGUSR1 ;
timer_create( CLOCK_REALTIME , &event , &timer_id ) ;
/* preparar el conjunto de se?ales usado por la llamada sigwait */
sigemptyset( &set ) ;
sigaddset( &set , SIGUSR1 | SIGALRM ) ;
pthread_sigmask( SIG_BLOCK , &set , NULL ) ;
/* armar el temporizador en modo peridico con periodo X seg */
timerdata.it_interval.tv_sec = 10 ;
timerdata.it_value.tv_sec = 1 ;
timerdata.it_interval.tv_usec = 0 ;
timerdata.it_value.tv_usec = 0 ;
timer_settime( timer_id , 0 , &timerdata , NULL ) ;
while(1)
{
/* esperar la se?al */
sigwait( &set , &received_sig ) ;
Tarea_A( ) ;
}