38e8425
From c662ad097eaa0d8c3691a22254f5d0e9622b26b7 Mon Sep 17 00:00:00 2001
b61c40c
From: Peter Jones <pjones@redhat.com>
b61c40c
Date: Mon, 6 Jul 2020 16:13:09 -0400
38e8425
Subject: [PATCH 6/7] client: try /run and /var/run for the socket path.
b61c40c
b61c40c
Signed-off-by: Peter Jones <pjones@redhat.com>
b61c40c
---
38e8425
 src/client.c | 40 +++++++++++++++++++++++++++++-----------
38e8425
 1 file changed, 29 insertions(+), 11 deletions(-)
b61c40c
b61c40c
diff --git a/src/client.c b/src/client.c
38e8425
index 2119ef33bf8..a38383415d5 100644
b61c40c
--- a/src/client.c
b61c40c
+++ b/src/client.c
38e8425
@@ -49,24 +49,24 @@ print_flag_name(FILE *f, int flag)
b61c40c
 }
b61c40c
 
b61c40c
 static int
b61c40c
-connect_to_server(void)
b61c40c
+connect_to_server_helper(const char * const sockpath)
b61c40c
 {
b61c40c
-	int rc = access(SOCKPATH, R_OK);
b61c40c
+	int rc = access(sockpath, R_OK);
b61c40c
 	if (rc != 0) {
b61c40c
-		fprintf(stderr, "pesign-client: could not connect to server: "
b61c40c
-			"%m\n");
b61c40c
-		exit(1);
b61c40c
+		warn("could not access socket \"%s\"", sockpath);
b61c40c
+		return rc;
b61c40c
 	}
b61c40c
 
b61c40c
 	struct sockaddr_un addr_un = {
b61c40c
 		.sun_family = AF_UNIX,
b61c40c
-		.sun_path = SOCKPATH,
b61c40c
 	};
b61c40c
+	strncpy(addr_un.sun_path, sockpath, sizeof(addr_un.sun_path));
b61c40c
+	addr_un.sun_path[sizeof(addr_un.sun_path)-1] = '\0';
b61c40c
 
b61c40c
 	int sd = socket(AF_UNIX, SOCK_STREAM, 0);
b61c40c
 	if (sd < 0) {
b61c40c
-		fprintf(stderr, "pesign-client: could not open socket: %m\n");
b61c40c
-		exit(1);
b61c40c
+		warn("could not open socket \"%s\"", sockpath);
b61c40c
+		return sd;
b61c40c
 	}
b61c40c
 
b61c40c
 	socklen_t len = strlen(addr_un.sun_path) +
38e8425
@@ -74,14 +74,32 @@ connect_to_server(void)
b61c40c
 
b61c40c
 	rc = connect(sd, (struct sockaddr *)&addr_un, len);
b61c40c
 	if (rc < 0) {
b61c40c
-		fprintf(stderr, "pesign-client: could not connect to daemon: "
b61c40c
-			"%m\n");
b61c40c
-		exit(1);
b61c40c
+		warn("could not connect to daemon");
b61c40c
+		return sd;
b61c40c
 	}
b61c40c
 
b61c40c
 	return sd;
b61c40c
 }
b61c40c
 
b61c40c
+static int
b61c40c
+connect_to_server(void)
b61c40c
+{
b61c40c
+	int rc, i;
b61c40c
+	const char * const sockets[] = {
b61c40c
+		"/run/pesign/socket",
b61c40c
+		"/var/run/pesign/socket",
b61c40c
+		NULL
b61c40c
+	};
b61c40c
+
b61c40c
+	for (i = 0; sockets[i] != NULL; i++) {
b61c40c
+		rc = connect_to_server_helper(sockets[i]);
b61c40c
+		if (rc >= 0)
b61c40c
+			return rc;
b61c40c
+	}
b61c40c
+
b61c40c
+	exit(1);
b61c40c
+}
b61c40c
+
b61c40c
 static int32_t
b61c40c
 check_response(int sd, char **srvmsg);
b61c40c
 
b61c40c
-- 
b61c40c
2.26.2
b61c40c