aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2016-07-20 23:09:52 +0600
committerHarald Welte <laforge@gnumonks.org>2016-07-28 09:29:03 +0000
commitba656fff9186f76544cf4c59900d5a649c133599 (patch)
tree1c7f6149098607d84580ec128b3945a2d9d0cef9 /src
parent2b34ae32cf5f986ab594d3b9882392c0fb8fb4e3 (diff)
pcu_sock: use osmo_sock_unix_init() from libosmocore
Since the osmo_unixsock_listen() was moved to libosmocore it would be better to use the library's implementation instead of reinventing the wheel again. Change-Id: Id5828649d44ef11e70946793696b0d689d6b35e3
Diffstat (limited to 'src')
-rw-r--r--src/common/pcu_sock.c60
1 files changed, 5 insertions, 55 deletions
diff --git a/src/common/pcu_sock.c b/src/common/pcu_sock.c
index d40b19bf..22b6fabf 100644
--- a/src/common/pcu_sock.c
+++ b/src/common/pcu_sock.c
@@ -32,6 +32,7 @@
#include <osmocom/core/talloc.h>
#include <osmocom/core/select.h>
+#include <osmocom/core/socket.h>
#include <osmo-bts/logging.h>
#include <osmo-bts/gsm_data.h>
#include <osmo-bts/pcu_if.h>
@@ -58,8 +59,6 @@ static const char *sapi_string[] = {
};
static int pcu_sock_send(struct gsm_network *net, struct msgb *msg);
-/* FIXME: move this to libosmocore */
-int osmo_unixsock_listen(struct osmo_fd *bfd, int type, const char *path);
static struct gsm_bts_trx *trx_by_nr(struct gsm_bts *bts, uint8_t trx_nr)
@@ -853,12 +852,13 @@ int pcu_sock_init(const char *path)
bfd = &state->listen_bfd;
- rc = osmo_unixsock_listen(bfd, SOCK_SEQPACKET, path);
- if (rc < 0) {
+ bfd->fd = osmo_sock_unix_init(SOCK_SEQPACKET, 0, path,
+ OSMO_SOCK_F_BIND);
+ if (bfd->fd < 0) {
LOGP(DPCU, LOGL_ERROR, "Could not create unix socket: %s\n",
strerror(errno));
talloc_free(state);
- return rc;
+ return -1;
}
bfd->when = BSC_FD_READ;
@@ -900,56 +900,6 @@ void pcu_sock_exit(void)
bts_gsmnet.pcu_state = NULL;
}
-/* FIXME: move this to libosmocore */
-int osmo_unixsock_listen(struct osmo_fd *bfd, int type, const char *path)
-{
- struct sockaddr_un local;
- unsigned int namelen;
- int rc;
-
- bfd->fd = socket(AF_UNIX, type, 0);
-
- if (bfd->fd < 0) {
- fprintf(stderr, "Failed to create Unix Domain Socket.\n");
- return -1;
- }
-
- local.sun_family = AF_UNIX;
- strncpy(local.sun_path, path, sizeof(local.sun_path));
- local.sun_path[sizeof(local.sun_path) - 1] = '\0';
- unlink(local.sun_path);
-
- /* we use the same magic that X11 uses in Xtranssock.c for
- * calculating the proper length of the sockaddr */
-#if defined(BSD44SOCKETS) || defined(__UNIXWARE__)
- local.sun_len = strlen(local.sun_path);
-#endif
-#if defined(BSD44SOCKETS) || defined(SUN_LEN)
- namelen = SUN_LEN(&local);
-#else
- namelen = strlen(local.sun_path) +
- offsetof(struct sockaddr_un, sun_path);
-#endif
-
- rc = bind(bfd->fd, (struct sockaddr *) &local, namelen);
- if (rc != 0) {
- fprintf(stderr, "Failed to bind the unix domain socket. '%s'\n",
- local.sun_path);
- close(bfd->fd);
- bfd->fd = -1;
- return -1;
- }
-
- if (listen(bfd->fd, 0) != 0) {
- fprintf(stderr, "Failed to listen.\n");
- close(bfd->fd);
- bfd->fd = -1;
- return -1;
- }
-
- return 0;
-}
-
bool pcu_connected(void) {
struct gsm_network *net = &bts_gsmnet;
struct pcu_sock_state *state = net->pcu_state;