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