aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Holstein <nathan.holstein@gmail.com>2015-08-09 21:27:47 -0400
committerNathan Holstein <nathan.holstein@gmail.com>2015-08-09 22:18:37 -0400
commit45b991b31341fac961e4f933cb1d96de62889f7e (patch)
tree89d49ec4bb7a79a40be576faad58fac6afc161cf
parentfc0380731a8b1b1e02e2319f2f992b1973526b45 (diff)
downloadopendoas-45b991b31341fac961e4f933cb1d96de62889f7e.tar.gz
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.
-rw-r--r--Makefile2
-rw-r--r--doas.c19
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();