From nobody@FreeBSD.org  Wed May 15 14:16:34 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115])
	by hub.freebsd.org (Postfix) with ESMTP id 02EE275
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 15 May 2013 14:16:34 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.FreeBSD.org (oldred.freebsd.org [8.8.178.121])
	by mx1.freebsd.org (Postfix) with ESMTP id E97A314C
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 15 May 2013 14:16:33 +0000 (UTC)
Received: from oldred.FreeBSD.org ([127.0.1.6])
	by oldred.FreeBSD.org (8.14.5/8.14.5) with ESMTP id r4FEGWhn073616
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 15 May 2013 14:16:32 GMT
	(envelope-from nobody@oldred.FreeBSD.org)
Received: (from nobody@localhost)
	by oldred.FreeBSD.org (8.14.5/8.14.5/Submit) id r4FEGWCi073615;
	Wed, 15 May 2013 14:16:32 GMT
	(envelope-from nobody)
Message-Id: <201305151416.r4FEGWCi073615@oldred.FreeBSD.org>
Date: Wed, 15 May 2013 14:16:32 GMT
From: Mateusz Kwiatkowski <kwiat3k@panic.pl>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Truss may kill process
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         178664
>Category:       bin
>Synopsis:       truss(1) may kill process
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed May 15 14:20:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Wed Jul  3 21:20:02 UTC 2013
>Originator:     Mateusz Kwiatkowski
>Release:        9.1-RELEASE
>Organization:
>Environment:
FreeBSD stokrotka-v6 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243825: Tue Dec  4 09:23:10 UTC 2012     root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
Truss may kill process when attached to it. 
>How-To-Repeat:
# sleep 100 &
[1] 93212
# truss -p 93212
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0)
= 0 (0x0) sigprocmask(SIG_SETMASK,0x0,0x0)                 = 0 (0x0)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0)
= 0 (0x0) sigprocmask(SIG_SETMASK,0x0,0x0)                 = 0 (0x0)
process exit, rval = 0
[1]  + done       sleep 100

Sleep ends immediately instead of waiting 100 seconds.
>Fix:


>Release-Note:
>Audit-Trail:

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, kwiat3k@panic.pl
Cc:  
Subject: Re: bin/178664: truss(1) may kill process
Date: Sun, 19 May 2013 14:09:32 +0200

 In PR bin/178664, you wrote:
 > [attaching truss(1) may terminate sleep(1) early]
 
 What actually happens is that the nanosleep(2) system call fails with
 [EINTR] immediately when the debugger (ptrace(2)) attaches. You can
 verify this using ktrace(1).
 
 This is really a longstanding known bug, although I don't know where it
 is documented. It is longstanding because it is very hard to fix. The
 kernel wants threads to return to the kernel-userspace boundary when a
 debugger attaches, and this causes the state of the in-progress system
 call to be lost. The effect is much like a signal with SA_RESTART set.
 
 If you care about sleep(1) itself, that is easy to fix. It already
 continues the sleep when nanosleep(2) was interrupted by SIGINFO; this
 can be extended to any [EINTR] error.
 
 A workaround is to use ktrace(1) instead of truss(1) or strace(1) from
 ports. ktrace(1) generally affects the traced program much less.
 
 -- 
 Jilles Tjoelker

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/178664: commit references a PR
Date: Tue, 28 May 2013 22:07:48 +0000 (UTC)

 Author: jilles
 Date: Tue May 28 22:07:31 2013
 New Revision: 251078
 URL: http://svnweb.freebsd.org/changeset/base/251078
 
 Log:
   sleep: Improve nanosleep() error handling:
   
    * Work around kernel bugs that cause a spurious [EINTR] return if a
      debugger (such as truss(1)) is attached.
   
    * Write an error message if an error other than [EINTR] occurs.
   
   PR:		bin/178664
 
 Modified:
   head/bin/sleep/sleep.c
 
 Modified: head/bin/sleep/sleep.c
 ==============================================================================
 --- head/bin/sleep/sleep.c	Tue May 28 22:07:23 2013	(r251077)
 +++ head/bin/sleep/sleep.c	Tue May 28 22:07:31 2013	(r251078)
 @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
  
  #include <ctype.h>
  #include <err.h>
 +#include <errno.h>
  #include <limits.h>
  #include <signal.h>
  #include <stdint.h>
 @@ -87,8 +88,8 @@ main(int argc, char *argv[])
  			warnx("about %d second(s) left out of the original %d",
  			    (int)time_to_sleep.tv_sec, (int)original);
  			report_requested = 0;
 -		} else
 -			break;
 +		} else if (errno != EINTR)
 +			err(1, "nanosleep");
  	}
  	return (0);
  }
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/178664: commit references a PR
Date: Wed,  3 Jul 2013 21:12:09 +0000 (UTC)

 Author: jilles
 Date: Wed Jul  3 21:11:56 2013
 New Revision: 252606
 URL: http://svnweb.freebsd.org/changeset/base/252606
 
 Log:
   MFC r251078,r251433: sleep: Improve nanosleep() error handling:
   
    * Work around kernel bugs that cause a spurious [EINTR] return if a
      debugger (such as truss(1)) is attached.
   
    * Write an error message if an error other than [EINTR] occurs.
   
   PR:		bin/178664
 
 Modified:
   stable/9/bin/sleep/sleep.c
 Directory Properties:
   stable/9/bin/sleep/   (props changed)
 
 Modified: stable/9/bin/sleep/sleep.c
 ==============================================================================
 --- stable/9/bin/sleep/sleep.c	Wed Jul  3 21:07:02 2013	(r252605)
 +++ stable/9/bin/sleep/sleep.c	Wed Jul  3 21:11:56 2013	(r252606)
 @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
  
  #include <ctype.h>
  #include <err.h>
 +#include <errno.h>
  #include <limits.h>
  #include <signal.h>
  #include <stdint.h>
 @@ -81,14 +82,20 @@ main(int argc, char *argv[])
  	time_to_sleep.tv_nsec = 1e9 * (d - time_to_sleep.tv_sec);
  
  	signal(SIGINFO, report_request);
 +
 +	/*
 +	 * Note: [EINTR] is supposed to happen only when a signal was handled
 +	 * but the kernel also returns it when a ptrace-based debugger
 +	 * attaches. This is a bug but it is hard to fix.
 +	 */
  	while (nanosleep(&time_to_sleep, &time_to_sleep) != 0) {
  		if (report_requested) {
  			/* Reporting does not bother with nanoseconds. */
  			warnx("about %d second(s) left out of the original %d",
  			    (int)time_to_sleep.tv_sec, (int)original);
  			report_requested = 0;
 -		} else
 -			break;
 +		} else if (errno != EINTR)
 +			err(1, "nanosleep");
  	}
  	return (0);
  }
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
