diff options
author | 2015-11-06 23:47:42 +0000 | |
---|---|---|
committer | 2015-11-06 23:47:42 +0000 | |
commit | 4a3a0dd4deb9bd02100183014729398fe6c6b9d9 (patch) | |
tree | c18aa5cc6e665f05410587051e3208e945e0a39e | |
parent | In in_arpinput() do not make an extra route lookup to check wether (diff) | |
download | wireguard-openbsd-4a3a0dd4deb9bd02100183014729398fe6c6b9d9.tar.xz wireguard-openbsd-4a3a0dd4deb9bd02100183014729398fe6c6b9d9.zip |
Use __progname instead of the homegrown ProgramName.
-rw-r--r-- | usr.bin/at/at.c | 25 | ||||
-rw-r--r-- | usr.bin/at/parsetime.c | 16 | ||||
-rw-r--r-- | usr.sbin/cron/client.c | 6 | ||||
-rw-r--r-- | usr.sbin/cron/cron.c | 16 | ||||
-rw-r--r-- | usr.sbin/cron/crontab.c | 35 | ||||
-rw-r--r-- | usr.sbin/cron/globals.h | 14 | ||||
-rw-r--r-- | usr.sbin/cron/misc.c | 11 |
7 files changed, 52 insertions, 71 deletions
diff --git a/usr.bin/at/at.c b/usr.bin/at/at.c index 77499b8f404..9b607723420 100644 --- a/usr.bin/at/at.c +++ b/usr.bin/at/at.c @@ -1,4 +1,4 @@ -/* $OpenBSD: at.c,v 1.68 2015/11/04 20:28:17 millert Exp $ */ +/* $OpenBSD: at.c,v 1.69 2015/11/06 23:47:42 millert Exp $ */ /* * at.c : Put file into atrun queue @@ -31,8 +31,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define MAIN_PROGRAM - #include <sys/types.h> #include <sys/stat.h> @@ -100,7 +98,7 @@ time_t parsetime(int, char **); static __dead void panic(const char *a) { - (void)fprintf(stderr, "%s: %s\n", ProgramName, a); + (void)fprintf(stderr, "%s: %s\n", __progname, a); if (fcreated) unlink(atfile); @@ -113,7 +111,7 @@ panic(const char *a) static __dead void panic2(const char *a, const char *b) { - (void)fprintf(stderr, "%s: %s%s\n", ProgramName, a, b); + (void)fprintf(stderr, "%s: %s%s\n", __progname, a, b); if (fcreated) unlink(atfile); @@ -498,7 +496,7 @@ list_jobs(int argc, char **argv, int count_only, int csort) } else uids = NULL; - shortformat = strcmp(ProgramName, "at") == 0; + shortformat = strcmp(__progname, "at") == 0; if (chdir(AT_DIR) != 0) perr2("Cannot change to ", AT_DIR); @@ -660,7 +658,7 @@ process_jobs(int argc, char **argv, int what) if (user_uid != pw->pw_uid && user_uid != 0) { fprintf(stderr, "%s: Only the superuser" " may %s other users' jobs\n", - ProgramName, what == ATRM + __progname, what == ATRM ? "remove" : "view"); exit(EXIT_FAILURE); } @@ -745,7 +743,7 @@ process_jobs(int argc, char **argv, int what) if (jobs[i] != NULL) { if (!force) fprintf(stderr, "%s: %s: no such job\n", - ProgramName, jobs[i]); + __progname, jobs[i]); error++; } } @@ -908,23 +906,18 @@ main(int argc, char **argv) if (argc < 1) usage(); - if ((ProgramName = strrchr(argv[0], '/')) != NULL) - ProgramName++; - else - ProgramName = argv[0]; - user_uid = getuid(); user_gid = getgid(); spool_gid = getegid(); /* find out what this program is supposed to do */ - if (strcmp(ProgramName, "atq") == 0) { + if (strcmp(__progname, "atq") == 0) { program = ATQ; options = "cnvq:"; - } else if (strcmp(ProgramName, "atrm") == 0) { + } else if (strcmp(__progname, "atrm") == 0) { program = ATRM; options = "afi"; - } else if (strcmp(ProgramName, "batch") == 0) { + } else if (strcmp(__progname, "batch") == 0) { program = BATCH; options = "f:q:mv"; } diff --git a/usr.bin/at/parsetime.c b/usr.bin/at/parsetime.c index b01a6c81632..121041c2b14 100644 --- a/usr.bin/at/parsetime.c +++ b/usr.bin/at/parsetime.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parsetime.c,v 1.23 2015/08/20 22:32:41 deraadt Exp $ */ +/* $OpenBSD: parsetime.c,v 1.24 2015/11/06 23:47:42 millert Exp $ */ /* * parsetime.c - parse time for at(1) @@ -182,7 +182,7 @@ init_scanner(int argc, char **argv) if ((sc_token = malloc(sc_len)) == NULL) { fprintf(stderr, "%s: Insufficient virtual memory\n", - ProgramName); + __progname); return (-1); } return (0); @@ -264,7 +264,7 @@ token(void) static void plonk(int tok) { - fprintf(stderr, "%s: %s time\n", ProgramName, + fprintf(stderr, "%s: %s time\n", __progname, (tok == EOF) ? "incomplete" : "garbled"); } @@ -368,7 +368,7 @@ plus(struct tm *tm) case MINUTES: if (expectplur != sc_tokplur) fprintf(stderr, "%s: pluralization is wrong\n", - ProgramName); + __progname); dateadd(increment, tm); return (0); } @@ -446,7 +446,7 @@ tod(struct tm *tm) } return (0); bad: - fprintf(stderr, "%s: garbled time\n", ProgramName); + fprintf(stderr, "%s: garbled time\n", __progname); return (-1); } @@ -607,7 +607,7 @@ month(struct tm *tm) } return (0); bad: - fprintf(stderr, "%s: garbled time\n", ProgramName); + fprintf(stderr, "%s: garbled time\n", __progname); return (-1); } @@ -700,13 +700,13 @@ parsetime(int argc, char **argv) } if (runtimer < 0) { - fprintf(stderr, "%s: garbled time\n", ProgramName); + fprintf(stderr, "%s: garbled time\n", __progname); return (-1); } if (nowtimer > runtimer) { fprintf(stderr, "%s: cannot schedule jobs in the past\n", - ProgramName); + __progname); return (-1); } diff --git a/usr.sbin/cron/client.c b/usr.sbin/cron/client.c index 0334bff30e3..1957b6369f3 100644 --- a/usr.sbin/cron/client.c +++ b/usr.sbin/cron/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.3 2015/11/04 20:28:17 millert Exp $ */ +/* $OpenBSD: client.c,v 1.4 2015/11/06 23:47:42 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -101,7 +101,7 @@ poke_daemon(const char *spool_dir, unsigned char cookie) if (snprintf(s_un.sun_path, sizeof s_un.sun_path, "%s/%s", SPOOL_DIR, CRONSOCK) >= sizeof(s_un.sun_path)) { fprintf(stderr, "%s: %s/%s: path too long\n", - ProgramName, SPOOL_DIR, CRONSOCK); + __progname, SPOOL_DIR, CRONSOCK); return; } s_un.sun_family = AF_UNIX; @@ -110,7 +110,7 @@ poke_daemon(const char *spool_dir, unsigned char cookie) send(sock, &cookie, 1, MSG_NOSIGNAL); else fprintf(stderr, "%s: warning, cron does not appear to be " - "running.\n", ProgramName); + "running.\n", __progname); if (sock >= 0) close(sock); } diff --git a/usr.sbin/cron/cron.c b/usr.sbin/cron/cron.c index 68e12e22187..4111850981f 100644 --- a/usr.sbin/cron/cron.c +++ b/usr.sbin/cron/cron.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cron.c,v 1.62 2015/11/04 20:28:17 millert Exp $ */ +/* $OpenBSD: cron.c,v 1.63 2015/11/06 23:47:42 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -17,8 +17,6 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define MAIN_PROGRAM - #include <sys/types.h> #include <sys/socket.h> #include <sys/stat.h> @@ -71,7 +69,7 @@ static void usage(void) { - fprintf(stderr, "usage: %s [-n] [-l load_avg]\n", ProgramName); + fprintf(stderr, "usage: %s [-n] [-l load_avg]\n", __progname); exit(EXIT_FAILURE); } @@ -81,8 +79,6 @@ main(int argc, char *argv[]) struct sigaction sact; sigset_t blocked, omask; - ProgramName = argv[0]; - setlocale(LC_ALL, ""); setvbuf(stdout, NULL, _IOLBF, 0); @@ -434,7 +430,7 @@ open_socket(void) sock = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); if (sock == -1) { fprintf(stderr, "%s: can't create socket: %s\n", - ProgramName, strerror(errno)); + __progname, strerror(errno)); log_it("CRON", getpid(), "DEATH", "can't create socket"); exit(EXIT_FAILURE); } @@ -448,7 +444,7 @@ open_socket(void) s_un.sun_family = AF_UNIX; if (connect(sock, (struct sockaddr *)&s_un, sizeof(s_un)) == 0) { - fprintf(stderr, "%s: already running\n", ProgramName); + fprintf(stderr, "%s: already running\n", __progname); log_it("CRON", getpid(), "DEATH", "already running"); exit(EXIT_FAILURE); } @@ -460,13 +456,13 @@ open_socket(void) umask(omask); if (rc != 0) { fprintf(stderr, "%s: can't bind socket: %s\n", - ProgramName, strerror(errno)); + __progname, strerror(errno)); log_it("CRON", getpid(), "DEATH", "can't bind socket"); exit(EXIT_FAILURE); } if (listen(sock, SOMAXCONN)) { fprintf(stderr, "%s: can't listen on socket: %s\n", - ProgramName, strerror(errno)); + __progname, strerror(errno)); log_it("CRON", getpid(), "DEATH", "can't listen on socket"); exit(EXIT_FAILURE); } diff --git a/usr.sbin/cron/crontab.c b/usr.sbin/cron/crontab.c index afb38e10114..d695e79228f 100644 --- a/usr.sbin/cron/crontab.c +++ b/usr.sbin/cron/crontab.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crontab.c,v 1.82 2015/11/04 20:28:17 millert Exp $ */ +/* $OpenBSD: crontab.c,v 1.83 2015/11/06 23:47:42 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -17,8 +17,6 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define MAIN_PROGRAM - #include <sys/types.h> #include <sys/stat.h> #include <sys/wait.h> @@ -67,9 +65,9 @@ static int replace_cmd(void); static void usage(const char *msg) { - fprintf(stderr, "%s: usage error: %s\n", ProgramName, msg); - fprintf(stderr, "usage: %s [-u user] file\n", ProgramName); - fprintf(stderr, " %s [-e | -l | -r] [-u user]\n", ProgramName); + fprintf(stderr, "%s: usage error: %s\n", __progname, msg); + fprintf(stderr, "usage: %s [-u user] file\n", __progname); + fprintf(stderr, " %s [-e | -l | -r] [-u user]\n", __progname); fprintf(stderr, "\t\t(default operation is replace, per 1003.2)\n" "\t-e\t(edit user's crontab)\n" @@ -86,7 +84,6 @@ main(int argc, char *argv[]) Pid = getpid(); user_gid = getgid(); crontab_gid = getegid(); - ProgramName = argv[0]; if (pledge("stdio rpath wpath cpath fattr getpw unix flock id proc exec", NULL) == -1) { @@ -102,7 +99,7 @@ main(int argc, char *argv[]) if (!allowed(RealUser, CRON_ALLOW, CRON_DENY)) { fprintf(stderr, "You (%s) are not allowed to use this program (%s)\n", - User, ProgramName); + User, __progname); fprintf(stderr, "See crontab(1) for more information\n"); log_it(RealUser, Pid, "AUTH", "crontab command not allowed"); exit(EXIT_FAILURE); @@ -137,7 +134,7 @@ parse_args(int argc, char *argv[]) if (!(pw = getpwuid(getuid()))) { fprintf(stderr, "%s: your UID isn't in the passwd file.\n", - ProgramName); + __progname); fprintf(stderr, "bailing out.\n"); exit(EXIT_FAILURE); } @@ -159,7 +156,7 @@ parse_args(int argc, char *argv[]) } if (!(pw = getpwnam(optarg))) { fprintf(stderr, "%s: user `%s' unknown\n", - ProgramName, optarg); + __progname, optarg); exit(EXIT_FAILURE); } if (strlcpy(User, optarg, sizeof User) >= sizeof User) @@ -353,7 +350,7 @@ edit_cmd(void) rewind(NewCrontab); if (ferror(NewCrontab)) { fprintf(stderr, "%s: error while writing new crontab to %s\n", - ProgramName, Filename); + __progname, Filename); fatal: unlink(Filename); exit(EXIT_FAILURE); @@ -379,13 +376,13 @@ edit_cmd(void) if (lstat(Filename, &xstatbuf) == 0 && statbuf.st_ino != xstatbuf.st_ino) { fprintf(stderr, "%s: crontab temp file moved, editor " - "may create backup files improperly\n", ProgramName); + "may create backup files improperly\n", __progname); } fprintf(stderr, "%s: no changes made to crontab\n", - ProgramName); + __progname); goto remove; } - fprintf(stderr, "%s: installing new crontab\n", ProgramName); + fprintf(stderr, "%s: installing new crontab\n", __progname); switch (replace_cmd()) { case 0: break; @@ -413,11 +410,11 @@ edit_cmd(void) case -2: abandon: fprintf(stderr, "%s: edits left in %s\n", - ProgramName, Filename); + __progname, Filename); goto done; default: fprintf(stderr, "%s: panic: bad switch() in replace_cmd()\n", - ProgramName); + __progname); goto fatal; } remove: @@ -442,7 +439,7 @@ replace_cmd(void) char **envp = env_init(); if (envp == NULL) { - fprintf(stderr, "%s: Cannot allocate memory.\n", ProgramName); + fprintf(stderr, "%s: Cannot allocate memory.\n", __progname); return (-2); } if (snprintf(TempFilename, sizeof TempFilename, "%s/tmp.XXXXXXXXX", @@ -484,7 +481,7 @@ replace_cmd(void) if (ferror(tmp)) { fprintf(stderr, "%s: error while writing new crontab to %s\n", - ProgramName, TempFilename); + __progname, TempFilename); fclose(tmp); error = -2; goto done; @@ -546,7 +543,7 @@ replace_cmd(void) } if (rename(TempFilename, n)) { fprintf(stderr, "%s: error renaming %s to %s\n", - ProgramName, TempFilename, n); + __progname, TempFilename, n); perror("rename"); error = -2; goto done; diff --git a/usr.sbin/cron/globals.h b/usr.sbin/cron/globals.h index 60bd938ed72..342f8e217ac 100644 --- a/usr.sbin/cron/globals.h +++ b/usr.sbin/cron/globals.h @@ -1,4 +1,4 @@ -/* $OpenBSD: globals.h,v 1.12 2015/11/04 12:53:05 millert Exp $ */ +/* $OpenBSD: globals.h,v 1.13 2015/11/06 23:47:42 millert Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -17,13 +17,5 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef MAIN_PROGRAM -# define XTRN -# define INIT(x) = x -#else -# define XTRN extern -# define INIT(x) -#endif - -XTRN char *ProgramName INIT("amnesia"); -XTRN int LineNumber INIT(0); +extern int LineNumber; +extern char *__progname; diff --git a/usr.sbin/cron/misc.c b/usr.sbin/cron/misc.c index 9dd4ad08f3e..8a8180f2581 100644 --- a/usr.sbin/cron/misc.c +++ b/usr.sbin/cron/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.68 2015/11/04 20:28:17 millert Exp $ */ +/* $OpenBSD: misc.c,v 1.69 2015/11/06 23:47:42 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -33,6 +33,7 @@ #include "globals.h" static int syslog_open = FALSE; +int LineNumber; /* get_char(file) : like getc() but increment LineNumber on newlines */ @@ -126,7 +127,7 @@ log_it(const char *username, pid_t xpid, const char *event, const char *detail) "END EDIT", "LIST", "MAIL", "RELOAD", "REPLACE", "STARTUP", NULL }; if (!syslog_open) { - openlog(ProgramName, LOG_PID, LOG_CRON); + openlog(__progname, LOG_PID, LOG_CRON); syslog_open = TRUE; /* assume openlog success */ } @@ -140,8 +141,10 @@ log_it(const char *username, pid_t xpid, const char *event, const char *detail) void log_close(void) { - closelog(); - syslog_open = FALSE; + if (syslog_open) { + closelog(); + syslog_open = FALSE; + } } /* char *first_word(char *s, char *t) |