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
This commit is contained in:
parent
1ca11de03f
commit
021eca720d
4 changed files with 17 additions and 5 deletions
|
@ -13,7 +13,6 @@
|
||||||
|
|
||||||
#include <patty/ax25.h>
|
#include <patty/ax25.h>
|
||||||
#include <patty/print.h>
|
#include <patty/print.h>
|
||||||
#include <patty/daemon.h>
|
|
||||||
|
|
||||||
#include <patty/bin/kiss.h>
|
#include <patty/bin/kiss.h>
|
||||||
|
|
||||||
|
@ -48,7 +47,7 @@ int main(int argc, char **argv) {
|
||||||
void *buf;
|
void *buf;
|
||||||
ssize_t readlen;
|
ssize_t readlen;
|
||||||
|
|
||||||
char *sock = PATTY_DAEMON_DEFAULT_SOCK,
|
char *sock = NULL,
|
||||||
*ifname = NULL;
|
*ifname = NULL;
|
||||||
|
|
||||||
patty_kiss_tnc_info info;
|
patty_kiss_tnc_info info;
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include <sysexits.h>
|
#include <sysexits.h>
|
||||||
|
|
||||||
#include <patty/ax25.h>
|
#include <patty/ax25.h>
|
||||||
#include <patty/daemon.h>
|
|
||||||
#include <patty/print.h>
|
#include <patty/print.h>
|
||||||
|
|
||||||
#include <patty/bin/kiss.h>
|
#include <patty/bin/kiss.h>
|
||||||
|
@ -167,7 +166,7 @@ int main(int argc, char **argv) {
|
||||||
{ NULL, 0, NULL, 0 }
|
{ NULL, 0, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
char *sock = PATTY_DAEMON_DEFAULT_SOCK,
|
char *sock = NULL,
|
||||||
*ifname = NULL;
|
*ifname = NULL;
|
||||||
|
|
||||||
int ch,
|
int ch,
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef _PATTY_CLIENT_H
|
#ifndef _PATTY_CLIENT_H
|
||||||
#define _PATTY_CLIENT_H
|
#define _PATTY_CLIENT_H
|
||||||
|
|
||||||
|
#define PATTY_CLIENT_DEFAULT_SOCK_NAME "patty.sock"
|
||||||
|
|
||||||
enum patty_client_call {
|
enum patty_client_call {
|
||||||
PATTY_CLIENT_NONE,
|
PATTY_CLIENT_NONE,
|
||||||
PATTY_CLIENT_PING,
|
PATTY_CLIENT_PING,
|
||||||
|
|
14
src/client.c
14
src/client.c
|
@ -4,10 +4,12 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
|
||||||
#include <patty/ax25.h>
|
#include <patty/ax25.h>
|
||||||
|
#include <patty/daemon.h>
|
||||||
|
|
||||||
struct _patty_client_sock {
|
struct _patty_client_sock {
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -19,6 +21,15 @@ struct _patty_client {
|
||||||
patty_dict *socks;
|
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 *patty_client_new(const char *path) {
|
||||||
patty_client *client;
|
patty_client *client;
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
|
@ -37,7 +48,8 @@ patty_client *patty_client_new(const char *path) {
|
||||||
|
|
||||||
memset(&addr, '\0', sizeof(addr));
|
memset(&addr, '\0', sizeof(addr));
|
||||||
addr.sun_family = AF_UNIX;
|
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) {
|
if (connect(client->fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||||
goto error_connect;
|
goto error_connect;
|
||||||
|
|
Loading…
Add table
Reference in a new issue