diff options
author | Harald Welte <laforge@gnumonks.org> | 2013-09-27 22:42:41 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2013-09-29 14:56:44 +0200 |
commit | a72236a1d0effb1fe985f5685d40e6dc33ab65a3 (patch) | |
tree | b4ab5e143ff7631ee53f8691ce4a713f33c3f587 /src/gsmd | |
parent | 292e73a08c3445b4aa96057e559dbcec44b0d8f7 (diff) |
permit gsmd and libgsm to handle multiple instances
By using differntly-named unix domain sockets, we can run
multiple gsmd instances in parallel.
Diffstat (limited to 'src/gsmd')
-rw-r--r-- | src/gsmd/gsmd.c | 7 | ||||
-rw-r--r-- | src/gsmd/usock.c | 9 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/gsmd/gsmd.c b/src/gsmd/gsmd.c index 9389f5f..20daa7f 100644 --- a/src/gsmd/gsmd.c +++ b/src/gsmd/gsmd.c @@ -317,6 +317,7 @@ static struct option opts[] = { { "version", 0, NULL, 'V' }, { "daemon", 0, NULL, 'd' }, { "help", 0, NULL, 'h' }, + { "instance", 1, NULL, 'i' }, { "device", 1, NULL, 'p' }, { "speed", 1, NULL, 's' }, { "logfile", 1, NULL, 'l' }, @@ -347,6 +348,7 @@ static void print_usage(void) "\t-V\t--version\tDisplay program version\n" "\t-d\t--daemon\tDeamonize\n" "\t-h\t--help\t\tDisplay this help message\n" + "\t-i\t--instance <0-255>\t\tInstance number to use\n" "\t-p dev\t--device dev\tSpecify serial device to be used\n" "\t-s spd\t--speed spd\tSpecify speed in bps (9600,38400,115200,...)\n" "\t-F\t--hwflow\tHardware Flow Control (RTS/CTS)\n" @@ -396,7 +398,7 @@ int main(int argc, char **argv) print_header(); /*FIXME: parse commandline, set daemonize, device, ... */ - while ((argch = getopt_long(argc, argv, "FVLdhp:s:l:e:v:m:w:", opts, NULL)) != -1) { + while ((argch = getopt_long(argc, argv, "FVLdhi:p:s:l:e:v:m:w:", opts, NULL)) != -1) { switch (argch) { case 'V': print_version(); @@ -416,6 +418,9 @@ int main(int argc, char **argv) print_usage(); exit(0); break; + case 'i': + g.instance = atoi(optarg); + break; case 'p': device = optarg; break; diff --git a/src/gsmd/usock.c b/src/gsmd/usock.c index f258fd6..41814c8 100644 --- a/src/gsmd/usock.c +++ b/src/gsmd/usock.c @@ -1734,7 +1734,14 @@ int usock_init(struct gsmd *g) memset(&sun, 0, sizeof(sun)); sun.sun_family = AF_UNIX; - memcpy(sun.sun_path, GSMD_UNIX_SOCKET, sizeof(GSMD_UNIX_SOCKET)); + if (g->instance == 0) { + memcpy(sun.sun_path, GSMD_UNIX_SOCKET, + sizeof(GSMD_UNIX_SOCKET)); + } else { + sun.sun_path[0] = '\0'; + snprintf(sun.sun_path+1, sizeof(sun.sun_path)-1, "gsmd.%u", + g->instance); + } rc = bind(fd, (struct sockaddr *)&sun, sizeof(sun)); if (rc < 0) { |