From ba656fff9186f76544cf4c59900d5a649c133599 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Wed, 20 Jul 2016 23:09:52 +0600 Subject: 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 --- src/common/pcu_sock.c | 60 +++++---------------------------------------------- 1 file changed, 5 insertions(+), 55 deletions(-) (limited to 'src') 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 #include +#include #include #include #include @@ -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; -- cgit v1.2.3