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