From owner-freebsd-audit Sun Mar 24 11:27:11 2002 Delivered-To: freebsd-audit@freebsd.org Received: from greenpeace.grondar.org (grondar.demon.co.uk [158.152.143.227]) by hub.freebsd.org (Postfix) with ESMTP id 35B6137B400 for ; Sun, 24 Mar 2002 11:26:43 -0800 (PST) Received: from greenpeace (localhost [127.0.0.1]) by greenpeace.grondar.org (8.12.2/8.12.2) with ESMTP id g2OJQeER032292 for ; Sun, 24 Mar 2002 19:26:40 GMT (envelope-from root@greenpeace.grondar.org) Message-Id: <200203241926.g2OJQeER032292@greenpeace.grondar.org> To: audit@freebsd.org Subject: src/lib __progname cleanup ; review please From: markm@freebsd.org Date: Sun, 24 Mar 2002 19:26:34 +0000 Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Index: csu/alpha/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/alpha/crt1.c,v retrieving revision 1.10 diff -u -d -r1.10 crt1.c --- csu/alpha/crt1.c 26 Oct 2001 06:45:10 -0000 1.10 +++ csu/alpha/crt1.c 24 Mar 2002 17:53:45 -0000 @@ -40,6 +40,7 @@ #endif #include +#include "../../libc/include/libc_private.h" #include "crtbrand.c" struct Struct_Obj_Entry; @@ -60,7 +61,7 @@ #endif char **environ; -char *__progname = ""; +const char *__progname = ""; /* The entry function. */ void Index: csu/i386/crt0.c =================================================================== RCS file: /home/ncvs/src/lib/csu/i386/crt0.c,v retrieving revision 1.36 diff -u -d -r1.36 crt0.c --- csu/i386/crt0.c 27 Aug 1999 23:57:55 -0000 1.36 +++ csu/i386/crt0.c 24 Mar 2002 17:54:05 -0000 @@ -42,6 +42,8 @@ #include #include +#include "../../libc/include/libc_private.h" + /* !!! * This is gross, ld.so is a ZMAGIC a.out, but has `sizeof(hdr)' for * an entry point and not at PAGSIZ as the N_*ADDR macros assume. @@ -89,7 +91,7 @@ int _callmain(); int errno; static char empty[1]; -char *__progname = empty; +const char *__progname = empty; char **environ; /* Globals used by dlopen() and related functions in libc */ Index: csu/i386-elf/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/i386-elf/crt1.c,v retrieving revision 1.6 diff -u -d -r1.6 crt1.c --- csu/i386-elf/crt1.c 27 Feb 2002 22:08:05 -0000 1.6 +++ csu/i386-elf/crt1.c 24 Mar 2002 17:53:54 -0000 @@ -29,6 +29,7 @@ #include #include +#include "../../libc/include/libc_private.h" #include "crtbrand.c" typedef void (*fptr)(void); @@ -57,7 +58,7 @@ #endif char **environ; -char *__progname = ""; +const char *__progname = ""; void _start(char *arguments, ...) @@ -73,7 +74,7 @@ env = argv + argc + 1; environ = env; if (argc > 0 && argv[0] != NULL) { - char *s; + const char *s; __progname = argv[0]; for (s = __progname; *s != '\0'; s++) if (*s == '/') Index: csu/ia64/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/ia64/crt1.c,v retrieving revision 1.6 diff -u -d -r1.6 crt1.c --- csu/ia64/crt1.c 23 Mar 2002 18:14:20 -0000 1.6 +++ csu/ia64/crt1.c 24 Mar 2002 17:54:27 -0000 @@ -36,6 +36,7 @@ #endif #include +#include "../../libc/include/libc_private.h" #include "crtbrand.c" struct Struct_Obj_Entry; @@ -56,7 +57,7 @@ #endif char **environ; -char *__progname = ""; +const char *__progname = ""; /* The entry function. */ void Index: csu/powerpc/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/powerpc/crt1.c,v retrieving revision 1.7 diff -u -d -r1.7 crt1.c --- csu/powerpc/crt1.c 23 Mar 2002 18:14:04 -0000 1.7 +++ csu/powerpc/crt1.c 24 Mar 2002 17:54:37 -0000 @@ -43,6 +43,7 @@ #endif #include +#include "../../libc/include/libc_private.h" #include "crtbrand.c" struct Struct_Obj_Entry; @@ -63,7 +64,7 @@ #endif char **environ; -char *__progname = ""; +const char *__progname = ""; struct ps_strings *__ps_strings; /* The entry function. Index: csu/sparc64/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/sparc64/crt1.c,v retrieving revision 1.6 diff -u -d -r1.6 crt1.c --- csu/sparc64/crt1.c 16 Mar 2002 20:38:46 -0000 1.6 +++ csu/sparc64/crt1.c 24 Mar 2002 17:54:46 -0000 @@ -34,6 +34,7 @@ #endif #include +#include "../../libc/include/libc_private.h" #include "crtbrand.c" struct Struct_Obj_Entry; @@ -55,7 +56,7 @@ #endif char **environ; -char *__progname = ""; +const char *__progname = ""; /* The entry function. */ /* Index: libc/gen/err.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/err.c,v retrieving revision 1.12 diff -u -d -r1.12 err.c --- libc/gen/err.c 22 Mar 2002 21:52:05 -0000 1.12 +++ libc/gen/err.c 24 Mar 2002 13:42:26 -0000 @@ -47,8 +47,6 @@ #include -extern char *__progname; /* Program name, from crt0. */ - static FILE *err_file; /* file to use for error output */ static void (*err_exit)(int); @@ -110,7 +108,7 @@ { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", __progname); + fprintf(err_file, "%s: ", getprogname()); if (fmt != NULL) { vfprintf(err_file, fmt, ap); fprintf(err_file, ": "); @@ -138,7 +136,7 @@ { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", __progname); + fprintf(err_file, "%s: ", getprogname()); if (fmt != NULL) vfprintf(err_file, fmt, ap); fprintf(err_file, "\n"); @@ -183,7 +181,7 @@ { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", __progname); + fprintf(err_file, "%s: ", getprogname()); if (fmt != NULL) { vfprintf(err_file, fmt, ap); fprintf(err_file, ": "); @@ -207,7 +205,7 @@ { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", __progname); + fprintf(err_file, "%s: ", getprogname()); if (fmt != NULL) vfprintf(err_file, fmt, ap); fprintf(err_file, "\n"); Index: libc/gen/getprogname.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/getprogname.c,v retrieving revision 1.3 diff -u -d -r1.3 getprogname.c --- libc/gen/getprogname.c 1 Feb 2002 00:57:29 -0000 1.3 +++ libc/gen/getprogname.c 24 Mar 2002 17:47:44 -0000 @@ -3,7 +3,7 @@ #include -extern const char *__progname; +#include "../include/libc_private.h" const char * getprogname(void) Index: libc/gen/setproctitle.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/setproctitle.c,v retrieving revision 1.15 diff -u -d -r1.15 setproctitle.c --- libc/gen/setproctitle.c 1 Feb 2002 00:57:29 -0000 1.15 +++ libc/gen/setproctitle.c 24 Mar 2002 13:44:07 -0000 @@ -53,7 +53,6 @@ #include #define SPT_BUFSIZE 2048 /* from other parts of sendmail */ -extern char * __progname; /* is this defined in a .h anywhere? */ void setproctitle(const char *fmt, ...) @@ -83,7 +82,7 @@ len = 0; } else { /* print program name heading for grep */ - (void) snprintf(buf, sizeof(buf), "%s: ", __progname); + (void)snprintf(buf, sizeof(buf), "%s: ", getprogname()); len = strlen(buf); } Index: libc/gen/setprogname.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/setprogname.c,v retrieving revision 1.7 diff -u -d -r1.7 setprogname.c --- libc/gen/setprogname.c 1 Feb 2002 00:57:29 -0000 1.7 +++ libc/gen/setprogname.c 24 Mar 2002 17:48:00 -0000 @@ -4,7 +4,7 @@ #include #include -extern const char *__progname; +#include "../include/libc_private.h" void setprogname(const char *progname) Index: libc/gen/syslog.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/syslog.c,v retrieving revision 1.25 diff -u -d -r1.25 syslog.c --- libc/gen/syslog.c 9 Mar 2002 11:38:01 -0000 1.25 +++ libc/gen/syslog.c 24 Mar 2002 13:44:30 -0000 @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -67,7 +68,6 @@ static const char *LogTag = NULL; /* string to tag the entry with */ static int LogFacility = LOG_USER; /* default facility code */ static int LogMask = 0xff; /* mask of priorities to be logged */ -extern char *__progname; /* Program name, from crt0. */ static void disconnectlog(void); /* disconnect from syslogd */ static void connectlog(void); /* (re)connect to syslogd */ @@ -181,7 +181,7 @@ stdp = tbuf + (sizeof(tbuf) - tbuf_cookie.left); } if (LogTag == NULL) - LogTag = __progname; + LogTag = getprogname(); if (LogTag != NULL) (void)fprintf(fp, "%s", LogTag); if (LogStat & LOG_PID) Index: libc/gmon/gmon.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gmon/gmon.c,v retrieving revision 1.13 diff -u -d -r1.13 gmon.c --- libc/gmon/gmon.c 15 Feb 2002 02:37:08 -0000 1.13 +++ libc/gmon/gmon.c 24 Mar 2002 13:47:42 -0000 @@ -46,8 +46,9 @@ #include "namespace.h" #include #include "un-namespace.h" -#include #include +#include +#include #include #include #include "un-namespace.h" @@ -58,8 +59,6 @@ extern char *minbrk asm ("minbrk"); #endif -extern char *__progname; - struct gmonparam _gmonparam = { GMON_PROF_OFF }; static int s_scale; @@ -175,7 +174,7 @@ } moncontrol(0); - snprintf(outname, sizeof(outname), "%s.gmon", __progname); + snprintf(outname, sizeof(outname), "%s.gmon", getprogname()); fd = _open(outname, O_CREAT|O_TRUNC|O_WRONLY, 0666); if (fd < 0) { _warn("_mcleanup: %s", outname); Index: libc/include/libc_private.h =================================================================== RCS file: /home/ncvs/src/lib/libc/include/libc_private.h,v retrieving revision 1.4 diff -u -d -r1.4 libc_private.h --- libc/include/libc_private.h 24 Jan 2001 13:00:08 -0000 1.4 +++ libc/include/libc_private.h 24 Mar 2002 17:50:22 -0000 @@ -63,4 +63,9 @@ #define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) #define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp) +/* + * Used in the C Run-Time startup + */ +extern const char *__progname; + #endif /* _LIBC_PRIVATE_H_ */ Index: libc/locale/collate.c =================================================================== RCS file: /home/ncvs/src/lib/libc/locale/collate.c,v retrieving revision 1.23 diff -u -d -r1.23 collate.c --- libc/locale/collate.c 22 Mar 2002 21:52:18 -0000 1.23 +++ libc/locale/collate.c 24 Mar 2002 13:48:10 -0000 @@ -176,11 +176,10 @@ void __collate_err(int ex, const char *f) { - extern char *__progname; /* Program name, from crt0. */ const char *s; int serrno = errno; - s = __progname; + s = getprogname(); _write(STDERR_FILENO, s, strlen(s)); _write(STDERR_FILENO, ": ", 2); s = f; Index: libc/stdlib/getopt.c =================================================================== RCS file: /home/ncvs/src/lib/libc/stdlib/getopt.c,v retrieving revision 1.5 diff -u -d -r1.5 getopt.c --- libc/stdlib/getopt.c 22 Mar 2002 21:53:10 -0000 1.5 +++ libc/stdlib/getopt.c 24 Mar 2002 13:49:11 -0000 @@ -61,7 +61,6 @@ char * const *nargv; const char *ostr; { - extern char *__progname; static char *place = EMSG; /* option letter processing */ char *oli; /* option letter list index */ @@ -88,8 +87,8 @@ if (!*place) ++optind; if (opterr && *ostr != ':' && optopt != BADCH) - (void)fprintf(stderr, - "%s: illegal option -- %c\n", __progname, optopt); + (void)fprintf(stderr, "%s: illegal option -- %c\n", + getprogname(), optopt); return (BADCH); } if (*++oli != ':') { /* don't need argument */ @@ -107,7 +106,7 @@ if (opterr) (void)fprintf(stderr, "%s: option requires an argument -- %c\n", - __progname, optopt); + getprogname(), optopt); return (BADCH); } else /* white space */ Index: libc/stdlib/malloc.c =================================================================== RCS file: /home/ncvs/src/lib/libc/stdlib/malloc.c,v retrieving revision 1.66 diff -u -d -r1.66 malloc.c --- libc/stdlib/malloc.c 22 Mar 2002 21:53:10 -0000 1.66 +++ libc/stdlib/malloc.c 24 Mar 2002 13:49:57 -0000 @@ -297,14 +297,12 @@ void (*_malloc_message)(char *p1, char *p2, char *p3, char *p4) = wrtmessage; -extern char *__progname; - static void wrterror(char *p) { suicide = 1; - _malloc_message(__progname, malloc_func, " error: ", p); + _malloc_message(getprogname(), malloc_func, " error: ", p); abort(); } @@ -314,7 +312,7 @@ if (malloc_abort) wrterror(p); - _malloc_message(__progname, malloc_func, " warning: ", p); + _malloc_message(getprogname(), malloc_func, " warning: ", p); } /* Index: libc_r/uthread/uthread_spinlock.c =================================================================== RCS file: /home/ncvs/src/lib/libc_r/uthread/uthread_spinlock.c,v retrieving revision 1.9 diff -u -d -r1.9 uthread_spinlock.c --- libc_r/uthread/uthread_spinlock.c 24 Jan 2001 13:03:36 -0000 1.9 +++ libc_r/uthread/uthread_spinlock.c 24 Mar 2002 14:00:10 -0000 @@ -33,14 +33,14 @@ * */ +#include #include +#include #include -#include #include -#include -#include "pthread_private.h" +#include -extern char *__progname; +#include "pthread_private.h" /* * Lock a location for the running thread. Yield to allow other @@ -91,7 +91,7 @@ cnt++; if (cnt > 100) { char str[256]; - snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", __progname, curthread, lck, fname, lineno, lck->fname, lck->lineno); + snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", getprogname(), curthread, lck, fname, lineno, lck->fname, lck->lineno); __sys_write(2,str,strlen(str)); __sleep(1); cnt = 0; Index: libfetch/http.c =================================================================== RCS file: /home/ncvs/src/lib/libfetch/http.c,v retrieving revision 1.51 diff -u -d -r1.51 http.c --- libfetch/http.c 5 Feb 2002 22:13:51 -0000 1.51 +++ libfetch/http.c 24 Mar 2002 13:52:48 -0000 @@ -80,8 +80,6 @@ #include "common.h" #include "httperr.h" -extern char *__progname; /* XXX not portable */ - /* Maximum number of redirects to follow */ #define MAX_REDIRECT 5 @@ -840,7 +838,7 @@ if ((p = getenv("HTTP_USER_AGENT")) != NULL && *p != '\0') _http_cmd(fd, "User-Agent: %s", p); else - _http_cmd(fd, "User-Agent: %s " _LIBFETCH_VER, __progname); + _http_cmd(fd, "User-Agent: %s " _LIBFETCH_VER, getprogname()); if (url->offset) _http_cmd(fd, "Range: bytes=%lld-", (long long)url->offset); _http_cmd(fd, "Connection: close"); Index: libncp/ncpl_subr.c =================================================================== RCS file: /home/ncvs/src/lib/libncp/ncpl_subr.c,v retrieving revision 1.5 diff -u -d -r1.5 ncpl_subr.c --- libncp/ncpl_subr.c 30 Sep 2001 22:01:19 -0000 1.5 +++ libncp/ncpl_subr.c 24 Mar 2002 14:00:40 -0000 @@ -51,8 +51,6 @@ /*#include */ #include "ncp_mod.h" -extern char *__progname; - int sysentoffset; void @@ -309,7 +307,7 @@ ++ncp_optind; if (ncp_opterr && *ostr != ':') (void)fprintf(stderr, - "%s: illegal option -- %c\n", __progname, ncp_optopt); + "%s: illegal option -- %c\n", getprogname(), ncp_optopt); return (BADCH); } if (*++oli != ':') { /* don't need argument */ @@ -327,7 +325,7 @@ if (ncp_opterr) (void)fprintf(stderr, "%s: option requires an argument -- %c\n", - __progname, ncp_optopt); + getprogname(), ncp_optopt); return (BADCH); } else /* white space */ @@ -439,7 +437,7 @@ ncp_error(const char *fmt, int error, ...) { va_list ap; - fprintf(stderr, "%s: ", __progname); + fprintf(stderr, "%s: ", getprogname()); va_start(ap, error); vfprintf(stderr, fmt, ap); va_end(ap); To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Mon Mar 25 3:41:44 2002 Delivered-To: freebsd-audit@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 6498E37B419; Mon, 25 Mar 2002 03:41:38 -0800 (PST) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id WAA28987; Mon, 25 Mar 2002 22:41:35 +1100 Date: Mon, 25 Mar 2002 22:42:01 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: markm@FreeBSD.ORG Cc: audit@FreeBSD.ORG Subject: Re: src/lib __progname cleanup ; review please In-Reply-To: <200203241926.g2OJQeER032292@greenpeace.grondar.org> Message-ID: <20020325221929.W879-100000@gamplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Sun, 24 Mar 2002 markm@FreeBSD.ORG wrote: > ... > Index: csu/i386/crt0.c > =================================================================== > RCS file: /home/ncvs/src/lib/csu/i386/crt0.c,v > retrieving revision 1.36 > diff -u -d -r1.36 crt0.c > --- csu/i386/crt0.c 27 Aug 1999 23:57:55 -0000 1.36 > +++ csu/i386/crt0.c 24 Mar 2002 17:54:05 -0000 > ... > @@ -89,7 +91,7 @@ > int _callmain(); > int errno; > static char empty[1]; > -char *__progname = empty; > +const char *__progname = empty; Why is the empty string spelled differently on i386's (aout case) only? > Index: csu/i386-elf/crt1.c > =================================================================== > RCS file: /home/ncvs/src/lib/csu/i386-elf/crt1.c,v > retrieving revision 1.6 > diff -u -d -r1.6 crt1.c > --- csu/i386-elf/crt1.c 27 Feb 2002 22:08:05 -0000 1.6 > +++ csu/i386-elf/crt1.c 24 Mar 2002 17:53:54 -0000 > ... > @@ -73,7 +74,7 @@ > env = argv + argc + 1; > environ = env; > if (argc > 0 && argv[0] != NULL) { > - char *s; > + const char *s; This change is missing in most places. You might fix the style bugs involving this line when changing it. > ... > Index: libc/gen/err.c > =================================================================== > RCS file: /home/ncvs/src/lib/libc/gen/err.c,v > retrieving revision 1.12 > diff -u -d -r1.12 err.c > --- libc/gen/err.c 22 Mar 2002 21:52:05 -0000 1.12 > +++ libc/gen/err.c 24 Mar 2002 13:42:26 -0000 > ... > @@ -110,7 +108,7 @@ > { > if (err_file == 0) > err_set_file((FILE *)0); > - fprintf(err_file, "%s: ", __progname); > + fprintf(err_file, "%s: ", getprogname()); A version of getprogname() that is not in the application namespace should be used, since some members of the err() family are called internally in libc. Similarly elsewhere. This is even more imporartant in Standard functions like malloc() and getopt(). > ... > Index: libc/gen/getprogname.c > =================================================================== > RCS file: /home/ncvs/src/lib/libc/gen/getprogname.c,v > retrieving revision 1.3 > diff -u -d -r1.3 getprogname.c > --- libc/gen/getprogname.c 1 Feb 2002 00:57:29 -0000 1.3 > +++ libc/gen/getprogname.c 24 Mar 2002 17:47:44 -0000 > @@ -3,7 +3,7 @@ > > #include > > -extern const char *__progname; > +#include "../include/libc_private.h" Bogus path. The path to libc_private.h is in CFLAGS, and every other include of libc_private.h in libc/gen depends on this. Similarly elsewhere. > Index: libc/include/libc_private.h > =================================================================== > RCS file: /home/ncvs/src/lib/libc/include/libc_private.h,v > retrieving revision 1.4 > diff -u -d -r1.4 libc_private.h > --- libc/include/libc_private.h 24 Jan 2001 13:00:08 -0000 1.4 > +++ libc/include/libc_private.h 24 Mar 2002 17:50:22 -0000 > @@ -63,4 +63,9 @@ > #define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) > #define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp) > > +/* > + * Used in the C Run-Time startup > + */ Should be an English sentence in a non-block comment. > ... > Index: libc_r/uthread/uthread_spinlock.c > =================================================================== > RCS file: /home/ncvs/src/lib/libc_r/uthread/uthread_spinlock.c,v > retrieving revision 1.9 > diff -u -d -r1.9 uthread_spinlock.c > --- libc_r/uthread/uthread_spinlock.c 24 Jan 2001 13:03:36 -0000 1.9 > +++ libc_r/uthread/uthread_spinlock.c 24 Mar 2002 14:00:10 -0000 > ... > @@ -91,7 +91,7 @@ > cnt++; > if (cnt > 100) { > char str[256]; > - snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", __progname, curthread, lck, fname, lineno, lck->fname, lck->lineno); > + snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", getprogname(), curthread, lck, fname, lineno, lck->fname, lck->lineno); Disgustingly long line in both suce and output (old bug). Now longer than before. Similarly elsewhere. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Mon Mar 25 4:40:18 2002 Delivered-To: freebsd-audit@freebsd.org Received: from storm.FreeBSD.org.uk (storm.FreeBSD.org.uk [194.242.139.170]) by hub.freebsd.org (Postfix) with ESMTP id 2A2B237B400 for ; Mon, 25 Mar 2002 04:40:13 -0800 (PST) Received: (from uucp@localhost) by storm.FreeBSD.org.uk (8.11.6/8.11.6) with UUCP id g2PCe3M23881; Mon, 25 Mar 2002 12:40:03 GMT (envelope-from mark@grimreaper.grondar.za) Received: from grimreaper (localhost [127.0.0.1]) by grimreaper.grondar.org (8.12.2/8.12.2) with ESMTP id g2PCc8xG002769; Mon, 25 Mar 2002 12:38:08 GMT (envelope-from mark@grimreaper.grondar.za) Message-Id: <200203251238.g2PCc8xG002769@grimreaper.grondar.org> To: Bruce Evans Cc: audit@FreeBSD.ORG Subject: Re: src/lib __progname cleanup ; review please References: <20020325221929.W879-100000@gamplex.bde.org> In-Reply-To: <20020325221929.W879-100000@gamplex.bde.org> ; from Bruce Evans "Mon, 25 Mar 2002 22:42:01 +1100." Date: Mon, 25 Mar 2002 12:38:08 +0000 From: Mark Murray Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > > -char *__progname = empty; > > +const char *__progname = empty; > > Why is the empty string spelled differently on i386's (aout case) only? I assume you mean "blank"? Changed to that. > > - char *s; > > + const char *s; > > This change is missing in most places. Fixed. > You might fix the style bugs involving this line when changing it. If "style bugs" mean the declaration should be moved to the top of the function, then fixed. > > Index: libc/gen/err.c > > =================================================================== > > RCS file: /home/ncvs/src/lib/libc/gen/err.c,v > > retrieving revision 1.12 > > diff -u -d -r1.12 err.c > > --- libc/gen/err.c 22 Mar 2002 21:52:05 -0000 1.12 > > +++ libc/gen/err.c 24 Mar 2002 13:42:26 -0000 > > ... > > @@ -110,7 +108,7 @@ > > { > > if (err_file == 0) > > err_set_file((FILE *)0); > > - fprintf(err_file, "%s: ", __progname); > > + fprintf(err_file, "%s: ", getprogname()); > > A version of getprogname() that is not in the application namespace > should be used, since some members of the err() family are called > internally in libc. Similarly elsewhere. This is even more imporartant > in Standard functions like malloc() and getopt(). I don't understand this. > > -extern const char *__progname; > > +#include "../include/libc_private.h" > > Bogus path. The path to libc_private.h is in CFLAGS, and every other > include of libc_private.h in libc/gen depends on this. Similarly > elsewhere. Fixed. ("Elsewhere" == libc only, right?) M -- o Mark Murray \_ O.\_ Warning: this .sig is umop ap!sdn To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Mon Mar 25 9:16:42 2002 Delivered-To: freebsd-audit@freebsd.org Received: from flood.ping.uio.no (flood.ping.uio.no [129.240.78.31]) by hub.freebsd.org (Postfix) with ESMTP id D2ADB37B400 for ; Mon, 25 Mar 2002 09:16:38 -0800 (PST) Received: by flood.ping.uio.no (Postfix, from userid 2602) id 682585346; Mon, 25 Mar 2002 18:16:34 +0100 (CET) X-URL: http://www.ofug.org/~des/ X-Disclaimer: The views expressed in this message do not necessarily coincide with those of any organisation or company with which I am or have been affiliated. To: Mark Murray Cc: Bruce Evans , audit@FreeBSD.ORG Subject: Re: src/lib __progname cleanup ; review please References: <20020325221929.W879-100000@gamplex.bde.org> <200203251238.g2PCc8xG002769@grimreaper.grondar.org> From: Dag-Erling Smorgrav Date: 25 Mar 2002 18:16:34 +0100 In-Reply-To: <200203251238.g2PCc8xG002769@grimreaper.grondar.org> Message-ID: Lines: 21 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Mark Murray writes: > > A version of getprogname() that is not in the application namespace > > should be used, since some members of the err() family are called > > internally in libc. Similarly elsewhere. This is even more imporartant > > in Standard functions like malloc() and getopt(). > I don't understand this. The name "getprogname" is in the application namespace. If an application that calls err(3) (directly or indirectly) defines a non-static function or variable called getprogname, then err(3) will use that instead of the "real" getprogname(), possibly with very unpleasant consequences. You should therefore rename getprogname() to _getprogname(), which is in the implementation namespace, use only _getprogname() internally in libc, and add getprogname() as a weak alias for _getprogname() like this: __weak_alias(getprogname, _getprogname) DES -- Dag-Erling Smorgrav - des@ofug.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Mon Mar 25 15:43:21 2002 Delivered-To: freebsd-audit@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 43CA937B49B for ; Mon, 25 Mar 2002 15:42:54 -0800 (PST) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id KAA14651; Tue, 26 Mar 2002 10:41:45 +1100 Date: Tue, 26 Mar 2002 10:42:12 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Mark Murray Cc: audit@FreeBSD.ORG Subject: Re: src/lib __progname cleanup ; review please In-Reply-To: <200203251238.g2PCc8xG002769@grimreaper.grondar.org> Message-ID: <20020326103726.F3046-100000@gamplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Mon, 25 Mar 2002, Mark Murray wrote: > > > -char *__progname = empty; > > > +const char *__progname = empty; > > > > Why is the empty string spelled differently on i386's (aout case) only? > > I assume you mean "blank"? Changed to that. No, I mean the empty string (""). > > > - char *s; > > > + const char *s; > > > > This change is missing in most places. > > Fixed. > > > You might fix the style bugs involving this line when changing it. > > If "style bugs" mean the declaration should be moved to the top > of the function, then fixed. No, I meant style bugs in plural. There is at least one more (a larger one): missing blank line after declarations. > > > Index: libc/gen/err.c > > > =================================================================== > > > RCS file: /home/ncvs/src/lib/libc/gen/err.c,v > > > retrieving revision 1.12 > > > diff -u -d -r1.12 err.c > > > --- libc/gen/err.c 22 Mar 2002 21:52:05 -0000 1.12 > > > +++ libc/gen/err.c 24 Mar 2002 13:42:26 -0000 > > > ... > > > @@ -110,7 +108,7 @@ > > > { > > > if (err_file == 0) > > > err_set_file((FILE *)0); > > > - fprintf(err_file, "%s: ", __progname); > > > + fprintf(err_file, "%s: ", getprogname()); > > > > A version of getprogname() that is not in the application namespace > > should be used, since some members of the err() family are called > > internally in libc. Similarly elsewhere. This is even more imporartant > > in Standard functions like malloc() and getopt(). > > I don't understand this. Standard functions can't call ones in the application namespace because the application migh have a function of that name. getprogname() is in the application namespace. See my commits for namespace de-pollution of some members of the err() family. > > > -extern const char *__progname; > > > +#include "../include/libc_private.h" > > > > Bogus path. The path to libc_private.h is in CFLAGS, and every other > > include of libc_private.h in libc/gen depends on this. Similarly > > elsewhere. > > Fixed. ("Elsewhere" == libc only, right?) "Elsewhere" == in other parts of your patch. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Tue Mar 26 0:25:21 2002 Delivered-To: freebsd-audit@freebsd.org Received: from storm.FreeBSD.org.uk (storm.FreeBSD.org.uk [194.242.139.170]) by hub.freebsd.org (Postfix) with ESMTP id 8FB3C37B400 for ; Tue, 26 Mar 2002 00:25:11 -0800 (PST) Received: (from uucp@localhost) by storm.FreeBSD.org.uk (8.11.6/8.11.6) with UUCP id g2Q8P8v88985; Tue, 26 Mar 2002 08:25:08 GMT (envelope-from mark@grimreaper.grondar.za) Received: from grimreaper (localhost [127.0.0.1]) by grimreaper.grondar.org (8.12.2/8.12.2) with ESMTP id g2Q8OrxG078620; Tue, 26 Mar 2002 08:24:54 GMT (envelope-from mark@grimreaper.grondar.za) Message-Id: <200203260824.g2Q8OrxG078620@grimreaper.grondar.org> To: Dag-Erling Smorgrav Cc: audit@FreeBSD.ORG Subject: Re: src/lib __progname cleanup ; review please References: In-Reply-To: ; from Dag-Erling Smorgrav "25 Mar 2002 18:16:34 +0100." Date: Tue, 26 Mar 2002 08:24:53 +0000 From: Mark Murray Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > The name "getprogname" is in the application namespace. If an > application that calls err(3) (directly or indirectly) defines a > non-static function or variable called getprogname, then err(3) will > use that instead of the "real" getprogname(), possibly with very > unpleasant consequences. You should therefore rename getprogname() to > _getprogname(), which is in the implementation namespace, use only > _getprogname() internally in libc, and add getprogname() as a weak > alias for _getprogname() like this: > > __weak_alias(getprogname, _getprogname) This does not work (getprogname is not in the library, whereas _getprogname is). If I grep -r for __weak_alias, I only find what looks like deprecated uses in libraries. It is not documented or declared anywhere else. M -- o Mark Murray \_ O.\_ Warning: this .sig is umop ap!sdn To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Tue Mar 26 5:24:38 2002 Delivered-To: freebsd-audit@freebsd.org Received: from greenpeace.grondar.org (grondar.demon.co.uk [158.152.143.227]) by hub.freebsd.org (Postfix) with ESMTP id AF37337B400 for ; Tue, 26 Mar 2002 05:23:55 -0800 (PST) Received: from greenpeace (localhost [127.0.0.1]) by greenpeace.grondar.org (8.12.2/8.12.2) with ESMTP id g2QDNmER049112 for ; Tue, 26 Mar 2002 13:23:49 GMT (envelope-from root@greenpeace.grondar.org) Message-Id: <200203261323.g2QDNmER049112@greenpeace.grondar.org> To: audit@freebsd.org Subject: Library __progname cleanups - commit candidate From: markm@freebsd.org Date: Tue, 26 Mar 2002 13:23:42 +0000 Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Index: csu/alpha/Makefile =================================================================== RCS file: /home/ncvs/src/lib/csu/alpha/Makefile,v retrieving revision 1.16 diff -u -d -r1.16 Makefile --- csu/alpha/Makefile 27 Oct 2001 08:29:51 -0000 1.16 +++ csu/alpha/Makefile 26 Mar 2002 12:09:52 -0000 @@ -6,7 +6,8 @@ OBJS= ${SRCS:N*.h:R:S/$/.o/g} OBJS+= gcrt1.o CFLAGS+= -Wall -Wno-unused \ - -I${.CURDIR}/../common + -I${.CURDIR}/../common \ + -I${.CURDIR}/../../libc/include NOMAN= true NOPIC= true NOPROFILE= true Index: csu/alpha/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/alpha/crt1.c,v retrieving revision 1.10 diff -u -d -r1.10 crt1.c --- csu/alpha/crt1.c 26 Oct 2001 06:45:10 -0000 1.10 +++ csu/alpha/crt1.c 26 Mar 2002 12:11:31 -0000 @@ -40,6 +40,7 @@ #endif #include +#include #include "crtbrand.c" struct Struct_Obj_Entry; @@ -60,7 +61,7 @@ #endif char **environ; -char *__progname = ""; +const char *__progname = ""; /* The entry function. */ void @@ -72,13 +73,13 @@ int argc; char **argv; char **env; + const char *s; argc = * (long *) ap; argv = ap + 1; env = ap + 2 + argc; environ = env; if(argc > 0 && argv[0] != NULL) { - char *s; __progname = argv[0]; for (s = __progname; *s != '\0'; s++) if (*s == '/') Index: csu/i386/Makefile =================================================================== RCS file: /home/ncvs/src/lib/csu/i386/Makefile,v retrieving revision 1.40 diff -u -d -r1.40 Makefile --- csu/i386/Makefile 27 Aug 1999 23:57:54 -0000 1.40 +++ csu/i386/Makefile 26 Mar 2002 12:10:19 -0000 @@ -1,7 +1,8 @@ # from: @(#)Makefile 5.6 (Berkeley) 5/22/91 # $FreeBSD: src/lib/csu/i386/Makefile,v 1.40 1999/08/27 23:57:54 peter Exp $ -CFLAGS+= -DLIBC_SCCS -fno-omit-frame-pointer +CFLAGS+= -DLIBC_SCCS -fno-omit-frame-pointer \ + -I${.CURDIR}/../../libc/include OBJS= crt0.o c++rt0.o gcrt0.o scrt0.o sgcrt0.o CLEANFILES= a.out crt0.o.tmp c++rt0.o.tmp gcrt0.o.tmp scrt0.o.tmp \ sgcrt0.o.tmp Index: csu/i386/crt0.c =================================================================== RCS file: /home/ncvs/src/lib/csu/i386/crt0.c,v retrieving revision 1.36 diff -u -d -r1.36 crt0.c --- csu/i386/crt0.c 27 Aug 1999 23:57:55 -0000 1.36 +++ csu/i386/crt0.c 26 Mar 2002 12:05:26 -0000 @@ -37,10 +37,13 @@ #ifdef DYNAMIC #include #include -#include -#include #include + +#include #include +#include + +#include "../../libc/include/libc_private.h" /* !!! * This is gross, ld.so is a ZMAGIC a.out, but has `sizeof(hdr)' for @@ -88,8 +91,7 @@ int _callmain(); int errno; -static char empty[1]; -char *__progname = empty; +const char *__progname = ""; char **environ; /* Globals used by dlopen() and related functions in libc */ @@ -144,6 +146,7 @@ register struct kframe *kfp; register char **targv; register char **argv; + register const char *s; extern void _mcleanup(); #ifdef DYNAMIC volatile caddr_t x; @@ -162,7 +165,6 @@ environ = targv; if (argv[0]) { - register char *s; __progname = argv[0]; for (s=__progname; *s != '\0'; s++) if (*s == '/') Index: csu/i386-elf/Makefile =================================================================== RCS file: /home/ncvs/src/lib/csu/i386-elf/Makefile,v retrieving revision 1.9 diff -u -d -r1.9 Makefile --- csu/i386-elf/Makefile 27 Oct 2001 08:30:36 -0000 1.9 +++ csu/i386-elf/Makefile 26 Mar 2002 12:10:02 -0000 @@ -6,7 +6,8 @@ OBJS= ${SRCS:N*.h:R:S/$/.o/g} OBJS+= gcrt1.o CFLAGS+= -elf -Wall -fkeep-inline-functions \ - -I${.CURDIR}/../common + -I${.CURDIR}/../common \ + -I${.CURDIR}/../../libc/include LDFLAGS+= -elf NOMAN= true NOPIC= true Index: csu/i386-elf/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/i386-elf/crt1.c,v retrieving revision 1.6 diff -u -d -r1.6 crt1.c --- csu/i386-elf/crt1.c 27 Feb 2002 22:08:05 -0000 1.6 +++ csu/i386-elf/crt1.c 26 Mar 2002 12:11:47 -0000 @@ -29,6 +29,7 @@ #include #include +#include #include "crtbrand.c" typedef void (*fptr)(void); @@ -57,7 +58,7 @@ #endif char **environ; -char *__progname = ""; +const char *__progname = ""; void _start(char *arguments, ...) @@ -66,6 +67,7 @@ int argc; char **argv; char **env; + const char *s; rtld_cleanup = get_rtld_cleanup(); argv = &arguments; @@ -73,7 +75,6 @@ env = argv + argc + 1; environ = env; if (argc > 0 && argv[0] != NULL) { - char *s; __progname = argv[0]; for (s = __progname; *s != '\0'; s++) if (*s == '/') Index: csu/ia64/Makefile =================================================================== RCS file: /home/ncvs/src/lib/csu/ia64/Makefile,v retrieving revision 1.4 diff -u -d -r1.4 Makefile --- csu/ia64/Makefile 27 Oct 2001 08:29:03 -0000 1.4 +++ csu/ia64/Makefile 26 Mar 2002 12:10:27 -0000 @@ -6,7 +6,8 @@ OBJS= ${SRCS:N*.h:R:S/$/.o/g} OBJS+= gcrt1.o CFLAGS+= -Wall -Wno-unused \ - -I${.CURDIR}/../common + -I${.CURDIR}/../common \ + -I${.CURDIR}/../../libc/include NOMAN= true NOPIC= true NOPROFILE= true Index: csu/ia64/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/ia64/crt1.c,v retrieving revision 1.6 diff -u -d -r1.6 crt1.c --- csu/ia64/crt1.c 23 Mar 2002 18:14:20 -0000 1.6 +++ csu/ia64/crt1.c 26 Mar 2002 12:12:04 -0000 @@ -36,6 +36,7 @@ #endif #include +#include #include "crtbrand.c" struct Struct_Obj_Entry; @@ -56,7 +57,7 @@ #endif char **environ; -char *__progname = ""; +const char *__progname = ""; /* The entry function. */ void @@ -67,6 +68,7 @@ int argc; char **argv; char **env; + const char *s; /* Calculate gp */ __asm __volatile(" \ @@ -82,7 +84,6 @@ env = ap + 2 + argc; environ = env; if (argc > 0 && argv[0] != NULL) { - char *s; __progname = argv[0]; for (s = __progname; *s != '\0'; s++) if (*s == '/') Index: csu/powerpc/Makefile =================================================================== RCS file: /home/ncvs/src/lib/csu/powerpc/Makefile,v retrieving revision 1.2 diff -u -d -r1.2 Makefile --- csu/powerpc/Makefile 27 Oct 2001 08:32:07 -0000 1.2 +++ csu/powerpc/Makefile 26 Mar 2002 12:10:33 -0000 @@ -6,7 +6,8 @@ OBJS= ${SRCS:N*.h:R:S/$/.o/g} OBJS+= gcrt1.o CFLAGS+= -Wall -Wno-unused \ - -I${.CURDIR}/../common + -I${.CURDIR}/../common \ + -I${.CURDIR}/../../libc/include NOMAN= true NOPIC= true NOPROFILE= true Index: csu/powerpc/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/powerpc/crt1.c,v retrieving revision 1.7 diff -u -d -r1.7 crt1.c --- csu/powerpc/crt1.c 23 Mar 2002 18:14:04 -0000 1.7 +++ csu/powerpc/crt1.c 26 Mar 2002 12:12:22 -0000 @@ -43,6 +43,7 @@ #endif #include +#include #include "crtbrand.c" struct Struct_Obj_Entry; @@ -63,7 +64,7 @@ #endif char **environ; -char *__progname = ""; +const char *__progname = ""; struct ps_strings *__ps_strings; /* The entry function. @@ -80,11 +81,11 @@ struct ps_strings *ps_strings; /* BSD extension */ { char *namep; + const char *s; environ = envp; if (argc > 0 && argv[0] != NULL) { - char *s; __progname = argv[0]; for (s = __progname; *s != '\0'; s++) if (*s == '/') Index: csu/sparc64/Makefile =================================================================== RCS file: /home/ncvs/src/lib/csu/sparc64/Makefile,v retrieving revision 1.3 diff -u -d -r1.3 Makefile --- csu/sparc64/Makefile 10 Mar 2002 23:33:49 -0000 1.3 +++ csu/sparc64/Makefile 26 Mar 2002 12:10:44 -0000 @@ -5,7 +5,8 @@ SRCS= crt1.c crti.S crtn.S OBJS= ${SRCS:N*.h:R:S/$/.o/g} OBJS+= gcrt1.o -CFLAGS+= -I${.CURDIR}/../common +CFLAGS+= -I${.CURDIR}/../common \ + -I${.CURDIR}/../../libc/include NOMAN= true NOPIC= true NOPROFILE= true Index: csu/sparc64/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/sparc64/crt1.c,v retrieving revision 1.6 diff -u -d -r1.6 crt1.c --- csu/sparc64/crt1.c 16 Mar 2002 20:38:46 -0000 1.6 +++ csu/sparc64/crt1.c 26 Mar 2002 12:12:37 -0000 @@ -34,6 +34,7 @@ #endif #include +#include #include "crtbrand.c" struct Struct_Obj_Entry; @@ -55,7 +56,7 @@ #endif char **environ; -char *__progname = ""; +const char *__progname = ""; /* The entry function. */ /* @@ -77,6 +78,7 @@ int argc; char **argv; char **env; + const char *s; #if 0 void (*term)(void); @@ -91,7 +93,6 @@ env = ap + 2 + argc; environ = env; if (argc > 0 && argv[0] != NULL) { - char *s; __progname = argv[0]; for (s = __progname; *s != '\0'; s++) if (*s == '/') Index: libc/gen/err.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/err.c,v retrieving revision 1.12 diff -u -d -r1.12 err.c --- libc/gen/err.c 22 Mar 2002 21:52:05 -0000 1.12 +++ libc/gen/err.c 25 Mar 2002 21:15:17 -0000 @@ -41,13 +41,12 @@ #include #include "un-namespace.h" #include +#include #include #include #include -#include - -extern char *__progname; /* Program name, from crt0. */ +#include static FILE *err_file; /* file to use for error output */ static void (*err_exit)(int); @@ -110,7 +109,7 @@ { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", __progname); + fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) { vfprintf(err_file, fmt, ap); fprintf(err_file, ": "); @@ -138,7 +137,7 @@ { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", __progname); + fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) vfprintf(err_file, fmt, ap); fprintf(err_file, "\n"); @@ -183,7 +182,7 @@ { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", __progname); + fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) { vfprintf(err_file, fmt, ap); fprintf(err_file, ": "); @@ -207,7 +206,7 @@ { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", __progname); + fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) vfprintf(err_file, fmt, ap); fprintf(err_file, "\n"); Index: libc/gen/getprogname.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/getprogname.c,v retrieving revision 1.3 diff -u -d -r1.3 getprogname.c --- libc/gen/getprogname.c 1 Feb 2002 00:57:29 -0000 1.3 +++ libc/gen/getprogname.c 26 Mar 2002 08:33:48 -0000 @@ -3,10 +3,12 @@ #include -extern const char *__progname; +#include + +__weak_reference(_getprogname, getprogname); const char * -getprogname(void) +_getprogname(void) { return (__progname); Index: libc/gen/setproctitle.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/setproctitle.c,v retrieving revision 1.15 diff -u -d -r1.15 setproctitle.c --- libc/gen/setproctitle.c 1 Feb 2002 00:57:29 -0000 1.15 +++ libc/gen/setproctitle.c 25 Mar 2002 21:20:39 -0000 @@ -32,6 +32,8 @@ #include #include +#include + /* * Older FreeBSD 2.0, 2.1 and 2.2 had different ps_strings structures and * in different locations. @@ -53,7 +55,6 @@ #include #define SPT_BUFSIZE 2048 /* from other parts of sendmail */ -extern char * __progname; /* is this defined in a .h anywhere? */ void setproctitle(const char *fmt, ...) @@ -83,7 +84,7 @@ len = 0; } else { /* print program name heading for grep */ - (void) snprintf(buf, sizeof(buf), "%s: ", __progname); + (void)snprintf(buf, sizeof(buf), "%s: ", _getprogname()); len = strlen(buf); } Index: libc/gen/setprogname.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/setprogname.c,v retrieving revision 1.7 diff -u -d -r1.7 setprogname.c --- libc/gen/setprogname.c 1 Feb 2002 00:57:29 -0000 1.7 +++ libc/gen/setprogname.c 26 Mar 2002 10:39:01 -0000 @@ -4,7 +4,7 @@ #include #include -extern const char *__progname; +#include void setprogname(const char *progname) Index: libc/gen/syslog.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/syslog.c,v retrieving revision 1.25 diff -u -d -r1.25 syslog.c --- libc/gen/syslog.c 9 Mar 2002 11:38:01 -0000 1.25 +++ libc/gen/syslog.c 25 Mar 2002 21:21:52 -0000 @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +61,8 @@ #endif #include "un-namespace.h" +#include + static int LogFile = -1; /* fd for log */ static int connected; /* have done connect */ static int opened; /* have done openlog() */ @@ -67,7 +70,6 @@ static const char *LogTag = NULL; /* string to tag the entry with */ static int LogFacility = LOG_USER; /* default facility code */ static int LogMask = 0xff; /* mask of priorities to be logged */ -extern char *__progname; /* Program name, from crt0. */ static void disconnectlog(void); /* disconnect from syslogd */ static void connectlog(void); /* (re)connect to syslogd */ @@ -181,7 +183,7 @@ stdp = tbuf + (sizeof(tbuf) - tbuf_cookie.left); } if (LogTag == NULL) - LogTag = __progname; + LogTag = _getprogname(); if (LogTag != NULL) (void)fprintf(fp, "%s", LogTag); if (LogStat & LOG_PID) Index: libc/gmon/gmon.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gmon/gmon.c,v retrieving revision 1.13 diff -u -d -r1.13 gmon.c --- libc/gmon/gmon.c 15 Feb 2002 02:37:08 -0000 1.13 +++ libc/gmon/gmon.c 25 Mar 2002 21:22:48 -0000 @@ -46,20 +46,21 @@ #include "namespace.h" #include #include "un-namespace.h" -#include #include +#include +#include #include #include #include "un-namespace.h" +#include + #if defined(__ELF__) && (defined(i386) || defined(__sparc64__)) extern char *minbrk asm (".minbrk"); #else extern char *minbrk asm ("minbrk"); #endif -extern char *__progname; - struct gmonparam _gmonparam = { GMON_PROF_OFF }; static int s_scale; @@ -175,7 +176,7 @@ } moncontrol(0); - snprintf(outname, sizeof(outname), "%s.gmon", __progname); + snprintf(outname, sizeof(outname), "%s.gmon", _getprogname()); fd = _open(outname, O_CREAT|O_TRUNC|O_WRONLY, 0666); if (fd < 0) { _warn("_mcleanup: %s", outname); Index: libc/include/libc_private.h =================================================================== RCS file: /home/ncvs/src/lib/libc/include/libc_private.h,v retrieving revision 1.4 diff -u -d -r1.4 libc_private.h --- libc/include/libc_private.h 24 Jan 2001 13:00:08 -0000 1.4 +++ libc/include/libc_private.h 25 Mar 2002 21:19:31 -0000 @@ -63,4 +63,16 @@ #define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) #define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp) +/* + * This is a pointer in the C run-time startup code. It is used + * by getprogname() and setprogname(). + */ +extern const char *__progname; + +/* + * Declare an internal version of getprogname() to allow for + * the programmer declaring her own. + */ +const char *_getprogname(void); + #endif /* _LIBC_PRIVATE_H_ */ Index: libc/locale/collate.c =================================================================== RCS file: /home/ncvs/src/lib/libc/locale/collate.c,v retrieving revision 1.23 diff -u -d -r1.23 collate.c --- libc/locale/collate.c 22 Mar 2002 21:52:18 -0000 1.23 +++ libc/locale/collate.c 25 Mar 2002 21:23:29 -0000 @@ -41,6 +41,8 @@ #include "collate.h" #include "setlocale.h" +#include + int __collate_load_error = 1; int __collate_substitute_nontrivial; char __collate_version[STR_LEN]; @@ -176,11 +178,10 @@ void __collate_err(int ex, const char *f) { - extern char *__progname; /* Program name, from crt0. */ const char *s; int serrno = errno; - s = __progname; + s = _getprogname(); _write(STDERR_FILENO, s, strlen(s)); _write(STDERR_FILENO, ": ", 2); s = f; Index: libc/stdlib/getopt.c =================================================================== RCS file: /home/ncvs/src/lib/libc/stdlib/getopt.c,v retrieving revision 1.5 diff -u -d -r1.5 getopt.c --- libc/stdlib/getopt.c 22 Mar 2002 21:53:10 -0000 1.5 +++ libc/stdlib/getopt.c 25 Mar 2002 21:24:06 -0000 @@ -41,6 +41,8 @@ #include #include +#include + int opterr = 1, /* if error message should be printed */ optind = 1, /* index into parent argv vector */ optopt, /* character checked for validity */ @@ -61,7 +63,6 @@ char * const *nargv; const char *ostr; { - extern char *__progname; static char *place = EMSG; /* option letter processing */ char *oli; /* option letter list index */ @@ -88,8 +89,8 @@ if (!*place) ++optind; if (opterr && *ostr != ':' && optopt != BADCH) - (void)fprintf(stderr, - "%s: illegal option -- %c\n", __progname, optopt); + (void)fprintf(stderr, "%s: illegal option -- %c\n", + _getprogname(), optopt); return (BADCH); } if (*++oli != ':') { /* don't need argument */ @@ -107,7 +108,7 @@ if (opterr) (void)fprintf(stderr, "%s: option requires an argument -- %c\n", - __progname, optopt); + _getprogname(), optopt); return (BADCH); } else /* white space */ Index: libc/stdlib/malloc.c =================================================================== RCS file: /home/ncvs/src/lib/libc/stdlib/malloc.c,v retrieving revision 1.66 diff -u -d -r1.66 malloc.c --- libc/stdlib/malloc.c 22 Mar 2002 21:53:10 -0000 1.66 +++ libc/stdlib/malloc.c 25 Mar 2002 19:47:36 -0000 @@ -297,14 +297,12 @@ void (*_malloc_message)(char *p1, char *p2, char *p3, char *p4) = wrtmessage; -extern char *__progname; - static void wrterror(char *p) { suicide = 1; - _malloc_message(__progname, malloc_func, " error: ", p); + _malloc_message(_getprogname(), malloc_func, " error: ", p); abort(); } @@ -314,7 +312,7 @@ if (malloc_abort) wrterror(p); - _malloc_message(__progname, malloc_func, " warning: ", p); + _malloc_message(_getprogname(), malloc_func, " warning: ", p); } /* Index: libc_r/uthread/uthread_spinlock.c =================================================================== RCS file: /home/ncvs/src/lib/libc_r/uthread/uthread_spinlock.c,v retrieving revision 1.9 diff -u -d -r1.9 uthread_spinlock.c --- libc_r/uthread/uthread_spinlock.c 24 Jan 2001 13:03:36 -0000 1.9 +++ libc_r/uthread/uthread_spinlock.c 25 Mar 2002 19:52:44 -0000 @@ -33,14 +33,16 @@ * */ +#include #include +#include #include -#include #include -#include -#include "pthread_private.h" +#include -extern char *__progname; +#include + +#include "pthread_private.h" /* * Lock a location for the running thread. Yield to allow other @@ -91,7 +93,7 @@ cnt++; if (cnt > 100) { char str[256]; - snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", __progname, curthread, lck, fname, lineno, lck->fname, lck->lineno); + snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", _getprogname(), curthread, lck, fname, lineno, lck->fname, lck->lineno); __sys_write(2,str,strlen(str)); __sleep(1); cnt = 0; Index: libfetch/http.c =================================================================== RCS file: /home/ncvs/src/lib/libfetch/http.c,v retrieving revision 1.51 diff -u -d -r1.51 http.c --- libfetch/http.c 5 Feb 2002 22:13:51 -0000 1.51 +++ libfetch/http.c 25 Mar 2002 19:53:14 -0000 @@ -80,8 +80,6 @@ #include "common.h" #include "httperr.h" -extern char *__progname; /* XXX not portable */ - /* Maximum number of redirects to follow */ #define MAX_REDIRECT 5 @@ -840,7 +838,7 @@ if ((p = getenv("HTTP_USER_AGENT")) != NULL && *p != '\0') _http_cmd(fd, "User-Agent: %s", p); else - _http_cmd(fd, "User-Agent: %s " _LIBFETCH_VER, __progname); + _http_cmd(fd, "User-Agent: %s " _LIBFETCH_VER, _getprogname()); if (url->offset) _http_cmd(fd, "Range: bytes=%lld-", (long long)url->offset); _http_cmd(fd, "Connection: close"); Index: libncp/ncpl_subr.c =================================================================== RCS file: /home/ncvs/src/lib/libncp/ncpl_subr.c,v retrieving revision 1.5 diff -u -d -r1.5 ncpl_subr.c --- libncp/ncpl_subr.c 30 Sep 2001 22:01:19 -0000 1.5 +++ libncp/ncpl_subr.c 25 Mar 2002 19:53:32 -0000 @@ -51,8 +51,6 @@ /*#include */ #include "ncp_mod.h" -extern char *__progname; - int sysentoffset; void @@ -309,7 +307,7 @@ ++ncp_optind; if (ncp_opterr && *ostr != ':') (void)fprintf(stderr, - "%s: illegal option -- %c\n", __progname, ncp_optopt); + "%s: illegal option -- %c\n", _getprogname(), ncp_optopt); return (BADCH); } if (*++oli != ':') { /* don't need argument */ @@ -327,7 +325,7 @@ if (ncp_opterr) (void)fprintf(stderr, "%s: option requires an argument -- %c\n", - __progname, ncp_optopt); + _getprogname(), ncp_optopt); return (BADCH); } else /* white space */ @@ -439,7 +437,7 @@ ncp_error(const char *fmt, int error, ...) { va_list ap; - fprintf(stderr, "%s: ", __progname); + fprintf(stderr, "%s: ", _getprogname()); va_start(ap, error); vfprintf(stderr, fmt, ap); va_end(ap); To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Tue Mar 26 20:48: 6 2002 Delivered-To: freebsd-audit@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 2A55337B405; Tue, 26 Mar 2002 20:47:56 -0800 (PST) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id PAA22412; Wed, 27 Mar 2002 15:47:52 +1100 Date: Wed, 27 Mar 2002 15:48:24 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: markm@FreeBSD.ORG Cc: audit@FreeBSD.ORG Subject: Re: Library __progname cleanups - commit candidate In-Reply-To: <200203261323.g2QDNmER049112@greenpeace.grondar.org> Message-ID: <20020327151238.W2670-100000@gamplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Tue, 26 Mar 2002 markm@FreeBSD.ORG wrote: > Index: csu/alpha/crt1.c > =================================================================== > RCS file: /home/ncvs/src/lib/csu/alpha/crt1.c,v > retrieving revision 1.10 > diff -u -d -r1.10 crt1.c > --- csu/alpha/crt1.c 26 Oct 2001 06:45:10 -0000 1.10 > +++ csu/alpha/crt1.c 26 Mar 2002 12:11:31 -0000 > @@ -40,6 +40,7 @@ > #endif > > #include > +#include Angle-bracket includes are bogus for nonstandard includes. They are correctly not used in most places in old code. Also, would be unsorted if it belonged with the standard headers. Similarly elsewhere in these patches. > Index: csu/i386/crt0.c > =================================================================== > RCS file: /home/ncvs/src/lib/csu/i386/crt0.c,v > retrieving revision 1.36 > diff -u -d -r1.36 crt0.c > --- csu/i386/crt0.c 27 Aug 1999 23:57:55 -0000 1.36 > +++ csu/i386/crt0.c 26 Mar 2002 12:05:26 -0000 > @@ -37,10 +37,13 @@ > #ifdef DYNAMIC > #include > #include > -#include > -#include > #include is still unsorted. > + > +#include > #include > +#include > + > +#include "../../libc/include/libc_private.h" Another bogus path. You just added a -I to the Makefile so that the full path is not needed here. > Index: libc/gen/getprogname.c > =================================================================== > RCS file: /home/ncvs/src/lib/libc/gen/getprogname.c,v > retrieving revision 1.3 > diff -u -d -r1.3 getprogname.c > --- libc/gen/getprogname.c 1 Feb 2002 00:57:29 -0000 1.3 > +++ libc/gen/getprogname.c 26 Mar 2002 08:33:48 -0000 > @@ -3,10 +3,12 @@ > > #include This is missing includes of "namespace.h" and "un-namespace.h", except you do things in a nonstandard way. Similarly elsewhere. Not so similarly in err.c above (I limited the scopy of the namespace includes too carefully there, so they don't already cover ). > > -extern const char *__progname; > +#include As usual. > + > +__weak_reference(_getprogname, getprogname); > > const char * > -getprogname(void) > +_getprogname(void) OK. This part of namespace hiding is easy. > Index: libc/gen/setproctitle.c > =================================================================== > RCS file: /home/ncvs/src/lib/libc/gen/setproctitle.c,v > retrieving revision 1.15 > diff -u -d -r1.15 setproctitle.c > --- libc/gen/setproctitle.c 1 Feb 2002 00:57:29 -0000 1.15 > +++ libc/gen/setproctitle.c 25 Mar 2002 21:20:39 -0000 > ... > @@ -83,7 +84,7 @@ > len = 0; > } else { > /* print program name heading for grep */ > - (void) snprintf(buf, sizeof(buf), "%s: ", __progname); > + (void)snprintf(buf, sizeof(buf), "%s: ", _getprogname()); Line too long. > Index: libc/gmon/gmon.c > =================================================================== > RCS file: /home/ncvs/src/lib/libc/gmon/gmon.c,v > retrieving revision 1.13 > diff -u -d -r1.13 gmon.c > --- libc/gmon/gmon.c 15 Feb 2002 02:37:08 -0000 1.13 > +++ libc/gmon/gmon.c 25 Mar 2002 21:22:48 -0000 > @@ -46,20 +46,21 @@ > #include "namespace.h" > #include > #include "un-namespace.h" My bad. This inner pair of namespace includes probably breaks the outer pair. The outer pair should already cover . > Index: libc/include/libc_private.h > =================================================================== > RCS file: /home/ncvs/src/lib/libc/include/libc_private.h,v > retrieving revision 1.4 > diff -u -d -r1.4 libc_private.h > --- libc/include/libc_private.h 24 Jan 2001 13:00:08 -0000 1.4 > +++ libc/include/libc_private.h 25 Mar 2002 21:19:31 -0000 > @@ -63,4 +63,16 @@ > #define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) > #define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp) > > +/* > + * This is a pointer in the C run-time startup code. It is used > + * by getprogname() and setprogname(). > + */ > +extern const char *__progname; > + > +/* > + * Declare an internal version of getprogname() to allow for > + * the programmer declaring her own. > + */ > +const char *_getprogname(void); > + Why not use the standard namespace mechanism? It just happens that this header provides a convenient place to put prototype for the implementatation name so that a less hackish mechanism can be used, but this is surprising. > Index: libc_r/uthread/uthread_spinlock.c > =================================================================== > RCS file: /home/ncvs/src/lib/libc_r/uthread/uthread_spinlock.c,v > retrieving revision 1.9 > diff -u -d -r1.9 uthread_spinlock.c > --- libc_r/uthread/uthread_spinlock.c 24 Jan 2001 13:03:36 -0000 1.9 > +++ libc_r/uthread/uthread_spinlock.c 25 Mar 2002 19:52:44 -0000 > ... > - snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", __progname, curthread, lck, fname, lineno, lck->fname, lck->lineno); > + snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", _getprogname(), curthread, lck, fname, lineno, lck->fname, lck->lineno); Disgustingly long line longer than before. > Index: libfetch/http.c > =================================================================== > RCS file: /home/ncvs/src/lib/libfetch/http.c,v > retrieving revision 1.51 > diff -u -d -r1.51 http.c > --- libfetch/http.c 5 Feb 2002 22:13:51 -0000 1.51 > +++ libfetch/http.c 25 Mar 2002 19:53:14 -0000 > ... > @@ -840,7 +838,7 @@ > if ((p = getenv("HTTP_USER_AGENT")) != NULL && *p != '\0') > _http_cmd(fd, "User-Agent: %s", p); > else > - _http_cmd(fd, "User-Agent: %s " _LIBFETCH_VER, __progname); > + _http_cmd(fd, "User-Agent: %s " _LIBFETCH_VER, _getprogname()); Long line longer than before. Similarly elsewhere. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Wed Mar 27 1: 5:19 2002 Delivered-To: freebsd-audit@freebsd.org Received: from storm.FreeBSD.org.uk (storm.FreeBSD.org.uk [194.242.139.170]) by hub.freebsd.org (Postfix) with ESMTP id BCE1E37B404 for ; Wed, 27 Mar 2002 01:05:14 -0800 (PST) Received: (from uucp@localhost) by storm.FreeBSD.org.uk (8.11.6/8.11.6) with UUCP id g2R950381103; Wed, 27 Mar 2002 09:05:00 GMT (envelope-from mark@grimreaper.grondar.za) Received: from grimreaper (localhost [127.0.0.1]) by grimreaper.grondar.org (8.12.2/8.12.2) with ESMTP id g2R91DQE006444; Wed, 27 Mar 2002 09:01:13 GMT (envelope-from mark@grimreaper.grondar.za) Message-Id: <200203270901.g2R91DQE006444@grimreaper.grondar.org> To: Bruce Evans Cc: audit@FreeBSD.ORG Subject: Re: Library __progname cleanups - commit candidate References: <20020327151238.W2670-100000@gamplex.bde.org> In-Reply-To: <20020327151238.W2670-100000@gamplex.bde.org> ; from Bruce Evans "Wed, 27 Mar 2002 15:48:24 +1100." Date: Wed, 27 Mar 2002 09:01:13 +0000 From: Mark Murray Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > > retrieving revision 1.3 > > diff -u -d -r1.3 getprogname.c > > --- libc/gen/getprogname.c 1 Feb 2002 00:57:29 -0000 1.3 > > +++ libc/gen/getprogname.c 26 Mar 2002 08:33:48 -0000 > > @@ -3,10 +3,12 @@ > > > > #include > > This is missing includes of "namespace.h" and "un-namespace.h", except > you do things in a nonstandard way. Similarly elsewhere. Not so > similarly in err.c above (I limited the scopy of the namespace includes > too carefully there, so they don't already cover ). You don't think this "standard way" could be documented somewhere, do you? > Why not use the standard namespace mechanism? It just happens that > this header provides a convenient place to put prototype for the > implementatation name so that a less hackish mechanism can be used, > but this is surprising. "Standard"? No documentation == no standard. Even the headers themselves have no useful comments. > > - snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", __progname, curthread, lck, fname, lineno, lck->fname, lck->lineno); > > + snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", _getprogname(), curthread, lck, fname, lineno, lck->fname, lck->lineno); > > Disgustingly long line longer than before. I'd prefer to solve this with an appropriate indent(1). M -- o Mark Murray \_ O.\_ Warning: this .sig is umop ap!sdn To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Wed Mar 27 2:56: 3 2002 Delivered-To: freebsd-audit@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id CCE7337B405 for ; Wed, 27 Mar 2002 02:55:46 -0800 (PST) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id VAA31282; Wed, 27 Mar 2002 21:54:38 +1100 Date: Wed, 27 Mar 2002 21:55:11 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Mark Murray Cc: audit@FreeBSD.ORG Subject: Re: Library __progname cleanups - commit candidate In-Reply-To: <200203270901.g2R91DQE006444@grimreaper.grondar.org> Message-ID: <20020327214800.B3808-100000@gamplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Wed, 27 Mar 2002, Mark Murray wrote: > > > retrieving revision 1.3 > > > diff -u -d -r1.3 getprogname.c > > > --- libc/gen/getprogname.c 1 Feb 2002 00:57:29 -0000 1.3 > > > +++ libc/gen/getprogname.c 26 Mar 2002 08:33:48 -0000 > > > @@ -3,10 +3,12 @@ > > > > > > #include > > > > This is missing includes of "namespace.h" and "un-namespace.h", except > > you do things in a nonstandard way. Similarly elsewhere. Not so > > similarly in err.c above (I limited the scopy of the namespace includes > > too carefully there, so they don't already cover ). > > You don't think this "standard way" could be documented somewhere, do you? The logs for the commits that added it should be sufficient. There are hundreds of examples. > > > - snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", __progname, curthread, lck, fname, lineno, lck->fname, lck->lineno); > > > + snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", _getprogname(), curthread, lck, fname, lineno, lck->fname, lck->lineno); > > > > Disgustingly long line longer than before. > > I'd prefer to solve this with an appropriate indent(1). FreeBSD's indent(1) doesn't understand long lines at all. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Wed Mar 27 3:30:28 2002 Delivered-To: freebsd-audit@freebsd.org Received: from storm.FreeBSD.org.uk (storm.FreeBSD.org.uk [194.242.139.170]) by hub.freebsd.org (Postfix) with ESMTP id AB6C937B400 for ; Wed, 27 Mar 2002 03:30:23 -0800 (PST) Received: (from uucp@localhost) by storm.FreeBSD.org.uk (8.11.6/8.11.6) with UUCP id g2RBUBs82346; Wed, 27 Mar 2002 11:30:11 GMT (envelope-from mark@grimreaper.grondar.za) Received: from grimreaper (localhost [127.0.0.1]) by grimreaper.grondar.org (8.12.2/8.12.2) with ESMTP id g2RBTnQE007451; Wed, 27 Mar 2002 11:29:49 GMT (envelope-from mark@grimreaper.grondar.za) Message-Id: <200203271129.g2RBTnQE007451@grimreaper.grondar.org> To: Bruce Evans Cc: audit@FreeBSD.ORG Subject: Re: Library __progname cleanups - commit candidate References: <20020327214800.B3808-100000@gamplex.bde.org> In-Reply-To: <20020327214800.B3808-100000@gamplex.bde.org> ; from Bruce Evans "Wed, 27 Mar 2002 21:55:11 +1100." Date: Wed, 27 Mar 2002 11:29:49 +0000 From: Mark Murray Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > > > too carefully there, so they don't already cover ). > > > > You don't think this "standard way" could be documented somewhere, do you? > > The logs for the commits that added it should be sufficient. There are > hundreds of examples. "Should be" != "Is". Grovelling out the right example is an exercise in futility, as for each example there is usually a counterexample. > > > > - snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", __progname, curthread, lck, fname, lineno, lck->fname, lck->lineno); > > > > + snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", _getprogname(), curthread, lck, fname, lineno, lck->fname, lck->lineno); > > > > > > Disgustingly long line longer than before. > > > > I'd prefer to solve this with an appropriate indent(1). > > FreeBSD's indent(1) doesn't understand long lines at all. FSF/GNU indent is much better, and large parts of it are still BSD licensed. I'm working on backporting those bits. M -- o Mark Murray \_ O.\_ Warning: this .sig is umop ap!sdn To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Thu Mar 28 1:26:47 2002 Delivered-To: freebsd-audit@freebsd.org Received: from melchior.cuivre.fr.eu.org (melchior.enst.fr [137.194.161.6]) by hub.freebsd.org (Postfix) with ESMTP id F35B937B416 for ; Thu, 28 Mar 2002 01:26:40 -0800 (PST) Received: from melusine.cuivre.fr.eu.org (melusine.enst.fr [137.194.160.34]) by melchior.cuivre.fr.eu.org (Postfix) with ESMTP id 195F27606 for ; Thu, 28 Mar 2002 10:26:38 +0100 (CET) Received: by melusine.cuivre.fr.eu.org (Postfix, from userid 1000) id E829E2C3D1; Thu, 28 Mar 2002 10:26:37 +0100 (CET) Date: Thu, 28 Mar 2002 10:26:37 +0100 From: Thomas Quinot To: freebsd-audit@freebsd.org Subject: boot2.c deobfuscation Message-ID: <20020328102637.A842@melusine.cuivre.fr.eu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Could others please review the following patch (originally PR i386/36015, diff updated to reflect the commit of 36016)? Thanks, Thomas. >Fix: The following patches clarifies the stream of control at the beginning of main() by making autoboot a two-state variable (instead of a 3-state), with no functional change at all. Magical numeric values for ioctrl are replaced with #define'd macros. Hard-coded tick values for calls to keyhit are replaced by static expressions in terms of multiples of a SECOND #define. This change introduces a functional difference: the first time-out will be 1 tick shorter. Index: boot2.c =================================================================== RCS file: /home/ncvs/src/sys/boot/i386/boot2/boot2.c,v retrieving revision 1.38 diff -u -r1.38 boot2.c --- boot2.c 23 Mar 2002 19:40:27 -0000 1.38 +++ boot2.c 28 Mar 2002 09:25:42 -0000 @@ -37,6 +37,11 @@ #include "boot2.h" #include "lib.h" +#define IO_KEYBOARD 1 +#define IO_SERIAL 2 + +#define SECOND 18 /* Circa that many ticks in a second. */ + #define RBX_ASKNAME 0x0 /* -a */ #define RBX_SINGLE 0x1 /* -s */ #define RBX_DFLTROOT 0x5 /* -r */ @@ -138,7 +143,7 @@ static struct bootinfo bootinfo; static int ls; static uint32_t fs_off; -static uint8_t ioctrl = 0x1; +static uint8_t ioctrl = IO_KEYBOARD; void exit(int); static void load(const char *); @@ -281,34 +286,39 @@ bootinfo.bi_memsizes_valid++; for (i = 0; i < N_BIOS_GEOM; i++) bootinfo.bi_bios_geom[i] = drvinfo(i); - autoboot = 2; + + /* Process configuration file */ + + autoboot = 1; readfile(PATH_CONFIG, cmd, sizeof(cmd)); if (*cmd) { printf("%s: %s", PATH_CONFIG, cmd); if (parse(cmd)) autoboot = 0; - *cmd = 0; } - if (autoboot && !*kname) { - if (autoboot == 2) { - memcpy(kname, PATH_BOOT3, sizeof(PATH_BOOT3)); - if (!keyhit(0x37)) { - load(kname); - autoboot = 1; - } - } - if (autoboot == 1) + + /* Try to exec stage 3 boot loader. If interrupted by a keypress, * + * or in case of failure, try to load a kernel directly instaed. */ + + if (autoboot) { + memcpy(kname, PATH_BOOT3, sizeof(PATH_BOOT3)); + if (!keyhit(3 * SECOND)) { + load(kname); memcpy(kname, PATH_KERNEL, sizeof(PATH_KERNEL)); + } } + + /* Present the user with the boot2 prompt. */ + for (;;) { printf(" \n>> FreeBSD/i386 BOOT\n" "Default: %u:%s(%u,%c)%s\n" "boot: ", dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit, 'a' + dsk.part, kname); - if (ioctrl & 0x2) + if (ioctrl & IO_SERIAL) sio_flush(); - if (!autoboot || keyhit(0x5a)) + if (!autoboot || keyhit(5 * SECOND)) getstr(cmd, sizeof(cmd)); else putchar('\n'); @@ -447,9 +457,9 @@ opts |= 1 << RBX_DUAL | 1 << RBX_SERIAL; opts &= ~(1 << RBX_PROBEKBD); } - ioctrl = opts & 1 << RBX_DUAL ? 0x3 : - opts & 1 << RBX_SERIAL ? 0x2 : 0x1; - if (ioctrl & 0x2) + ioctrl = opts & 1 << RBX_DUAL ? (IO_SERIAL | IO_KEYBOARD) : + opts & 1 << RBX_SERIAL ? IO_SERIAL : IO_KEYBOARD; + if (ioctrl & IO_SERIAL) sio_init(); } else { for (q = arg--; *q && *q != '('; q++); @@ -794,9 +804,9 @@ static int xputc(int c) { - if (ioctrl & 0x1) + if (ioctrl & IO_KEYBOARD) putc(c); - if (ioctrl & 0x2) + if (ioctrl & IO_SERIAL) sio_putc(c); return c; } @@ -807,9 +817,9 @@ if (opts & 1 << RBX_NOINTR) return 0; for (;;) { - if (ioctrl & 0x1 && getc(1)) + if (ioctrl & IO_KEYBOARD && getc(1)) return fn ? 1 : getc(0); - if (ioctrl & 0x2 && sio_ischar()) + if (ioctrl & IO_SERIAL && sio_ischar()) return fn ? 1 : sio_getc(); if (fn) return 0; -- Thomas.Quinot@Cuivre.FR.EU.ORG To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Thu Mar 28 12:30: 7 2002 Delivered-To: freebsd-audit@freebsd.org Received: from greenpeace.grondar.org (grondar.demon.co.uk [158.152.143.227]) by hub.freebsd.org (Postfix) with ESMTP id 8014B37B405 for ; Thu, 28 Mar 2002 12:29:16 -0800 (PST) Received: from greenpeace (localhost [127.0.0.1]) by greenpeace.grondar.org (8.12.2/8.12.2) with ESMTP id g2SKTDdC005176 for ; Thu, 28 Mar 2002 20:29:14 GMT (envelope-from root@greenpeace.grondar.org) Message-Id: <200203282029.g2SKTDdC005176@greenpeace.grondar.org> To: audit@freebsd.org Subject: __progname cleanups - commit candidate 2 From: markm@freebsd.org Date: Thu, 28 Mar 2002 20:29:07 +0000 Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Index: csu/alpha/Makefile =================================================================== RCS file: /home/ncvs/src/lib/csu/alpha/Makefile,v retrieving revision 1.16 diff -u -d -r1.16 Makefile --- csu/alpha/Makefile 27 Oct 2001 08:29:51 -0000 1.16 +++ csu/alpha/Makefile 26 Mar 2002 12:09:52 -0000 @@ -6,7 +6,8 @@ OBJS= ${SRCS:N*.h:R:S/$/.o/g} OBJS+= gcrt1.o CFLAGS+= -Wall -Wno-unused \ - -I${.CURDIR}/../common + -I${.CURDIR}/../common \ + -I${.CURDIR}/../../libc/include NOMAN= true NOPIC= true NOPROFILE= true Index: csu/alpha/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/alpha/crt1.c,v retrieving revision 1.10 diff -u -d -r1.10 crt1.c --- csu/alpha/crt1.c 26 Oct 2001 06:45:10 -0000 1.10 +++ csu/alpha/crt1.c 27 Mar 2002 12:18:32 -0000 @@ -40,6 +40,7 @@ #endif #include +#include "libc_private.h" #include "crtbrand.c" struct Struct_Obj_Entry; @@ -60,7 +61,7 @@ #endif char **environ; -char *__progname = ""; +const char *__progname = ""; /* The entry function. */ void @@ -72,13 +73,13 @@ int argc; char **argv; char **env; + const char *s; argc = * (long *) ap; argv = ap + 1; env = ap + 2 + argc; environ = env; if(argc > 0 && argv[0] != NULL) { - char *s; __progname = argv[0]; for (s = __progname; *s != '\0'; s++) if (*s == '/') Index: csu/i386/Makefile =================================================================== RCS file: /home/ncvs/src/lib/csu/i386/Makefile,v retrieving revision 1.40 diff -u -d -r1.40 Makefile --- csu/i386/Makefile 27 Aug 1999 23:57:54 -0000 1.40 +++ csu/i386/Makefile 26 Mar 2002 12:10:19 -0000 @@ -1,7 +1,8 @@ # from: @(#)Makefile 5.6 (Berkeley) 5/22/91 # $FreeBSD: src/lib/csu/i386/Makefile,v 1.40 1999/08/27 23:57:54 peter Exp $ -CFLAGS+= -DLIBC_SCCS -fno-omit-frame-pointer +CFLAGS+= -DLIBC_SCCS -fno-omit-frame-pointer \ + -I${.CURDIR}/../../libc/include OBJS= crt0.o c++rt0.o gcrt0.o scrt0.o sgcrt0.o CLEANFILES= a.out crt0.o.tmp c++rt0.o.tmp gcrt0.o.tmp scrt0.o.tmp \ sgcrt0.o.tmp Index: csu/i386/crt0.c =================================================================== RCS file: /home/ncvs/src/lib/csu/i386/crt0.c,v retrieving revision 1.36 diff -u -d -r1.36 crt0.c --- csu/i386/crt0.c 27 Aug 1999 23:57:55 -0000 1.36 +++ csu/i386/crt0.c 27 Mar 2002 12:19:46 -0000 @@ -37,10 +37,13 @@ #ifdef DYNAMIC #include #include -#include -#include #include + +#include #include +#include + +#include "libc_private.h" /* !!! * This is gross, ld.so is a ZMAGIC a.out, but has `sizeof(hdr)' for @@ -88,8 +91,7 @@ int _callmain(); int errno; -static char empty[1]; -char *__progname = empty; +const char *__progname = ""; char **environ; /* Globals used by dlopen() and related functions in libc */ @@ -144,6 +146,7 @@ register struct kframe *kfp; register char **targv; register char **argv; + register const char *s; extern void _mcleanup(); #ifdef DYNAMIC volatile caddr_t x; @@ -162,7 +165,6 @@ environ = targv; if (argv[0]) { - register char *s; __progname = argv[0]; for (s=__progname; *s != '\0'; s++) if (*s == '/') Index: csu/i386-elf/Makefile =================================================================== RCS file: /home/ncvs/src/lib/csu/i386-elf/Makefile,v retrieving revision 1.9 diff -u -d -r1.9 Makefile --- csu/i386-elf/Makefile 27 Oct 2001 08:30:36 -0000 1.9 +++ csu/i386-elf/Makefile 26 Mar 2002 12:10:02 -0000 @@ -6,7 +6,8 @@ OBJS= ${SRCS:N*.h:R:S/$/.o/g} OBJS+= gcrt1.o CFLAGS+= -elf -Wall -fkeep-inline-functions \ - -I${.CURDIR}/../common + -I${.CURDIR}/../common \ + -I${.CURDIR}/../../libc/include LDFLAGS+= -elf NOMAN= true NOPIC= true Index: csu/i386-elf/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/i386-elf/crt1.c,v retrieving revision 1.6 diff -u -d -r1.6 crt1.c --- csu/i386-elf/crt1.c 27 Feb 2002 22:08:05 -0000 1.6 +++ csu/i386-elf/crt1.c 27 Mar 2002 12:18:40 -0000 @@ -29,6 +29,7 @@ #include #include +#include "libc_private.h" #include "crtbrand.c" typedef void (*fptr)(void); @@ -57,7 +58,7 @@ #endif char **environ; -char *__progname = ""; +const char *__progname = ""; void _start(char *arguments, ...) @@ -66,6 +67,7 @@ int argc; char **argv; char **env; + const char *s; rtld_cleanup = get_rtld_cleanup(); argv = &arguments; @@ -73,7 +75,6 @@ env = argv + argc + 1; environ = env; if (argc > 0 && argv[0] != NULL) { - char *s; __progname = argv[0]; for (s = __progname; *s != '\0'; s++) if (*s == '/') Index: csu/ia64/Makefile =================================================================== RCS file: /home/ncvs/src/lib/csu/ia64/Makefile,v retrieving revision 1.4 diff -u -d -r1.4 Makefile --- csu/ia64/Makefile 27 Oct 2001 08:29:03 -0000 1.4 +++ csu/ia64/Makefile 26 Mar 2002 12:10:27 -0000 @@ -6,7 +6,8 @@ OBJS= ${SRCS:N*.h:R:S/$/.o/g} OBJS+= gcrt1.o CFLAGS+= -Wall -Wno-unused \ - -I${.CURDIR}/../common + -I${.CURDIR}/../common \ + -I${.CURDIR}/../../libc/include NOMAN= true NOPIC= true NOPROFILE= true Index: csu/ia64/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/ia64/crt1.c,v retrieving revision 1.6 diff -u -d -r1.6 crt1.c --- csu/ia64/crt1.c 23 Mar 2002 18:14:20 -0000 1.6 +++ csu/ia64/crt1.c 27 Mar 2002 12:18:47 -0000 @@ -36,6 +36,7 @@ #endif #include +#include "libc_private.h" #include "crtbrand.c" struct Struct_Obj_Entry; @@ -56,7 +57,7 @@ #endif char **environ; -char *__progname = ""; +const char *__progname = ""; /* The entry function. */ void @@ -67,6 +68,7 @@ int argc; char **argv; char **env; + const char *s; /* Calculate gp */ __asm __volatile(" \ @@ -82,7 +84,6 @@ env = ap + 2 + argc; environ = env; if (argc > 0 && argv[0] != NULL) { - char *s; __progname = argv[0]; for (s = __progname; *s != '\0'; s++) if (*s == '/') Index: csu/powerpc/Makefile =================================================================== RCS file: /home/ncvs/src/lib/csu/powerpc/Makefile,v retrieving revision 1.2 diff -u -d -r1.2 Makefile --- csu/powerpc/Makefile 27 Oct 2001 08:32:07 -0000 1.2 +++ csu/powerpc/Makefile 26 Mar 2002 12:10:33 -0000 @@ -6,7 +6,8 @@ OBJS= ${SRCS:N*.h:R:S/$/.o/g} OBJS+= gcrt1.o CFLAGS+= -Wall -Wno-unused \ - -I${.CURDIR}/../common + -I${.CURDIR}/../common \ + -I${.CURDIR}/../../libc/include NOMAN= true NOPIC= true NOPROFILE= true Index: csu/powerpc/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/powerpc/crt1.c,v retrieving revision 1.7 diff -u -d -r1.7 crt1.c --- csu/powerpc/crt1.c 23 Mar 2002 18:14:04 -0000 1.7 +++ csu/powerpc/crt1.c 27 Mar 2002 12:18:59 -0000 @@ -43,6 +43,7 @@ #endif #include +#include "libc_private.h" #include "crtbrand.c" struct Struct_Obj_Entry; @@ -63,7 +64,7 @@ #endif char **environ; -char *__progname = ""; +const char *__progname = ""; struct ps_strings *__ps_strings; /* The entry function. @@ -80,11 +81,11 @@ struct ps_strings *ps_strings; /* BSD extension */ { char *namep; + const char *s; environ = envp; if (argc > 0 && argv[0] != NULL) { - char *s; __progname = argv[0]; for (s = __progname; *s != '\0'; s++) if (*s == '/') Index: csu/sparc64/Makefile =================================================================== RCS file: /home/ncvs/src/lib/csu/sparc64/Makefile,v retrieving revision 1.3 diff -u -d -r1.3 Makefile --- csu/sparc64/Makefile 10 Mar 2002 23:33:49 -0000 1.3 +++ csu/sparc64/Makefile 26 Mar 2002 12:10:44 -0000 @@ -5,7 +5,8 @@ SRCS= crt1.c crti.S crtn.S OBJS= ${SRCS:N*.h:R:S/$/.o/g} OBJS+= gcrt1.o -CFLAGS+= -I${.CURDIR}/../common +CFLAGS+= -I${.CURDIR}/../common \ + -I${.CURDIR}/../../libc/include NOMAN= true NOPIC= true NOPROFILE= true Index: csu/sparc64/crt1.c =================================================================== RCS file: /home/ncvs/src/lib/csu/sparc64/crt1.c,v retrieving revision 1.6 diff -u -d -r1.6 crt1.c --- csu/sparc64/crt1.c 16 Mar 2002 20:38:46 -0000 1.6 +++ csu/sparc64/crt1.c 27 Mar 2002 12:19:09 -0000 @@ -34,6 +34,7 @@ #endif #include +#include "libc_private.h" #include "crtbrand.c" struct Struct_Obj_Entry; @@ -55,7 +56,7 @@ #endif char **environ; -char *__progname = ""; +const char *__progname = ""; /* The entry function. */ /* @@ -77,6 +78,7 @@ int argc; char **argv; char **env; + const char *s; #if 0 void (*term)(void); @@ -91,7 +93,6 @@ env = ap + 2 + argc; environ = env; if (argc > 0 && argv[0] != NULL) { - char *s; __progname = argv[0]; for (s = __progname; *s != '\0'; s++) if (*s == '/') Index: libc/gen/err.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/err.c,v retrieving revision 1.12 diff -u -d -r1.12 err.c --- libc/gen/err.c 22 Mar 2002 21:52:05 -0000 1.12 +++ libc/gen/err.c 27 Mar 2002 11:08:23 -0000 @@ -39,15 +39,14 @@ #include "namespace.h" #include -#include "un-namespace.h" #include +#include #include #include #include +#include "un-namespace.h" -#include - -extern char *__progname; /* Program name, from crt0. */ +#include "libc_private.h" static FILE *err_file; /* file to use for error output */ static void (*err_exit)(int); @@ -110,7 +109,7 @@ { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", __progname); + fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) { vfprintf(err_file, fmt, ap); fprintf(err_file, ": "); @@ -138,7 +137,7 @@ { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", __progname); + fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) vfprintf(err_file, fmt, ap); fprintf(err_file, "\n"); @@ -183,7 +182,7 @@ { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", __progname); + fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) { vfprintf(err_file, fmt, ap); fprintf(err_file, ": "); @@ -207,7 +206,7 @@ { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", __progname); + fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) vfprintf(err_file, fmt, ap); fprintf(err_file, "\n"); Index: libc/gen/getlogin.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/getlogin.c,v retrieving revision 1.7 diff -u -d -r1.7 getlogin.c --- libc/gen/getlogin.c 1 Feb 2002 00:57:29 -0000 1.7 +++ libc/gen/getlogin.c 27 Mar 2002 08:47:31 -0000 @@ -48,7 +48,7 @@ #include #include "un-namespace.h" -#include +#include "libc_private.h" #define THREAD_LOCK() if (__isthreaded) _pthread_mutex_lock(&logname_mutex) #define THREAD_UNLOCK() if (__isthreaded) _pthread_mutex_unlock(&logname_mutex) Index: libc/gen/getprogname.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/getprogname.c,v retrieving revision 1.3 diff -u -d -r1.3 getprogname.c --- libc/gen/getprogname.c 1 Feb 2002 00:57:29 -0000 1.3 +++ libc/gen/getprogname.c 27 Mar 2002 11:13:57 -0000 @@ -1,12 +1,16 @@ #include __FBSDID("$FreeBSD: src/lib/libc/gen/getprogname.c,v 1.3 2002/02/01 00:57:29 obrien Exp $"); +#include "namespace.h" #include +#include "un-namespace.h" -extern const char *__progname; +#include "libc_private.h" + +__weak_reference(_getprogname, getprogname); const char * -getprogname(void) +_getprogname(void) { return (__progname); Index: libc/gen/setproctitle.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/setproctitle.c,v retrieving revision 1.15 diff -u -d -r1.15 setproctitle.c --- libc/gen/setproctitle.c 1 Feb 2002 00:57:29 -0000 1.15 +++ libc/gen/setproctitle.c 27 Mar 2002 11:13:25 -0000 @@ -18,6 +18,7 @@ #include __FBSDID("$FreeBSD: src/lib/libc/gen/setproctitle.c,v 1.15 2002/02/01 00:57:29 obrien Exp $"); +#include "namespace.h" #include #include #include @@ -31,6 +32,9 @@ #include #include #include +#include "un-namespace.h" + +#include "libc_private.h" /* * Older FreeBSD 2.0, 2.1 and 2.2 had different ps_strings structures and @@ -53,7 +57,6 @@ #include #define SPT_BUFSIZE 2048 /* from other parts of sendmail */ -extern char * __progname; /* is this defined in a .h anywhere? */ void setproctitle(const char *fmt, ...) @@ -83,7 +86,7 @@ len = 0; } else { /* print program name heading for grep */ - (void) snprintf(buf, sizeof(buf), "%s: ", __progname); + (void)snprintf(buf, sizeof(buf), "%s: ", _getprogname()); len = strlen(buf); } Index: libc/gen/setprogname.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/setprogname.c,v retrieving revision 1.7 diff -u -d -r1.7 setprogname.c --- libc/gen/setprogname.c 1 Feb 2002 00:57:29 -0000 1.7 +++ libc/gen/setprogname.c 27 Mar 2002 08:47:31 -0000 @@ -4,7 +4,7 @@ #include #include -extern const char *__progname; +#include "libc_private.h" void setprogname(const char *progname) Index: libc/gen/syslog.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/syslog.c,v retrieving revision 1.25 diff -u -d -r1.25 syslog.c --- libc/gen/syslog.c 9 Mar 2002 11:38:01 -0000 1.25 +++ libc/gen/syslog.c 27 Mar 2002 11:13:09 -0000 @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +61,8 @@ #endif #include "un-namespace.h" +#include "libc_private.h" + static int LogFile = -1; /* fd for log */ static int connected; /* have done connect */ static int opened; /* have done openlog() */ @@ -67,7 +70,6 @@ static const char *LogTag = NULL; /* string to tag the entry with */ static int LogFacility = LOG_USER; /* default facility code */ static int LogMask = 0xff; /* mask of priorities to be logged */ -extern char *__progname; /* Program name, from crt0. */ static void disconnectlog(void); /* disconnect from syslogd */ static void connectlog(void); /* (re)connect to syslogd */ @@ -181,7 +183,7 @@ stdp = tbuf + (sizeof(tbuf) - tbuf_cookie.left); } if (LogTag == NULL) - LogTag = __progname; + LogTag = _getprogname(); if (LogTag != NULL) (void)fprintf(fp, "%s", LogTag); if (LogStat & LOG_PID) Index: libc/gmon/gmon.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gmon/gmon.c,v retrieving revision 1.13 diff -u -d -r1.13 gmon.c --- libc/gmon/gmon.c 15 Feb 2002 02:37:08 -0000 1.13 +++ libc/gmon/gmon.c 27 Mar 2002 11:14:05 -0000 @@ -43,23 +43,22 @@ #include #include -#include "namespace.h" #include -#include "un-namespace.h" -#include #include +#include +#include #include #include #include "un-namespace.h" +#include "libc_private.h" + #if defined(__ELF__) && (defined(i386) || defined(__sparc64__)) extern char *minbrk asm (".minbrk"); #else extern char *minbrk asm ("minbrk"); #endif -extern char *__progname; - struct gmonparam _gmonparam = { GMON_PROF_OFF }; static int s_scale; @@ -175,7 +174,7 @@ } moncontrol(0); - snprintf(outname, sizeof(outname), "%s.gmon", __progname); + snprintf(outname, sizeof(outname), "%s.gmon", _getprogname()); fd = _open(outname, O_CREAT|O_TRUNC|O_WRONLY, 0666); if (fd < 0) { _warn("_mcleanup: %s", outname); Index: libc/include/libc_private.h =================================================================== RCS file: /home/ncvs/src/lib/libc/include/libc_private.h,v retrieving revision 1.4 diff -u -d -r1.4 libc_private.h --- libc/include/libc_private.h 24 Jan 2001 13:00:08 -0000 1.4 +++ libc/include/libc_private.h 27 Mar 2002 11:14:18 -0000 @@ -63,4 +63,10 @@ #define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) #define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp) +/* + * This is a pointer in the C run-time startup code. It is used + * by getprogname() and setprogname(). + */ +extern const char *__progname; + #endif /* _LIBC_PRIVATE_H_ */ Index: libc/include/namespace.h =================================================================== RCS file: /home/ncvs/src/lib/libc/include/namespace.h,v retrieving revision 1.8 diff -u -d -r1.8 namespace.h --- libc/include/namespace.h 22 Mar 2002 23:41:48 -0000 1.8 +++ libc/include/namespace.h 27 Mar 2002 11:14:23 -0000 @@ -67,6 +67,7 @@ #define getdirentries _getdirentries #define getlogin _getlogin #define getpeername _getpeername +#define getprogname _getprogname #define getsockname _getsockname #define getsockopt _getsockopt #define ioctl _ioctl Index: libc/include/un-namespace.h =================================================================== RCS file: /home/ncvs/src/lib/libc/include/un-namespace.h,v retrieving revision 1.6 diff -u -d -r1.6 un-namespace.h --- libc/include/un-namespace.h 11 Nov 2001 02:48:09 -0000 1.6 +++ libc/include/un-namespace.h 27 Mar 2002 11:14:29 -0000 @@ -52,6 +52,7 @@ #undef getdirentries #undef getlogin #undef getpeername +#undef getprogname #undef getsockname #undef getsockopt #undef ioctl Index: libc/locale/collate.c =================================================================== RCS file: /home/ncvs/src/lib/libc/locale/collate.c,v retrieving revision 1.23 diff -u -d -r1.23 collate.c --- libc/locale/collate.c 22 Mar 2002 21:52:18 -0000 1.23 +++ libc/locale/collate.c 27 Mar 2002 11:14:40 -0000 @@ -41,6 +41,8 @@ #include "collate.h" #include "setlocale.h" +#include "libc_private.h" + int __collate_load_error = 1; int __collate_substitute_nontrivial; char __collate_version[STR_LEN]; @@ -176,11 +178,10 @@ void __collate_err(int ex, const char *f) { - extern char *__progname; /* Program name, from crt0. */ const char *s; int serrno = errno; - s = __progname; + s = _getprogname(); _write(STDERR_FILENO, s, strlen(s)); _write(STDERR_FILENO, ": ", 2); s = f; Index: libc/stdlib/getopt.c =================================================================== RCS file: /home/ncvs/src/lib/libc/stdlib/getopt.c,v retrieving revision 1.5 diff -u -d -r1.5 getopt.c --- libc/stdlib/getopt.c 22 Mar 2002 21:53:10 -0000 1.5 +++ libc/stdlib/getopt.c 27 Mar 2002 11:14:49 -0000 @@ -37,9 +37,13 @@ #include __FBSDID("$FreeBSD: src/lib/libc/stdlib/getopt.c,v 1.5 2002/03/22 21:53:10 obrien Exp $"); +#include "namespace.h" #include #include #include +#include "un-namespace.h" + +#include "libc_private.h" int opterr = 1, /* if error message should be printed */ optind = 1, /* index into parent argv vector */ @@ -61,7 +65,6 @@ char * const *nargv; const char *ostr; { - extern char *__progname; static char *place = EMSG; /* option letter processing */ char *oli; /* option letter list index */ @@ -88,8 +91,8 @@ if (!*place) ++optind; if (opterr && *ostr != ':' && optopt != BADCH) - (void)fprintf(stderr, - "%s: illegal option -- %c\n", __progname, optopt); + (void)fprintf(stderr, "%s: illegal option -- %c\n", + _getprogname(), optopt); return (BADCH); } if (*++oli != ':') { /* don't need argument */ @@ -107,7 +110,7 @@ if (opterr) (void)fprintf(stderr, "%s: option requires an argument -- %c\n", - __progname, optopt); + _getprogname(), optopt); return (BADCH); } else /* white space */ Index: libc/stdlib/malloc.c =================================================================== RCS file: /home/ncvs/src/lib/libc/stdlib/malloc.c,v retrieving revision 1.66 diff -u -d -r1.66 malloc.c --- libc/stdlib/malloc.c 22 Mar 2002 21:53:10 -0000 1.66 +++ libc/stdlib/malloc.c 27 Mar 2002 11:15:33 -0000 @@ -297,14 +297,12 @@ void (*_malloc_message)(char *p1, char *p2, char *p3, char *p4) = wrtmessage; -extern char *__progname; - static void wrterror(char *p) { suicide = 1; - _malloc_message(__progname, malloc_func, " error: ", p); + _malloc_message(_getprogname(), malloc_func, " error: ", p); abort(); } @@ -314,7 +312,7 @@ if (malloc_abort) wrterror(p); - _malloc_message(__progname, malloc_func, " warning: ", p); + _malloc_message(_getprogname(), malloc_func, " warning: ", p); } /* Index: libc_r/uthread/uthread_spinlock.c =================================================================== RCS file: /home/ncvs/src/lib/libc_r/uthread/uthread_spinlock.c,v retrieving revision 1.9 diff -u -d -r1.9 uthread_spinlock.c --- libc_r/uthread/uthread_spinlock.c 24 Jan 2001 13:03:36 -0000 1.9 +++ libc_r/uthread/uthread_spinlock.c 25 Mar 2002 19:52:44 -0000 @@ -33,14 +33,16 @@ * */ +#include #include +#include #include -#include #include -#include -#include "pthread_private.h" +#include -extern char *__progname; +#include + +#include "pthread_private.h" /* * Lock a location for the running thread. Yield to allow other @@ -91,7 +93,7 @@ cnt++; if (cnt > 100) { char str[256]; - snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", __progname, curthread, lck, fname, lineno, lck->fname, lck->lineno); + snprintf(str, sizeof(str), "%s - Warning: Thread %p attempted to lock %p from %s (%d) was left locked from %s (%d)\n", _getprogname(), curthread, lck, fname, lineno, lck->fname, lck->lineno); __sys_write(2,str,strlen(str)); __sleep(1); cnt = 0; Index: libfetch/http.c =================================================================== RCS file: /home/ncvs/src/lib/libfetch/http.c,v retrieving revision 1.51 diff -u -d -r1.51 http.c --- libfetch/http.c 5 Feb 2002 22:13:51 -0000 1.51 +++ libfetch/http.c 25 Mar 2002 19:53:14 -0000 @@ -80,8 +80,6 @@ #include "common.h" #include "httperr.h" -extern char *__progname; /* XXX not portable */ - /* Maximum number of redirects to follow */ #define MAX_REDIRECT 5 @@ -840,7 +838,7 @@ if ((p = getenv("HTTP_USER_AGENT")) != NULL && *p != '\0') _http_cmd(fd, "User-Agent: %s", p); else - _http_cmd(fd, "User-Agent: %s " _LIBFETCH_VER, __progname); + _http_cmd(fd, "User-Agent: %s " _LIBFETCH_VER, _getprogname()); if (url->offset) _http_cmd(fd, "Range: bytes=%lld-", (long long)url->offset); _http_cmd(fd, "Connection: close"); Index: libncp/ncpl_subr.c =================================================================== RCS file: /home/ncvs/src/lib/libncp/ncpl_subr.c,v retrieving revision 1.5 diff -u -d -r1.5 ncpl_subr.c --- libncp/ncpl_subr.c 30 Sep 2001 22:01:19 -0000 1.5 +++ libncp/ncpl_subr.c 25 Mar 2002 19:53:32 -0000 @@ -51,8 +51,6 @@ /*#include */ #include "ncp_mod.h" -extern char *__progname; - int sysentoffset; void @@ -309,7 +307,7 @@ ++ncp_optind; if (ncp_opterr && *ostr != ':') (void)fprintf(stderr, - "%s: illegal option -- %c\n", __progname, ncp_optopt); + "%s: illegal option -- %c\n", _getprogname(), ncp_optopt); return (BADCH); } if (*++oli != ':') { /* don't need argument */ @@ -327,7 +325,7 @@ if (ncp_opterr) (void)fprintf(stderr, "%s: option requires an argument -- %c\n", - __progname, ncp_optopt); + _getprogname(), ncp_optopt); return (BADCH); } else /* white space */ @@ -439,7 +437,7 @@ ncp_error(const char *fmt, int error, ...) { va_list ap; - fprintf(stderr, "%s: ", __progname); + fprintf(stderr, "%s: ", _getprogname()); va_start(ap, error); vfprintf(stderr, fmt, ap); va_end(ap); To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Thu Mar 28 14:23: 0 2002 Delivered-To: freebsd-audit@freebsd.org Received: from smtp2.enst.fr (matrix2.enst.fr [137.194.2.14]) by hub.freebsd.org (Postfix) with ESMTP id 2801A37B400 for ; Thu, 28 Mar 2002 14:22:56 -0800 (PST) Received: from bofh.enst.fr (bofh-2.enst.fr [137.194.2.37]) (using TLSv1 with cipher EDH-RSA-DES-CBC3-SHA (168/168 bits)) (Client did not present a certificate) by smtp2.enst.fr (Postfix) with ESMTP id 28BC91EEC7; Thu, 28 Mar 2002 23:22:54 +0100 (MET) Received: (from beyssac@localhost) by bofh.enst.fr (8.11.6/8.11.6) id g2SMMsK51941; Thu, 28 Mar 2002 23:22:54 +0100 (CET) (envelope-from beyssac) Date: Thu, 28 Mar 2002 23:22:54 +0100 From: Pierre Beyssac To: Thomas Quinot Cc: freebsd-audit@FreeBSD.ORG Subject: Re: boot2.c deobfuscation Message-ID: <20020328232254.A51714@bofh.enst.fr> References: <20020328102637.A842@melusine.cuivre.fr.eu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20020328102637.A842@melusine.cuivre.fr.eu.org>; from thomas@cuivre.fr.eu.org on Thu, Mar 28, 2002 at 10:26:37AM +0100 Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Thu, Mar 28, 2002 at 10:26:37AM +0100, Thomas Quinot wrote: > Could others please review the following patch (originally > PR i386/36015, diff updated to reflect the commit of 36016)? I'll commit it, unless someone seriously objects to it. Just a minor nitpick, I will style(9)ise the following and fix the typo: > + /* Try to exec stage 3 boot loader. If interrupted by a keypress, * > + * or in case of failure, try to load a kernel directly instaed. */ -- Pierre Beyssac pb@enst.fr To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Sat Mar 30 1: 5:40 2002 Delivered-To: freebsd-audit@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 62E2637B405; Sat, 30 Mar 2002 01:05:36 -0800 (PST) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id UAA25387; Sat, 30 Mar 2002 20:05:33 +1100 Date: Sat, 30 Mar 2002 20:06:17 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: markm@FreeBSD.ORG Cc: audit@FreeBSD.ORG Subject: Re: __progname cleanups - commit candidate 2 In-Reply-To: <200203282029.g2SKTDdC005176@greenpeace.grondar.org> Message-ID: <20020330195324.F745-100000@gamplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Thu, 28 Mar 2002 markm@FreeBSD.ORG wrote: > Index: libc/gen/err.c > =================================================================== > RCS file: /home/ncvs/src/lib/libc/gen/err.c,v > retrieving revision 1.12 > diff -u -d -r1.12 err.c > --- libc/gen/err.c 22 Mar 2002 21:52:05 -0000 1.12 > +++ libc/gen/err.c 27 Mar 2002 11:08:23 -0000 > @@ -39,15 +39,14 @@ > > #include "namespace.h" > #include > -#include "un-namespace.h" > #include > +#include > #include > #include > #include > +#include "un-namespace.h" Note another advantage of bracketing all other includes with the namespace includes: it hides all the prototypes for standard interfaces that are redefined in namespace.h, so we get errors if we reference the standard interfaces, provided we compile the library with WARNS, which we don't. Declaring additional prototypes for the nonstandard entry points doesn't work so well since it doesn't generate these errors. > Index: libc/include/namespace.h > =================================================================== > RCS file: /home/ncvs/src/lib/libc/include/namespace.h,v > retrieving revision 1.8 > diff -u -d -r1.8 namespace.h > --- libc/include/namespace.h 22 Mar 2002 23:41:48 -0000 1.8 > +++ libc/include/namespace.h 27 Mar 2002 11:14:23 -0000 > @@ -67,6 +67,7 @@ > #define getdirentries _getdirentries > #define getlogin _getlogin > #define getpeername _getpeername > +#define getprogname _getprogname > #define getsockname _getsockname > #define getsockopt _getsockopt > #define ioctl _ioctl > Index: libc/include/un-namespace.h > =================================================================== > RCS file: /home/ncvs/src/lib/libc/include/un-namespace.h,v > retrieving revision 1.6 > diff -u -d -r1.6 un-namespace.h > --- libc/include/un-namespace.h 11 Nov 2001 02:48:09 -0000 1.6 > +++ libc/include/un-namespace.h 27 Mar 2002 11:14:29 -0000 > @@ -52,6 +52,7 @@ > #undef getdirentries > #undef getlogin > #undef getpeername > +#undef getprogname > #undef getsockname > #undef getsockopt > #undef ioctl Misplaced #define and #undef. They are in the libc_r/libpthread section but have nothing to do with libc_r/libpthread. Everything else except the line lengths seems to be OK. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message