Skip to content

Commit

Permalink
Use syslog() on older glibcs (pre 2.09 versions)
Browse files Browse the repository at this point in the history
  • Loading branch information
bostjan committed Jan 27, 2015
1 parent 6a9d4af commit 6e7a009
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/output/socketoutput.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
* Return:
* void
*/
#include <features.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>

Expand All @@ -58,9 +58,13 @@ int snoopy_output_socketoutput (char *logMessage, int errorOrMessage)
return 0;
}


#if (defined(__GLIBC__) && (2 == __GLIBC__) && (__GLIBC_MINOR__ < 9))
/* Prepare socket - non-blocking sockets are not supported on older glibc */
if ((s = socket(AF_LOCAL, SOCK_DGRAM, 0)) == -1) {
#else
/* Prepare socket - NON BLOCKING (systemd blocks /dev/log if journald is not running) */
if ((s = socket(AF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0)) == -1) {
#endif
return -1;
}

Expand Down
23 changes: 19 additions & 4 deletions src/snoopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,26 @@


/**
* SNOOPY_MAX_ARG_LENGTH
*
* Maximum length of arguments passed to execv(e) functions
* Include all required system headers
*/

/* This should generaly be done wherever unistd.h is required. */
/* But sysconf is needed here, and all files include snoopy.h. */
/* Needed to get getpgid and getsid on older glibc */
/* This must be the first file to be included, or implicit inclusion (by i.e. <features.h>) does the wrong thing */
#define _XOPEN_SOURCE 500
#include <unistd.h>

/* Needed for GLIBC macros here */
#include <features.h>



/**
* SNOOPY_MAX_ARG_LENGTH
*
* Maximum length of arguments passed to execv(e) functions
*/
#define SNOOPY_SYSCONF_ARG_MAX sysconf(_SC_ARG_MAX)


Expand Down Expand Up @@ -231,7 +240,13 @@
#define SNOOPY_OUTPUT_PROVIDER_SOCKET "socket"
#define SNOOPY_OUTPUT_PROVIDER_SYSLOG "syslog"

#define SNOOPY_OUTPUT_PROVIDER SNOOPY_OUTPUT_PROVIDER_DEVLOG // Was 'syslog' before, but systemd is funny
#if (defined(__GLIBC__) && (2 == __GLIBC__) && (__GLIBC_MINOR__ < 9))
/* Use 'syslog' on older linuxes that od not support SOCK_CLOEXEC and SOCK_NONBLOCK */
#define SNOOPY_OUTPUT_PROVIDER SNOOPY_OUTPUT_PROVIDER_SYSLOG
#else
/* Otherwise do not use 'syslog' (was default before), because systemd is funny (blocks the syslog() call */
#define SNOOPY_OUTPUT_PROVIDER SNOOPY_OUTPUT_PROVIDER_DEVLOG
#endif
#define SNOOPY_OUTPUT_PATH ""


Expand Down

0 comments on commit 6e7a009

Please sign in to comment.