Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 May 2003 19:46:11 +0200 (CEST)
From:      Jilles Tjoelker <jilles@stack.nl>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   kern/52490: ^T'ing a zombie causes 'calcru: negative time' messages
Message-ID:  <20030520174611.4C53E1CC5D@turtle.stack.nl>
Resent-Message-ID: <200305201750.h4KHo8wa094693@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         52490
>Category:       kern
>Synopsis:       ^T'ing a zombie causes 'calcru: negative time' messages
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 20 10:50:08 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     Jilles Tjoelker
>Release:        FreeBSD 5.1-BETA i386
>Organization:
>Environment:
System: FreeBSD turtle.stack.nl 5.1-BETA FreeBSD 5.1-BETA #10: Mon May 12 15:30:54 CEST 2003 jilles@turtle.stack.nl:/usr/obj/usr/src/sys/TURTLE i386

It occurs on 4.8-RELEASE and many older 4.x versions as well.
>Description:
When ^T'ing (ttyinfo) a zombie, calcru() is called and logs a 'negative time'
message. To achieve this, only zombies must be in the foreground process group
of the terminal.
>How-To-Repeat:
Compile and run the negtime program. Pressing ^T after it has printed the
message 'done' causes a log message 'calcru: negative time...'. (It may be
necessary to do stty status ^t beforehand.)
>Fix:
A patch (against 4-STABLE) is attached which prevents calcru() from being
called on zombies from ttyinfo(). I don't know in what process states calcru()
may be called exactly, but for the rest of /sys/kern it's only used for
accounting, exiting and getrusage() and therefore cannot be called on zombies.
(Perhaps this is or should be documented somewhere.)

--- negtime.c begins here ---
/* Copyright (C) 2001 by Jilles Tjoelker */

#include	<sys/types.h>
#include	<stdio.h>
#include	<signal.h>
#include	<unistd.h>

int
main(int argc, char *argv[])
{
    int pid,pgid;

    if (argc != 1)
    {
	fprintf(stderr, "Usage: %s\n", argv[0]);
	return(1);
    }

    switch (pid=fork())
    {
	case 0:
	    signal(SIGTTOU,SIG_IGN);
	    pid=getpid();
	    pgid=getpgrp();
	    if (setpgid(pid,pid)==-1)
	    {
		perror("Error in setpgid()");
		_exit(1);
	    }
	    if (tcsetpgrp(0,pid)==-1)
	    {
		setpgid(pid,pgid);
		perror("Error in tcsetpgrp()");
		_exit(2);
	    }
	    sleep(1);
	    printf("done\n");
	    _exit(127);
	    break;

	case -1:
	    fprintf(stderr, "Error in fork().\n");
	    break;

	default:
	    sleep(10);
    }
    return 0;
}

/* vim:ts=8:cin:sw=4:kp=man\ -S3\:2\:9\:1\:4\:5\:6\:7\:8\:n
    */
--- negtime.c ends here ---

--- ttyinfo_zombie.patch begins here ---
--- /usr/src/sys/kern/tty.c.orig	Mon Mar 11 02:32:31 2002
+++ /usr/src/sys/kern/tty.c	Sun Jan 19 21:40:16 2003
@@ -2323,7 +2323,7 @@
 		    pick->p_stat == SRUN ? "running" :
 		    pick->p_wmesg ? pick->p_wmesg : "iowait");
 
-		if (pick->p_flag & P_INMEM) {
+		if (pick->p_flag & P_INMEM && pick->p_stat != SZOMB) {
 			calcru(pick, &utime, &stime, NULL);
 
 			/* Print user time. */
--- ttyinfo_zombie.patch ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030520174611.4C53E1CC5D>