Change in osmocom-bb[master]: osmoload: 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 13:03:19 UTC 2018


Harald Welte has uploaded this change for review. ( https://gerrit.osmocom.org/10803


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

osmoload: 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: Iedcec4591cf0fcbd6f956ed022169eae10a9b16e
---
M src/host/osmocon/osmoload.c
1 file changed, 4 insertions(+), 14 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/03/10803/1

diff --git a/src/host/osmocon/osmoload.c b/src/host/osmocon/osmoload.c
index 1c20382..5b56208 100644
--- a/src/host/osmocon/osmoload.c
+++ b/src/host/osmocon/osmoload.c
@@ -1,6 +1,7 @@
 /* control utility for the Calypso bootloader */
 
 /* (C) 2010 by Ingo Albrecht <prom at berlin.ccc.de>
+ * (C) 2018 by Harald Welte <laforge at gnumonks.org>
  *
  * All Rights Reserved
  *
@@ -39,6 +40,7 @@
 #include <osmocom/core/select.h>
 #include <osmocom/core/timer.h>
 #include <osmocom/core/crc16.h>
+#include <osmocom/core/socket.h>
 
 #include <loader/protocol.h>
 
@@ -493,23 +495,11 @@
 static void
 loader_connect(const char *socket_path) {
 	int rc;
-	struct sockaddr_un local;
 	struct osmo_fd *conn = &connection;
 
-	local.sun_family = AF_UNIX;
-	strncpy(local.sun_path, socket_path, sizeof(local.sun_path));
-	local.sun_path[sizeof(local.sun_path) - 1] = '\0';
-
-	conn->fd = socket(AF_UNIX, SOCK_STREAM, 0);
-	if (conn->fd < 0) {
-		fprintf(stderr, "Failed to create unix domain socket.\n");
-		exit(1);
-	}
-
-	rc = connect(conn->fd, (struct sockaddr *) &local,
-				 sizeof(local.sun_family) + strlen(local.sun_path));
+	rc = osmo_sock_unix_init_ofd(conn, SOCK_STREAM, 0, socket_path, OSMO_SOCK_F_CONNECT);
 	if (rc < 0) {
-		fprintf(stderr, "Failed to connect to '%s'.\n", local.sun_path);
+		fprintf(stderr, "Failed to create unix domain socket.\n");
 		exit(1);
 	}
 

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

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iedcec4591cf0fcbd6f956ed022169eae10a9b16e
Gerrit-Change-Number: 10803
Gerrit-PatchSet: 1
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180906/b895c89c/attachment.htm>


More information about the gerrit-log mailing list