getopt: don't modify argv as it breaks restart()
This commit is contained in:
parent
c173a8ad44
commit
5adde7a4ed
4 changed files with 11 additions and 13 deletions
|
@ -37,7 +37,7 @@ struct lgetopt
|
||||||
|
|
||||||
extern struct lgetopt myopts[];
|
extern struct lgetopt myopts[];
|
||||||
|
|
||||||
void usage(char *);
|
void usage(const char *);
|
||||||
void parseargs(int *, char ***, struct lgetopt *);
|
void parseargs(int *, char * const **, struct lgetopt *);
|
||||||
|
|
||||||
#endif /* __GETOPT_H_INCLUDED__ */
|
#endif /* __GETOPT_H_INCLUDED__ */
|
||||||
|
|
|
@ -29,10 +29,10 @@
|
||||||
# define OPTCHAR '-'
|
# define OPTCHAR '-'
|
||||||
|
|
||||||
void
|
void
|
||||||
parseargs(int *argc, char ***argv, struct lgetopt *opts)
|
parseargs(int *argc, char * const **argv, struct lgetopt *opts)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *progname = (*argv)[0];
|
const char *progname = (*argv)[0];
|
||||||
|
|
||||||
/* loop through each argument */
|
/* loop through each argument */
|
||||||
for (;;)
|
for (;;)
|
||||||
|
@ -53,12 +53,10 @@ parseargs(int *argc, char ***argv, struct lgetopt *opts)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*argv)[0]++;
|
|
||||||
|
|
||||||
/* search through our argument list, and see if it matches */
|
/* search through our argument list, and see if it matches */
|
||||||
for (i = 0; opts[i].opt; i++)
|
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 our argument */
|
||||||
found = 1;
|
found = 1;
|
||||||
|
@ -74,7 +72,7 @@ parseargs(int *argc, char ***argv, struct lgetopt *opts)
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Error: option '%c%s' requires an argument\n",
|
"Error: option '%c%s' requires an argument\n",
|
||||||
OPTCHAR, opts[i].opt);
|
OPTCHAR, opts[i].opt);
|
||||||
usage((*argv)[0]);
|
usage(progname);
|
||||||
}
|
}
|
||||||
|
|
||||||
*((int *) opts[i].argloc) = atoi((*argv)[1]);
|
*((int *) opts[i].argloc) = atoi((*argv)[1]);
|
||||||
|
@ -111,14 +109,14 @@ parseargs(int *argc, char ***argv, struct lgetopt *opts)
|
||||||
}
|
}
|
||||||
if(!found)
|
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);
|
usage(progname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
usage(char *name)
|
usage(const char *name)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
|
|
@ -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 local_oper_list; /* our opers, duplicated in lclient_list */
|
||||||
rb_dlink_list oper_list; /* network opers */
|
rb_dlink_list oper_list; /* network opers */
|
||||||
|
|
||||||
char **myargv;
|
char * const *myargv;
|
||||||
volatile sig_atomic_t dorehash = false;
|
volatile sig_atomic_t dorehash = false;
|
||||||
volatile sig_atomic_t dorehashbans = false;
|
volatile sig_atomic_t dorehashbans = false;
|
||||||
volatile sig_atomic_t doremotd = 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
|
* Side Effects - this is where the ircd gets going right now
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
charybdis_main(int argc, char *argv[])
|
charybdis_main(int argc, char * const argv[])
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include "ircd_signal.h"
|
#include "ircd_signal.h"
|
||||||
|
|
||||||
/* external var */
|
/* external var */
|
||||||
extern char **myargv;
|
extern char * const *myargv;
|
||||||
|
|
||||||
void
|
void
|
||||||
restart(const char *mesg)
|
restart(const char *mesg)
|
||||||
|
|
Loading…
Reference in a new issue