From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH v3 6/7] conf, log, Makefile: Add versioning information
Date: Mon, 10 Oct 2022 10:35:47 +0200 [thread overview]
Message-ID: <20221010083548.831309-7-sbrivio@redhat.com> (raw)
In-Reply-To: <20221010083548.831309-1-sbrivio@redhat.com>
Add a --version option displaying that, and also include this
information in the log files.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
Makefile | 3 +++
conf.c | 8 ++++++++
contrib/fedora/passt.spec | 1 +
log.c | 4 ++--
passt.1 | 4 ++++
util.h | 8 ++++++++
6 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index e4c64fe..6b22408 100644
--- a/Makefile
+++ b/Makefile
@@ -9,6 +9,8 @@
# Copyright (c) 2021 Red Hat GmbH
# Author: Stefano Brivio <sbrivio@redhat.com>
+VERSION ?= $(shell git describe --tags HEAD 2>/dev/null || echo "unknown\ version")
+
RLIMIT_STACK_VAL := $(shell /bin/sh -c 'ulimit -s')
ifeq ($(RLIMIT_STACK_VAL),unlimited)
RLIMIT_STACK_VAL := 1024
@@ -31,6 +33,7 @@ FLAGS += -DNETNS_RUN_DIR=\"/run/netns\"
FLAGS += -DPASST_AUDIT_ARCH=AUDIT_ARCH_$(AUDIT_ARCH)
FLAGS += -DRLIMIT_STACK_VAL=$(RLIMIT_STACK_VAL)
FLAGS += -DARCH=\"$(TARGET_ARCH)\"
+FLAGS += -DVERSION=\"$(VERSION)\"
PASST_SRCS = 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("");
+
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");
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 = { .c = c };
@@ -1197,6 +1200,11 @@ void conf(struct ctx *c, int argc, char **argv)
usage(argv[0]);
}
break;
+ case 14:
+ fprintf(stdout,
+ c->mode == MODE_PASST ? "passt " : "pasta ");
+ fprintf(stdout, VERSION_BLOB);
+ exit(EXIT_SUCCESS);
case 'd':
if (c->debug) {
err("Multiple --debug options given");
diff --git a/contrib/fedora/passt.spec b/contrib/fedora/passt.spec
index bd60650..f441f5c 100644
--- a/contrib/fedora/passt.spec
+++ b/contrib/fedora/passt.spec
@@ -48,6 +48,7 @@ This package adds SELinux enforcement to passt(1) and pasta(1).
%setup -q -n passt-%{git_hash}
%build
+%global optflags %{optflags} -DVERSION=\"%{version}-%{release}.%{_arch}\"
%set_build_flags
%make_build
diff --git a/log.c b/log.c
index 993c617..468c730 100644
--- a/log.c
+++ b/log.c
@@ -172,7 +172,7 @@ void passt_vsyslog(int pri, const char *format, va_list ap)
}
/**
- * 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, size_t size)
log_size = size ? size : LOGFILE_SIZE_DEFAULT;
- n = snprintf(log_header, sizeof(log_header), "%s: %s (%i)",
+ n = snprintf(log_header, sizeof(log_header), "%s " VERSION ": %s (%i)",
name, exe, getpid());
if (write(log_file, log_header, n) <= 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.
+.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
+#define VERSION_BLOB \
+ VERSION "\n" \
+ "Copyright Red Hat\n" \
+ "GNU Affero GPL version 3 or later " \
+ "<https://www.gnu.org/licenses/agpl-3.0.html>\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
--
@@ -6,6 +6,14 @@
#ifndef UTIL_H
#define UTIL_H
+#define VERSION_BLOB \
+ VERSION "\n" \
+ "Copyright Red Hat\n" \
+ "GNU Affero GPL version 3 or later " \
+ "<https://www.gnu.org/licenses/agpl-3.0.html>\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
--
2.35.1
next prev parent reply other threads:[~2022-10-10 8:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-10 8:35 [PATCH v3 0/7] Add support for log file and version display Stefano Brivio
2022-10-10 8:35 ` [PATCH v3 1/7] Move logging functions to a new file, log.c Stefano Brivio
2022-10-10 8:35 ` [PATCH v3 2/7] conf: Drop duplicate, diverging optstring assignments Stefano Brivio
2022-10-10 8:35 ` [PATCH v3 3/7] passt.h: Include netinet/if_ether.h before struct ctx declaration Stefano Brivio
2022-10-10 8:35 ` [PATCH v3 4/7] log, conf: Add support for logging to file Stefano Brivio
2022-10-11 0:11 ` David Gibson
2022-10-10 8:35 ` [PATCH v3 5/7] log: Add missing function comment for trace_init() Stefano Brivio
2022-10-10 8:35 ` Stefano Brivio [this message]
2022-10-11 0:12 ` [PATCH v3 6/7] conf, log, Makefile: Add versioning information David Gibson
2022-10-10 8:35 ` [PATCH v3 7/7] util: Check return value of lseek() while reading bound ports from procfs Stefano Brivio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221010083548.831309-7-sbrivio@redhat.com \
--to=sbrivio@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).