Initialise the "name" variable properly and compare all 32 bytes
Without this patch, calling sys_mq_open() with same names specified results in two separate queues being opened and their descriptors returned instead of the same descriptor being returned for both. Do the initialisation and comparison properly, so that when the same name is specified to sys_mq_open multiple times in same process or different process, the same opened queue descriptor is returned.
This commit is contained in:
parent
8501cb7ed8
commit
368b5fc155
1 changed files with 2 additions and 1 deletions
|
@ -80,7 +80,7 @@ int mq_open(const char *name, int oflag)
|
|||
|
||||
for (int i = 0; i < number_of_queues; i++)
|
||||
if (mq.queue_slot_empty[i] == NOT_EMPTY)
|
||||
if (strcmp(mq.msg[i].name, name) == 0) {
|
||||
if (strncmp(mq.msg[i].name, name, NAME_SIZE) == 0) {
|
||||
mq.msg[i].num_users++;
|
||||
return (mqd_t) i;
|
||||
}
|
||||
|
@ -91,6 +91,7 @@ int mq_open(const char *name, int oflag)
|
|||
mq.queue_slot_empty[i] = NOT_EMPTY;
|
||||
mq.num_queues++;
|
||||
mq.msg[i].num_users++;
|
||||
memset(mq.msg[i].name, '\0', NAME_SIZE);
|
||||
strncpy(mq.msg[i].name, name, strlen(name));
|
||||
|
||||
for (int j = 0; j < number_of_messages; j++) {
|
||||
|
|
Loading…
Reference in a new issue