summaryrefslogtreecommitdiff
path: root/src/libgsmd
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2013-09-27 22:42:41 +0200
committerHarald Welte <laforge@gnumonks.org>2013-09-29 14:56:44 +0200
commita72236a1d0effb1fe985f5685d40e6dc33ab65a3 (patch)
treeb4ab5e143ff7631ee53f8691ce4a713f33c3f587 /src/libgsmd
parent292e73a08c3445b4aa96057e559dbcec44b0d8f7 (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/libgsmd')
-rw-r--r--src/libgsmd/libgsmd.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/libgsmd/libgsmd.c b/src/libgsmd/libgsmd.c
index 1626b04..03642ea 100644
--- a/src/libgsmd/libgsmd.c
+++ b/src/libgsmd/libgsmd.c
@@ -64,7 +64,7 @@ static int lgsm_open_backend(struct lgsm_handle *lh, const char *device)
{
int rc;
- if (!strcmp(device, LGSMD_DEVICE_GSMD)) {
+ if (!strncmp(device, LGSMD_DEVICE_GSMD, strlen(LGSMD_DEVICE_GSMD))) {
struct sockaddr_un sun;
/* use unix domain socket to gsm daemon */
@@ -74,7 +74,8 @@ static int lgsm_open_backend(struct lgsm_handle *lh, const char *device)
memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_UNIX;
- memcpy(sun.sun_path, GSMD_UNIX_SOCKET, sizeof(GSMD_UNIX_SOCKET));
+ sun.sun_path[0] = '\0';
+ strncpy(sun.sun_path+1, device, sizeof(sun.sun_path)-1);
rc = connect(lh->fd, (struct sockaddr *)&sun, sizeof(sun));
if (rc < 0) {
@@ -184,6 +185,19 @@ struct lgsm_handle *lgsm_init(const char *device)
return lh;
}
+struct lgsm_handle *lgsm_init_inst(unsigned int instance)
+{
+ struct lgsm_handle *lh = malloc(sizeof(*lh));
+ char buf[32];
+ if (instance == 0)
+ snprintf(buf, sizeof(buf), "gsmd");
+ else
+ snprintf(buf, sizeof(buf), "gsmd.%u", instance);
+
+ return lgsm_init(buf);
+}
+
+
int lgsm_exit(struct lgsm_handle *lh)
{
free(lh);
@@ -191,7 +205,6 @@ int lgsm_exit(struct lgsm_handle *lh)
return 0;
}
-
static u_int16_t next_msg_id;
int lgsm_send(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh)
personal git repositories of Harald Welte. Your mileage may vary