0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #include <stdio.h>
0037 #include <stdlib.h>
0038 #include <time.h>
0039
0040 #include <unistd.h>
0041 #include <stdarg.h>
0042 #include <ctype.h>
0043 #include <memory.h>
0044 #include <errno.h>
0045 #include <signal.h>
0046 #include <limits.h>
0047 #include <pthread.h>
0048 #include <string.h>
0049
0050 #include <ndrx_config.h>
0051 #include <ndrstandard.h>
0052 #include <ndebug.h>
0053 #include <nstdutil.h>
0054 #include <limits.h>
0055 #include <mqueue.h>
0056 #include <sys/stat.h>
0057 #include <fcntl.h>
0058
0059
0060
0061
0062
0063
0064
0065
0066 #define API_ENTRY if (M_first)\
0067 {\
0068 strcpy(M_qpath, getenv(CONF_NDRX_QPATH));\
0069 M_first = EXFALSE;\
0070 }
0071
0072
0073
0074
0075 static int M_first = EXTRUE;
0076 static char M_qpath[PATH_MAX] = {EXEOS};
0077
0078
0079
0080
0081
0082
0083
0084 expublic mqd_t ndrx_mq_open_with_registry(char *name, int oflag,
0085 mode_t mode, struct mq_attr *attr)
0086 {
0087 mqd_t ret;
0088 char regpath[PATH_MAX];
0089 int err;
0090 API_ENTRY;
0091
0092 sprintf(regpath, "%s%s", M_qpath, name);
0093
0094 NDRX_LOG(log_debug, "opening, registry path built: [%s]", regpath);
0095
0096 ret = mq_open(name, oflag, mode, attr);
0097
0098 if ((mqd_t)EXFAIL!=ret && (oflag & O_CREAT))
0099 {
0100 if (EXSUCCEED!=mkfifo(regpath, S_IWUSR | S_IRUSR))
0101 {
0102 err = errno;
0103 NDRX_LOG(log_error, "Failed to open fifo file [%s]: %s",
0104 regpath, strerror(errno));
0105 if (EEXIST==err)
0106 {
0107 NDRX_LOG(log_warn, "File already exists, ignore error...");
0108 errno = 0;
0109 }
0110 else
0111 {
0112 ret=(mqd_t)EXFAIL;
0113 errno = err;
0114 NDRX_LOG(log_error, "Removing queue...");
0115 if (EXSUCCEED!=mq_unlink(name))
0116 {
0117 NDRX_LOG(log_error, "Failed to mq_unlink [%s]: %s",
0118 name, strerror(errno));
0119 }
0120 }
0121 }
0122 }
0123
0124 return ret;
0125 }
0126
0127
0128
0129
0130
0131
0132 expublic int ndrx_mq_unlink_with_registry (char *name)
0133 {
0134 char regpath[PATH_MAX];
0135 int ret, err;
0136 API_ENTRY;
0137
0138 sprintf(regpath, "%s%s", M_qpath, name);
0139
0140 NDRX_LOG(log_debug, "deleting, registry path built: [%s]", regpath);
0141
0142 if (EXSUCCEED!=(ret = mq_unlink(name)))
0143 {
0144 err = errno;
0145 NDRX_LOG(log_error, "Failed to mq_unlink [%s]: %s", name, strerror(err));
0146 }
0147
0148 if (EXSUCCEED!=unlink(regpath))
0149 {
0150 NDRX_LOG(log_error, "Failed to unlink [%s]: %s", regpath, strerror(errno));
0151 }
0152
0153 errno = err;
0154
0155 return ret;
0156 }
0157
0158