From d85a58feebc279b6c4a2d8d5e3ca379574bc4089 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Fri, 6 Jul 2012 23:18:24 -0700 Subject: [PATCH] Autogenerate man page for mnexec. --- Makefile | 18 ++++++++++++------ bin/mn | 2 +- mnexec.c | 34 +++++++++++++++++++++++----------- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index d41fd8c..ac83ca5 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ MN = bin/mn BIN = $(MN) PYSRC = $(MININET) $(TEST) $(EXAMPLES) $(BIN) MNEXEC = mnexec -MANPAGE = mn.1 +MANPAGES = mn.1 mnexec.1 P8IGN = E251,E201,E302,E202 BINDIR = /usr/bin MANDIR = /usr/share/man/man1 @@ -13,7 +13,7 @@ MANDIR = /usr/share/man/man1 all: codecheck test clean: - rm -rf build dist *.egg-info *.pyc $(MNEXEC) $(MANPAGE) + rm -rf build dist *.egg-info *.pyc $(MNEXEC) $(MANPAGES) codecheck: $(PYSRC) -echo "Running code check" @@ -41,12 +41,18 @@ develop: $(MNEXEC) $(MANPAGE) install $(MANPAGE) $(MANDIR) python setup.py develop -man: $(MANPAGE) +man: $(MANPAGES) -$(MANPAGE): $(MN) +mn.1: $(MN) PYTHONPATH=. help2man -N -n "create a Mininet network." \ - --no-discard-stderr $(MN) \ - -o $@ + --no-discard-stderr $< -o $@ + +mnexec: mnexec.c $(MN) mininet/net.py + cc -DVERSION=\"`$(MN) --version`\" $< -o $@ + +mnexec.1: mnexec + help2man -N -n "execution utility for Mininet." \ + -h "-h" -v "-v" --no-discard-stderr ./$< -o $@ doc: man doxygen doxygen.cfg diff --git a/bin/mn b/bin/mn index 548a452..a8b12cd 100755 --- a/bin/mn +++ b/bin/mn @@ -89,7 +89,7 @@ def addDictOption( opts, choicesDict, default, name, helpStr=None ): def version( *_args ): "Print Mininet version and exit" - print "mn (Mininet %s)" % VERSION + print "%s" % VERSION exit() class MininetRunner( object ): diff --git a/mnexec.c b/mnexec.c index ebd479c..42a9cf6 100644 --- a/mnexec.c +++ b/mnexec.c @@ -23,17 +23,23 @@ #include #include +#if !defined(VERSION) +#define VERSION "(devel)" +#endif + void usage(char *name) { - printf("Execution utility for Mininet.\n" - "usage: %s [-cdnp] [-a pid] [-g group] [-r rtprio] cmd args...\n" - "-c: close all file descriptors except stdin/out/error\n" - "-d: detach from tty by calling setsid()\n" - "-n: run in new network namespace\n" - "-p: print ^A + pid\n" - "-a pid: attach to pid's network namespace\n" - "-g group: add to cgroup\n" - "-r rtprio: run with SCHED_RR (usually requires -g)\n", + printf("Execution utility for Mininet\n\n" + "Usage: %s [-cdnp] [-a pid] [-g group] [-r rtprio] cmd args...\n\n" + "Options:\n" + " -c: close all file descriptors except stdin/out/error\n" + " -d: detach from tty by calling setsid()\n" + " -n: run in new network namespace\n" + " -p: print ^A + pid\n" + " -a pid: attach to pid's network namespace\n" + " -g group: add to cgroup\n" + " -r rtprio: run with SCHED_RR (usually requires -g)\n" + " -v: print version\n", name); } @@ -92,7 +98,7 @@ int main(int argc, char *argv[]) int nsid; int pid; static struct sched_param sp; - while ((c = getopt(argc, argv, "+cdnpa:g:r:")) != -1) + while ((c = getopt(argc, argv, "+cdnpa:g:r:vh")) != -1) switch(c) { case 'c': /* close file descriptors except stdin/out/error */ @@ -152,9 +158,15 @@ int main(int argc, char *argv[]) return 1; } break; + case 'v': + printf("%s\n", VERSION); + exit(0); + case 'h': + usage(argv[0]); + exit(0); default: usage(argv[0]); - break; + exit(1); } if (optind < argc) {