commit f7cbd2e1573c52727e07572eb8725623f4ce0a3f2776c82191ac0d1413b4a20f from: Kyle Ackerman date: Fri Jun 12 23:16:55 2026 UTC Add version flag (-V, --version) to gotd ok stsp@ commit - 34ecf1f030cf41f30dc79b4ae23c87e1d5894006c8c325100ec7868806bd4225 commit + f7cbd2e1573c52727e07572eb8725623f4ce0a3f2776c82191ac0d1413b4a20f blob - 3db7aa9e8772d148dfb7c5695892fb7a70c5f0690f6c7ae51d41fe2a2fa5cd2f blob + 9e4e8158c8e32767c34b79abe53947ba80ed667b2374b99d3c04298ed9bcd0f1 --- gotd/gotd.8 +++ gotd/gotd.8 @@ -72,6 +72,8 @@ will be used if it exists. .It Fl v Verbose mode. Verbosity increases if this option is used multiple times. +.It Fl V , -version +Display program version and exit immediately. .El .Sh FILES .Bl -tag -width Ds -compact blob - 58bc2370451ae7cfb8d5cbd8aa9dce6c9a953d727779b30e9e5a2aca18adf194 blob + bb6b2fe3a9f72ef4e2344976b12e15458378f3bfd13c82750e30e1526883e49a --- gotd/gotd.c +++ gotd/gotd.c @@ -42,7 +42,9 @@ #include #include #include +#include +#include "got_version.h" #include "got_error.h" #include "got_opentemp.h" #include "got_path.h" @@ -3404,7 +3406,7 @@ main(int argc, char **argv) { const struct got_error *error = NULL; struct gotd_secrets *secrets = NULL; - int ch, daemonize = 1, verbosity = 0, noaction = 0; + int ch, daemonize = 1, verbosity = 0, noaction = 0, version_flag = 0; const char *confpath = GOTD_CONF_PATH; char *secretspath = NULL; char *argv0 = argv[0]; @@ -3421,12 +3423,16 @@ main(int argc, char **argv) FILE *diff_f1 = NULL, *diff_f2 = NULL, *tmp_f1 = NULL, *tmp_f2 = NULL; int diff_fd1 = -1, diff_fd2 = -1, tmp_fd = -1; const char *errstr; - + static const struct option longopts[] = { + { "version", no_argument, NULL, 'V' }, + { NULL, 0, NULL, 0 } + }; + TAILQ_INIT(&procs); log_init(1, LOG_DAEMON); /* Log to stderr until daemonized. */ - while ((ch = getopt(argc, argv, "df:nP:s:T:v")) != -1) { + while ((ch = getopt_long(argc, argv, "df:nP:s:T:vV", longopts, NULL)) != -1) { switch (ch) { case 'd': daemonize = 0; @@ -3481,6 +3487,9 @@ main(int argc, char **argv) if (verbosity < 3) verbosity++; break; + case 'V': + version_flag = 1; + break; default: usage(); } @@ -3492,6 +3501,10 @@ main(int argc, char **argv) if (argc != 0) usage(); + if (version_flag) { + got_version_print_str(); + return 0; + } if (geteuid() && proc_id == GOTD_PROC_GOTD) fatalx("need root privileges"); if (geteuid() == 0 && proc_id != GOTD_PROC_GOTD)