Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 159113 Details for
Bug 247971
PTRACE_SETOPTIONS reports wrong status in multi-threaded prog
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
exitcode.c source code to demo bug
exitcode.c (text/plain), 3.93 KB, created by
Tom Horsley
on 2007-07-13 01:48:32 UTC
(
hide
)
Description:
exitcode.c source code to demo bug
Filename:
MIME Type:
Creator:
Tom Horsley
Created:
2007-07-13 01:48:32 UTC
Size:
3.93 KB
patch
obsolete
>/* Demonstrate that the about to exit status fails to appear when tracking > * exit via PTRACE_SETOPTIONS. > */ >#include <stdio.h> >#include <sys/types.h> >#include <unistd.h> >#include <sys/ptrace.h> >#include <errno.h> >#include <string.h> >#include <signal.h> >#include <stdlib.h> >#include <sys/wait.h> >#include <pthread.h> > >/* These only seem to appear in kernel source, so just #define them here */ > >#define PTRACE_SETOPTIONS ((enum __ptrace_request)0x4200) >#define PTRACE_O_TRACEEXIT 0x00000040 >#define PTRACE_EVENT_EXIT 6 > >void >report_error(char * name, char * func) { > int errnum = errno; > fprintf(stderr, "ERR: %s %s call failed: %s (errno = %d)\n", > name, func, strerror(errnum), errnum); > fflush(stderr); >} > >void >fatal_error(char * name, char * func) { > report_error(name, func); > exit(2); >} > >void * >twiddle(void * arg) { > int i; > for (i = 0; i < 1000; ++i) { > sleep(1); > } > return arg; >} > >int >main() { > > pid_t kid; > sigset_t maskoff; > int i; > pthread_t thr; > > sigemptyset(&maskoff); > sigaddset(&maskoff, SIGCHLD); > sigaddset(&maskoff, SIGPIPE); > sigprocmask(SIG_BLOCK, &maskoff, NULL); > > sigemptyset(&maskoff); > sigaddset(&maskoff, SIGUSR1); > sigprocmask(SIG_UNBLOCK, &maskoff, NULL); > > kid = fork(); > if (kid == (pid_t)-1) { > fatal_error("exitcode", "fork()"); > } > if (kid == 0) { > > /* In kid say we should be debugged */ > > if (ptrace(PTRACE_TRACEME, 0, 0, 0) == -1) { > fatal_error("exitcode child", "ptrace(PTRACE_TRACEME)"); > } > > /* Then send myself a signal which the parent can grab */ > > kill(getpid(), SIGUSR1); > > /* complicate things a bit by creatng a thread (only fails if I do this) */ > > pthread_create(&thr, NULL, twiddle, (void *)0); > > sleep(1); > > /* Then just exit so parent can trace my about to exit status */ > > _exit(0); > } else { > > int waitstat; > > /* Wait for the kid to send himself SIGUSR1, set exit option once we > * have control. > */ > > if (waitpid(kid, &waitstat, WUNTRACED|__WALL) != kid) { > fatal_error("exitcode parent", "waitpid(kid)"); > } > if (ptrace(PTRACE_SETOPTIONS, kid, 0, PTRACE_O_TRACEEXIT) == -1) { > fatal_error("exitcode parent", "ptrace(PTRACE_SETOPTIONS, exit)"); > } > > /* Now continue kid and wait for the about to exit */ > > if (ptrace(PTRACE_CONT, kid, 0, 0) == -1) { > fatal_error("exitcode parent", "ptrace(PTRACE_CONT)"); > } > if (waitpid(kid, &waitstat, WUNTRACED|__WALL) != kid) { > fatal_error("exitcode parent", "waitpid(kid)"); > } > > /* what status info did we get? Expecting a SIGTRAP with an > * extended code that mentions PTRACE_EVENT_EXIT. > */ > > printf("waitpid status: 0x%x\n", waitstat); > if (WIFSTOPPED(waitstat)) { > int sig = WSTOPSIG(waitstat); > if (sig == SIGTRAP) { > int event_code = (waitstat >> 16) & 0xff; > if (event_code == PTRACE_EVENT_EXIT) { > printf("PASS: got SIGTRAP with event code PTRACE_EVENT_EXIT\n"); > } else { > printf("FAIL: got SIGTRAP with event code %d\n", event_code); > } > } else { > printf("FAIL: unexpected stop signal %d\n", sig); > } > } else if (WIFEXITED(waitstat)) { > int es = WEXITSTATUS(waitstat); > printf("FAIL: unexpected exit status %d\n", es); > } else if (WIFSIGNALED(waitstat)) { > int sig = WTERMSIG(waitstat); > printf("FAIL: unexpected termination signal: %d\n", sig); > } else { > printf("FAIL: unknown waitstat: 0x%x for kid %d\n", waitstat, (int)kid); > } > > /* Now let kid die (Oh no! The religious right will come after me!) */ > > if (ptrace(PTRACE_CONT, kid, 0, 0) == -1) { > fatal_error("exitcode parent", "ptrace(PTRACE_CONT)"); > } > if (waitpid(kid, &waitstat, WUNTRACED|__WALL) != kid) { > fatal_error("exitcode parent", "waitpid(kid)"); > } > } > return 0; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 247971
: 159113