PROBLEM:  (QAR 48248) 		(Patch ID: OSF400-109)
********
This patch fixes a problem in which a system running the POSIX Message Queue 
functions in the realtime library (librt.a, librt.so) will either exhibit 
message queue data corruption or it will hang.

The problem occurs if more than one message queue is actively used in a user 
process.

If two or more user processes open more than one POSIX message queue using 
mq_open(), and open them in a different order, for example, process 1 opens 
queue 1 followed by queue 2, and process 2 opens queue2 followed by queue 1, 
then data corruption in the queue will occur. The data corruption may show up 
as a panic or a hang, or simply as bad data.  The problem may present itself in
other forms.

To reproduce the problem,  compile and execute the following two tests. The 
sources for these tests (mqread.c and mqwrite.c) are included at the end of 
this text.

To compile:
# cc -o mqread mqread.c -lrt
# cc -o mqwrite mqwrite.c -lrt

To execute:

In order to demonstrate the problem, run mqwrite followed by mqread, but pass 
argument 1 to mqwrite. This forces mqwrite to open the two queues in a 
different order than the order in which mqread opens them in. The mqwrite will 
succeed, but the mqread will fail, but not always in the same way.  Sometimes 
mqread will kill the window that the test is running in.  At other times, the 
test will complete, but the data will be corrupted.

The output of the data corruption case is included below:

    # ./mqwrite 1
    START OF TEST_SEND

     SWAPPED ORDER A
    queues descriptors : mqueue_1 65537 mqueue_2 65536
    successful call to mq_send, i = 0
    successful call to mq_send, i = 1
    successful call to mq_send, i = 2
    successful call to mq_send, i = 3
    successful call to mq_send, i = 4
    successful call to mq_send, i = 5
    successful call to mq_send, i = 6
    successful call to mq_send, i = 7
    successful call to mq_send, i = 8
    successful call to mq_send, i = 9
    About to exit the sending process after closing the queue

    # ./mqread 
    START OF TEST_RECEIVE

     NORMAL ORDER
    queue descriptors : mqueue_1 65536 mqueue_2 65537
    data read for iteration 0 = x`r@
    data read for iteration 1 = PRIORITY2a@
    data read for iteration 2 = PRIORITY2a@
    data read for iteration 3 = PRIORITY2a@   
    data read for iteration 4 = PRIORITY2a@
    data read for iteration 5 = PRIORITY2a@
    data read for iteration 6 = PRIORITY2a@
    data read for iteration 7 = PRIORITY2a@
    data read for iteration 8 = PRIORITY2a@
    data read for iteration 9 = PRIORITY2a@
    About to exit the receiving process after closing and unlinking the queue

NOTE that the 'data read for iteration 0' shows corrupt data.

After the patch is installed, and the test is rerun, the mqread will succeed, 
and it will print the following to the screen:

    # ./mqread
    START OF TEST_RECEIVE

     NORMAL ORDER
    queue descriptors : mqueue_1 65536 mqueue_2 65537
    data read for iteration 0 = PRIORITY2a@
    data read for iteration 1 = PRIORITY2a@
    data read for iteration 2 = PRIORITY2a@
    data read for iteration 3 = PRIORITY2a@
    data read for iteration 4 = PRIORITY2a@
    data read for iteration 5 = PRIORITY2a@
    data read for iteration 6 = PRIORITY2a@
    data read for iteration 7 = PRIORITY2a@
    data read for iteration 8 = PRIORITY2a@
    data read for iteration 9 = PRIORITY2a@
    About to exit the receiving process after closing and unlinking the queue
 


The following are the mqwrite.c and mqread.c source files:
/******************************************************************/
/* mqwrite.c: 
 *
 * Example of write (send) message queue
 *
 * Opens two queues "mqueue_1" which is the only queue used in transfers and
 * a second queue "mqueue_2" which after being opened is never used
 *
 * To open queues in the order mqueue_1 followed by mqueue_2 run program with
 * argument 0, or no argument
 * i.e.
 *   mqwrite 0
 * To open queues in the order mqueue_2 followed by mqueue_1 run program with
 * argument=1
 * i.e.
 *   mqwrite 1
 *
 */
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <time.h>
#include <sys/resource.h>
#include <time.h>
#include <sched.h>
#include <sys/mman.h>
#include <sys/fcntl.h>
#include <sys/rt_syscall.h>
#include <mqueue.h>
#include <errno.h>
#define PMODE 0666

int main(int argc, char *argv[])
{
int i;
int status = 0;
mqd_t mqueue_1, mqueue_2;
char msg_buffer[P4IPC_MSGSIZE];
struct mq_attr attr;
int open_flags = 0;
int num_bytes_to_send;
int priority_of_msg;

int swap;

swap=0;
if (argc < 2)
    swap=0;
else
    {
    if (atoi(argv[1]) != 1)
        swap=0;
    else
       swap=1;
    }

printf("START OF TEST_SEND \n");

/* Fill in attributes for message queue */
attr.mq_maxmsg = 20;
attr.mq_msgsize = P4IPC_MSGSIZE;
attr.mq_flags   = 0;

if (swap != 0)
    {
    printf ("\n SWAPPED ORDER A\n");    
    if ((mqueue_2 = mq_open ("mqueue_2", O_WRONLY | O_CREAT, PMODE, &attr)) == -1)
        {
        perror ("mq_open of mqueue_2 failed");
        exit (1);
        }
    if ((mqueue_1 = mq_open ("mqueue_1", O_WRONLY | O_CREAT, PMODE, &attr)) == -1)
        {
        perror ("mq_open of mqueue_1 failed");
        exit (1);
        }
    }
else
    {
    printf("\n NORMAL ORDER\n"); 
    if ((mqueue_1 = mq_open ("mqueue_1", O_WRONLY | O_CREAT, PMODE, &attr)) == -1)
        {
        perror ("mq_open of mqueue_1 failed");
        exit (1);
        }
    if ((mqueue_2 = mq_open ("mqueue_2", O_WRONLY | O_CREAT, PMODE, &attr)) == -1)
        {
        perror ("mq_open of mqueue_2 failed");
        exit (1);
        }
    }

printf("queues descriptors : mqueue_1 %d mqueue_2 %d \n", mqueue_1, mqueue_2);

/* Fill in a test message buffer to send */
msg_buffer[0] = 'P';
msg_buffer[1] = 'R';
msg_buffer[2] = 'I';
msg_buffer[3] = 'O';
msg_buffer[4] = 'R';
msg_buffer[5] = 'I';
msg_buffer[6] = 'T';
msg_buffer[7] = 'Y';
msg_buffer[8] = '2';
msg_buffer[9] = 'a';

num_bytes_to_send = 10;
priority_of_msg = 1;
for (i = 0; i < 10; i++)
    {
    if (mq_send (mqueue_1, msg_buffer, num_bytes_to_send, priority_of_msg) == -1)
        perror ("mq_send failure on mqueue_1");
    else
        printf ("successful call to mq_send, i = %d\n",i);
    }

/* Done with queue, so close it */
if (mq_close(mqueue_1) == -1)

    perror ("mq_close failure on mqfd");

printf("About to exit the sending process after closing the queue \n");
mq_close(mqueue_2);

}

/******************************************************************/
/*
 * Example of read (receive) message queue
 *
 * Opens two queues "mqueue_1" which is the only queue used in transfers and
 * a second queue "mqueue_2" which after being opened is never used
 *
 * To open queues in the order mqueue_1 followed by mqueue_2 run program with
 * argument 0, or no argument:
 * i.e.
 *   mqread 0
 * To open queues in the order mqueue_2 followed by mqueue_1 run program
 * with argument=1
 * i.e.
 *   mqread 1
 *
 */
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <time.h>
#include <sched.h>
#include <sys/mman.h>
#include <sys/fcntl.h>
#include <sys/rt_syscall.h>
#include <mqueue.h>
#include <errno.h>
#define PMODE 0666


int main(int argc, char *argv[])
{
int i;
int status = 0;
mqd_t mqueue_1, mqueue_2;
char msg_buffer[P4IPC_MSGSIZE];
struct mq_attr attr;
int open_flags = 0;
int priority_of_msg;
int swap;

swap=0;
if (argc < 2)
    swap=0;
else
    {
    if (atoi(argv[1]) != 1)
        swap=0;
    else
        swap=1;
    }


printf("START OF TEST_RECEIVE\n");

/* Fill in attributes for message queue */
attr.mq_maxmsg = 20;
attr.mq_msgsize = P4IPC_MSGSIZE;
attr.mq_flags   = 0;

if (swap != 0)
    {
    printf ("\n SWAPPED ORDER A\n");
    if ((mqueue_2 = mq_open ("mqueue_2",  O_RDONLY | O_CREAT, PMODE, &attr)) == -1)
        {
        perror ("mq_open of mqueue_2 failed");
        exit (1);
        }
    if ((mqueue_1 = mq_open ("mqueue_1",  O_RDONLY | O_CREAT, PMODE, &attr)) == -1)
        {
        perror ("mq_open of mqueue_1 failed");
        exit (1);
        }
    }
else
    {
    printf ("\n NORMAL ORDER\n");
    if ((mqueue_1 = mq_open ("mqueue_1", O_RDONLY | O_CREAT, PMODE, &attr)) == -1)
        {
        perror ("mq_open of mqueue_1 failed");
        exit (1);
        }
    if ((mqueue_2 = mq_open ("mqueue_2", O_RDONLY | O_CREAT, PMODE, &attr)) == -1)
        {
        perror ("mq_open of mqueue_2 failed");
        exit (1);
        }
    }

printf("queue descriptors : mqueue_1 %d mqueue_2 %d \n", mqueue_1, mqueue_2);

for (i = 0; i < 10; i++)
    {
    if (mq_receive (mqueue_1, msg_buffer, P4IPC_MSGSIZE, 0) == -1)
        perror ("mq_receive failure on mqfd");
    else
        printf ("data read for iteration %d = %s \n", i, msg_buffer);
    }

/* Done with queue, so close it */
if (mq_close (mqueue_1) == -1)
    perror("mq_close failure on mqueue_1");

/* Done with test, so unlink the queue,
 * which destroys it.
 * You only need one call to unlink.
 */
if (mq_unlink("mqueue_1") == -1)
    perror("mq_unlink failure in test_ipc");

printf("About to exit the receiving process after closing and unlinking the queue \n");
mq_close(mqueue_2);
mq_unlink("mqueue_2");
}

PROBLEM:  (CLD MCPM20W7F, QAR 51771)	 (Patch ID: OSF400-215)
********
When setting the date with the clock_settime rtl service routine, the date will
not get past the date of 'Sat Sep  8 19:46:39 2001'.  If you try to set past
this date the routine returns a EINVAL error.


FILE(s):

/usr/sys/include/mqueue.h	    subset OSFBINCOM400
CHECKSUM: 03140      9     RCSfile: mqueue.h      RCS: 1.1.16.2
/usr/ccs/lib/librt.a		    subset OSFRTDEV400
CHECKSUM: 18365     59
/usr/shlib/librt.so		    subset OSFRTDEV400
CHECKSUM: 02745     72
