diff options
author | Austin Adams <git@austinjadams.com> | 2016-01-23 12:32:39 -0500 |
---|---|---|
committer | Austin Adams <git@austinjadams.com> | 2016-01-23 12:32:39 -0500 |
commit | 31f557dab9e391420096b06339e9ab5c00e0cca8 (patch) | |
tree | 36b8712cf5a6ec48d54cd82241861a5863038ea4 | |
parent | 91169ec0ec95566e4450e82debd6543605ab67ae (diff) | |
download | nsdo-1.0.tar.gz nsdo-1.0.tar.xz |
add --version flag, which prints "1.0"v1.0
For printing the current version, nsdo now accepts --version/-V. I've
updated the manpage to reflect this.
-rw-r--r-- | README.md | 13 | ||||
-rw-r--r-- | nsdo.1 | 8 | ||||
-rw-r--r-- | nsdo.c | 21 |
3 files changed, 33 insertions, 9 deletions
@@ -54,14 +54,14 @@ manpage nsdo(1) General Commands Manual nsdo(1) - - NAME nsdo - run a command in a network namespace SYNOPSIS nsdo namespace command [args ...] + nsdo { --version | -V } + DESCRIPTION Execute command as the current user/group in namespace, a Linux network namespace set up with iproute2 (see ip- @@ -74,9 +74,12 @@ manpage rent namespace exists in that directory. Consequently, you can not nest instances of nsdo. + OPTIONS + --version, -V + Instead of running a command, print nsdo's version + and exit. + SEE ALSO ip(8), ip-netns(8), namespaces(7) - - - 2015-08-08 nsdo(1) + 2016-01-23 nsdo(1) @@ -1,15 +1,21 @@ -.TH nsdo 1 2015-08-08 +.TH nsdo 1 2016-01-23 .SH NAME nsdo \- run a command in a network namespace .SH SYNOPSIS .B nsdo .I namespace command [\fIargs\fR ...] +.PP +.B nsdo +{ --version | -V } .SH DESCRIPTION Execute \fIcommand\fR as the current user/group in \fInamespace\fR, a Linux network namespace set up with \fBiproute2\fR (see \fBip-netns(8)\fR). .PP By default, \fBiproute2\fR places network namespaces in /var/run/netns/, so \fBnsdo\fR searces for namespaces there (including \fInamespace\fR). To prevent \fIcommand\fR from easily escaping the namespace 'jail,' \fBnsdo\fR will exit if the current namespace exists in that directory. Consequently, you can not nest instances of \fBnsdo\fR. +.SH OPTIONS +.IP "--version, -V" +Instead of running a command, print \fBnsdo\fR's version and exit. .SH SEE ALSO .B ip(8), ip-netns(8), namespaces(7) @@ -35,8 +35,11 @@ #include <sys/stat.h> #include <sys/types.h> -#define NS_PATH "/var/run/netns" #define PROGRAM "nsdo" +#define VERSION "1.0" +#define NS_PATH "/var/run/netns" +#define VERSION_FLAG "--version" +#define VERSION_FLAG_SHORT "-V" enum { EXIT_OK, @@ -54,8 +57,17 @@ enum { ARG_MIN_ARGS }; +void print_version() { + puts(PROGRAM " version " VERSION); +} + void print_usage() { - fprintf(stderr, "usage: " PROGRAM " <namespace> <command> [args...]\n"); + fprintf(stderr, "usage: " PROGRAM " <namespace> <command> [args...]\n" + " " PROGRAM " { " VERSION_FLAG " | " VERSION_FLAG_SHORT " }\n"); +} + +int is_version_flag(char *arg) { + return !strcmp(arg, VERSION_FLAG) || !strcmp(arg, VERSION_FLAG_SHORT); } int current_ns_inode(ino_t *inode) { @@ -193,7 +205,10 @@ int run(char *cmd, char **argv) { } int main(int argc, char **argv) { - if (argc < ARG_MIN_ARGS) { + if (argc-1 == 1 && is_version_flag(argv[1])) { + print_version(); + return EXIT_OK; + } else if (argc < ARG_MIN_ARGS) { print_usage(); return EXIT_BAD_INVOCATION; } |