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 <richardcochran@gmail.com>
master
Richard Cochran 2013-09-29 20:15:45 +02:00
parent ba12da671f
commit e5ddfd491e
3 changed files with 7 additions and 4 deletions

View File

@ -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));

6
uds.c
View File

@ -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);

3
uds.h
View File

@ -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.