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 309666 Details for
Bug 451849
ptrace(PTRACE_CONT, sig) kills app even if sig is blocked
[?]
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.
test case: 2 1-file C programs
ptrace_bug.txt (text/plain), 4.07 KB, created by
Tom Fleck
on 2008-06-17 19:29:57 UTC
(
hide
)
Description:
test case: 2 1-file C programs
Filename:
MIME Type:
Creator:
Tom Fleck
Created:
2008-06-17 19:29:57 UTC
Size:
4.07 KB
patch
obsolete
> >/** app.c ----------------------------------------------------------- */ >#include <unistd.h> >#include <stdio.h> >#include <stdlib.h> >#include <errno.h> >#include <signal.h> > >/* app waits on sigusr1 before exec'ing to ensure that even the quickest > * app gets traced */ >sigset_t oldset, sigset; >static void block_sigusr1(void) >{ > sigemptyset (&sigset); > sigaddset (&sigset, SIGUSR1); > sigprocmask (SIG_BLOCK, &sigset, &oldset); >} >static void unblock_sigusr1(void) >{ > sigprocmask (SIG_SETMASK, &oldset, 0); >} >static void waitfor_sigusr1(void) >{ > int sig; > sigwait (&sigset, &sig); >} > >int main (int argc, char **argv) >{ > int app = getpid(); > >/* block sigusr1 before fork so debugger doesn't kill app */ > block_sigusr1(); > > printf("%d is waiting for signal %d...\n", app, SIGUSR1); > fflush(stdout); > waitfor_sigusr1(); > > printf("got it, continuing...\n"); fflush(stdout); > unblock_sigusr1(); > > execl ("/bin/pwd", "pwd", NULL); > > perror("returned from exec"); > return -1; >} > >/** deb.c ----------------------------------------------------------------- */ >#include <unistd.h> >#include <stdio.h> >#include <stdlib.h> >#include <errno.h> >#include <sys/wait.h> >#include <sys/ptrace.h> >#include <signal.h> > >#define USAGE "Usage: %s [-w] app_pid\n" \ >" -w => apply workaround to avoid bug\n" > >static int do_workaround = 0; >static void getargs(int argc, char **argv, int *app_pid); > >/* after fork, either parent or child can play debugger or application, > * just pass in their pids */ >static void do_deb(int deb, int app); > >int main (int argc, char **argv) >{ > int app; > int deb = getpid(); > int Status; > >/* get pid, set do_workaround? */ > getargs(argc, argv, &app); > > printf("In deb=%d, attach\n", deb); fflush(stdout); > if (ptrace(PTRACE_ATTACH, app, 0, 0) == -1) > { > perror("attach failed"); fflush(stderr); > exit(1); > } > printf("In deb=%d, 1st wait(%d, ...)\n", deb, app); fflush(stdout); > Status = 0; > if (waitpid(app, &Status, 0) != -1) > { > printf("- 1st waitpid returned with %#x\n", Status); > fflush(stdout); > } > else > { > perror("* 1st waitpid failed"); fflush(stderr); > } > > if (!do_workaround) > { > printf("In deb=%d, ptrace(PTRACE_CONT, %d, 0, %d)\n", deb, app, > SIGUSR1); > fflush(stdout); > if (ptrace (PTRACE_CONT, app, 0, SIGUSR1) == -1) > { > perror("PTRACE_CONT(SIGUSR1) failed"); fflush(stderr); > exit(2); > } > } > else > { /* do separate PTRACE_CONT(..., 0), kill(..., SIGUSR1) */ > printf("In deb=%d, ptrace(PTRACE_CONT, %d, 0, 0)\n", deb, app); > fflush(stdout); > if (ptrace (PTRACE_CONT, app, 0, 0) == -1) > { > perror("PTRACE_CONT(0) failed"); fflush(stderr); > exit(2); > } > printf("In deb=%d, kill(%d, %d)\n", deb, app, SIGUSR1); fflush(stdout); > kill(app, SIGUSR1); > } > >/* wait for SIGTRAP from app's exec */ > printf("In deb=%d, 2nd wait(%d, ...)\n", deb, app); fflush(stdout); > if (waitpid(app, &Status, 0) != -1) > { > printf("- 3rd waitpid returned with %#x\n", Status); fflush(stdout); > if (!(WIFSTOPPED(Status) && WSTOPSIG (Status) == SIGTRAP)) > { > fprintf(stderr, "Didn't get SIGTRAP\n"); fflush(stderr); > exit(6); > } > } > else > { > perror("* 3rd waitpid failed"); fflush(stderr); > exit(7); > } > > printf("In deb=%d, detach\n", deb); fflush(stdout); > if (ptrace(PTRACE_DETACH, app, 0, 0) == -1) > { > perror("detach failed"); fflush(stderr); exit(3); > } > printf("=== PASSED!\n"); > return 0; >} > >static void getargs(int argc, char **argv, int *app_pid) >{ > int i; > int pid = 0; > if (argc < 2) > { > fprintf(stderr, USAGE, argv[0]); > exit(0); > } > for (i = 1; i < argc; i++) > { > if (!strcmp(argv[i], "-w")) > { > do_workaround = 1; > } > else if ((*app_pid = atoi(argv[i])) == 0) > { > fprintf(stderr, "Invalid arg %s\n" USAGE, argv[i], argv[0]); > exit(1); > } > } >}
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 451849
: 309666 |
328559