From 5adde7a4edf1af48b5cde624324bdf7538d859b4 Mon Sep 17 00:00:00 2001 From: Simon Arlott Date: Mon, 25 Apr 2016 23:21:38 +0100 Subject: [PATCH] getopt: don't modify argv as it breaks restart() --- include/ircd_getopt.h | 4 ++-- ircd/getopt.c | 14 ++++++-------- ircd/ircd.c | 4 ++-- ircd/restart.c | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/include/ircd_getopt.h b/include/ircd_getopt.h index 763cb489c..9ffeb76da 100644 --- a/include/ircd_getopt.h +++ b/include/ircd_getopt.h @@ -37,7 +37,7 @@ struct lgetopt extern struct lgetopt myopts[]; -void usage(char *); -void parseargs(int *, char ***, struct lgetopt *); +void usage(const char *); +void parseargs(int *, char * const **, struct lgetopt *); #endif /* __GETOPT_H_INCLUDED__ */ diff --git a/ircd/getopt.c b/ircd/getopt.c index 9e28ea2f8..f7c6c826c 100644 --- a/ircd/getopt.c +++ b/ircd/getopt.c @@ -29,10 +29,10 @@ # define OPTCHAR '-' void -parseargs(int *argc, char ***argv, struct lgetopt *opts) +parseargs(int *argc, char * const **argv, struct lgetopt *opts) { int i; - char *progname = (*argv)[0]; + const char *progname = (*argv)[0]; /* loop through each argument */ for (;;) @@ -53,12 +53,10 @@ parseargs(int *argc, char ***argv, struct lgetopt *opts) return; } - (*argv)[0]++; - /* search through our argument list, and see if it matches */ for (i = 0; opts[i].opt; i++) { - if(!strcmp(opts[i].opt, (*argv)[0])) + if(!strcmp(opts[i].opt, &(*argv)[0][1])) { /* found our argument */ found = 1; @@ -74,7 +72,7 @@ parseargs(int *argc, char ***argv, struct lgetopt *opts) fprintf(stderr, "Error: option '%c%s' requires an argument\n", OPTCHAR, opts[i].opt); - usage((*argv)[0]); + usage(progname); } *((int *) opts[i].argloc) = atoi((*argv)[1]); @@ -111,14 +109,14 @@ parseargs(int *argc, char ***argv, struct lgetopt *opts) } if(!found) { - fprintf(stderr, "error: unknown argument '%c%s'\n", OPTCHAR, (*argv)[0]); + fprintf(stderr, "error: unknown argument '%c%s'\n", OPTCHAR, &(*argv)[0][1]); usage(progname); } } } void -usage(char *name) +usage(const char *name) { int i = 0; diff --git a/ircd/ircd.c b/ircd/ircd.c index 45f58db12..3a16a40c7 100644 --- a/ircd/ircd.c +++ b/ircd/ircd.c @@ -94,7 +94,7 @@ rb_dlink_list global_serv_list; /* global servers on the network */ rb_dlink_list local_oper_list; /* our opers, duplicated in lclient_list */ rb_dlink_list oper_list; /* network opers */ -char **myargv; +char * const *myargv; volatile sig_atomic_t dorehash = false; volatile sig_atomic_t dorehashbans = false; volatile sig_atomic_t doremotd = false; @@ -645,7 +645,7 @@ seed_random(void *unused) * Side Effects - this is where the ircd gets going right now */ int -charybdis_main(int argc, char *argv[]) +charybdis_main(int argc, char * const argv[]) { int fd; diff --git a/ircd/restart.c b/ircd/restart.c index f91f9293c..2db2a2ec1 100644 --- a/ircd/restart.c +++ b/ircd/restart.c @@ -32,7 +32,7 @@ #include "ircd_signal.h" /* external var */ -extern char **myargv; +extern char * const *myargv; void restart(const char *mesg)