From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH v2 6/7] conf, log, Makefile: Add versioning information Date: Fri, 07 Oct 2022 13:51:05 +0200 Message-ID: <20221007115106.1983846-7-sbrivio@redhat.com> In-Reply-To: <20221007115106.1983846-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1743380641470510599==" --===============1743380641470510599== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Add a --version option displaying that, and also include this information in the log files. Signed-off-by: Stefano Brivio --- v2: - Drop (C) and years from license notice in version information (David Gibson) - Rewrite commit message (David Gibson) - Drop short form -v, it often means --verbose (David Gibson) Makefile | 3 +++ conf.c | 8 ++++++++ log.c | 4 ++-- passt.1 | 4 ++++ util.h | 8 ++++++++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index fafb024..f7ddb84 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,8 @@ # Copyright (c) 2021 Red Hat GmbH # Author: Stefano Brivio =20 +VERSION ?=3D $(shell git describe --tags HEAD || echo "unknown\ version") + RLIMIT_STACK_VAL :=3D $(shell /bin/sh -c 'ulimit -s') ifeq ($(RLIMIT_STACK_VAL),unlimited) RLIMIT_STACK_VAL :=3D 1024 @@ -31,6 +33,7 @@ FLAGS +=3D -DNETNS_RUN_DIR=3D\"/run/netns\" FLAGS +=3D -DPASST_AUDIT_ARCH=3DAUDIT_ARCH_$(AUDIT_ARCH) FLAGS +=3D -DRLIMIT_STACK_VAL=3D$(RLIMIT_STACK_VAL) FLAGS +=3D -DARCH=3D\"$(TARGET_ARCH)\" +FLAGS +=3D -DVERSION=3D\"$(VERSION)\" =20 PASST_SRCS =3D arch.c arp.c checksum.c conf.c dhcp.c dhcpv6.c icmp.c igmp.c \ isolation.c lineread.c log.c mld.c ndp.c netlink.c packet.c passt.c \ diff --git a/conf.c b/conf.c index f22940b..7c3e346 100644 --- a/conf.c +++ b/conf.c @@ -626,6 +626,7 @@ static void usage(const char *name) } info(""); =20 + info( " -d, --debug Be verbose, don't run in background"); info( " --trace Be extra verbose, implies --debug"); info( " -q, --quiet Don't print informational messages"); @@ -640,6 +641,7 @@ static void usage(const char *name) info( " numeric, or login and group names"); info( " default: drop to user \"nobody\""); info( " -h, --help Display this help message and exit"); + info( " --version Show version and exit"); =20 if (strstr(name, "pasta")) { info( " -I, --ns-ifname NAME namespace interface name"); @@ -1039,6 +1041,7 @@ void conf(struct ctx *c, int argc, char **argv) {"trace", no_argument, NULL, 11 }, {"runas", required_argument, NULL, 12 }, {"log-size", required_argument, NULL, 13 }, + {"version", no_argument, NULL, 14 }, { 0 }, }; struct get_bound_ports_ns_arg ns_ports_arg =3D { .c =3D c }; @@ -1197,6 +1200,11 @@ void conf(struct ctx *c, int argc, char **argv) usage(argv[0]); } break; + case 14: + fprintf(stdout, + c->mode =3D=3D MODE_PASST ? "passt " : "pasta "); + fprintf(stdout, VERSION_BLOB); + exit(EXIT_SUCCESS); case 'd': if (c->debug) { err("Multiple --debug options given"); diff --git a/log.c b/log.c index 3bf0a18..47e4b4f 100644 --- a/log.c +++ b/log.c @@ -172,7 +172,7 @@ void passt_vsyslog(int pri, const char *format, va_list a= p) } =20 /** - * logfile_init() - Open log file and write header with PID and path + * logfile_init() - Open log file and write header with PID, version, path * @name: Identifier for header: passt or pasta * @path: Path to log file * @size: Maximum size of log file: log_cut_size is calculatd here @@ -196,7 +196,7 @@ void logfile_init(const char *name, const char *path, siz= e_t size) =20 log_size =3D size ? size : LOGFILE_SIZE_DEFAULT; =20 - n =3D snprintf(log_header, sizeof(log_header), "%s: %s (%i)", + n =3D snprintf(log_header, sizeof(log_header), "%s " VERSION ": %s (%i)", name, exe, getpid()); =20 if (write(log_file, log_header, n) <=3D 0 || diff --git a/passt.1 b/passt.1 index 64236b6..667c1bc 100644 --- a/passt.1 +++ b/passt.1 @@ -124,6 +124,10 @@ Default is to change to user \fInobody\fR if started as = root. .BR \-h ", " \-\-help Display a help message and exit. =20 +.TP +.BR \-\-version +Show version and exit. + .TP .BR \-p ", " \-\-pcap " " \fIfile Capture tap-facing (that is, guest-side or namespace-side) network packets to diff --git a/util.h b/util.h index 1adbf04..f9a8ec6 100644 --- a/util.h +++ b/util.h @@ -6,6 +6,14 @@ #ifndef UTIL_H #define UTIL_H =20 +#define VERSION_BLOB \ + VERSION "\n" \ + "Copyright Red Hat\n" \ + "GNU Affero GPL version 3 or later " \ + "\n" \ + "This is free software: you are free to change and redistribute it.\n" \ + "There is NO WARRANTY, to the extent permitted by law.\n\n" + #ifndef SECCOMP_RET_KILL_PROCESS #define SECCOMP_RET_KILL_PROCESS SECCOMP_RET_KILL #endif --=20 2.35.1 --===============1743380641470510599==--