FreeBSD Bugzilla – Attachment 200557 Details for
Bug 234442
libnetgraph race condition
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
fight race with mutex
libnetgraph.diff (text/plain), 1.55 KB, created by
Eugene Grosbein
on 2018-12-27 11:25:47 UTC
(
hide
)
Description:
fight race with mutex
Filename:
MIME Type:
Creator:
Eugene Grosbein
Created:
2018-12-27 11:25:47 UTC
Size:
1.55 KB
patch
obsolete
>Index: lib/libnetgraph/msg.c >=================================================================== >--- lib/libnetgraph/msg.c (revision 336962) >+++ lib/libnetgraph/msg.c (working copy) >@@ -44,6 +44,7 @@ > #include <sys/types.h> > #include <sys/socket.h> > #include <stdarg.h> >+#include <pthread.h> > #include <netgraph/ng_message.h> > #include <netgraph/ng_socket.h> > >@@ -52,7 +53,17 @@ > > /* Next message token value */ > static int gMsgId; >+static pthread_mutex_t msgid_mutex = PTHREAD_MUTEX_INITIALIZER; > >+#define THREAD_LOCK() \ >+ do { \ >+ if (__isthreaded) pthread_mutex_lock(&msgid_mutex); \ >+ } while(0) >+#define THREAD_UNLOCK() \ >+ do { \ >+ if (__isthreaded) pthread_mutex_unlock(&msgid_mutex); \ >+ } while(0) >+ > /* For delivering both messages and replies */ > static int NgDeliverMsg(int cs, const char *path, > const struct ng_mesg *hdr, const void *args, size_t arglen); >@@ -72,9 +83,13 @@ > memset(&msg, 0, sizeof(msg)); > msg.header.version = NG_VERSION; > msg.header.typecookie = cookie; >+ >+ THREAD_LOCK(); > if (++gMsgId < 0) > gMsgId = 1; > msg.header.token = gMsgId; >+ THREAD_UNLOCK(); >+ > msg.header.flags = NGF_ORIG; > msg.header.cmd = cmd; > snprintf((char *)msg.header.cmdstr, NG_CMDSTRSIZ, "cmd%d", cmd); >@@ -143,9 +158,13 @@ > > /* Now send binary version */ > binary = (struct ng_mesg *)reply->data; >+ >+ THREAD_LOCK(); > if (++gMsgId < 0) > gMsgId = 1; > binary->header.token = gMsgId; >+ THREAD_UNLOCK(); >+ > binary->header.version = NG_VERSION; > if (NgDeliverMsg(cs, > path, binary, binary->data, binary->header.arglen) < 0) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 234442
: 200557 |
200960