From 45b991b31341fac961e4f933cb1d96de62889f7e Mon Sep 17 00:00:00 2001 From: Nathan Holstein Date: Sun, 9 Aug 2015 21:27:47 -0400 Subject: [PATCH] Add version information to doas executable. This pulls in the dependency on version.h and adds the -v command line option to print the version and build information. --- Makefile | 2 ++ doas.c | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 59c4ee7..9e1dbf3 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,8 @@ LDFLAGS+= -lpam include bsd.prog.mk +doas.o: version.h + /etc/pam.d/doas: pam.d__doas cp $< $@ install: /etc/pam.d/doas diff --git a/doas.c b/doas.c index f0cbab2..1457925 100644 --- a/doas.c +++ b/doas.c @@ -32,11 +32,19 @@ #include "openbsd.h" #include "doas.h" +#include "version.h" + +static void __dead +version(void) +{ + fprintf(stderr, "doas: version %s built %s\n", VERSION, __DATE__); + exit(1); +} static void __dead usage(void) { - fprintf(stderr, "usage: doas [-ns] [-C config] [-u user] command [args]\n"); + fprintf(stderr, "usage: doas [-nsv] [-C config] [-u user] command [args]\n"); exit(1); } @@ -330,10 +338,11 @@ main(int argc, char **argv, char **envp) int i, ch; int sflag = 0; int nflag = 0; + int vflag = 0; uid = getuid(); - while ((ch = getopt(argc, argv, "C:nsu:")) != -1) { + while ((ch = getopt(argc, argv, "C:nsu:v")) != -1) { switch (ch) { case 'C': confpath = optarg; @@ -348,6 +357,9 @@ main(int argc, char **argv, char **envp) case 's': sflag = 1; break; + case 'v': + vflag = 1; + break; default: usage(); break; @@ -356,6 +368,9 @@ main(int argc, char **argv, char **envp) argv += optind; argc -= optind; + if (vflag) + version(); + if (confpath) { if (sflag) usage(); -- 2.39.2