summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2004-07-14 20:31:05 +0000
committerrwatson <rwatson@FreeBSD.org>2004-07-14 20:31:05 +0000
commit1ec4fa638a46111fc03087cf5121e7929c26e76e (patch)
treec6ba73e367815e5fcc5df71dbd878723b5b2f2e9
parent1c3ad086a91e03e89be49565e8ea08ab35d749c6 (diff)
downloadFreeBSD-src-1ec4fa638a46111fc03087cf5121e7929c26e76e.zip
FreeBSD-src-1ec4fa638a46111fc03087cf5121e7929c26e76e.tar.gz
Add a mutex ng_tty_mtx to protect the global variable ngt_unit. Note
that the locking of globals here isn't complete, and there's also a locking issue relating to calling into and out of the tty code.
-rw-r--r--sys/netgraph/ng_tty.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/sys/netgraph/ng_tty.c b/sys/netgraph/ng_tty.c
index 9e4ecc3..bd341da 100644
--- a/sys/netgraph/ng_tty.c
+++ b/sys/netgraph/ng_tty.c
@@ -166,10 +166,18 @@ static struct ng_type typestruct = {
};
NETGRAPH_INIT(tty, &typestruct);
+/*
+ * XXXRW: ngt_unit is protected by ng_tty_mtx. ngt_ldisc is constant once
+ * ng_tty is initialized. ngt_nodeop_ok is untouched, and might want to be a
+ * sleep lock in the future?
+ */
static int ngt_unit;
static int ngt_nodeop_ok; /* OK to create/remove node */
static int ngt_ldisc;
+static struct mtx ng_tty_mtx;
+MTX_SYSINIT(ng_tty, &ng_tty_mtx, "ng_tty", MTX_DEF);
+
/******************************************************************
LINE DISCIPLINE METHODS
******************************************************************/
@@ -214,7 +222,9 @@ ngt_open(struct cdev *dev, struct tty *tp)
FREE(sc, M_NETGRAPH);
goto done;
}
+ mtx_lock(&ng_tty_mtx);
snprintf(name, sizeof(name), "%s%d", typestruct.name, ngt_unit++);
+ mtx_unlock(&ng_tty_mtx);
/* Assign node its name */
if ((error = ng_name_node(sc->node, name))) {
OpenPOWER on IntegriCloud