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