From 021eca720d280636f27136bac025445fa731f381 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Mon, 26 Oct 2020 23:29:21 -0400 Subject: [PATCH] Search for patty.sock in ax25dump(8), tncd(8) Changes: * Modify patty_client_new() to accept NULL as a Unix domain socket path; when NULL is provided, search for the pattyd(8) socket in pattyd.sock, followed by the default full socket path, /var/run/patty/patty.sock * Modify bin/ax25dump.c, bin/tncd.c to use default socket paths when calling patty_client_new() by defaulting to NULL when no -s flag is provided --- bin/ax25dump.c | 3 +-- bin/tncd.c | 3 +-- include/patty/client.h | 2 ++ src/client.c | 14 +++++++++++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/bin/ax25dump.c b/bin/ax25dump.c index f3df769..8f35455 100644 --- a/bin/ax25dump.c +++ b/bin/ax25dump.c @@ -13,7 +13,6 @@ #include #include -#include #include @@ -48,7 +47,7 @@ int main(int argc, char **argv) { void *buf; ssize_t readlen; - char *sock = PATTY_DAEMON_DEFAULT_SOCK, + char *sock = NULL, *ifname = NULL; patty_kiss_tnc_info info; diff --git a/bin/tncd.c b/bin/tncd.c index 9f55fc6..080bed5 100644 --- a/bin/tncd.c +++ b/bin/tncd.c @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -167,7 +166,7 @@ int main(int argc, char **argv) { { NULL, 0, NULL, 0 } }; - char *sock = PATTY_DAEMON_DEFAULT_SOCK, + char *sock = NULL, *ifname = NULL; int ch, diff --git a/include/patty/client.h b/include/patty/client.h index e804f28..7059542 100644 --- a/include/patty/client.h +++ b/include/patty/client.h @@ -1,6 +1,8 @@ #ifndef _PATTY_CLIENT_H #define _PATTY_CLIENT_H +#define PATTY_CLIENT_DEFAULT_SOCK_NAME "patty.sock" + enum patty_client_call { PATTY_CLIENT_NONE, PATTY_CLIENT_PING, diff --git a/src/client.c b/src/client.c index 533b138..5db87cb 100644 --- a/src/client.c +++ b/src/client.c @@ -4,10 +4,12 @@ #include #include #include +#include #include #include #include +#include struct _patty_client_sock { int fd; @@ -19,6 +21,15 @@ struct _patty_client { patty_dict *socks; }; +static const char *find_sock(const char *path) { + struct stat st; + + return path? + path: stat(PATTY_CLIENT_DEFAULT_SOCK_NAME, &st) == 0? + PATTY_CLIENT_DEFAULT_SOCK_NAME: + PATTY_DAEMON_DEFAULT_SOCK; +} + patty_client *patty_client_new(const char *path) { patty_client *client; struct sockaddr_un addr; @@ -37,7 +48,8 @@ patty_client *patty_client_new(const char *path) { memset(&addr, '\0', sizeof(addr)); addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, path, sizeof(addr.sun_path)-1); + + strncpy(addr.sun_path, find_sock(path), sizeof(addr.sun_path)-1); if (connect(client->fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { goto error_connect;