]> git.armaanb.net Git - opendoas.git/commitdiff
Add version information to doas executable.
authorNathan Holstein <nathan.holstein@gmail.com>
Mon, 10 Aug 2015 01:27:47 +0000 (21:27 -0400)
committerNathan Holstein <nathan.holstein@gmail.com>
Mon, 10 Aug 2015 02:18:37 +0000 (22:18 -0400)
This pulls in the dependency on version.h and adds the -v command line
option to print the version and build information.

Makefile
doas.c

index 59c4ee76d5d3824587243666f3b14a0657d17c6d..9e1dbf33fb8d170234bfed3090961873827c3716 100644 (file)
--- 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 f0cbab295bfb265cc4c03f9bf2e4077c0e68d293..1457925bb928946910df44c13e984aa2e971e471 100644 (file)
--- a/doas.c
+++ b/doas.c
 #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();