From 6d1e2a9c7fd8c293768712d87821e7c77560daf9 Mon Sep 17 00:00:00 2001 From: jwh1 Date: Wed, 12 Jul 2000 06:28:58 +0000 Subject: Wed Jul 12 01:25:44 2000 John Heitmann --- PACE/pace/config/compiler.h | 6 + PACE/pace/emulation/mqueue.c | 285 +++++++++++++++++++++++++------------------ PACE/pace/emulation/mqueue.h | 46 +++++-- PACE/pace/emulation/time.c | 57 --------- PACE/pace/emulation/time.h | 67 ++++++---- PACE/pace/mqueue.h | 1 + PACE/pace/posix/mqueue.c | 4 + PACE/pace/posix/mqueue.h | 10 -- PACE/pace/posix/stdio.c | 33 +++++ PACE/pace/posix/stdio.inl | 32 ----- PACE/pace/posix/string.inl | 12 +- PACE/pace/posix/time.h | 9 +- PACE/pace/posix/time.inl | 14 ++- PACE/pace/posix/unistd.inl | 30 ++--- PACE/tests/Makefile | 4 +- PACE/tests/mqueue_test.c | 62 ++++++++++ 16 files changed, 387 insertions(+), 285 deletions(-) delete mode 100644 PACE/pace/emulation/time.c create mode 100644 PACE/tests/mqueue_test.c diff --git a/PACE/pace/config/compiler.h b/PACE/pace/config/compiler.h index 7f127fc0de4..92e25c97a05 100644 --- a/PACE/pace/config/compiler.h +++ b/PACE/pace/config/compiler.h @@ -34,6 +34,12 @@ # endif /* ! PACE_HAS_INLINE */ #endif /* ! __cplusplus */ +#if defined (PACE_HAS_INLINE) && defined (__GNUC__) && !(PACE_LYNXOS) +# define PACE_BROKEN_INLINE inline +#else +# define PACE_BROKEN_INLINE +#endif /* PACE_HAS_INLINE */ + /* ============================================================================ * Compiler Silencing macros * diff --git a/PACE/pace/emulation/mqueue.c b/PACE/pace/emulation/mqueue.c index c1c7440a5fc..e30e927e60c 100644 --- a/PACE/pace/emulation/mqueue.c +++ b/PACE/pace/emulation/mqueue.c @@ -1,4 +1,19 @@ -/* $Id$ */ +/* $Id$ + * ============================================================================ + * + * = LIBRARY + * pace + * + * = FILENAME + * pace/emulation/mqueue.c + * + * = AUTHOR + * John Heitmann + * + * ============================================================================ */ + +#if PACE_LINUX + #include "pace/sys/mman.h" #include "pace/stdio.h" #include "pace/fcntl.h" @@ -6,15 +21,15 @@ #include "pace/stdlib.h" #include "pace/sys/types.h" #include "pace/pthread.h" +#include "pace/sys/stat.h" #include "pace/emulation/mqueue.h" -typedef struct mqd* pace_mqd_t; - typedef struct { pace_mq_attr attr; pace_size_t num_open; pace_pthread_mutex_t mutex; + pace_pthread_cond_t cond; pace_size_t head; pace_size_t freelist; } mqfile; @@ -28,26 +43,43 @@ typedef struct struct mq_attr attrdefault = { 0, 32, 256, 0 }; -pace_mqd_t mq_open (const char* name, int oflag, pace_mode_t mode, pace_mq_attr* attr) +/* This remains mq_open due to the macro in pace/mqueue.h */ +pace_mqd_t mq_open (const char* name, + int oflag, + pace_mode_t mode, + pace_mq_attr* attr) { int m_padding = sizeof (message_header); /* How much extra space per message do we need */ int f_padding = sizeof (mqfile); /* How much fixed padding is needed */ int mflags, mprot; int fd; - pace_size_t i; + int i; pace_size_t mapsize; char* mmaploc; + char* new_name; int create_mmap = 0; /* 1 if the file has never be inited */ - pace_pthread_mutexattr_t mattr; message_header* temp = 0; /*Used in initializaiton of mqueue*/ long index; /* index into the file */ pace_mqd_t result = pace_malloc (sizeof (struct mqd)); + pace_stat_s statbuf; +retry: if (attr == 0) { attr = &attrdefault; } + else + { + if (attr->mq_maxmsg < 0 || attr->mq_msgsize < 0) + { + errno = EBADF; + return (pace_mqd_t)-1; + } + } + /* Create a name that will go to /tmp with a unique name */ + new_name = malloc (256); + snprintf (new_name, 256, "/tmp/mq013028%s", name); /* Fix alignment */ if (attr->mq_msgsize % sizeof (long) != 0) { @@ -56,7 +88,7 @@ pace_mqd_t mq_open (const char* name, int oflag, pace_mode_t mode, pace_mq_attr* if (oflag & PACE_O_CREAT) { /* We need to protect access without the help of O_RDONLY in the fs */ - fd = pace_open ((name, PACE_O_RDWR | PACE_O_CREAT | PACE_O_EXCL, mode)); + fd = pace_open ((new_name, PACE_O_RDWR | PACE_O_CREAT | PACE_O_EXCL, mode & ~S_IXUSR)); if (fd == -1 && errno != EEXIST) { @@ -77,19 +109,49 @@ pace_mqd_t mq_open (const char* name, int oflag, pace_mode_t mode, pace_mq_attr* else { /* We want the existing file */ - fd = pace_open ((name, PACE_O_RDWR)); + fd = pace_open ((new_name, PACE_O_RDWR)); + if (fd == -1 && errno == ENOENT) + { + /* Something odd is going on */ + goto retry; + } + else if (fd == -1) + { + return (pace_mqd_t)-1; + } } } else { - fd = pace_open ((name, PACE_O_RDWR)); + fd = pace_open ((new_name, PACE_O_RDWR)); if (fd == -1) { - errno = ENOENT; return (pace_mqd_t)-1; } } + /* + The following loop makes shure that we haven't entered a race condition. If a file + has been created but not initialized, its IXUSR will not be set (see above). + */ + while (create_mmap == 0) + { + if (stat (new_name, &statbuf) == -1) + { + close (fd); + if (errno == ENOENT && (oflag & O_CREAT)) + { + goto retry; + } + return (pace_mqd_t)-1; + } + else if ((statbuf.st_mode & S_IXUSR) == 0) + { + break; + } + pace_sleep (1); + } + mapsize = f_padding + (attr->mq_msgsize + m_padding) * (attr->mq_maxmsg); mprot = PACE_PROT_READ | PACE_PROT_WRITE; mflags = PACE_MAP_SHARED; @@ -99,30 +161,43 @@ pace_mqd_t mq_open (const char* name, int oflag, pace_mode_t mode, pace_mq_attr* /* Create and 0 out the file */ if (pace_lseek (fd, mapsize, PACE_SEEK_SET) == -1) { + pace_unlink (new_name); return (pace_mqd_t)-1; } if (pace_write (fd, "", 1) != 1) { + pace_unlink (new_name); return (pace_mqd_t)-1; } - mmaploc = mmap (0, mapsize, mprot, mflags, fd, 0); - if ((int)mmaploc == -1) + mmaploc = pace_mmap (0, mapsize, mprot, mflags, fd, 0); + + if (mmaploc == MAP_FAILED) { + pace_unlink (new_name); return (pace_mqd_t)-1; } + + pace_close (fd); + pace_memset (mmaploc, 0, mapsize); - if (pace_pthread_mutexattr_init (&mattr) == -1) + if ((errno = pace_pthread_mutex_init (&(((mqfile*)mmaploc)->mutex), 0)) != 0) { + pace_unlink (new_name); + pace_munmap (mmaploc, mapsize); return (pace_mqd_t)-1; } - if (pace_pthread_mutex_init (&(((mqfile*)mmaploc)->mutex), &mattr) == -1) + if ((errno = pace_pthread_mutex_lock (&(((mqfile*)mmaploc)->mutex))) != 0) { + pace_unlink (new_name); + pace_munmap (mmaploc, mapsize); return (pace_mqd_t)-1; } - if (pace_pthread_mutex_lock (&(((mqfile*)mmaploc)->mutex)) == -1) + if ((errno = pace_pthread_cond_init (&(((mqfile*)mmaploc)->cond), 0)) != 0) { + pace_unlink (new_name); + pace_munmap (mmaploc, mapsize); return (pace_mqd_t)-1; } @@ -139,20 +214,30 @@ pace_mqd_t mq_open (const char* name, int oflag, pace_mode_t mode, pace_mq_attr* temp->next = 0; attr->mq_curmsgs = 0; ((mqfile*)mmaploc)->attr = *attr; + + /* Set S_IXUSR so that the file is known to be inited */ + if (pace_fchmod (fd, mode | S_IXUSR) == -1) + { + pace_unlink (new_name); + pace_munmap (mmaploc, mapsize); + return (pace_mqd_t)-1; + } } else { /* Just open the existing map */ - mmaploc = mmap (0, mapsize, mprot, mflags, fd, 0); - if ((int)mmaploc == -1) + mmaploc = pace_mmap (0, mapsize, mprot, mflags, fd, 0); + if (mmaploc == MAP_FAILED) { return (pace_mqd_t)-1; } + pace_close (fd); /* ???? Test here for race */ if (pace_pthread_mutex_lock (&(((mqfile*)mmaploc)->mutex)) == -1) { + pace_munmap (mmaploc, mapsize); return (pace_mqd_t)-1; } ((mqfile*)mmaploc)->attr.mq_flags = attr->mq_flags; @@ -163,6 +248,7 @@ pace_mqd_t mq_open (const char* name, int oflag, pace_mode_t mode, pace_mq_attr* if (pace_pthread_mutex_unlock (&(((mqfile*)mmaploc)->mutex)) == -1) { + pace_munmap (mmaploc, mapsize); return (pace_mqd_t)-1; } @@ -200,7 +286,10 @@ int mq_unlink (const char* name) return pace_unlink (name); } -int mq_send (pace_mqd_t mqdes, const char* ptr, pace_size_t length, unsigned int priority) +int mq_send (pace_mqd_t mqdes, + const char* ptr, + pace_size_t length, + unsigned int priority) { mqfile* queue = ((mqfile*)mqdes->mptr); long index, old_index; @@ -210,13 +299,16 @@ int mq_send (pace_mqd_t mqdes, const char* ptr, pace_size_t length, unsigned int errno = EBADF; return -1; } - if (queue->attr.mq_msgsize < length) + if (queue->attr.mq_msgsize < (int) length) { /* Message too long */ errno = EMSGSIZE; return -1; } - + if ((errno = pace_pthread_mutex_lock (&queue->mutex)) != 0) + { + return -1; + } /* If the queue is full... */ if (queue->attr.mq_curmsgs >= queue->attr.mq_maxmsg) { @@ -225,65 +317,70 @@ int mq_send (pace_mqd_t mqdes, const char* ptr, pace_size_t length, unsigned int errno = EAGAIN; return -1; } - else + while (queue->attr.mq_maxmsg <= queue->attr.mq_curmsgs) { - /* ???? */ + pace_pthread_cond_wait (&queue->cond, &queue->mutex); } } + + /* Fill in the fields of the header */ + ((message_header*)(&mqdes->mptr[queue->freelist]))->priority = priority; + ((message_header*)(&mqdes->mptr[queue->freelist]))->length = length; + pace_memcpy (((void*)(&mqdes->mptr[queue->freelist + sizeof (message_header)])), + ptr, length); + + /* Update the linked list */ + old_index = 0; + index = queue->head; + while (index != 0 && ((message_header*)(&mqdes->mptr[index]))->priority >= priority) + { + old_index = index; + index = ((message_header*)(&mqdes->mptr[index]))->next; + } + + /* If the msg goes at the head */ + if (old_index == 0) + { + queue->head = queue->freelist; + queue->freelist = ((message_header*)(&mqdes->mptr[queue->freelist]))->next; + ((message_header*)(&mqdes->mptr[queue->head]))->next = index; + } else { - if (pace_pthread_mutex_lock (&queue->mutex) == -1) - { - return -1; - } + ((message_header*)(&mqdes->mptr[old_index]))->next = queue->freelist; + old_index = queue->freelist; + queue->freelist = ((message_header*)(&mqdes->mptr[queue->freelist]))->next; + ((message_header*)(&mqdes->mptr[old_index]))->next = index; + } - queue->attr.mq_curmsgs++; - /* Fill in the fields of the header */ - ((message_header*)(&mqdes->mptr[queue->freelist]))->priority = priority; - ((message_header*)(&mqdes->mptr[queue->freelist]))->length = length; - pace_memcpy (((void*)(&mqdes->mptr[queue->freelist + sizeof (message_header)])), - ptr, length); - - /* Update the linked list */ - old_index = 0; - index = queue->head; - while (index != 0 && ((message_header*)(&mqdes->mptr[index]))->priority >= priority) - { - old_index = index; - index = ((message_header*)(&mqdes->mptr[index]))->next; - } - /* If the msg goes at the head */ - if (old_index == 0) - { - queue->head = queue->freelist; - queue->freelist = ((message_header*)(&mqdes->mptr[queue->freelist]))->next; - ((message_header*)(&mqdes->mptr[queue->head]))->next = index; - } - else - { - ((message_header*)(&mqdes->mptr[old_index]))->next = queue->freelist; - old_index = queue->freelist; - queue->freelist = ((message_header*)(&mqdes->mptr[queue->freelist]))->next; - ((message_header*)(&mqdes->mptr[old_index]))->next = index; - } - if (pace_pthread_mutex_unlock (&queue->mutex) == -1) + if (queue->attr.mq_curmsgs == 0) + { + /* Let other waiting threads know there is food on the table */ + if ((errno = pace_pthread_cond_signal (&((mqfile*)mqdes->mptr)->cond)) != 0) { return -1; } } + queue->attr.mq_curmsgs++; + + if ((errno = pace_pthread_mutex_unlock (&queue->mutex)) != 0) + { + return -1; + } + return 0; } pace_ssize_t mq_receive (pace_mqd_t mqdes, - char * msg_ptr, - pace_size_t msg_len, - unsigned int * nmsg_prio) + char * msg_ptr, + pace_size_t msg_len, + unsigned int * nmsg_prio) { mqfile* queue = ((mqfile*)mqdes->mptr); pace_size_t temp; - if (queue->attr.mq_msgsize > msg_len) + if (queue->attr.mq_msgsize > (long) msg_len) { errno = EMSGSIZE; return -1; @@ -336,7 +433,9 @@ int mq_getattr (pace_mqd_t mqdes, pace_mq_attr * mqstat) return 0; } -int mq_setattr(pace_mqd_t mqdes, const pace_mq_attr * mqstat, pace_mq_attr * omqstat) +int mq_setattr(pace_mqd_t mqdes, + const pace_mq_attr * mqstat, + pace_mq_attr * omqstat) { if (omqstat != 0) { @@ -374,9 +473,9 @@ void print_queue (pace_mqd_t mqd) i++; index = ((message_header*)(&mqd->mptr[index]))->next; } - printf ("There are %i total blacks of size %i.\n", queue->attr.mq_maxmsg, queue->attr.mq_msgsize); + printf ("There are %li total blacks of size %li.\n", queue->attr.mq_maxmsg, queue->attr.mq_msgsize); printf ("There are %i free blocks left.\n", i); - printf ("There are %i messages on the queue.\n", queue->attr.mq_curmsgs); + printf ("There are %li messages on the queue.\n", queue->attr.mq_curmsgs); i=0; index = queue->head; @@ -391,62 +490,4 @@ void print_queue (pace_mqd_t mqd) printf ("\n"); } -int main (int argc, char** argv) -{ - int flags; - pace_mqd_t mqd; - pace_mq_attr attr; - char* string; - char* s2; - flags = O_RDWR | O_CREAT | O_NONBLOCK; - attr.mq_flags |= O_NONBLOCK; - attr.mq_msgsize = 51; - attr.mq_maxmsg = 50; - - mqd = mq_open ("hello", flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, &attr); - - PACE_UNUSED_ARG (argc); - PACE_UNUSED_ARG (argv); - - string = "Message\n"; - s2 = malloc (1600); - - print_queue (mqd); - - printf ("Sending message 1\n"); - if (mq_send (mqd, string, 9, 11) == -1) - { - perror ("send"); - return -1; - } - print_queue (mqd); - - printf ("Sending message 2\n"); - string = "Message2\n"; - if (mq_send (mqd, string, 10, 10) == -1) - { - perror ("send"); - return -1; - } -print_queue (mqd); - - printf ("Getting message one\n"); - flags = mq_receive (mqd, s2, 1600, 0); - if (flags == -1) - { - perror ("receiev:"); - exit (0); - } -print_queue (mqd); - printf (s2); - flags = mq_receive (mqd, s2, 1600, 0); - if (flags == -1) - { - perror ("receiev:"); - exit (0); - } -print_queue (mqd); - printf (s2); - - return mq_close (mqd); -} +#endif /* PACE_LINUX */ diff --git a/PACE/pace/emulation/mqueue.h b/PACE/pace/emulation/mqueue.h index 2c865b2b179..9ab9d853a7d 100644 --- a/PACE/pace/emulation/mqueue.h +++ b/PACE/pace/emulation/mqueue.h @@ -1,16 +1,38 @@ -/* $Id$ */ +/* $Id$ + * ============================================================================ + * + * = LIBRARY + * pace + * + * = FILENAME + * pace/emulation/mqueue.h + * + * = AUTHOR + * John Heitmann + * + * = DESCRIPTION + * An implementation of POSIX message queues originally built for Linux, + * which lacks mqueue.h. Some ideas were taken from the W. Richard Stevens + * book Unix Network Programming Interprocess Communications Volume 2 + * Second Edition. + * Memory Mapped io is used to enable a quick but persistent queue. + * + * ============================================================================ */ + #ifndef PACE_EMU_MQUEUE_H #define PACE_EMU_MQUEUE_H -#include "pace/signal.h" +#if defined (PACE_HAS_CPLUSPLUS) +extern "C" { +#endif /* PACE_HAS_CPLUSPLUS */ #define PACE_MQ_ATTR typedef struct mq_attr { long mq_flags; - pace_size_t mq_maxmsg; - pace_size_t mq_msgsize; - pace_size_t mq_curmsgs; + long mq_maxmsg; + long mq_msgsize; + long mq_curmsgs; } pace_mq_attr; struct mqd @@ -35,14 +57,22 @@ int mq_send (pace_mqd_t mqdes, const char* ptr, pace_size_t length, unsigned int priority); + pace_ssize_t mq_receive (pace_mqd_t mqdes, char * msg_ptr, pace_size_t msg_len, unsigned int * nmsg_prio); + int mq_getattr (pace_mqd_t mqdes, pace_mq_attr * mqstat); -int mq_setattr (pace_mqd_t mqdes, - const pace_mq_attr * mqstat, - pace_mq_attr * omqstat); + +int mq_setattr(pace_mqd_t mqdes, + const pace_mq_attr * mqstat, + pace_mq_attr * omqstat); + int mq_notify (pace_mqd_t mqd, const pace_sigevent* notification); +#if defined (PACE_HAS_CPLUSPLUS) +} +#endif /* PACE_HAS_CPLUSPLUS */ + #endif /* PACE_EMU_MQUEUE_H */ diff --git a/PACE/pace/emulation/time.c b/PACE/pace/emulation/time.c deleted file mode 100644 index e7f2c053c0e..00000000000 --- a/PACE/pace/emulation/time.c +++ /dev/null @@ -1,57 +0,0 @@ -/* $Id$ */ - -#include "pace/emulation/time.h" - -int pace_emu_clock_settime (pace_emu_clockid_t clock_id, const pace_timespec* tp) -{ - errno = ENOSYS; - return -1; -} - -int pace_emu_clock_gettime (pace_emu_clockid_t clock_id, pace_timespec* tp) -{ - errno = ENOSYS; - return -1; -} - -int pace_emu_clock_getres (pace_emu_clockid_t clock_id, pace_timespec* res) -{ - errno = ENOSYS; - return -1; -} - -int pace_emu_timer_create (pace_emu_clockid_t clock_id, - pace_sigevent* evp, - pace_emu_timer_t* timerid) -{ - errno = ENOSYS; - return -1; -} - -int pace_emu_timer_delete (pace_emu_timer_t timerid) -{ - errno = ENOSYS; - return -1; -} - -int pace_emu_timer_settime (pace_emu_timer_t timerid, - int flags, - const pace_itimerspec* value, - pace_itimerspec* ovalue) -{ - errno = ENOSYS; - return -1; -} - -int pace_emu_timer_gettime (pace_emu_timer_t timerid, - const pace_itimerspec* value) -{ - errno = ENOSYS; - return -1; -} - -int pace_emu_timer_getoverrun (pace_emu_timer_t timerid) -{ - errno = ENOSYS; - return -1; -} diff --git a/PACE/pace/emulation/time.h b/PACE/pace/emulation/time.h index 6c08dc826f7..f4784190c81 100644 --- a/PACE/pace/emulation/time.h +++ b/PACE/pace/emulation/time.h @@ -1,33 +1,46 @@ -/* $Id$ */ +/* $Id$ + * ============================================================================ + * + * = LIBRARY + * pace + * + * = FILENAME + * pace/emulation/time.h + * + * = AUTHOR + * John Heitmann + * + * ============================================================================ */ #ifndef PACE_EMU_TIME_H #define PACE_EMU_TIME_H -#include "pace/signal.h" - -typedef int pace_emu_clockid_t; -typedef int pace_emu_timer_t; -typedef struct emu_itimerspec {} pace_emu_itimerspec; -typedef struct emu_timespec {} pace_emu_timespec; - -#ifndef PACE_SIGEVENT -#define PACE_SIGEVENT - typedef struct sigevent pace_sigevent; -#endif /* PACE_SIGEVENT */ -int pace_emu_clock_settime (pace_emu_clockid_t clock_id, const pace_emu_timespec* tp); -int pace_emu_clock_gettime (pace_emu_clockid_t clock_id, pace_emu_timespec* tp); -int pace_emu_clock_getres (pace_emu_clockid_t clock_id, pace_emu_timespec* res); - -int pace_emu_timer_create (pace_emu_clockid_t clock_id, - pace_sigevent* evp, - pace_emu_timer_t* timerid); -int pace_emu_timer_delete (pace_emu_timer_t timerid); -int pace_emu_timer_settime (pace_emu_timer_t timerid, - int flags, - const pace_emu_itimerspec* value, - pace_emu_itimerspec* ovalue); -int pace_emu_timer_gettime (pace_emu_timer_t timerid, - const pace_emu_itimerspec* value); -int pace_emu_timer_getoverrun (pace_emu_timer_t timerid); +#if defined (PACE_HAS_CPLUSPLUS) +extern "C" { +#endif /* PACE_HAS_CPLUSPLUS */ + +#ifndef PACE_EMU_CLOCKID_T +#define PACE_EMU_CLOCKID_T + typedef int pace_emu_clockid_t; +#endif /* PACE_EMU_CLOCKID_T */ + +#ifndef PACE_EMU_TIMER_T +#define PACE_EMU_TIMER_T + typedef int pace_emu_timer_t; +#endif /* PACE_EMU_TIMER_T */ + +#ifndef PACE_EMU_ITIMERSPEC +#define PACE_EMU_ITIMERSPEC + typedef struct emu_itimerspec {} pace_emu_itimerspec; +#endif /* PACE_EMU_ITIMERSPEC */ + +#ifndef PACE_EMU_TIMESPEC +#define PACE_EMU_TIMESPEC + typedef struct emu_timespec {} pace_emu_timespec; +#endif /* PACE_EMU_TIMESPEC */ + +#if defined (PACE_HAS_CPLUSPLUS) +} +#endif /* PACE_HAS_CPLUSPLUS */ #endif /* PACE_EMU_TIME_H */ diff --git a/PACE/pace/mqueue.h b/PACE/pace/mqueue.h index 5f205c31ade..18c8c3a4b06 100644 --- a/PACE/pace/mqueue.h +++ b/PACE/pace/mqueue.h @@ -17,6 +17,7 @@ #define PACE_MQUEUE_H #include "pace/config/defines.h" +#include "pace/signal.h" #if (PACE_HAS_POSIX) # include "pace/posix/mqueue.h" diff --git a/PACE/pace/posix/mqueue.c b/PACE/pace/posix/mqueue.c index 32937ccb02e..596c75e3905 100644 --- a/PACE/pace/posix/mqueue.c +++ b/PACE/pace/posix/mqueue.c @@ -15,6 +15,10 @@ #include "pace/mqueue.h" +#if PACE_LINUX +# include "pace/emulation/mqueue.c" +#endif /* PACE_LINUX */ + #if !defined (PACE_HAS_INLINE) # include "pace/posix/mqueue.inl" #endif /* ! PACE_HAS_INLINE */ diff --git a/PACE/pace/posix/mqueue.h b/PACE/pace/posix/mqueue.h index c85500b4d01..66483f040cf 100644 --- a/PACE/pace/posix/mqueue.h +++ b/PACE/pace/posix/mqueue.h @@ -22,28 +22,18 @@ # include #endif /* PACE_LINUX */ -#include "pace/signal.h" - #if defined (PACE_HAS_CPLUSPLUS) extern "C" { #endif /* PACE_HAS_CPLUSPLUS */ #ifndef PACE_MQD_T #define PACE_MQD_T -# if PACE_LINUX - typedef pace_emu_mqd_t pace_mqd_t; -# else typedef mqd_t pace_mqd_t; -# endif /* PACE_LINUX */ #endif /* PACE_MQD_T */ #ifndef PACE_MQ_ATTR #define PACE_MQ_ATTR -# if PACE_LINUX - typedef struct pace_emu_mq_attr pace_mq_attr; -# else typedef struct mq_attr pace_mq_attr; -# endif /* PACE_LINUX */ #endif /* PACE_MQ_ATTR */ #if defined (PACE_HAS_CPLUSPLUS) diff --git a/PACE/pace/posix/stdio.c b/PACE/pace/posix/stdio.c index 251d6da309d..740f6d88b44 100644 --- a/PACE/pace/posix/stdio.c +++ b/PACE/pace/posix/stdio.c @@ -15,6 +15,39 @@ #include "pace/stdio.h" +int +pace_fprintf (FILE *fp, const char *format, ...) +{ + int result = 0; + va_list ap; + va_start (ap, format); + result = vfprintf (fp, format, ap); + va_end (ap); + return result; +} + +int +pace_printf (const char* format, ...) +{ + int result = 0; + va_list ap; + va_start (ap, format); + result = vprintf (format, ap); + va_end (ap); + return result; +} + +int +pace_sprintf (char* s, const char* format, ...) +{ + int result = 0; + va_list ap; + va_start (ap, format); + result = vsprintf (s, format, ap); + va_end (ap); + return result; +} + #if !defined (PACE_HAS_INLINE) # include "pace/posix/stdio.inl" #endif /* ! PACE_HAS_INLINE */ diff --git a/PACE/pace/posix/stdio.inl b/PACE/pace/posix/stdio.inl index 9f4bc03a340..ecacff52f09 100644 --- a/PACE/pace/posix/stdio.inl +++ b/PACE/pace/posix/stdio.inl @@ -131,17 +131,6 @@ pace_fputc (int c, stream); } -int -pace_fprintf (FILE *fp, const char *format, ...) -{ - int result = 0; - va_list ap; - va_start (ap, format); - result = vfprintf (fp, format, ap); - va_end (ap); - return result; -} - PACE_INLINE int pace_fputs (const char * s, @@ -286,17 +275,6 @@ pace_perror (const char * s) return; } -int -pace_printf (const char* format, ...) -{ - int result = 0; - va_list ap; - va_start (ap, format); - result = vprintf (format, ap); - va_end (ap); - return result; -} - PACE_INLINE int pace_putc (int c, @@ -385,16 +363,6 @@ pace_setvbuf(PACE_FILE * stream, { return setvbuf (stream, buf, mode, size); } -int -pace_sprintf (char* s, const char* format, ...) -{ - int result = 0; - va_list ap; - va_start (ap, format); - result = vsprintf (s, format, ap); - va_end (ap); - return result; -} PACE_INLINE FILE * diff --git a/PACE/pace/posix/string.inl b/PACE/pace/posix/string.inl index 8380b13ab85..47cf1af2742 100644 --- a/PACE/pace/posix/string.inl +++ b/PACE/pace/posix/string.inl @@ -44,7 +44,7 @@ pace_memmove (void *s1, const void *s2, pace_size_t n) return memmove (s1, s2, n); } -PACE_INLINE +PACE_BROKEN_INLINE void * pace_memset (void *s, int c, pace_size_t n) { @@ -80,21 +80,21 @@ pace_strrchr (const char * s, int c) return strrchr (s, c); } -PACE_INLINE +PACE_BROKEN_INLINE int pace_strcmp (const char * s1, const char * s2) { return strcmp (s1, s2); } -PACE_INLINE +PACE_BROKEN_INLINE int pace_strncmp (const char * s1, const char * s2, size_t n) { return strncmp (s1, s2, n); } -PACE_INLINE +PACE_BROKEN_INLINE char * pace_strcpy (char * s1, const char * s2) { @@ -108,7 +108,7 @@ pace_strncpy (char * s1, const char * s2, size_t n) return strncpy (s1, s2, n); } -PACE_INLINE +PACE_BROKEN_INLINE size_t pace_strcspn (const char * s1, const char * s2) { @@ -129,7 +129,7 @@ pace_strlen (const char * s) return strlen (s); } -PACE_INLINE +PACE_BROKEN_INLINE const char * pace_strpbrk (const char * s1, const char * s2) { diff --git a/PACE/pace/posix/time.h b/PACE/pace/posix/time.h index 835c7917c15..f1c0df84f42 100644 --- a/PACE/pace/posix/time.h +++ b/PACE/pace/posix/time.h @@ -16,12 +16,13 @@ #ifndef PACE_TIME_H_POSIX #define PACE_TIME_H_POSIX -#include -#include "pace/signal.h" #if PACE_LINUX # include "pace/emulation/time.h" #endif /* PACE_LINUX */ +#include +#include "pace/signal.h" + #if defined (PACE_HAS_CPLUSPLUS) extern "C" { #endif /* PACE_HAS_CPLUSPLUS */ @@ -34,7 +35,7 @@ extern "C" { #ifndef PACE_CLOCKID_T #define PACE_CLOCKID_T -# if PACE_LINUX +# if defined PACE_EMU_CLOCKID_T typedef pace_emu_clockid_t pace_clockid_t; # else typedef clockid_t pace_clockid_t; @@ -53,7 +54,7 @@ extern "C" { #ifndef PACE_TIMER_T #define PACE_TIMER_T -# if PACE_LINUX +# if defined PACE_EMU_TIMER_T typedef pace_emu_timer_t pace_timer_t; # else typedef timer_t pace_timer_t; diff --git a/PACE/pace/posix/time.inl b/PACE/pace/posix/time.inl index 70daf78062d..8ade3089d4f 100644 --- a/PACE/pace/posix/time.inl +++ b/PACE/pace/posix/time.inl @@ -198,7 +198,11 @@ pace_timer_create (pace_clockid_t clock_id, pace_timer_t *timerid) { #if PACE_LINUX - return pace_emu_timer_create (clock_id, evp, timerid); + errno = ENOSYS; + PACE_UNUSED_ARG (clock_id); + PACE_UNUSED_ARG (evp); + PACE_UNUSED_ARG (timerid); + return -1; #else return timer_create (clock_id, evp, timerid); #endif /* PACE_LINUX */ @@ -209,7 +213,9 @@ int pace_timer_delete (pace_timer_t timerid) { #if PACE_LINUX - return pace_emu_timer_delete (timerid); + errno = ENOSYS; + PACE_UNUSED_ARG (timerid); + return -1; #else return timer_delete (timerid); #endif /* PACE_LINUX */ @@ -220,7 +226,9 @@ int pace_timer_getoverrun (pace_timer_t timerid) { #if PACE_LINUX - return pace_emu_timer_getoverrun (timerid); + errno = ENOSYS; + PACE_UNUSED_ARG (timerid); + return -1; #else return timer_getoverrun (timerid); #endif /* PACE_LINUX */ diff --git a/PACE/pace/posix/unistd.inl b/PACE/pace/posix/unistd.inl index 9a0cc9f607f..fbb5ce6b403 100644 --- a/PACE/pace/posix/unistd.inl +++ b/PACE/pace/posix/unistd.inl @@ -75,6 +75,15 @@ pace_dup2 (int fildes, int fildes2) PACE_INLINE int +pace_execv (const char * path, + char * const argv[]) +{ + return execv (path, argv); + /* if successful, this operation does NOT return */ +} + +PACE_BROKEN_INLINE +int pace_execl (const char* path, const char* arg, ...) { int result = 0; @@ -87,14 +96,15 @@ pace_execl (const char* path, const char* arg, ...) PACE_INLINE int -pace_execv (const char * path, - char * const argv[]) +pace_execve (const char * path, + char * const argv[], + char * const envp[]) { - return execv (path, argv); + return execve (path, argv, envp); /* if successful, this operation does NOT return */ } -PACE_INLINE +PACE_BROKEN_INLINE int pace_execle (const char* path, const char* arg, ...) { @@ -115,7 +125,7 @@ pace_execvp (const char * file, /* if successful, this operation does NOT return */ } -PACE_INLINE +PACE_BROKEN_INLINE int pace_execlp (const char* file, const char* arg, ...) { @@ -127,16 +137,6 @@ pace_execlp (const char* file, const char* arg, ...) return result; } -PACE_INLINE -int -pace_execve (const char * path, - char * const argv[], - char * const envp[]) -{ - return execve (path, argv, envp); - /* if successful, this operation does NOT return */ -} - PACE_INLINE int pace_fdatasync (int fildes) diff --git a/PACE/tests/Makefile b/PACE/tests/Makefile index 6c40fd9e590..85bc9796392 100644 --- a/PACE/tests/Makefile +++ b/PACE/tests/Makefile @@ -14,6 +14,7 @@ endif # static_libs_only # If we are inlining the PACE functions then we don't want to include # the PACE library (and we need to define PACE_HAS_INLINE). If we're not # inlining then we need to include the PACE library. Inlining is the default. +LIBS += -L$(PACE_ROOT)/pace -lPACE ifndef inline CFLAGS += -DPACE_HAS_INLINE else @@ -29,7 +30,8 @@ LIBS += -L$(PACE_ROOT)/pace -lPACE #---------------------------------------------------------------------------- BIN = Stdio_Test \ - Posix_SP_Test + Posix_SP_Test \ + mqueue_test #### If the PACE library wasn't built with all components, don't #### try to build certain tests. diff --git a/PACE/tests/mqueue_test.c b/PACE/tests/mqueue_test.c new file mode 100644 index 00000000000..3c949fcdc0d --- /dev/null +++ b/PACE/tests/mqueue_test.c @@ -0,0 +1,62 @@ +#include "pace/stdio.h" +#include "pace/fcntl.h" +#include "pace/mqueue.h" +#include "pace/stdlib.h" + +int main (int argc, char** argv) +{ + char* m1 = "Message1\n "; + int s1 = 10; + char* m2 = "Message 2\n "; + int s2 = 11; + pace_mqd_t mqd; + pace_mq_attr attr; + int flags = O_RDWR | O_CREAT; + + attr.mq_flags = O_NONBLOCK; + attr.mq_msgsize = 51; + attr.mq_maxmsg = 50; + mqd = pace_mq_open (("/hello3", flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, &attr)); + if ((int)mqd == -1) + { + perror ("Open"); + return -1; + } + + PACE_UNUSED_ARG (argc); + PACE_UNUSED_ARG (argv); + + printf ("Sending Message 1\n"); + + if (pace_mq_send (mqd, m1, s1, s1) == -1) + { + perror ("send"); + return -1; + } + + printf ("Sending Message 2\n"); + + + if (pace_mq_send (mqd, m2, s2, s2) == -1) + { + perror ("send"); + return -1; + } + + m1 = malloc (60); + m2 = malloc (60); + + if (pace_mq_receive (mqd, m1, 60, 0) == -1) + { + perror ("receive"); + return -1; + } + printf (m1); + if (pace_mq_receive (mqd, m2, 60, 0) == -1) + { + perror ("receive"); + return -1; + } + printf (m2); + exit (EXIT_SUCCESS); +} -- cgit v1.2.1