Change in osmocom-bb[master]: osmocon: Use osmo_sock_unix_init_ofd() 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/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Sep 6 14:23:15 UTC 2018


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/10802 )

Change subject: osmocon: Use osmo_sock_unix_init_ofd() from libosmocore
......................................................................

osmocon: Use osmo_sock_unix_init_ofd() from libosmocore

We don't need to hand-code unix domain socket initialization but
can simply use our library function for it.  As an added benefit,
the library code already contains corner case handling for non-NUL
terminated unix domain socket path.

Change-Id: I3ab69a971be555c9f9b5b7a7e5da53008a119504
---
M src/host/osmocon/osmocon.c
1 file changed, 4 insertions(+), 41 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved



diff --git a/src/host/osmocon/osmocon.c b/src/host/osmocon/osmocon.c
index 6075e61..26416f7 100644
--- a/src/host/osmocon/osmocon.c
+++ b/src/host/osmocon/osmocon.c
@@ -1,6 +1,6 @@
 /* osmocon */
 
-/* (C) 2010 by Harald Welte <laforge at gnumonks.org>
+/* (C) 2010,2018 by Harald Welte <laforge at gnumonks.org>
  * (C) 2010 by Holger Hans Peter Freyther <zecke at selfish.org>
  * (C) 2010 by Steve Markgraf <steve at steve-m.de>
  *
@@ -45,6 +45,7 @@
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/timer.h>
 #include <osmocom/core/application.h>
+#include <osmocom/core/socket.h>
 
 #include <arpa/inet.h>
 
@@ -1333,47 +1334,14 @@
 				uint8_t dlci)
 {
 	struct osmo_fd *bfd = &ts->bfd;
-	struct sockaddr_un local;
-	unsigned int namelen;
 	int rc;
 
-	bfd->fd = socket(AF_UNIX, SOCK_STREAM, 0);
-
-	if (bfd->fd < 0) {
+	rc = osmo_sock_unix_init_ofd(bfd, SOCK_STREAM, 0, path, OSMO_SOCK_F_BIND);
+	if (rc < 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);
-		return -1;
-	}
-
-	if (listen(bfd->fd, 0) != 0) {
-		fprintf(stderr, "Failed to listen.\n");
-		return -1;
-	}
-
-	bfd->when = BSC_FD_READ;
 	bfd->cb = tool_accept;
 	bfd->data = ts;
 
@@ -1384,11 +1352,6 @@
 
 	sercomm_register_rx_cb(dlci, hdlc_tool_cb);
 
-	if (osmo_fd_register(bfd) != 0) {
-		fprintf(stderr, "Failed to register the bfd.\n");
-		return -1;
-	}
-
 	return 0;
 }
 

-- 
To view, visit https://gerrit.osmocom.org/10802
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I3ab69a971be555c9f9b5b7a7e5da53008a119504
Gerrit-Change-Number: 10802
Gerrit-PatchSet: 2
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180906/ceed40fc/attachment.htm>


More information about the gerrit-log mailing list