Main: Add local option

Add option that changes default paths for config file and control socket
to the current working directory.
This commit is contained in:
Ondrej Zajicek (work) 2016-04-07 12:20:45 +02:00
parent 06edbb67ed
commit f2ae2badff
4 changed files with 32 additions and 5 deletions

View file

@ -37,7 +37,7 @@
#define SERVER_READ_BUF_LEN 4096 #define SERVER_READ_BUF_LEN 4096
static char *opt_list = "s:vr"; static char *opt_list = "s:vrl";
static int verbose, restricted, once; static int verbose, restricted, once;
static char *init_cmd; static char *init_cmd;
@ -59,13 +59,14 @@ int term_lns, term_cls;
static void static void
usage(char *name) usage(char *name)
{ {
fprintf(stderr, "Usage: %s [-s <control-socket>] [-v] [-r]\n", name); fprintf(stderr, "Usage: %s [-s <control-socket>] [-v] [-r] [-l]\n", name);
exit(1); exit(1);
} }
static void static void
parse_args(int argc, char **argv) parse_args(int argc, char **argv)
{ {
int server_changed = 0;
int c; int c;
while ((c = getopt(argc, argv, opt_list)) >= 0) while ((c = getopt(argc, argv, opt_list)) >= 0)
@ -73,6 +74,7 @@ parse_args(int argc, char **argv)
{ {
case 's': case 's':
server_path = optarg; server_path = optarg;
server_changed = 1;
break; break;
case 'v': case 'v':
verbose++; verbose++;
@ -80,6 +82,10 @@ parse_args(int argc, char **argv)
case 'r': case 'r':
restricted = 1; restricted = 1;
break; break;
case 'l':
if (!server_changed)
server_path = xbasename(server_path);
break;
default: default:
usage(argv[0]); usage(argv[0]);
} }

View file

@ -171,6 +171,11 @@ BIRD executable by configuring out routing protocols you don't use, and
<tag>-f</tag> <tag>-f</tag>
run bird in foreground. run bird in foreground.
<tag>-l</tag>
look for a configuration file and a communication socket in the current
working directory instead of in default system paths. However, paths
specified by options <cf/-c/, <cf/-s/ have higher priority.
<tag>-R</tag> <tag>-R</tag>
apply graceful restart recovery after start. apply graceful restart recovery after start.
</descrip> </descrip>

View file

@ -24,4 +24,10 @@ void buffer_puts(buffer *buf, const char *str);
int patmatch(const byte *pat, const byte *str); int patmatch(const byte *pat, const byte *str);
static inline char *xbasename(const char *str)
{
char *s = strrchr(str, '/');
return s ? s+1 : (char *) str;
}
#endif #endif

View file

@ -617,7 +617,7 @@ signal_init(void)
* Parsing of command-line arguments * Parsing of command-line arguments
*/ */
static char *opt_list = "c:dD:ps:P:u:g:fR"; static char *opt_list = "c:dD:ps:P:u:g:flR";
static int parse_and_exit; static int parse_and_exit;
char *bird_name; char *bird_name;
static char *use_user; static char *use_user;
@ -627,7 +627,7 @@ static int run_in_foreground = 0;
static void static void
usage(void) usage(void)
{ {
fprintf(stderr, "Usage: %s [-c <config-file>] [-d] [-D <debug-file>] [-p] [-s <control-socket>] [-P <pid-file>] [-u <user>] [-g <group>] [-f] [-R]\n", bird_name); fprintf(stderr, "Usage: %s [-c <config-file>] [-d] [-D <debug-file>] [-p] [-s <control-socket>] [-P <pid-file>] [-u <user>] [-g <group>] [-f] [-l] [-R]\n", bird_name);
exit(1); exit(1);
} }
@ -677,7 +677,7 @@ get_gid(const char *s)
if (!s) if (!s)
return 0; return 0;
errno = 0; errno = 0;
rv = strtol(s, &endptr, 10); rv = strtol(s, &endptr, 10);
@ -694,6 +694,8 @@ get_gid(const char *s)
static void static void
parse_args(int argc, char **argv) parse_args(int argc, char **argv)
{ {
int config_changed = 0;
int socket_changed = 0;
int c; int c;
bird_name = get_bird_name(argv[0], "bird"); bird_name = get_bird_name(argv[0], "bird");
@ -712,6 +714,7 @@ parse_args(int argc, char **argv)
{ {
case 'c': case 'c':
config_name = optarg; config_name = optarg;
config_changed = 1;
break; break;
case 'd': case 'd':
debug_flag |= 1; debug_flag |= 1;
@ -725,6 +728,7 @@ parse_args(int argc, char **argv)
break; break;
case 's': case 's':
path_control_socket = optarg; path_control_socket = optarg;
socket_changed = 1;
break; break;
case 'P': case 'P':
pid_file = optarg; pid_file = optarg;
@ -738,6 +742,12 @@ parse_args(int argc, char **argv)
case 'f': case 'f':
run_in_foreground = 1; run_in_foreground = 1;
break; break;
case 'l':
if (!config_changed)
config_name = xbasename(config_name);
if (!socket_changed)
path_control_socket = xbasename(path_control_socket);
break;
case 'R': case 'R':
graceful_restart_recovery(); graceful_restart_recovery();
break; break;