From: guenther Date: Wed, 5 Jul 2023 18:45:14 +0000 (+0000) Subject: It isn't portable to use stderr (or std{in,out}) in file-scope X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c0c90351672c5fc26a45cc4e1c51ee3b16e9c570;p=openbsd It isn't portable to use stderr (or std{in,out}) in file-scope initializers as they are not required to be compile-time constants. So, intialize these global variables at the top of main(). ok miod@ deraadt@ yasuoka@ millert@ --- diff --git a/bin/pax/pax.c b/bin/pax/pax.c index 0ddfd9d91ed..cd5fcd69021 100644 --- a/bin/pax/pax.c +++ b/bin/pax/pax.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pax.c,v 1.53 2019/06/28 13:34:59 deraadt Exp $ */ +/* $OpenBSD: pax.c,v 1.54 2023/07/05 18:45:14 guenther Exp $ */ /* $NetBSD: pax.c,v 1.5 1996/03/26 23:54:20 mrg Exp $ */ /*- @@ -93,7 +93,7 @@ char *dirptr; /* destination dir in a copy */ char *argv0; /* root of argv[0] */ enum op_mode op_mode; /* what program are we acting as? */ sigset_t s_mask; /* signal mask for cleanup critical sect */ -FILE *listf = stderr; /* file pointer to print file list to */ +FILE *listf; /* file pointer to print file list to */ int listfd = STDERR_FILENO; /* fd matching listf, for sighandler output */ char *tempfile; /* tempfile to use for mkstemp(3) */ char *tempbase; /* basename of tempfile to use for mkstemp(3) */ @@ -224,6 +224,8 @@ main(int argc, char **argv) char *tmpdir; size_t tdlen; + listf = stderr; + /* * Keep a reference to cwd, so we can always come back home. */ diff --git a/usr.sbin/amd/amd/amd.c b/usr.sbin/amd/amd/amd.c index 03163b129d1..1c777cd9672 100644 --- a/usr.sbin/amd/amd/amd.c +++ b/usr.sbin/amd/amd/amd.c @@ -32,7 +32,7 @@ * SUCH DAMAGE. * * from: @(#)amd.c 8.1 (Berkeley) 6/6/93 - * $Id: amd.c,v 1.24 2021/10/21 10:55:56 deraadt Exp $ + * $Id: amd.c,v 1.25 2023/07/05 18:45:14 guenther Exp $ */ /* @@ -190,6 +190,8 @@ main(int argc, char *argv[]) pid_t ppid = 0; int error; + logfp = stderr; /* Log errors to stderr initially */ + /* * Make sure some built-in assumptions are true before we start */ diff --git a/usr.sbin/amd/amd/xutil.c b/usr.sbin/amd/amd/xutil.c index ea36fec9c98..082ac1555e9 100644 --- a/usr.sbin/amd/amd/xutil.c +++ b/usr.sbin/amd/amd/xutil.c @@ -32,7 +32,7 @@ * SUCH DAMAGE. * * from: @(#)xutil.c 8.1 (Berkeley) 6/6/93 - * $Id: xutil.c,v 1.19 2015/12/12 20:06:42 mmcc Exp $ + * $Id: xutil.c,v 1.20 2023/07/05 18:45:14 guenther Exp $ */ #include "am.h" @@ -45,7 +45,7 @@ #include #include -FILE *logfp = stderr; /* Log errors to stderr initially */ +FILE *logfp; int syslogging; int xlog_level = XLOG_ALL & ~XLOG_MAP & ~XLOG_STATS & ~XLOG_INFO; int xlog_level_init = ~0;