From 76fe441a7bf75d73962641b785f158b5cc9dc7f8 Mon Sep 17 00:00:00 2001 From: markm Date: Fri, 29 Mar 2002 22:43:43 +0000 Subject: Do not use __progname directly (except in [gs]etprogname(3)). Also, make an internal _getprogname() that is used only inside libc. For libc, getprogname(3) is a weak symbol in case a function of the same name is defined in userland. --- lib/csu/alpha/Makefile | 3 ++- lib/csu/alpha/crt1.c | 5 +++-- lib/csu/amd64/Makefile | 3 ++- lib/csu/amd64/crt1.c | 5 +++-- lib/csu/i386-elf/Makefile | 3 ++- lib/csu/i386-elf/crt1.c | 5 +++-- lib/csu/i386/Makefile | 3 ++- lib/csu/i386/crt0.c | 12 +++++++----- lib/csu/ia64/Makefile | 3 ++- lib/csu/ia64/crt1.c | 5 +++-- lib/csu/powerpc/Makefile | 3 ++- lib/csu/powerpc/crt1.c | 5 +++-- lib/csu/sparc64/Makefile | 3 ++- lib/csu/sparc64/crt1.c | 5 +++-- lib/libc/gen/err.c | 15 +++++++-------- lib/libc/gen/getlogin.c | 2 +- lib/libc/gen/getprogname.c | 8 ++++++-- lib/libc/gen/setproctitle.c | 7 +++++-- lib/libc/gen/setprogname.c | 2 +- lib/libc/gen/syslog.c | 6 ++++-- lib/libc/gmon/gmon.c | 11 +++++------ lib/libc/include/libc_private.h | 6 ++++++ lib/libc/include/namespace.h | 1 + lib/libc/include/un-namespace.h | 1 + lib/libc/locale/collate.c | 5 +++-- lib/libc/stdlib/getopt.c | 11 +++++++---- lib/libc/stdlib/malloc.c | 6 ++---- lib/libc_r/uthread/uthread_spinlock.c | 12 +++++++----- lib/libfetch/http.c | 4 +--- lib/libkse/thread/thr_spinlock.c | 12 +++++++----- lib/libncp/ncpl_subr.c | 8 +++----- lib/libpthread/thread/thr_spinlock.c | 12 +++++++----- 32 files changed, 113 insertions(+), 79 deletions(-) diff --git a/lib/csu/alpha/Makefile b/lib/csu/alpha/Makefile index 0ee91e0..5528e4e 100644 --- a/lib/csu/alpha/Makefile +++ b/lib/csu/alpha/Makefile @@ -6,7 +6,8 @@ SRCS= crt1.c crti.S crtn.S 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 diff --git a/lib/csu/alpha/crt1.c b/lib/csu/alpha/crt1.c index b092c67..9a76159 100644 --- a/lib/csu/alpha/crt1.c +++ b/lib/csu/alpha/crt1.c @@ -40,6 +40,7 @@ #endif #include +#include "libc_private.h" #include "crtbrand.c" struct Struct_Obj_Entry; @@ -60,7 +61,7 @@ extern int etext; #endif char **environ; -char *__progname = ""; +const char *__progname = ""; /* The entry function. */ void @@ -72,13 +73,13 @@ _start(char **ap, 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 == '/') diff --git a/lib/csu/amd64/Makefile b/lib/csu/amd64/Makefile index cb1bc63..b602a02 100644 --- a/lib/csu/amd64/Makefile +++ b/lib/csu/amd64/Makefile @@ -6,7 +6,8 @@ SRCS= crt1.c crti.S crtn.S 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 diff --git a/lib/csu/amd64/crt1.c b/lib/csu/amd64/crt1.c index 60ca5b5..5dcd90e 100644 --- a/lib/csu/amd64/crt1.c +++ b/lib/csu/amd64/crt1.c @@ -29,6 +29,7 @@ #include #include +#include "libc_private.h" #include "crtbrand.c" typedef void (*fptr)(void); @@ -57,7 +58,7 @@ extern int _DYNAMIC; #endif char **environ; -char *__progname = ""; +const char *__progname = ""; void _start(char *arguments, ...) @@ -66,6 +67,7 @@ _start(char *arguments, ...) int argc; char **argv; char **env; + const char *s; rtld_cleanup = get_rtld_cleanup(); argv = &arguments; @@ -73,7 +75,6 @@ _start(char *arguments, ...) 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 == '/') diff --git a/lib/csu/i386-elf/Makefile b/lib/csu/i386-elf/Makefile index cb1bc63..b602a02 100644 --- a/lib/csu/i386-elf/Makefile +++ b/lib/csu/i386-elf/Makefile @@ -6,7 +6,8 @@ SRCS= crt1.c crti.S crtn.S 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 diff --git a/lib/csu/i386-elf/crt1.c b/lib/csu/i386-elf/crt1.c index 60ca5b5..5dcd90e 100644 --- a/lib/csu/i386-elf/crt1.c +++ b/lib/csu/i386-elf/crt1.c @@ -29,6 +29,7 @@ #include #include +#include "libc_private.h" #include "crtbrand.c" typedef void (*fptr)(void); @@ -57,7 +58,7 @@ extern int _DYNAMIC; #endif char **environ; -char *__progname = ""; +const char *__progname = ""; void _start(char *arguments, ...) @@ -66,6 +67,7 @@ _start(char *arguments, ...) int argc; char **argv; char **env; + const char *s; rtld_cleanup = get_rtld_cleanup(); argv = &arguments; @@ -73,7 +75,6 @@ _start(char *arguments, ...) 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 == '/') diff --git a/lib/csu/i386/Makefile b/lib/csu/i386/Makefile index 02f14f2..b3be808 100644 --- a/lib/csu/i386/Makefile +++ b/lib/csu/i386/Makefile @@ -1,7 +1,8 @@ # from: @(#)Makefile 5.6 (Berkeley) 5/22/91 # $FreeBSD$ -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 diff --git a/lib/csu/i386/crt0.c b/lib/csu/i386/crt0.c index e1a5551..49431d9 100644 --- a/lib/csu/i386/crt0.c +++ b/lib/csu/i386/crt0.c @@ -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 @@ static void __do_dynamic_link(char **argv); 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 @@ start() 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 @@ start() environ = targv; if (argv[0]) { - register char *s; __progname = argv[0]; for (s=__progname; *s != '\0'; s++) if (*s == '/') diff --git a/lib/csu/ia64/Makefile b/lib/csu/ia64/Makefile index 0ee91e0..5528e4e 100644 --- a/lib/csu/ia64/Makefile +++ b/lib/csu/ia64/Makefile @@ -6,7 +6,8 @@ SRCS= crt1.c crti.S crtn.S 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 diff --git a/lib/csu/ia64/crt1.c b/lib/csu/ia64/crt1.c index 474bad8..4320b7b 100644 --- a/lib/csu/ia64/crt1.c +++ b/lib/csu/ia64/crt1.c @@ -36,6 +36,7 @@ #endif #include +#include "libc_private.h" #include "crtbrand.c" struct Struct_Obj_Entry; @@ -56,7 +57,7 @@ extern int etext; #endif char **environ; -char *__progname = ""; +const char *__progname = ""; /* The entry function. */ void @@ -67,6 +68,7 @@ _start(char **ap, int argc; char **argv; char **env; + const char *s; /* Calculate gp */ __asm __volatile(" \ @@ -82,7 +84,6 @@ _start(char **ap, 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 == '/') diff --git a/lib/csu/powerpc/Makefile b/lib/csu/powerpc/Makefile index 65dd009..44f1f3a 100644 --- a/lib/csu/powerpc/Makefile +++ b/lib/csu/powerpc/Makefile @@ -6,7 +6,8 @@ SRCS= crt1.c crti.S crtn.S 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 diff --git a/lib/csu/powerpc/crt1.c b/lib/csu/powerpc/crt1.c index eb293d6..46156eb 100644 --- a/lib/csu/powerpc/crt1.c +++ b/lib/csu/powerpc/crt1.c @@ -43,6 +43,7 @@ #endif #include +#include "libc_private.h" #include "crtbrand.c" struct Struct_Obj_Entry; @@ -63,7 +64,7 @@ extern int etext; #endif char **environ; -char *__progname = ""; +const char *__progname = ""; struct ps_strings *__ps_strings; /* The entry function. @@ -80,11 +81,11 @@ _start(argc, argv, envp, obj, cleanup, ps_strings) 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 == '/') diff --git a/lib/csu/sparc64/Makefile b/lib/csu/sparc64/Makefile index 566c5d9..5985c8c 100644 --- a/lib/csu/sparc64/Makefile +++ b/lib/csu/sparc64/Makefile @@ -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 diff --git a/lib/csu/sparc64/crt1.c b/lib/csu/sparc64/crt1.c index 0c20383..99a63c8 100644 --- a/lib/csu/sparc64/crt1.c +++ b/lib/csu/sparc64/crt1.c @@ -34,6 +34,7 @@ #endif #include +#include "libc_private.h" #include "crtbrand.c" struct Struct_Obj_Entry; @@ -55,7 +56,7 @@ extern int etext; #endif char **environ; -char *__progname = ""; +const char *__progname = ""; /* The entry function. */ /* @@ -77,6 +78,7 @@ _start(char **ap, int argc; char **argv; char **env; + const char *s; #if 0 void (*term)(void); @@ -91,7 +93,6 @@ _start(char **ap, 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 == '/') diff --git a/lib/libc/gen/err.c b/lib/libc/gen/err.c index e3a5142..9365d7d 100644 --- a/lib/libc/gen/err.c +++ b/lib/libc/gen/err.c @@ -39,15 +39,14 @@ __FBSDID("$FreeBSD$"); #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 @@ verrc(eval, code, fmt, ap) { 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 @@ verrx(eval, fmt, ap) { 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 @@ vwarnc(code, fmt, ap) { 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 @@ vwarnx(fmt, ap) { 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"); diff --git a/lib/libc/gen/getlogin.c b/lib/libc/gen/getlogin.c index ea895ba..664f208 100644 --- a/lib/libc/gen/getlogin.c +++ b/lib/libc/gen/getlogin.c @@ -48,7 +48,7 @@ __FBSDID("$FreeBSD$"); #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) diff --git a/lib/libc/gen/getprogname.c b/lib/libc/gen/getprogname.c index b0a8dec..fd51d13 100644 --- a/lib/libc/gen/getprogname.c +++ b/lib/libc/gen/getprogname.c @@ -1,12 +1,16 @@ #include __FBSDID("$FreeBSD$"); +#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); diff --git a/lib/libc/gen/setproctitle.c b/lib/libc/gen/setproctitle.c index b9b8418..d6101e1 100644 --- a/lib/libc/gen/setproctitle.c +++ b/lib/libc/gen/setproctitle.c @@ -18,6 +18,7 @@ #include __FBSDID("$FreeBSD$"); +#include "namespace.h" #include #include #include @@ -31,6 +32,9 @@ __FBSDID("$FreeBSD$"); #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 @@ struct old_ps_strings { #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 @@ setproctitle(const char *fmt, ...) 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); } diff --git a/lib/libc/gen/setprogname.c b/lib/libc/gen/setprogname.c index 5be00fa..29a6cd0 100644 --- a/lib/libc/gen/setprogname.c +++ b/lib/libc/gen/setprogname.c @@ -4,7 +4,7 @@ __FBSDID("$FreeBSD$"); #include #include -extern const char *__progname; +#include "libc_private.h" void setprogname(const char *progname) diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c index 11ae5b5..621e63a 100644 --- a/lib/libc/gen/syslog.c +++ b/lib/libc/gen/syslog.c @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -60,6 +61,8 @@ __FBSDID("$FreeBSD$"); #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 int LogStat = 0; /* status bits, set by openlog() */ 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 @@ vsyslog(pri, fmt, ap) 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) diff --git a/lib/libc/gmon/gmon.c b/lib/libc/gmon/gmon.c index be373b0..49326e5 100644 --- a/lib/libc/gmon/gmon.c +++ b/lib/libc/gmon/gmon.c @@ -43,23 +43,22 @@ __FBSDID("$FreeBSD$"); #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 @@ _mcleanup() } 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); diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h index f356e18..e47e756 100644 --- a/lib/libc/include/libc_private.h +++ b/lib/libc/include/libc_private.h @@ -63,4 +63,10 @@ extern int __isthreaded; #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_ */ diff --git a/lib/libc/include/namespace.h b/lib/libc/include/namespace.h index 7753f98..bbd33c0 100644 --- a/lib/libc/include/namespace.h +++ b/lib/libc/include/namespace.h @@ -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 diff --git a/lib/libc/include/un-namespace.h b/lib/libc/include/un-namespace.h index 855c101..3b21900 100644 --- a/lib/libc/include/un-namespace.h +++ b/lib/libc/include/un-namespace.h @@ -52,6 +52,7 @@ #undef getdirentries #undef getlogin #undef getpeername +#undef getprogname #undef getsockname #undef getsockopt #undef ioctl diff --git a/lib/libc/locale/collate.c b/lib/libc/locale/collate.c index 347baef..6766c9e 100644 --- a/lib/libc/locale/collate.c +++ b/lib/libc/locale/collate.c @@ -41,6 +41,8 @@ __FBSDID("$FreeBSD$"); #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 @@ __collate_strdup(s) 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; diff --git a/lib/libc/stdlib/getopt.c b/lib/libc/stdlib/getopt.c index 0f9918d..4cad100 100644 --- a/lib/libc/stdlib/getopt.c +++ b/lib/libc/stdlib/getopt.c @@ -37,9 +37,13 @@ static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95"; #include __FBSDID("$FreeBSD$"); +#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 @@ getopt(nargc, nargv, ostr) 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 @@ getopt(nargc, nargv, ostr) 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 @@ getopt(nargc, nargv, ostr) if (opterr) (void)fprintf(stderr, "%s: option requires an argument -- %c\n", - __progname, optopt); + _getprogname(), optopt); return (BADCH); } else /* white space */ diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 202ac69..43aad2d 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -297,14 +297,12 @@ wrtmessage(char *p1, char *p2, char *p3, char *p4) 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 @@ wrtwarning(char *p) if (malloc_abort) wrterror(p); - _malloc_message(__progname, malloc_func, " warning: ", p); + _malloc_message(_getprogname(), malloc_func, " warning: ", p); } /* diff --git a/lib/libc_r/uthread/uthread_spinlock.c b/lib/libc_r/uthread/uthread_spinlock.c index 696174e..7333709 100644 --- a/lib/libc_r/uthread/uthread_spinlock.c +++ b/lib/libc_r/uthread/uthread_spinlock.c @@ -33,14 +33,16 @@ * */ +#include #include +#include #include -#include #include -#include -#include "pthread_private.h" +#include + +#include -extern char *__progname; +#include "pthread_private.h" /* * Lock a location for the running thread. Yield to allow other @@ -91,7 +93,7 @@ _spinlock_debug(spinlock_t *lck, char *fname, int lineno) 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; diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c index eed12f2..8d040d0 100644 --- a/lib/libfetch/http.c +++ b/lib/libfetch/http.c @@ -80,8 +80,6 @@ __FBSDID("$FreeBSD$"); #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 @@ _http_request(struct url *URL, const char *op, struct url_stat *us, 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"); diff --git a/lib/libkse/thread/thr_spinlock.c b/lib/libkse/thread/thr_spinlock.c index 696174e..7333709 100644 --- a/lib/libkse/thread/thr_spinlock.c +++ b/lib/libkse/thread/thr_spinlock.c @@ -33,14 +33,16 @@ * */ +#include #include +#include #include -#include #include -#include -#include "pthread_private.h" +#include + +#include -extern char *__progname; +#include "pthread_private.h" /* * Lock a location for the running thread. Yield to allow other @@ -91,7 +93,7 @@ _spinlock_debug(spinlock_t *lck, char *fname, int lineno) 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; diff --git a/lib/libncp/ncpl_subr.c b/lib/libncp/ncpl_subr.c index f516ece..ed70eb8 100644 --- a/lib/libncp/ncpl_subr.c +++ b/lib/libncp/ncpl_subr.c @@ -51,8 +51,6 @@ __FBSDID("$FreeBSD$"); /*#include */ #include "ncp_mod.h" -extern char *__progname; - int sysentoffset; void @@ -309,7 +307,7 @@ ncp_getopt(nargc, nargv, ostr) ++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 @@ ncp_getopt(nargc, nargv, ostr) 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 @@ void 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); diff --git a/lib/libpthread/thread/thr_spinlock.c b/lib/libpthread/thread/thr_spinlock.c index 696174e..7333709 100644 --- a/lib/libpthread/thread/thr_spinlock.c +++ b/lib/libpthread/thread/thr_spinlock.c @@ -33,14 +33,16 @@ * */ +#include #include +#include #include -#include #include -#include -#include "pthread_private.h" +#include + +#include -extern char *__progname; +#include "pthread_private.h" /* * Lock a location for the running thread. Yield to allow other @@ -91,7 +93,7 @@ _spinlock_debug(spinlock_t *lck, char *fname, int lineno) 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; -- cgit v1.1