From: Nathan Holstein Date: Mon, 10 Aug 2015 01:27:47 +0000 (-0400) Subject: Add version information to doas executable. X-Git-Tag: v0.1~18 X-Git-Url: https://git.armaanb.net/?p=opendoas.git;a=commitdiff_plain;h=45b991b31341fac961e4f933cb1d96de62889f7e 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. --- 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();