[PATCH] osmo-bts[master]: pcu_sock: use osmo_sock_unix_init() from libosmocore

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Wed Jul 20 17:11:36 UTC 2016


Review at  https://gerrit.osmocom.org/557

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
---
M src/common/pcu_sock.c
1 file changed, 5 insertions(+), 55 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/57/557/1

diff --git a/src/common/pcu_sock.c b/src/common/pcu_sock.c
index d52cdb1..7a40bcf 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 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)
@@ -845,12 +844,13 @@
 
 	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;
@@ -890,56 +890,6 @@
 	osmo_fd_unregister(bfd);
 	talloc_free(state);
 	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) {

-- 
To view, visit https://gerrit.osmocom.org/557
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id5828649d44ef11e70946793696b0d689d6b35e3
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>



More information about the gerrit-log mailing list