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 311250 Details for
Bug 454404
ptrace: PTRACE_DETACH(..., SIGSTOP) does not stop
[?]
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.
Testcase.
detach-stopped.c (text/plain), 5.70 KB, created by
Jan Kratochvil
on 2008-07-08 10:05:19 UTC
(
hide
)
Description:
Testcase.
Filename:
MIME Type:
Creator:
Jan Kratochvil
Created:
2008-07-08 10:05:19 UTC
Size:
5.70 KB
patch
obsolete
>/* Try to detach a multithreaded process with all its tasks T (stopped). > > This software is provided 'as-is', without any express or implied > warranty. In no event will the authors be held liable for any damages > arising from the use of this software. > > Permission is granted to anyone to use this software for any purpose, > including commercial applications, and to alter it and redistribute it > freely. */ > >/* 1 for a non-threaded process, 2 for single pthread_create(), 3 for two > pthread_create) calls etc. */ >#define THREADS 10 > >#if THREADS < 1 ># error "Use THREADS 1 for a non-threaded process." >#endif > >#define _GNU_SOURCE >#ifdef __ia64__ >#define ia64_fpreg ia64_fpreg_DISABLE >#define pt_all_user_regs pt_all_user_regs_DISABLE >#endif /* __ia64__ */ >#include <sys/ptrace.h> >#ifdef __ia64__ >#undef ia64_fpreg >#undef pt_all_user_regs >#endif /* __ia64__ */ >#include <linux/ptrace.h> >#include <sys/types.h> >#include <sys/user.h> >#if defined __i386__ || defined __x86_64__ >#include <sys/debugreg.h> >#endif > >#include <signal.h> >#include <assert.h> >#include <dirent.h> >#include <limits.h> >#include <sys/wait.h> >#include <stdio.h> >#include <errno.h> >#include <stdlib.h> >#include <string.h> >#include <unistd.h> >#if THREADS > 1 ># include <pthread.h> >#endif > >static pid_t child[THREADS]; > >static void >cleanup (void) >{ > if (child[0] > 0) > kill (child[0], SIGKILL); >} > >static void >handler_fail (int signo) >{ > cleanup (); > > signal (SIGABRT, SIG_DFL); > assert (0); >} > >#if THREADS > 1 >static volatile unsigned started; > >static void *child_thread (void *data) >{ > started++; > > /* The main task is PTRACE_TRACEMEd, the other tasks are PTRACE_ATTACHed. */ > > for (;;) > pause (); > /* NOTREACHED */ > assert (0); >} >#endif /* THREADS > 1 */ > >static void child_func (void) >{ > long l; > >#if THREADS > 1 > int i, thread_count; > > for (thread_count = 1; thread_count < THREADS; thread_count++) > { > pthread_t thread; > > i = pthread_create (&thread, NULL, child_thread, NULL); > assert (i == 0); > } >#endif /* THREADS > 1 */ > > /* The main task is PTRACE_TRACEMEd, the other tasks are PTRACE_ATTACHed. */ > l = ptrace (PTRACE_TRACEME, 0, NULL, NULL); > assert (l == 0); > > i = raise (SIGUSR1); > assert (i == 0); > > for (;;) > pause (); > /* NOTREACHED */ >} > >int main (void) >{ > long l; > int status, i; > pid_t pid; > char dirname[64], filename[64]; > int child_count; > DIR *dir; > struct dirent *dirent; > /* PASS */ > int retval = 0; > > setbuf (stdout, NULL); > atexit (cleanup); > signal (SIGINT, handler_fail); > signal (SIGABRT, handler_fail); > signal (SIGALRM, handler_fail); > alarm (10); > > child[0] = fork (); > switch (child[0]) > { > case -1: > assert_perror (errno); > assert (0); > case 0: > child_func (); > /* NOTREACHED */ > assert (0); > default: > break; > } > > /* The main task is PTRACE_TRACEMEd, the other tasks are PTRACE_ATTACHed. */ > > pid = waitpid (child[0], &status, 0); > assert (pid == child[0]); > assert (WIFSTOPPED (status)); > assert (WSTOPSIG (status) == SIGUSR1); > > /* Read the thread TIDs from the `/proc/PID/task' directory. */ > > snprintf (dirname, sizeof dirname, "/proc/%d/task", (int) child[0]); > dir = opendir (dirname); > assert (dir != NULL); > > child_count = 1; > for (;;) > { > char *s; > pid_t tid; > > errno = 0; > dirent = readdir (dir); > if (!dirent) > { > assert_perror (errno); > break; > } > > if (strcmp (dirent->d_name, ".") == 0) > continue; > if (strcmp (dirent->d_name, "..") == 0) > continue; > l = strtol (dirent->d_name, &s, 10); > assert (l > 0 && l < LONG_MAX && (s == NULL || *s == 0)); > tid = l; > assert (tid == l); > /* The main task is PTRACE_TRACEMEd, the other tasks are > PTRACE_ATTACHed. */ > if (tid == child[0]) > continue; > assert (child_count < THREADS); > child[child_count++] = tid; > > l = ptrace (PTRACE_ATTACH, tid, NULL, NULL); > assert (l == 0); > > pid = waitpid (tid, &status, (tid == child[0] ? 0 : __WCLONE)); > assert (pid == tid); > assert (WIFSTOPPED (status)); > assert (WSTOPSIG (status) == SIGSTOP); > } > assert (child_count == THREADS); > > i = closedir (dir); > assert (i == 0); > > /* Some (last ones) tasks are usually left S (sleeping). */ >#if 0 > for (child_count = 0; child_count < THREADS; child_count++) > { > l = ptrace (PTRACE_DETACH, child[child_count], NULL, (void *) SIGSTOP); > assert (l == 0); > } >#endif > /* Some (first ones) tasks are usually left S (sleeping). */ >#if 1 > for (child_count = THREADS - 1; child_count >= 0; child_count--) > { > l = ptrace (PTRACE_DETACH, child[child_count], NULL, (void *) SIGSTOP); > assert (l == 0); > } >#endif > /* All left T (stopped) BUT the non-first tasks run for a moment > unstopped. */ >#if 0 > for (child_count = THREADS - 1; child_count >= 0; child_count--) > { > l = ptrace (PTRACE_DETACH, child[child_count], NULL, > (void *) (long) (child_count > 0 ? 0 : SIGSTOP)); > assert (l == 0); > } >#endif > > i = sleep (1); > assert (i == 0); > > /* Check if all the tasks are stopped now (they are not). */ > > for (child_count = 0; child_count < THREADS; child_count++) > { > FILE *f; > char buf[LINE_MAX]; > > snprintf (filename, sizeof filename, "/proc/%d/status", > (int) child[child_count]); > f = fopen (filename, "r"); > assert (f != NULL); > for (;;) > { > errno = 0; > if (!fgets (buf, sizeof buf, f)) > { > assert_perror (errno); > break; > } > if (strncmp (buf, "State:\t", sizeof ("State:\t") - 1)) > continue; > printf ("%d: %s", child_count, buf); > if (!strstr (buf, "T (stopped)")) > { > /* FAIL */ > retval = 1; > } > } > i = fclose (f); > assert (i == 0); > } > > return retval; >}
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 454404
: 311250 |
312150