]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ssh-generator: split out one more helper function
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 18 Nov 2025 10:34:37 +0000 (11:34 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 19 Nov 2025 10:37:48 +0000 (11:37 +0100)
src/ssh-generator/ssh-generator.c
src/ssh-generator/ssh-issue.c
src/ssh-generator/ssh-util.c
src/ssh-generator/ssh-util.h

index 8454d31141d904545eccdb0e49633296ac414589..2364f86e256aa603d0cddcf6c0c34f93307e3a15 100644 (file)
@@ -219,15 +219,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,
index 71cd596cf85bb133a62e9aa22a7f975d3239f4f0..61ac5c02409e07319937dd2c571263cce3fe10d9 100644 (file)
@@ -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[]) {
index 5723a2bf2ac8fc20ed73b1705919abe5ba90c518..d414713486658fcf91b5ddee462d63d97d5caf91 100644 (file)
@@ -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;
+}
index 60984a5401300b3b29b665b7cffbcbae4713fe42..2a38e1955efd39c935f28223e1270b2cdc83dfba 100644 (file)
@@ -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);