From nobody@FreeBSD.ORG  Fri Jun  9 08:04:19 2000
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id 061C237C3E1; Fri,  9 Jun 2000 08:04:19 -0700 (PDT)
Message-Id: <20000609150419.061C237C3E1@hub.freebsd.org>
Date: Fri,  9 Jun 2000 08:04:19 -0700 (PDT)
From: billh@europe.yahoo-inc.com
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@FreeBSD.org
Subject: ps not annotatable in 4.0
X-Send-Pr-Version: www-1.0

>Number:         19145
>Category:       bin
>Synopsis:       ps not annotatable in 4.0
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jun 09 08:10:00 PDT 2000
>Closed-Date:    Mon Jun 12 02:48:46 PDT 2000
>Last-Modified:  Mon Jun 12 02:51:25 PDT 2000
>Originator:     Bill Hails
>Release:        4.0
>Organization:
Yahoo! Europe
>Environment:
FreeBSD pagegen7.europe.yahoo.com 4.0-YAHOO-20000510 FreeBSD 4.0-YAHOO-20000510 #0: Thu May 11 00:39:30 PDT 2000     root@fb40.yahoo.com:/home/src/sys/compile/YAHOO  i386

>Description:
the kvm_getargv function returns the original argv passed to the
process, ignoring any changes that the process may have made to
ARGV, in conflict with the manual page.
>How-To-Repeat:
create this C program, call it getargv.c, and compile with
cc -O -pipe  getargv.c  -lkvm -o getargv
#include <fcntl.h>
#include <kvm.h>
#include <sys/param.h>
#include <sys/user.h>
#include <sys/sysctl.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    kvm_t *kd;

    kd = kvm_open(NULL, "/dev/mem", NULL, O_RDONLY, "kvm_open:");

    if (kd != NULL) {
        int cnt;
        struct kinfo_proc *p = kvm_getprocs(kd, KERN_PROC_ALL, 0, &cnt);

        if (p != NULL) {
            int c;
            for (c = 0; c < cnt; ++c) {
                char **res = kvm_getargv(kd, p, 0);
                if (res) {
                    while (*res) {
                        printf("%s ", *res);
                        res++;
                    }
                    printf("\n");
                }
                else break;
                ++p;
            }
        } else {
            return(2);
        }
        kvm_close(kd);
    } else {
        return(1);
    }
    return(0);
}

then compile and run the following (call it argv0.c, "make argv0")

int main(int argc, char *argv[])
{
        argv[0] = "test";
        sleep(500);
        return(0);
}

in another window run the already compiled getargv as root.
When I do this I see that the argv0 process has not had its
ARGV[0] changed
>Fix:


>Release-Note:
>Audit-Trail:

From: Ruslan Ermilov <ru@sunbay.com>
To: billh@europe.yahoo-inc.com
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/19145: ps not annotatable in 4.0
Date: Fri, 9 Jun 2000 18:41:33 +0300

 On Fri, Jun 09, 2000 at 08:04:19AM -0700, billh@europe.yahoo-inc.com wrote:
 > 
 > create this C program, call it getargv.c, and compile with
 > cc -O -pipe  getargv.c  -lkvm -o getargv
 > 
 [...]
 > 
 > then compile and run the following (call it argv0.c, "make argv0")
 > 
 > int main(int argc, char *argv[])
 > {
 >         argv[0] = "test";
 >         sleep(500);
 >         return(0);
 > }
 > 
 Try to setproctitle(3) in argv0(1).
 
 -- 
 Ruslan Ermilov		Oracle Developer/DBA,
 ru@sunbay.com		Sunbay Software AG,
 ru@FreeBSD.org		FreeBSD committer,
 +380.652.512.251	Simferopol, Ukraine
 
 http://www.FreeBSD.org	The Power To Serve
 http://www.oracle.com	Enabling The Information Age
 

From: Poul-Henning Kamp <phk@critter.freebsd.dk>
To: billh@europe.yahoo-inc.com
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/19145: ps not annotatable in 4.0 
Date: Fri, 09 Jun 2000 20:43:03 +0200

 >then compile and run the following (call it argv0.c, "make argv0")
 >
 >int main(int argc, char *argv[])
 >{
 >        argv[0] = "test";
 >        sleep(500);
 >        return(0);
 >}
 
 Use setproctitle()
 
 --
 Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
 phk@FreeBSD.ORG         | TCP/IP since RFC 956
 FreeBSD coreteam member | BSD since 4.3-tahoe    
 Never attribute to malice what can adequately be explained by incompetence.
 

From: Jeroen Ruigrok/Asmodai <asmodai@wxs.nl>
To: billh@europe.yahoo-inc.com
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/19145: ps not annotatable in 4.0
Date: Sun, 11 Jun 2000 13:16:58 +0200

 -On [20000609 20:01], billh@europe.yahoo-inc.com (billh@europe.yahoo-inc.com) wrote:
 >
 >>Description:
 >the kvm_getargv function returns the original argv passed to the
 >process, ignoring any changes that the process may have made to
 >ARGV, in conflict with the manual page.
 
 Which manual page are you referring to?  kvm_getargv(3)?
 
 -- 
 Jeroen Ruigrok vd Werven/Asmodai    asmodai@[wxs.nl|bart.nl|freebsd.org]
 Documentation nutter/C-rated Coder BSD: Technical excellence at its best  
 The BSD Programmer's Documentation Project <http://home.wxs.nl/~asmodai>
 Necessity relieves us of the ordeal of choice...
 
State-Changed-From-To: open->closed 
State-Changed-By: ru 
State-Changed-When: Mon Jun 12 02:48:46 PDT 2000 
State-Changed-Why:  
On Mon, Jun 12, 2000 at 10:28:14AM +0100, Bill Hails wrote: 
> 
> Thanks very much for the info. We've just upgraded some of our boxes to 
> 4.0 and man -k argv didn't show up setproctitle. My real problem is 
> that in perl 5.6 assignment to $0 no longer has the desired effect, 
> and some of our monitor code relies on it. I'll have to code something 
> up with XS to tide us over. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=19145 
>Unformatted:
