From cejkar@dcse.fee.vutbr.cz  Wed Dec  9 10:48:27 1998
Received: from boco.fee.vutbr.cz (boco.fee.vutbr.cz [147.229.9.11])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id KAA12949
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 9 Dec 1998 10:48:24 -0800 (PST)
          (envelope-from cejkar@dcse.fee.vutbr.cz)
Received: from kazi.dcse.fee.vutbr.cz (kazi.dcse.fee.vutbr.cz [147.229.8.12])
	by boco.fee.vutbr.cz (8.9.1/8.9.1) with ESMTP id TAA80834
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 9 Dec 1998 19:48:11 +0100 (CET)
Received: (from cejkar@localhost)
	by kazi.dcse.fee.vutbr.cz (8.8.8/8.8.8) id TAA18006;
	Wed, 9 Dec 1998 19:48:06 +0100 (CET)
Message-Id: <199812091848.TAA18006@kazi.dcse.fee.vutbr.cz>
Date: Wed, 9 Dec 1998 19:48:06 +0100 (CET)
From: cejkar@dcse.fee.vutbr.cz
Reply-To: cejkar@dcse.fee.vutbr.cz
To: FreeBSD-gnats-submit@freebsd.org
Subject: Bad __progname content in ELF programs
X-Send-Pr-Version: 3.2

>Number:         9035
>Category:       bin
>Synopsis:       Bad __progname content in ELF programs
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec  9 10:50:00 PST 1998
>Closed-Date:    Thu Jan 7 12:20:38 PST 1999
>Last-Modified:  Thu Jan  7 12:21:28 PST 1999
>Originator:     Rudolf Cejka
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
FEE TU Brno, Czech Republic
>Environment:

	ELFoized current -current :-) [YY-MM-DD: 98-12-09]

>Description:

	For aout programs, __progname variable contains only program name.
	For ELF programs, __progname variable contains program name
	with full path (i386 & alpha).

	(
	There must be something wrong. If this difference is right you must
	fix at least manpage for err*()/warn*() or err*()/warn*() itself:

	... In all cases, the last component of the program name,
	a colon character, and a space are output ...

	... Which for ELF programs at this time doen't apply.
	)

>How-To-Repeat:

	Simple program test.c:

		#include <stdio.h>
		extern char *__progname;
		int main(void)
		{
			printf("%s\n", __progname);
			return 0;
		}

	gives there results:

	# gcc -aout -o test test.c
	# ./././test
	test
	# gcc -elf -o test test.c
	# ./././test
	./././test
	
>Fix:
	
	Patch is taken from /usr/src/lib/csu/i386/crt0.c. It isn't tested
	so you must review my patch!

	patch /usr/src/lib/csu/i386-elf/crt1.c:
	(You need similar patch for /usr/src/lib/csu/alpha/crt1.c!)

--- crt1.c	Wed Sep  9 10:11:21 1998
+++ /tmp/crt1.c.new	Wed Dec  9 19:43:17 1998
@@ -72,8 +72,13 @@
     argc = * (int *) (argv - 1);
     env = argv + argc + 1;
     environ = env;
-    if(argc > 0)
+    if(argc > 0 && argv[0]) {
+	register char *s;
 	__progname = argv[0];
+	for (s = __progname; *s != '\0'; s++)
+		if (*s == '/')
+			__progname = s + 1;
+    }
 
     if(&_DYNAMIC != 0)
 	atexit(rtld_cleanup);

--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--
Rudolf Cejka  (cejkar@dcse.fee.vutbr.cz;  http://www.fee.vutbr.cz/~cejkar)
Technical University of Brno, Faculty of El. Engineering and Comp. Science
Bozetechova 2, 612 66  Brno, Czech Republic
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: steve 
State-Changed-When: Thu Jan 7 12:20:38 PST 1999 
State-Changed-Why:  
Fixed in rev. 1.3 of src/lib/csu/i386-elf/crt1.c and src/lib/csu/alpha/crt1.c. 
>Unformatted:
