projects
/
ossec-hids.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git]
/
src
/
shared
/
mq_op.c
diff --git
a/src/shared/mq_op.c
b/src/shared/mq_op.c
old mode 100755
(executable)
new mode 100644
(file)
index
81c2772
..
5915e46
--- a/
src/shared/mq_op.c
+++ b/
src/shared/mq_op.c
@@
-1,5
+1,3
@@
-/* @(#) $Id$ */
-
/* Copyright (C) 2009 Trend Micro Inc.
* All rights reserved.
*
/* Copyright (C) 2009 Trend Micro Inc.
* All rights reserved.
*
@@
-9,43
+7,31
@@
* Foundation
*/
* Foundation
*/
-
#include "shared.h"
#include "os_net/os_net.h"
#ifndef WIN32
#include "shared.h"
#include "os_net/os_net.h"
#ifndef WIN32
-/* StartMQ v0.2, 2004/07/30
- * Start the Message Queue. type: WRITE||READ
- */
-int StartMQ(char * path, short int type)
+/* Start the Message Queue. type: WRITE||READ */
+int StartMQ(const char *path, short int type)
{
{
-
- if(type == READ)
- {
- return(OS_BindUnixDomain(path, 0660, OS_MAXSTR + 512));
+ if (type == READ) {
+ return (OS_BindUnixDomain(path, 0660, OS_MAXSTR + 512));
}
}
-
- /* We give up to 21 seconds for the other end to
- * start
- */
- else
- {
+
+ /* We give up to 21 seconds for the other end to start */
+ else {
int rc = 0;
int rc = 0;
- if(File_DateofChange(path) < 0)
- {
+ if (File_DateofChange(path) < 0) {
sleep(1);
sleep(1);
- if(File_DateofChange(path) < 0)
- {
+ if (File_DateofChange(path) < 0) {
sleep(5);
sleep(5);
- if(File_DateofChange(path) < 0)
- {
- merror(QUEUE_ERROR, __local_name, path, "Queue not found");
+ if (File_DateofChange(path) < 0) {
sleep(15);
sleep(15);
- if(File_DateofChange(path) < 0)
- {
- return(-1);
+ if (File_DateofChange(path) < 0) {
+ merror(QUEUE_ERROR, __local_name, path, "Queue not found");
+ return (-1);
}
}
}
}
}
}
@@
-54,66
+40,58
@@
int StartMQ(char * path, short int type)
/* Wait up to 3 seconds to connect to the unix domain.
* After three errors, exit.
*/
/* Wait up to 3 seconds to connect to the unix domain.
* After three errors, exit.
*/
- if((rc = OS_ConnectUnixDomain(path, OS_MAXSTR + 256)) < 0)
- {
+ if ((rc = OS_ConnectUnixDomain(path, OS_MAXSTR + 256)) < 0) {
sleep(1);
sleep(1);
- if((rc = OS_ConnectUnixDomain(path, OS_MAXSTR + 256)) < 0)
- {
+ if ((rc = OS_ConnectUnixDomain(path, OS_MAXSTR + 256)) < 0) {
sleep(2);
sleep(2);
- if((rc = OS_ConnectUnixDomain(path, OS_MAXSTR + 256)) < 0)
- {
- merror(QUEUE_ERROR, __local_name, path,
+ if ((rc = OS_ConnectUnixDomain(path, OS_MAXSTR + 256)) < 0) {
+ merror(QUEUE_ERROR, __local_name, path,
strerror(errno));
strerror(errno));
- return(-1);
+ return (-1);
}
}
}
debug1(MSG_SOCKET_SIZE, __local_name, OS_getsocketsize(rc));
}
}
}
debug1(MSG_SOCKET_SIZE, __local_name, OS_getsocketsize(rc));
- return(rc);
+ return (rc);
}
}
}
}
-
-/* SendMSG v0.1, 2005/02/15
- * Send a message to the queue.
- */
-int SendMSG(int queue, char *message, char *locmsg, char loc)
+/* Send a message to the queue */
+int SendMSG(int queue, const char *message, const char *locmsg, char loc)
{
int __mq_rcode;
{
int __mq_rcode;
- char tmpstr[OS_MAXSTR+1];
+ char tmpstr[OS_MAXSTR + 1];
tmpstr[OS_MAXSTR] = '\0';
tmpstr[OS_MAXSTR] = '\0';
-
- /* Checking for global locks */
+ /* Check for global locks */
os_wait();
os_wait();
-
-
- if(loc == SECURE_MQ)
- {
+
+ if (loc == SECURE_MQ) {
loc = message[0];
message++;
loc = message[0];
message++;
- if(message[0] != ':')
- {
+ if (message[0] != ':') {
merror(FORMAT_ERROR, __local_name);
merror(FORMAT_ERROR, __local_name);
- return(0);
+ return (0);
}
}
-
message++; /* Pointing now to the location */
message++; /* Pointing now to the location */
-
- snprintf(tmpstr,OS_MAXSTR,"%c:%s->%s",loc, locmsg, message);
- }
- else
- snprintf(tmpstr,OS_MAXSTR,"%c:%s:%s",loc,locmsg,message);
+ if (strncmp(message, "keepalive", 9) == 0) {
+ return (0);
+ }
- /* queue not available */
- if(queue < 0)
- return(-1);
+ snprintf(tmpstr, OS_MAXSTR, "%c:%s->%s", loc, locmsg, message);
+ } else {
+ snprintf(tmpstr, OS_MAXSTR, "%c:%s:%s", loc, locmsg, message);
+ }
+
+ /* Queue not available */
+ if (queue < 0) {
+ return (-1);
+ }
-
/* We attempt 5 times to send the message if
* the receiver socket is busy.
* After the first error, we wait 1 second.
/* We attempt 5 times to send the message if
* the receiver socket is busy.
* After the first error, we wait 1 second.
@@
-123,54
+101,43
@@
int SendMSG(int queue, char *message, char *locmsg, char loc)
* If we failed again, the message is not going
* to be delivered and an error is sent back.
*/
* If we failed again, the message is not going
* to be delivered and an error is sent back.
*/
- if((__mq_rcode = OS_SendUnix(queue, tmpstr,0)) < 0)
- {
+ if ((__mq_rcode = OS_SendUnix(queue, tmpstr, 0)) < 0) {
/* Error on the socket */
/* Error on the socket */
- if(__mq_rcode == OS_SOCKTERR)
- {
+ if (__mq_rcode == OS_SOCKTERR) {
merror("%s: socketerr (not available).", __local_name);
close(queue);
merror("%s: socketerr (not available).", __local_name);
close(queue);
- queue = -1;
- return(-1);
+ return (-1);
}
}
-
/* Unable to send. Socket busy */
sleep(1);
/* Unable to send. Socket busy */
sleep(1);
- if(OS_SendUnix(queue, tmpstr, 0) < 0)
- {
+ if (OS_SendUnix(queue, tmpstr, 0) < 0) {
/* When the socket is to busy, we may get some
* error here. Just sleep 2 second and try
* again.
*/
sleep(3);
/* merror("%s: socket busy", __local_name); */
/* When the socket is to busy, we may get some
* error here. Just sleep 2 second and try
* again.
*/
sleep(3);
/* merror("%s: socket busy", __local_name); */
- if(OS_SendUnix(queue, tmpstr,0) < 0)
- {
+ if (OS_SendUnix(queue, tmpstr, 0) < 0) {
sleep(5);
merror("%s: socket busy ..", __local_name);
sleep(5);
merror("%s: socket busy ..", __local_name);
- if(OS_SendUnix(queue, tmpstr,0) < 0)
- {
+ if (OS_SendUnix(queue, tmpstr, 0) < 0) {
sleep(10);
merror("%s: socket busy ..", __local_name);
sleep(10);
merror("%s: socket busy ..", __local_name);
- if(OS_SendUnix(queue, tmpstr,0) < 0)
- {
+ if (OS_SendUnix(queue, tmpstr, 0) < 0) {
/* Message is going to be lost
* if the application does not care
/* Message is going to be lost
* if the application does not care
- * about checking the error
- */
+ * about checking the error
+ */
close(queue);
close(queue);
- queue = -1;
- return(-1);
+ return (-1);
}
}
}
}
}
}
}
}
}
}
- return(0);
+ return (0);
}
}
-#endif
-
-/* EOF */
+#endif /* !WIN32 */