lkml.org 
[lkml]   [1999]   [Jan]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: core files
On 981230, Michael Elizabeth Chastain wrote:
> You could do a lot of *this* in user space by having a library function
> set the default value for all signals, or just SIGSEGV, to a function
> that uses some kind of IPC, such as writing to a fifo whose name includes
> the uid. I wonder if it's possible to use preloading to inject that
> snippet of code into an existing executable without relinking it and
> without touching libc.

Yes. The only hard part I see is getting the executable filename.
core.c:
---
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
void init_libcore(void) __attribute__((constructor));

void
sighandler(int signo)
{
struct {
int signo;
pid_t pid;
} s;
int fd;
s.signo = signo;
s.pid = getpid();
fd = open(getenv("SIG_FIFO"), O_WRONLY);
write(fd, &s, sizeof s);
close(fd);
pause();
}
void
init_libcore(void)
{
struct sigaction act;
act.sa_handler = sighandler;
sigfillset(&act.sa_mask);
act.sa_flags = SA_RESETHAND;
sigaction(SIGSEGV, &act, NULL);
}
-----
% gcc -fPIC -o core.o -c core.c
% gcc -shared -o core.so core.o
% LD_PRELOAD=./core SIG_FIFO=$HOME/.crash_handler_fifo bash
A program to listen to the fifo should be straightforward.
--
ICQ UIN: 56155810

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:49    [from the cache]
©2003-2011 Jasper Spaans. Advertise on this site