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:
Sanchayan Maity 2016-03-23 11:11:30 +05:30
parent 8501cb7ed8
commit 368b5fc155

View file

@ -80,7 +80,7 @@ int mq_open(const char *name, int oflag)
for (int i = 0; i < number_of_queues; i++) for (int i = 0; i < number_of_queues; i++)
if (mq.queue_slot_empty[i] == NOT_EMPTY) 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++; mq.msg[i].num_users++;
return (mqd_t) i; return (mqd_t) i;
} }
@ -91,6 +91,7 @@ int mq_open(const char *name, int oflag)
mq.queue_slot_empty[i] = NOT_EMPTY; mq.queue_slot_empty[i] = NOT_EMPTY;
mq.num_queues++; mq.num_queues++;
mq.msg[i].num_users++; mq.msg[i].num_users++;
memset(mq.msg[i].name, '\0', NAME_SIZE);
strncpy(mq.msg[i].name, name, strlen(name)); strncpy(mq.msg[i].name, name, strlen(name));
for (int j = 0; j < number_of_messages; j++) { for (int j = 0; j < number_of_messages; j++) {