From e5ddfd491e6a444cfd5404ddfe251b17ce676230 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sun, 29 Sep 2013 20:15:45 +0200 Subject: [PATCH] Convert the hard coded UDS server path into a variable. This patch changes the macro for the server socket address into a global variable so that a subsequent patch can provide a way to set the variable. Signed-off-by: Richard Cochran --- clock.c | 2 +- uds.c | 6 ++++-- uds.h | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/clock.c b/clock.c index cf65fff..419a6b7 100644 --- a/clock.c +++ b/clock.c @@ -576,7 +576,7 @@ struct clock *clock_create(int phc_index, struct interface *iface, int count, struct interface udsif; memset(&udsif, 0, sizeof(udsif)); - snprintf(udsif.name, sizeof(udsif.name), UDS_PATH); + snprintf(udsif.name, sizeof(udsif.name), "%s", uds_path); udsif.transport = TRANS_UDS; srandom(time(NULL)); diff --git a/uds.c b/uds.c index 0d114c3..1dbfd6c 100644 --- a/uds.c +++ b/uds.c @@ -30,6 +30,8 @@ #include "transport_private.h" #include "uds.h" +char uds_path[MAX_IFNAME_SIZE + 1] = "/var/run/ptp4l"; + #define UDS_FILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) /*0660*/ struct uds { @@ -58,7 +60,7 @@ static int uds_open(struct transport *t, char *name, struct fdarray *fda, } memset(&sa, 0, sizeof(sa)); sa.sun_family = AF_LOCAL; - strcpy(sa.sun_path, name); + strncpy(sa.sun_path, name, sizeof(sa.sun_path) - 1); unlink(name); @@ -72,7 +74,7 @@ static int uds_open(struct transport *t, char *name, struct fdarray *fda, /* For client use, pre load the server path. */ memset(&sa, 0, sizeof(sa)); sa.sun_family = AF_LOCAL; - strcpy(sa.sun_path, UDS_PATH); + strncpy(sa.sun_path, uds_path, sizeof(sa.sun_path) - 1); uds->sa = sa; uds->len = sizeof(sa); diff --git a/uds.h b/uds.h index 24effa8..d7f6626 100644 --- a/uds.h +++ b/uds.h @@ -20,13 +20,14 @@ #ifndef HAVE_UDS_H #define HAVE_UDS_H +#include "config.h" #include "fd.h" #include "transport.h" /** * Address of the server. */ -#define UDS_PATH "/var/run/ptp4l" +extern char uds_path[MAX_IFNAME_SIZE + 1]; /** * Allocate an instance of a UDS transport.