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/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ggsn/+/17803 )
Change subject: lib/netns: OSMO_ASSERT() if user doesn't call init_netns()
......................................................................
lib/netns: OSMO_ASSERT() if user doesn't call init_netns()
It is vital that init_netns() is called first in order to initialize
default_nsfd.
Change-Id: Ic16646fa7d60c578056b17351c5fe2090a81dff0
---
M lib/netns.c
1 file changed, 13 insertions(+), 1 deletion(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/lib/netns.c b/lib/netns.c
index 1e77a04..6e0e179 100644
--- a/lib/netns.c
+++ b/lib/netns.c
@@ -40,12 +40,14 @@
#include <fcntl.h>
#include <errno.h>
+#include <osmocom/core/utils.h>
+
#include "netns.h"
#define NETNS_PATH "/var/run/netns"
/*! default namespace of the GGSN process */
-static int default_nsfd;
+static int default_nsfd = -1;
/*! switch to a (non-default) namespace, store existing signal mask in oldmask.
* \param[in] nsfd file descriptor representing the namespace to whch we shall switch
@@ -56,6 +58,8 @@
sigset_t intmask;
int rc;
+ OSMO_ASSERT(default_nsfd >= 0);
+
if (sigfillset(&intmask) < 0)
return -errno;
if ((rc = sigprocmask(SIG_BLOCK, &intmask, oldmask)) != 0)
@@ -71,6 +75,8 @@
* \returns 0 on successs; negative errno value in case of error */
int restore_ns(sigset_t *oldmask)
{
+ OSMO_ASSERT(default_nsfd >= 0);
+
int rc;
if (setns(default_nsfd, CLONE_NEWNET) < 0)
return -errno;
@@ -87,6 +93,8 @@
int fd;
int rc;
+ OSMO_ASSERT(default_nsfd >= 0);
+
/* mask off all signals, store old signal mask */
if (sigfillset(&intmask) < 0)
return -errno;
@@ -127,6 +135,8 @@
int sk;
int rc;
+ OSMO_ASSERT(default_nsfd >= 0);
+
/* mask off all signals, store old signal mask */
if (sigfillset(&intmask) < 0)
return -errno;
@@ -177,6 +187,8 @@
sigset_t intmask, oldmask;
char path[MAXPATHLEN] = NETNS_PATH;
+ OSMO_ASSERT(default_nsfd >= 0);
+
/* create /var/run/netns, if it doesn't exist already */
rc = mkdir(path, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
if (rc < 0 && errno != EEXIST)
--
To view, visit https://gerrit.osmocom.org/c/osmo-ggsn/+/17803
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-ggsn
Gerrit-Branch: master
Gerrit-Change-Id: Ic16646fa7d60c578056b17351c5fe2090a81dff0
Gerrit-Change-Number: 17803
Gerrit-PatchSet: 3
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200414/65d38846/attachment.htm>