systemd/0002-ssh-generator-split-out-one-more-helper-function.patch
2025-12-17 16:21:00 +01:00

110 lines
3.8 KiB
Diff

From df5380c79fde84a39069c9dc4489103d94a9458f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Tue, 18 Nov 2025 11:34:37 +0100
Subject: [PATCH 2/3] ssh-generator: split out one more helper function
(cherry picked from commit 8c019224a1ad7dd325da9fd2a4b9ab519534f659)
---
src/ssh-generator/ssh-generator.c | 12 +++---------
src/ssh-generator/ssh-issue.c | 16 +---------------
src/ssh-generator/ssh-util.c | 16 ++++++++++++++++
src/ssh-generator/ssh-util.h | 1 +
4 files changed, 21 insertions(+), 24 deletions(-)
diff --git a/src/ssh-generator/ssh-generator.c b/src/ssh-generator/ssh-generator.c
index bf807196ee..0820ab2de7 100644
--- a/src/ssh-generator/ssh-generator.c
+++ b/src/ssh-generator/ssh-generator.c
@@ -218,15 +218,9 @@ static int add_vsock_socket(
/* Determine the local CID so that we can log it to help users to connect to this VM */
unsigned local_cid;
- r = vsock_get_local_cid(&local_cid);
- if (r < 0) {
- if (ERRNO_IS_DEVICE_ABSENT(r)) {
- log_debug("Not creating AF_VSOCK ssh listener, since /dev/vsock is not available (even though AF_VSOCK is).");
- return 0;
- }
-
- return log_error_errno(r, "Failed to query local AF_VSOCK CID: %m");
- }
+ r = vsock_get_local_cid_or_warn(&local_cid);
+ if (r <= 0)
+ return r;
r = make_sshd_template_unit(
dest,
diff --git a/src/ssh-generator/ssh-issue.c b/src/ssh-generator/ssh-issue.c
index 9ad9a997bd..4ad83924f0 100644
--- a/src/ssh-generator/ssh-issue.c
+++ b/src/ssh-generator/ssh-issue.c
@@ -15,7 +15,6 @@
#include "mkdir.h"
#include "parse-argument.h"
#include "pretty-print.h"
-#include "socket-util.h"
#include "ssh-util.h"
#include "string-util.h"
#include "tmpfile-util.h"
@@ -140,20 +139,7 @@ static int acquire_cid(unsigned *ret_cid) {
if (r <= 0)
return r;
- unsigned local_cid;
- r = vsock_get_local_cid(&local_cid);
- if (r < 0) {
- if (ERRNO_IS_DEVICE_ABSENT(r)) {
- log_debug("Not creating issue file, since /dev/vsock is not available (even though AF_VSOCK is).");
- *ret_cid = 0;
- return 0;
- }
-
- return log_error_errno(r, "Failed to query local AF_VSOCK CID: %m");
- }
-
- *ret_cid = local_cid;
- return 1;
+ return vsock_get_local_cid_or_warn(ret_cid);
}
static int run(int argc, char* argv[]) {
diff --git a/src/ssh-generator/ssh-util.c b/src/ssh-generator/ssh-util.c
index 5723a2bf2a..d414713486 100644
--- a/src/ssh-generator/ssh-util.c
+++ b/src/ssh-generator/ssh-util.c
@@ -5,6 +5,7 @@
#include "errno-util.h"
#include "log.h"
+#include "socket-util.h"
#include "ssh-util.h"
int vsock_open_or_warn(int *ret) {
@@ -21,3 +22,18 @@ int vsock_open_or_warn(int *ret) {
return fd >= 0;
}
+
+int vsock_get_local_cid_or_warn(unsigned *ret) {
+ int r;
+
+ r = vsock_get_local_cid(ret);
+ if (ERRNO_IS_NEG_DEVICE_ABSENT(r)) {
+ log_debug_errno(r, "/dev/vsock is not available (even though AF_VSOCK is), ignoring: %m");
+ if (ret)
+ *ret = 0; /* bogus value */
+ return 0;
+ }
+ if (r < 0)
+ return log_error_errno(r, "Failed to query local AF_VSOCK CID: %m");
+ return 1;
+}
diff --git a/src/ssh-generator/ssh-util.h b/src/ssh-generator/ssh-util.h
index 60984a5401..2a38e1955e 100644
--- a/src/ssh-generator/ssh-util.h
+++ b/src/ssh-generator/ssh-util.h
@@ -1,3 +1,4 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
int vsock_open_or_warn(int *ret);
+int vsock_get_local_cid_or_warn(unsigned *ret);