summaryrefslogtreecommitdiffstats
path: root/src/host/osmocon
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2018-09-06 15:00:10 +0200
committerHarald Welte <laforge@gnumonks.org>2018-09-06 16:14:47 +0200
commit855cea63180d6564cf3a5c637bb92e405c7b6841 (patch)
tree44e543cf3037ec937d1132dac78b31ceaf221f52 /src/host/osmocon
parentdb144ce571748e691ea88b04f07436542cdfca99 (diff)
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
Diffstat (limited to 'src/host/osmocon')
-rw-r--r--src/host/osmocon/osmoload.c24
1 files changed, 4 insertions, 20 deletions
diff --git a/src/host/osmocon/osmoload.c b/src/host/osmocon/osmoload.c
index 1c20382d..b1b48e24 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@berlin.ccc.de>
+ * (C) 2018 by Harald Welte <laforge@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,34 +495,16 @@ loader_read_cb(struct osmo_fd *fd, unsigned int flags) {
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);
}
- conn->when = BSC_FD_READ;
conn->cb = loader_read_cb;
conn->data = NULL;
-
- if (osmo_fd_register(conn) != 0) {
- fprintf(stderr, "Failed to register fd.\n");
- exit(1);
- }
}
static void