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 208791 Details for
Bug 309461
utrace: tkill(SIGCONT) is not reported by waitpid() under ptrace
[?]
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.
attach-sigcont-wait.c (text/plain), 5.87 KB, created by
Jan Kratochvil
on 2007-09-27 18:00:19 UTC
(
hide
)
Description:
Testcase.
Filename:
MIME Type:
Creator:
Jan Kratochvil
Created:
2007-09-27 18:00:19 UTC
Size:
5.87 KB
patch
obsolete
>/* Fedora fix: https://bugzilla.redhat.com/show_bug.cgi?id=248532 */ > >// This file is part of the program FRYSK. >// >// Copyright 2007, Red Hat Inc. >// >// FRYSK is free software; you can redistribute it and/or modify it >// under the terms of the GNU General Public License as published by >// the Free Software Foundation; version 2 of the License. >// >// FRYSK is distributed in the hope that it will be useful, but >// WITHOUT ANY WARRANTY; without even the implied warranty of >// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU >// General Public License for more details. >// >// You should have received a copy of the GNU General Public License >// along with FRYSK; if not, write to the Free Software Foundation, >// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. >// >// In addition, as a special exception, Red Hat, Inc. gives You the >// additional right to link the code of FRYSK with code not covered >// under the GNU General Public License ("Non-GPL Code") and to >// distribute linked combinations including the two, subject to the >// limitations in this paragraph. Non-GPL Code permitted under this >// exception must only link to the code of FRYSK through those well >// defined interfaces identified in the file named EXCEPTION found in >// the source code files (the "Approved Interfaces"). The files of >// Non-GPL Code may instantiate templates or use macros or inline >// functions from the Approved Interfaces without causing the >// resulting work to be covered by the GNU General Public >// License. Only Red Hat, Inc. may make changes or additions to the >// list of Approved Interfaces. You must obey the GNU General Public >// License in all respects for all of the FRYSK code and other code >// used in conjunction with FRYSK except the Non-GPL Code covered by >// this exception. If you modify this file, you may extend this >// exception to your version of the file, but you are not obligated to >// do so. If you do not wish to provide this exception without >// modification, you must delete this exception statement from your >// version and license this file solely under the GPL without >// exception. > >#define _GNU_SOURCE >#include <signal.h> >#include <unistd.h> >#include <string.h> >#include <stdio.h> >#include <stdlib.h> >#include <errno.h> >#include <sys/wait.h> >#include <sys/ptrace.h> >#include <assert.h> >#include <fcntl.h> >#include <limits.h> >#include <ctype.h> >#include <linux/ptrace.h> >#include <error.h> > >#include <asm/unistd.h> >#include <unistd.h> >#define tkill(tid, sig) syscall (__NR_tkill, (tid), (sig)) > >/* Failure occurs either immediately or in about 20 runs. */ >#define LOOPS 10000 > >static pid_t child; > >static void >cleanup (void) >{ > if (child != 0) > kill (child, SIGKILL); >} > >static void >handler_fail (int signo) >{ > cleanup (); > > signal (SIGABRT, SIG_DFL); > abort (); >} > >int main (void) >{ > pid_t got_pid; > int status; > int loops; > > setbuf (stdout, NULL); > atexit (cleanup); > signal (SIGABRT, handler_fail); > signal (SIGALRM, handler_fail); > /* Be careful with SIGALRM / ALARM due to false positives under load. */ > > int bad = 0; > for (loops = 0; loops < LOOPS; loops++) > { > alarm (20); > > child = fork (); > switch (child) > { > case -1: > abort (); > case 0: > raise (SIGSTOP); > for (;;) > pause (); > /* NOTREACHED */ > default: > break; > } > > /* We must never WAITPID/WAITID on the child for this testcase. */ > > /* We need to wait till CHILD becomes stopped. Any DELAY may be > * race-prone, check its `/proc/${child}/status'. */ > for (;;) > { > char buf[0x1000]; > ssize_t got; > int fd, i; > > snprintf (buf, sizeof buf, "/proc/%d/status", (int) child); > fd = open (buf, O_RDONLY); > assert (fd != -1); > got = read (fd, buf, sizeof buf); > assert (got > 0); > assert (got < sizeof buf); > buf[got] = 0; > i = close (fd); > assert (i == 0); > if (strstr (buf, "\nState:\tT (stopped)\n")) > break; > } > > /* Here is a point where we - as a debugger - start to attach. */ > errno = 0; > ptrace (PTRACE_ATTACH, child, NULL, NULL); > assert_perror (errno); > > /* Any DELAY makes no difference here. */ > > /* `PTRACE_CONT, SIGSTOP' does not work in 100% cases as sometimes SIGSTOP > gets remembered by kernel during the first PTRACE_CONT later and we get > spurious SIGSTOP event. Expecting the signal may get delivered to > a different task of the thread group. > `tkill (SIGSTOP)' has no effect in this moment (it is already stopped). */ > errno = 0; > tkill (child, SIGCONT); > assert_perror (errno); > > /* Here must not be any DELAY() to properly test utrace. The bug was > that WAITPID reported a previous job-control-stop condition even > though SIGCONT has cleared the TASK_STOPPED state. */ > > got_pid = waitpid (child, &status, 0); > assert (got_pid == child); > assert (WIFSTOPPED (status)); > /* If we got SIGSTOP here it is a bug of the patch > https://bugzilla.redhat.com/show_bug.cgi?id=248532#c5 > tkill (SIGCONT) above should clear all the pending SIGSTOPs. */ > if (WSTOPSIG (status) != SIGCONT) > { >#if 1 > error (0, 0, "%s after %d iterations", > strsignal (WSTOPSIG (status)), loops); >#endif > ++bad; > } > else > { > /* This point is no longer a part of the test, if we want to validate > ptrace(2) below here also must be no DELAY(). */ > > /* At this moment we should be already able to ptrace(2) the inferior. > After the fix of Bug 248532 Comment 5 above there should be no problem > here. */ > errno = 0; > ptrace (PTRACE_PEEKUSR, child, (void *) 0UL, NULL); > assert_perror (errno); > } > > /* Cleanup. */ > errno = 0; > kill (child, SIGKILL); > assert_perror (errno); > > got_pid = waitpid (child, &status, 0); > assert (got_pid == child); > } > alarm (0); > > if (bad) > { > printf ("%d bad in %d iterations: %.2f%%\n", > bad, LOOPS, 100.0 * bad / LOOPS); > puts ("FAIL"); > return 1; > } > > puts ("PASS"); > 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 309461
: 208791