Togg writes:
Syslogd wont start if remote-logging is enabled and the connection to the remote-log server is not possible on syslogd startup. I found a patch somewhere which works like a charm. It uses sendto() which seems more reliable for this issue. Please see attached patch. Many people will be more happy with this included I think. Regards, Togg
This commit is contained in:
parent
138791050d
commit
75813eea23
@ -78,6 +78,8 @@ static char LocalHostName[64];
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
/* udp socket for logging to remote host */
|
/* udp socket for logging to remote host */
|
||||||
static int remotefd = -1;
|
static int remotefd = -1;
|
||||||
|
static struct sockaddr_in remoteaddr;
|
||||||
|
static int remoteaddrlen;
|
||||||
|
|
||||||
/* where do we log? */
|
/* where do we log? */
|
||||||
static char *RemoteHost;
|
static char *RemoteHost;
|
||||||
@ -384,6 +386,7 @@ static void logMessage(int pri, char *msg)
|
|||||||
time_t now;
|
time_t now;
|
||||||
char *timestamp;
|
char *timestamp;
|
||||||
static char res[20] = "";
|
static char res[20] = "";
|
||||||
|
static char line[512];
|
||||||
CODE *c_pri, *c_fac;
|
CODE *c_pri, *c_fac;
|
||||||
|
|
||||||
if (pri != 0) {
|
if (pri != 0) {
|
||||||
@ -414,21 +417,15 @@ static void logMessage(int pri, char *msg)
|
|||||||
#ifdef CONFIG_FEATURE_REMOTE_LOG
|
#ifdef CONFIG_FEATURE_REMOTE_LOG
|
||||||
/* send message to remote logger */
|
/* send message to remote logger */
|
||||||
if (-1 != remotefd) {
|
if (-1 != remotefd) {
|
||||||
static const int IOV_COUNT = 2;
|
|
||||||
struct iovec iov[IOV_COUNT];
|
|
||||||
struct iovec *v = iov;
|
|
||||||
|
|
||||||
memset(&res, 0, sizeof(res));
|
memset(&line, 0, sizeof(line));
|
||||||
snprintf(res, sizeof(res), "<%d>", pri);
|
snprintf(line, sizeof(line), "<%d> <%s>", pri, msg);
|
||||||
v->iov_base = res;
|
|
||||||
v->iov_len = strlen(res);
|
|
||||||
v++;
|
|
||||||
|
|
||||||
v->iov_base = msg;
|
retry:
|
||||||
v->iov_len = strlen(msg);
|
if(( -1 == sendto(remotefd, line, strlen(line), 0,
|
||||||
writev_retry:
|
(struct sockaddr *) &remoteaddr,
|
||||||
if ((-1 == writev(remotefd, iov, IOV_COUNT)) && (errno == EINTR)) {
|
remoteaddrlen)) && (errno == EINTR)) {
|
||||||
goto writev_retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (local_logging == TRUE)
|
if (local_logging == TRUE)
|
||||||
@ -508,12 +505,10 @@ static int serveConnection(char *tmpbuf, int n_read)
|
|||||||
#ifdef CONFIG_FEATURE_REMOTE_LOG
|
#ifdef CONFIG_FEATURE_REMOTE_LOG
|
||||||
static void init_RemoteLog(void)
|
static void init_RemoteLog(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
struct sockaddr_in remoteaddr;
|
|
||||||
struct hostent *hostinfo;
|
struct hostent *hostinfo;
|
||||||
int len = sizeof(remoteaddr);
|
remoteaddrlen = sizeof(remoteaddr);
|
||||||
|
|
||||||
memset(&remoteaddr, 0, len);
|
memset(&remoteaddr, 0, remoteaddrlen);
|
||||||
|
|
||||||
remotefd = socket(AF_INET, SOCK_DGRAM, 0);
|
remotefd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
|
||||||
@ -526,15 +521,6 @@ static void init_RemoteLog(void)
|
|||||||
remoteaddr.sin_family = AF_INET;
|
remoteaddr.sin_family = AF_INET;
|
||||||
remoteaddr.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
|
remoteaddr.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
|
||||||
remoteaddr.sin_port = htons(RemotePort);
|
remoteaddr.sin_port = htons(RemotePort);
|
||||||
|
|
||||||
/* Since we are using UDP sockets, connect just sets the default host and port
|
|
||||||
* for future operations
|
|
||||||
*/
|
|
||||||
if (0 != (connect(remotefd, (struct sockaddr *) &remoteaddr, len))) {
|
|
||||||
bb_error_msg_and_die("cannot connect to remote host %s:%d", RemoteHost,
|
|
||||||
RemotePort);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user