alfred: Make unix socket path configurable
PATCH 1/1 alfred: Make unix socket path configurable
The path to the socket used for client-server communication is currently hardcoded in alfred and its complimentary daemons. This makes it hard to run two instances of alfred on the same machine without any kind of virtualization or containers.
An user may still want to use two alfred instances to create a test setup or connect a single machine two separated alfred data clouds without exchanging data between them.
--- alfred.h | 7 ++++--- client.c | 6 +++--- gpsd/alfred-gpsd.c | 9 +++++++-- gpsd/alfred-gpsd.h | 3 ++- gpsd/man/alfred-gpsd.8 | 3 +++ main.c | 8 +++++++- man/alfred.8 | 3 +++ server.c | 2 +- unix_sock.c | 10 +++++----- vis/man/batadv-vis.8 | 3 +++ vis/vis.c | 10 ++++++++-- vis/vis.h | 3 ++- 12 files changed, 48 insertions(+), 19 deletions(-)
alfred.h +4 -3
@@ -35,7 +35,7 @@#define ALFRED_REQUEST_TIMEOUT 10#define ALFRED_SERVER_TIMEOUT 60#define ALFRED_DATA_TIMEOUT 600 -#define ALFRED_SOCK_PATH "/var/run/alfred.sock" +#define ALFRED_SOCK_PATH_DEFAULT "/var/run/alfred.sock"#define NO_FILTER -1enum data_source {
@@ -102,6 +102,7 @@ struct globals {int netsock;int unix_sock; +const char *unix_path;struct timespec if_check;
@@ -144,8 +145,8 @@ ssize_t send_alfred_packet(struct globals *globals, const struct in6_addr *dest, void *buf, int length);/* unix_sock.c */ int unix_sock_read (struct globals *globals); -int unix_sock_open_daemon (struct globals *globals,const char *path); -int unix_sock_open_client (struct globals *globals,const char *path); +int unix_sock_open_daemon (struct globals *globals); +int unix_sock_open_client (struct globals *globals);int unix_sock_close (struct globals *globals);int unix_sock_req_data_finish (struct globals *globals,struct transaction_head *head);
client.c +3 -3
@@ -40,7 +40,7 @@ int alfred_client_request_data(struct globals *globals)int ret, len, data_len, i;const size_t buf_data_len =sizeof (buf) -sizeof (*push) -sizeof (*data); -if (unix_sock_open_client (globals,ALFRED_SOCK_PATH )) +if (unix_sock_open_client (globals))return -1 ; request = (struct alfred_request_v0 *)buf;
@@ -146,7 +146,7 @@ int alfred_client_set_data(struct globals *globals)struct alfred_data *data;int ret, len; -if (unix_sock_open_client (globals,ALFRED_SOCK_PATH )) +if (unix_sock_open_client (globals))return -1 ; push = (struct alfred_push_data_v0 *)buf;
@@ -187,7 +187,7 @@ int alfred_client_modeswitch(struct globals *globals)struct alfred_modeswitch_v0 *modeswitch;int ret, len; -if (unix_sock_open_client (globals,ALFRED_SOCK_PATH )) +if (unix_sock_open_client (globals))return -1 ; modeswitch = (struct alfred_modeswitch_v0 *)buf;
gpsd/alfred-gpsd.c +7 -2
@@ -36,7 +36,7 @@ static int alfred_open_sock(struct globals *globals)memset (&addr,0 ,sizeof (addr)); addr.sun_family =AF_LOCAL ; -strncpy (addr.sun_path,ALFRED_SOCK_PATH ,sizeof (addr.sun_path)); +strncpy (addr.sun_path, globals->unix_path,sizeof (addr.sun_path)); addr.sun_path[sizeof (addr.sun_path) -1 ] ='\0' ; if (connect(globals->unix_sock, (struct sockaddr *)&addr,
@@ -399,6 +399,7 @@ static struct globals *gpsd_init(int argc, char *argv[]) {"server", no_argument, NULL, 's'}, {"location", required_argument, NULL, 'l'}, {"gpsd", required_argument, NULL, 'g'}, + {"unix-path", required_argument, NULL, 'u'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0},
@@ -410,8 +411,9 @@ static struct globals *gpsd_init(int argc, char *argv[]) globals->opmode =OPMODE_CLIENT ; globals->source =SOURCE_GPSD ; globals->gpsd_format =FORMAT_JSON ; + globals->unix_path =ALFRED_SOCK_PATH_DEFAULT ; -while ((opt =getopt_long (argc, argv,"shl:g:v" , long_options, +while ((opt =getopt_long (argc, argv,"shl:g:vu:" , long_options, &opt_ind)) !=-1 ) {switch (opt) {case 's' :
@@ -425,6 +427,9 @@ static struct globals *gpsd_init(int argc, char *argv[])gpsd_source_spec (optarg, &globals->gpsdsource); have_source = true;break ; +case 'u' : + globals->unix_path = optarg; +break ;case 'v' :printf ("%s %s\n" , argv[0 ],SOURCE_VERSION );printf ("GPSD alfred client\n" );
gpsd/alfred-gpsd.h +2 -1
@@ -41,7 +41,7 @@#define SOURCE_VERSION "2014.4.0"#endif -#define ALFRED_SOCK_PATH "/var/run/alfred.sock" +#define ALFRED_SOCK_PATH_DEFAULT "/var/run/alfred.sock"#define PATH_BUFF_LEN 200#define GPSD_PACKETTYPE 2#define GPSD_PACKETVERSION 1
@@ -95,6 +95,7 @@ struct globals {float lat, lon, alt;int unix_sock; +const char *unix_path;struct fixsource_t gpsdsource;struct gps_data_t gpsdata;
gpsd/man/alfred-gpsd.8 +3 -0
@@ -43,6 +43,9 @@ Print the version \fB\-h\fP, \fB\-\-help\fP Display a brief help message. .TP +\fB\-u\fP, \fB\-\-unix-path\fP \fIpath\fP +path to unix socket used for alfred server communication. +.TP \fB\-s\fP, \fB\-\-server\fP Start up in server mode. This server will read the current location from gpsd and set it in alfred via unix socket. The alfred server must
main.c +7 -1
@@ -49,6 +49,7 @@ static void alfred_usage(void)printf (" accepts data from slaves and synces it with\n" );printf (" other masters\n" );printf ("\n" ); +printf (" -u, --unix-path [path] path to unix socket used for client-server communication (default: \"" ALFRED_SOCK_PATH_DEFAULT "\")\n" );printf (" -v, --version print the version\n" );printf (" -h, --help this help\n" );printf ("\n" );
@@ -66,6 +67,7 @@ static struct globals *alfred_init(int argc, char *argv[]) {"help", no_argument, NULL, 'h'}, {"req-version", required_argument, NULL, 'V'}, {"modeswitch", required_argument, NULL, 'M'}, + {"unix-path", required_argument, NULL, 'u'}, {"version", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0}, };
@@ -79,10 +81,11 @@ static struct globals *alfred_init(int argc, char *argv[]) globals->best_server =NULL ; globals->clientmode_version =0 ; globals->mesh_iface ="bat0" ; + globals->unix_path =ALFRED_SOCK_PATH_DEFAULT ;time_random_seed (); -while ((opt =getopt_long (argc, argv,"ms:r:hi:b:vV:M:" , long_options, +while ((opt =getopt_long (argc, argv,"ms:r:hi:b:vV:M:u:" , long_options, &opt_ind)) !=-1 ) {switch (opt) {case 'r' :
@@ -132,6 +135,9 @@ static struct globals *alfred_init(int argc, char *argv[]) } globals->clientmode =CLIENT_MODESWITCH ;break ; +case 'u' : + globals->unix_path = optarg; +break ;case 'v' :printf ("%s %s\n" , argv[0 ],SOURCE_VERSION );printf ("A.L.F.R.E.D. - Almighty Lightweight Remote Fact Exchange Daemon\n" );
man/alfred.8 +3 -0
@@ -50,6 +50,9 @@ Print the version .TP \fB\-h\fP, \fB\-\-help\fP Display a brief help message. +.TP +\fB\-u\fP, \fB\-\-unix-path\fP \fIpath\fP +path to unix socket used for client-server communication. . .SH CLIENT OPTIONS .TP
server.c +1 -1
@@ -285,7 +285,7 @@ int alfred_server(struct globals *globals)if (create_hashes (globals))return -1 ; -if (unix_sock_open_daemon (globals,ALFRED_SOCK_PATH )) +if (unix_sock_open_daemon (globals))return -1 ;if (!globals->interface) {
unix_sock.c +5 -5
@@ -35,11 +35,11 @@#include "hash.h" #include "packet.h" -int unix_sock_open_daemon (struct globals *globals,const char *path) +int unix_sock_open_daemon (struct globals *globals) {struct sockaddr_un addr; -unlink (path); +unlink (globals->unix_path); globals->unix_sock =socket (AF_LOCAL ,SOCK_STREAM ,0 );if (globals->unix_sock <0 ) {
@@ -50,7 +50,7 @@ int unix_sock_open_daemon(struct globals *globals, const char *path)memset (&addr,0 ,sizeof (addr)); addr.sun_family =AF_LOCAL ; -strncpy (addr.sun_path, path,sizeof (addr.sun_path)); +strncpy (addr.sun_path, globals->unix_path,sizeof (addr.sun_path)); addr.sun_path[sizeof (addr.sun_path) -1 ] ='\0' ; if (bind(globals->unix_sock, (struct sockaddr *)&addr,
@@ -69,7 +69,7 @@ int unix_sock_open_daemon(struct globals *globals, const char *path)return 0 ; } -int unix_sock_open_client (struct globals *globals,const char *path) +int unix_sock_open_client (struct globals *globals) {struct sockaddr_un addr;
@@ -82,7 +82,7 @@ int unix_sock_open_client(struct globals *globals, const char *path)memset (&addr,0 ,sizeof (addr)); addr.sun_family =AF_LOCAL ; -strncpy (addr.sun_path, path,sizeof (addr.sun_path)); +strncpy (addr.sun_path, globals->unix_path,sizeof (addr.sun_path)); addr.sun_path[sizeof (addr.sun_path) -1 ] ='\0' ; if (connect(globals->unix_sock, (struct sockaddr *)&addr,
vis/man/batadv-vis.8 +3 -0
@@ -42,6 +42,9 @@ Print the version \fB\-h\fP, \fB\-\-help\fP Display a brief help message. .TP +\fB\-u\fP, \fB\-\-unix-path\fP \fIpath\fP +path to unix socket used for alfred server communication. +.TP \fB\-i\fP, \fB\-\-interface\fP \fIiface\fP Specify the batman-adv interface configured on the system (default: bat0) .TP
vis/vis.c +8 -2
@@ -169,7 +169,7 @@ static int alfred_open_sock(struct globals *globals)memset (&addr,0 ,sizeof (addr)); addr.sun_family =AF_LOCAL ; -strncpy (addr.sun_path,ALFRED_SOCK_PATH ,sizeof (addr.sun_path)); +strncpy (addr.sun_path, globals->unix_path,sizeof (addr.sun_path)); addr.sun_path[sizeof (addr.sun_path) -1 ] ='\0' ; if (connect(globals->unix_sock, (struct sockaddr *)&addr,
@@ -818,6 +818,7 @@ static void vis_usage(void)printf (" -i, --interface specify the batman-adv interface configured on the system (default: bat0)\n" );printf (" -s, --server start up in server mode, which regularly updates vis data from batman-adv\n" );printf (" -f, --format <format> specify the output format for client mode (either \"json\", \"jsondoc\" or \"dot\")\n" ); +printf (" -u, --unix-path <path> path to unix socket used for alfred server communication (default: \"" ALFRED_SOCK_PATH_DEFAULT "\")\n" );printf (" -v, --version print the version\n" );printf (" -h, --help this help\n" );printf ("\n" );
@@ -831,6 +832,7 @@ static struct globals *vis_init(int argc, char *argv[]) {"server", no_argument, NULL, 's'}, {"interface", required_argument, NULL, 'i'}, {"format", required_argument, NULL, 'f'}, + {"unix-path", required_argument, NULL, 'u'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0},
@@ -842,8 +844,9 @@ static struct globals *vis_init(int argc, char *argv[]) globals->opmode =OPMODE_CLIENT ; globals->interface ="bat0" ; globals->vis_format =FORMAT_DOT ; + globals->unix_path =ALFRED_SOCK_PATH_DEFAULT ; -while ((opt =getopt_long (argc, argv,"shf:i:v" , long_options, +while ((opt =getopt_long (argc, argv,"shf:i:vu:" , long_options, &opt_ind)) !=-1 ) {switch (opt) {case 's' :
@@ -864,6 +867,9 @@ static struct globals *vis_init(int argc, char *argv[])case 'i' : globals->interface =strdup (optarg);break ; +case 'u' : + globals->unix_path = optarg; +break ;case 'v' :printf ("%s %s\n" , argv[0 ],SOURCE_VERSION );printf ("VIS alfred client\n" );
vis/vis.h +2 -1
@@ -30,7 +30,7 @@#define SOURCE_VERSION "2014.4.0"#endif -#define ALFRED_SOCK_PATH "/var/run/alfred.sock" +#define ALFRED_SOCK_PATH_DEFAULT "/var/run/alfred.sock"#define PATH_BUFF_LEN 200#define VIS_PACKETTYPE 1#define VIS_PACKETVERSION 1
@@ -105,6 +105,7 @@ struct globals {struct list_head entry_list;int unix_sock; +const char *unix_path; };
Signature · 1 line
2.0.1
Hello Sven,
Quoted 8 lines · Sven Eckelmann
The path to the socket used for client-server communication is currently hardcoded in alfred and its complimentary daemons. This makes it hard to run two instances of alfred on the same machine without any kind of virtualization or containers.
An user may still want to use two alfred instances to create a test setup or connect a single machine two separated alfred data clouds without exchanging data between them.
Many thanks for writing the patch! Looking forward to test this...
Regards,
Tobias
Quoted 11 lines · Sven Eckelmann
The path to the socket used for client-server communication is currently hardcoded in alfred and its complimentary daemons. This makes it hard to run two instances of alfred on the same machine without any kind of virtualization or containers.
An user may still want to use two alfred instances to create a test setup or connect a single machine two separated alfred data clouds without exchanging data between them.
Reported-by Tobias Hachmer <[email protected]>Signed-off-by Sven Eckelmann <[email protected]>
Hi Sven
I've not tested your patch, just read it through. Looks O.K. to me.
Andrew
Quoted 358 lines
--- alfred.h | 7 ++++--- client.c | 6 +++--- gpsd/alfred-gpsd.c | 9 +++++++-- gpsd/alfred-gpsd.h | 3 ++- gpsd/man/alfred-gpsd.8 | 3 +++ main.c | 8 +++++++- man/alfred.8 | 3 +++ server.c | 2 +- unix_sock.c | 10 +++++----- vis/man/batadv-vis.8 | 3 +++ vis/vis.c | 10 ++++++++-- vis/vis.h | 3 ++- 12 files changed, 48 insertions(+), 19 deletions(-)alfred.h +4
-3@@ -35,7 +35,7 @@#define ALFRED_REQUEST_TIMEOUT 10#define ALFRED_SERVER_TIMEOUT 60#define ALFRED_DATA_TIMEOUT 600 -#define ALFRED_SOCK_PATH "/var/run/alfred.sock" +#define ALFRED_SOCK_PATH_DEFAULT "/var/run/alfred.sock"#define NO_FILTER -1enum data_source {@@ -102,6 +102,7 @@ struct globals {int netsock;int unix_sock; +const char *unix_path;struct timespec if_check;@@ -144,8 +145,8 @@ ssize_t send_alfred_packet(struct globals *globals, const struct in6_addr *dest, void *buf, int length);/* unix_sock.c */ int unix_sock_read (struct globals *globals); -int unix_sock_open_daemon (struct globals *globals,const char *path); -int unix_sock_open_client (struct globals *globals,const char *path); +int unix_sock_open_daemon (struct globals *globals); +int unix_sock_open_client (struct globals *globals);int unix_sock_close (struct globals *globals);int unix_sock_req_data_finish (struct globals *globals,struct transaction_head *head);client.c +3
-3@@ -40,7 +40,7 @@ int alfred_client_request_data(struct globals *globals)int ret, len, data_len, i;const size_t buf_data_len =sizeof (buf) -sizeof (*push) -sizeof (*data); -if (unix_sock_open_client (globals,ALFRED_SOCK_PATH )) +if (unix_sock_open_client (globals))return -1 ; request = (struct alfred_request_v0 *)buf;@@ -146,7 +146,7 @@ int alfred_client_set_data(struct globals *globals)struct alfred_data *data;int ret, len; -if (unix_sock_open_client (globals,ALFRED_SOCK_PATH )) +if (unix_sock_open_client (globals))return -1 ; push = (struct alfred_push_data_v0 *)buf;@@ -187,7 +187,7 @@ int alfred_client_modeswitch(struct globals *globals)struct alfred_modeswitch_v0 *modeswitch;int ret, len; -if (unix_sock_open_client (globals,ALFRED_SOCK_PATH )) +if (unix_sock_open_client (globals))return -1 ; modeswitch = (struct alfred_modeswitch_v0 *)buf;gpsd/alfred-gpsd.c +7
-2@@ -36,7 +36,7 @@ static int alfred_open_sock(struct globals *globals)memset (&addr,0 ,sizeof (addr)); addr.sun_family =AF_LOCAL ; -strncpy (addr.sun_path,ALFRED_SOCK_PATH ,sizeof (addr.sun_path)); +strncpy (addr.sun_path, globals->unix_path,sizeof (addr.sun_path)); addr.sun_path[sizeof (addr.sun_path) -1 ] ='\0' ; if (connect(globals->unix_sock, (struct sockaddr *)&addr,@@ -399,6 +399,7 @@ static struct globals *gpsd_init(int argc, char *argv[]) {"server", no_argument, NULL, 's'}, {"location", required_argument, NULL, 'l'}, {"gpsd", required_argument, NULL, 'g'}, + {"unix-path", required_argument, NULL, 'u'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0},@@ -410,8 +411,9 @@ static struct globals *gpsd_init(int argc, char *argv[]) globals->opmode =OPMODE_CLIENT ; globals->source =SOURCE_GPSD ; globals->gpsd_format =FORMAT_JSON ; + globals->unix_path =ALFRED_SOCK_PATH_DEFAULT ; -while ((opt =getopt_long (argc, argv,"shl:g:v" , long_options, +while ((opt =getopt_long (argc, argv,"shl:g:vu:" , long_options, &opt_ind)) !=-1 ) {switch (opt) {case 's' :@@ -425,6 +427,9 @@ static struct globals *gpsd_init(int argc, char *argv[])gpsd_source_spec (optarg, &globals->gpsdsource); have_source = true;break ; +case 'u' : + globals->unix_path = optarg; +break ;case 'v' :printf ("%s %s\n" , argv[0 ],SOURCE_VERSION );printf ("GPSD alfred client\n" );gpsd/alfred-gpsd.h +2
-1@@ -41,7 +41,7 @@#define SOURCE_VERSION "2014.4.0"#endif -#define ALFRED_SOCK_PATH "/var/run/alfred.sock" +#define ALFRED_SOCK_PATH_DEFAULT "/var/run/alfred.sock"#define PATH_BUFF_LEN 200#define GPSD_PACKETTYPE 2#define GPSD_PACKETVERSION 1@@ -95,6 +95,7 @@ struct globals {float lat, lon, alt;int unix_sock; +const char *unix_path;struct fixsource_t gpsdsource;struct gps_data_t gpsdata;gpsd/man/alfred-gpsd.8 +3
-0@@ -43,6 +43,9 @@ Print the version \fB\-h\fP, \fB\-\-help\fP Display a brief help message. .TP +\fB\-u\fP, \fB\-\-unix-path\fP \fIpath\fP +path to unix socket used for alfred server communication. +.TP \fB\-s\fP, \fB\-\-server\fP Start up in server mode. This server will read the current location from gpsd and set it in alfred via unix socket. The alfred server mustmain.c +7
-1@@ -49,6 +49,7 @@ static void alfred_usage(void)printf (" accepts data from slaves and synces it with\n" );printf (" other masters\n" );printf ("\n" ); +printf (" -u, --unix-path [path] path to unix socket used for client-server communication (default: \"" ALFRED_SOCK_PATH_DEFAULT "\")\n" );printf (" -v, --version print the version\n" );printf (" -h, --help this help\n" );printf ("\n" );@@ -66,6 +67,7 @@ static struct globals *alfred_init(int argc, char *argv[]) {"help", no_argument, NULL, 'h'}, {"req-version", required_argument, NULL, 'V'}, {"modeswitch", required_argument, NULL, 'M'}, + {"unix-path", required_argument, NULL, 'u'}, {"version", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0}, };@@ -79,10 +81,11 @@ static struct globals *alfred_init(int argc, char *argv[]) globals->best_server =NULL ; globals->clientmode_version =0 ; globals->mesh_iface ="bat0" ; + globals->unix_path =ALFRED_SOCK_PATH_DEFAULT ;time_random_seed (); -while ((opt =getopt_long (argc, argv,"ms:r:hi:b:vV:M:" , long_options, +while ((opt =getopt_long (argc, argv,"ms:r:hi:b:vV:M:u:" , long_options, &opt_ind)) !=-1 ) {switch (opt) {case 'r' :@@ -132,6 +135,9 @@ static struct globals *alfred_init(int argc, char *argv[]) } globals->clientmode =CLIENT_MODESWITCH ;break ; +case 'u' : + globals->unix_path = optarg; +break ;case 'v' :printf ("%s %s\n" , argv[0 ],SOURCE_VERSION );printf ("A.L.F.R.E.D. - Almighty Lightweight Remote Fact Exchange Daemon\n" );man/alfred.8 +3
-0@@ -50,6 +50,9 @@ Print the version .TP \fB\-h\fP, \fB\-\-help\fP Display a brief help message. +.TP +\fB\-u\fP, \fB\-\-unix-path\fP \fIpath\fP +path to unix socket used for client-server communication. . .SH CLIENT OPTIONS .TPserver.c +1
-1@@ -285,7 +285,7 @@ int alfred_server(struct globals *globals)if (create_hashes (globals))return -1 ; -if (unix_sock_open_daemon (globals,ALFRED_SOCK_PATH )) +if (unix_sock_open_daemon (globals))return -1 ;if (!globals->interface) {unix_sock.c +5
-5@@ -35,11 +35,11 @@#include "hash.h" #include "packet.h" -int unix_sock_open_daemon (struct globals *globals,const char *path) +int unix_sock_open_daemon (struct globals *globals) {struct sockaddr_un addr; -unlink (path); +unlink (globals->unix_path); globals->unix_sock =socket (AF_LOCAL ,SOCK_STREAM ,0 );if (globals->unix_sock <0 ) {@@ -50,7 +50,7 @@ int unix_sock_open_daemon(struct globals *globals, const char *path)memset (&addr,0 ,sizeof (addr)); addr.sun_family =AF_LOCAL ; -strncpy (addr.sun_path, path,sizeof (addr.sun_path)); +strncpy (addr.sun_path, globals->unix_path,sizeof (addr.sun_path)); addr.sun_path[sizeof (addr.sun_path) -1 ] ='\0' ; if (bind(globals->unix_sock, (struct sockaddr *)&addr,@@ -69,7 +69,7 @@ int unix_sock_open_daemon(struct globals *globals, const char *path)return 0 ; } -int unix_sock_open_client (struct globals *globals,const char *path) +int unix_sock_open_client (struct globals *globals) {struct sockaddr_un addr;@@ -82,7 +82,7 @@ int unix_sock_open_client(struct globals *globals, const char *path)memset (&addr,0 ,sizeof (addr)); addr.sun_family =AF_LOCAL ; -strncpy (addr.sun_path, path,sizeof (addr.sun_path)); +strncpy (addr.sun_path, globals->unix_path,sizeof (addr.sun_path)); addr.sun_path[sizeof (addr.sun_path) -1 ] ='\0' ; if (connect(globals->unix_sock, (struct sockaddr *)&addr,vis/man/batadv-vis.8 +3
-0@@ -42,6 +42,9 @@ Print the version \fB\-h\fP, \fB\-\-help\fP Display a brief help message. .TP +\fB\-u\fP, \fB\-\-unix-path\fP \fIpath\fP +path to unix socket used for alfred server communication. +.TP \fB\-i\fP, \fB\-\-interface\fP \fIiface\fP Specify the batman-adv interface configured on the system (default: bat0) .TPvis/vis.c +8
-2@@ -169,7 +169,7 @@ static int alfred_open_sock(struct globals *globals)memset (&addr,0 ,sizeof (addr)); addr.sun_family =AF_LOCAL ; -strncpy (addr.sun_path,ALFRED_SOCK_PATH ,sizeof (addr.sun_path)); +strncpy (addr.sun_path, globals->unix_path,sizeof (addr.sun_path)); addr.sun_path[sizeof (addr.sun_path) -1 ] ='\0' ; if (connect(globals->unix_sock, (struct sockaddr *)&addr,@@ -818,6 +818,7 @@ static void vis_usage(void)printf (" -i, --interface specify the batman-adv interface configured on the system (default: bat0)\n" );printf (" -s, --server start up in server mode, which regularly updates vis data from batman-adv\n" );printf (" -f, --format <format> specify the output format for client mode (either \"json\", \"jsondoc\" or \"dot\")\n" ); +printf (" -u, --unix-path <path> path to unix socket used for alfred server communication (default: \"" ALFRED_SOCK_PATH_DEFAULT "\")\n" );printf (" -v, --version print the version\n" );printf (" -h, --help this help\n" );printf ("\n" );@@ -831,6 +832,7 @@ static struct globals *vis_init(int argc, char *argv[]) {"server", no_argument, NULL, 's'}, {"interface", required_argument, NULL, 'i'}, {"format", required_argument, NULL, 'f'}, + {"unix-path", required_argument, NULL, 'u'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0},@@ -842,8 +844,9 @@ static struct globals *vis_init(int argc, char *argv[]) globals->opmode =OPMODE_CLIENT ; globals->interface ="bat0" ; globals->vis_format =FORMAT_DOT ; + globals->unix_path =ALFRED_SOCK_PATH_DEFAULT ; -while ((opt =getopt_long (argc, argv,"shf:i:v" , long_options, +while ((opt =getopt_long (argc, argv,"shf:i:vu:" , long_options, &opt_ind)) !=-1 ) {switch (opt) {case 's' :@@ -864,6 +867,9 @@ static struct globals *vis_init(int argc, char *argv[])case 'i' : globals->interface =strdup (optarg);break ; +case 'u' : + globals->unix_path = optarg; +break ;case 'v' :printf ("%s %s\n" , argv[0 ],SOURCE_VERSION );printf ("VIS alfred client\n" );vis/vis.h +2
-1@@ -30,7 +30,7 @@#define SOURCE_VERSION "2014.4.0"#endif -#define ALFRED_SOCK_PATH "/var/run/alfred.sock" +#define ALFRED_SOCK_PATH_DEFAULT "/var/run/alfred.sock"#define PATH_BUFF_LEN 200#define VIS_PACKETTYPE 1#define VIS_PACKETVERSION 1@@ -105,6 +105,7 @@ struct globals {struct list_head entry_list;int unix_sock; +const char *unix_path; };Signature · 1 line
2.0.1
Simon Wunderlich
AppliedQuoted 8 lines
The path to the socket used for client-server communication is currently hardcoded in alfred and its complimentary daemons. This makes it hard to run two instances of alfred on the same machine without any kind of virtualization or containers.
An user may still want to use two alfred instances to create a test setup or connect a single machine two separated alfred data clouds without exchanging data between them.
Applied in revision 6c6a6f7.
Thanks!
Simon
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Hello,
Quoted 1 line · Simon Wunderlich
Applied in revision 6c6a6f7.
Thanks so much for pushing this patch upstream! Just tested here on a ubuntu machine. Using the new command line option works fine, but I can't run another instance:
root 9063 1 0 19:55 ? 00:00:00 /usr/sbin/alfred -i
mzBR -b mzBAT -u /var/run/alfred-mz.sock -m
netstat | ss - output:
udp6 0 0 :::16962 :::*
0 66467 9063/alfred
UNCONN 0 0 :::16962
:::* users:(("alfred",9063,4)) ino:66467 sk:ffff88003bf0b300 <->
Error output after starting a second instance like "/usr/sbin/alfred
- -i wiBR -b wiBAT -u /var/run/alfred-wi.sock -m":
- ---
can't bind
- ---
What is the upd6 socket for? Is this the link-local multicast one?
- ---:~# netstat -g | grep mzBR | grep ff02
mzBR 2 ff02::1:ff00:0 mzBR 1 ff02::1:ff25:17 mzBR 1 ff02::1:ff6d:7aec
Any help appreciated.
Regards,
Tobias Hachmer
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQIcBAEBCgAGBQJT1pMLAAoJEHXGlTiIv2V4k7oQAJ3FZtgCyX3qsTVQWfYUOk2+ 2KxezBOvIiP5+Xqy24zQ1CfHDXj/anMaXilleOAmXC8R60Sh1NSREXYfIqNqiknQ v+s6gznZ5Wg9yfKYpwWLSsi4KFzRG4tCSa0+Hqr9I3HRy/3xwkAib8XLYJJMXPC7 RlWHFLn5Q9gxNbsJx+1JQVRzxDF+C7lGXI4tmyL9dIEMU0tPjlKUaw5yr2ZNEad1 BfcbzyplnTo5y1J3D2BfHNIZlruz4IqTDa1oIfbx9t/WzF3w8LYqLi6H6vdqJZ5T 9PPqTczGn/xyR01j7CQnU0WtlWsFdQr/gc4/NQcMxggSWpmEa+ZGwxR4hnXowDz+ jad7y9Cz8IqbrJ9WXKNeQ+9IiIf0MSi9hiY04d1m0/U3bswecGQsHiSWzlUVPC5c Ke6g2HHMYASNkC/DuKdPI4uA4eeBuVpNT/aT4V3KBWG2Ls2ssnbv+/sTQxGO7Moo 51JF1j15HYdqyfB/E9f4wA1QAwbIMDsAgJIQ34Z9owDMUCMUWWVt01XvBc+UnSSS X+l3qy7iGAWes3Cif/vP+Kvn4hXh2D4RAyrWl9p9G4rbxxA6SjTu64+ZDPuJpall 9NW+YjgL49ZrX6yxl/OPxV+BY8EN5aM2vuunKL8kCKloaKfCBZXOoHVrkLf+aTCY yoXk7v9YZPWWJlVcmXE4
=gk4U
-----END PGP SIGNATURE-----