From 344d6b9ac3c795f2942e457c1ab38b1dac5f7242 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 26 Feb 2012 12:39:46 +0100 Subject: [PATCH] Let tincctl use the NETNAME environment variable if no -n option is given. This allows administrators who frequently want to work with one tinc network to omit the -n option. Since the NETNAME variable is set by tincd when executing scripts, this makes it slightly easier to use tincctl from within scripts. --- doc/tinc.texi | 11 +++++++++++ doc/tincctl.8.in | 7 +++++++ src/tincctl.c | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/doc/tinc.texi b/doc/tinc.texi index 0c470123..c26bf770 100644 --- a/doc/tinc.texi +++ b/doc/tinc.texi @@ -1928,6 +1928,7 @@ tincctl -n @var{netname} reload @menu * tincctl runtime options:: +* tincctl environment variables:: * tincctl commands:: * tincctl examples:: * tincctl top:: @@ -1960,6 +1961,16 @@ Output version information and exit. @end table +@c ================================================================== +@node tincctl environment variables +@section tincctl environment variables + +@table @env +@cindex NETNAME +@item NETNAME +If no netname is specified on the command line with the @option{-n} option, +the value of this environment variable is used. +@end table @c ================================================================== @node tincctl commands diff --git a/doc/tincctl.8.in b/doc/tincctl.8.in index bbc8dba6..a3168ba9 100644 --- a/doc/tincctl.8.in +++ b/doc/tincctl.8.in @@ -37,6 +37,13 @@ Display short list of options. .It Fl -version Output version information and exit. .El +.Sh ENVIRONMENT VARIABLES +.Bl -tag -width indent +.It Ev NETNAME +If no netname is specified on the command line with the +.Fl n +option, the value of this environment variable is used. +.El .Sh COMMANDS .zZ .Bl -tag -width indent diff --git a/src/tincctl.c b/src/tincctl.c index 4f06daa6..d1df07be 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -138,6 +138,12 @@ static bool parse_options(int argc, char **argv) { } } + if(!netname) { + netname = getenv("NETNAME"); + if(netname) + netname = xstrdup(netname); + } + return true; } -- 2.20.1