* compile dummy for non-linux

* link to systemd instead of systemd-journal on newer systems
pull/2/merge
Anton Smirnov 8 years ago
parent fff1a1053b
commit 5fdcc82edd

1
.gitignore vendored

@ -26,3 +26,4 @@ Makefile
*.iws
.rakeTasks
.idea
extconf.h

@ -9,12 +9,27 @@ LIB_DIRS = [LIBDIR]
dir_config('systemd', HEADER_DIRS, LIB_DIRS)
def have_funcs
have_funcs = true
# check functions. redefine const list in sd_journal.h if changed
%w(sd_journal_print sd_journal_sendv sd_journal_perror).each do |func|
have_funcs &&= have_func(func)
end
have_funcs
end
# check headers
abort 'systemd/sd-journal.h is missing. please install systemd-journal' unless find_header('systemd/sd-journal.h')
have_header('systemd/sd-journal.h')
# first try to find funcs in systemd
have_library('systemd')
# check functions
%w(sd_journal_print sd_journal_sendv sd_journal_perror).each do |func|
abort "#{func}() is missing. systemd-journal is not usable" unless find_library('systemd-journal', func)
unless have_funcs
have_library('systemd-journal') # try to fall back to systemd-journal if older systemd
end
create_header
create_makefile('journald_native')

@ -2,7 +2,7 @@
#define SD_JOURNAL_SUPPRESS_LOCATION
#include <ruby.h>
#include <systemd/sd-journal.h>
#include "sd_journal.h"
void Init_journald_native();
@ -73,7 +73,7 @@ static VALUE jdl_native_print(VALUE v_self, VALUE v_priority, VALUE v_message)
static VALUE jdl_native_send(int argc, VALUE* argv, VALUE self)
{
struct iovec *msgs;
size_t i;
int i;
int result;
/* first check everything is a string / convertable to string */

@ -0,0 +1,63 @@
#ifndef JOURNALD_NATIVE_SD_JOURNAL_H
#define JOURNALD_NATIVE_SD_JOURNAL_H
#ifdef __linux__
/* do the real stuff */
#include "extconf.h"
/* check for extconf results */
#ifndef HAVE_SYSTEMD_SD_JOURNAL_H
#error Cannot include <systemd/sd-journal.h>. Please use linux version with systemd-journal installed
#endif
#ifndef HAVE_SD_JOURNAL_PRINT
#error Required function sd_journal_print is missing
#endif
#ifndef HAVE_SD_JOURNAL_SENDV
#error Required function sd_journal_sendv is missing
#endif
#ifndef HAVE_SD_JOURNAL_PERROR
#error Required function sd_journal_perror is missing
#endif
/* include systemd-journal headers */
#include <systemd/sd-journal.h>
#else
#warning Compiling dummy version of the gem for non-Linux OS
#include <stdlib.h>
/* use dummy */
#define JOURNALD_NATIVE_SYSTEMD_JOURNAL_DUMMY
/* syslog constants */
#define LOG_EMERG 0
#define LOG_ALERT 1
#define LOG_CRIT 2
#define LOG_ERR 3
#define LOG_WARNING 4
#define LOG_NOTICE 5
#define LOG_INFO 6
#define LOG_DEBUG 7
/* iovec */
struct iovec {
void *iov_base; /* Starting address */
size_t iov_len; /* Number of bytes to transfer */
};
int sd_journal_print(int priority, const char *format, ...);
int sd_journal_sendv(const struct iovec *iov, int n);
int sd_journal_perror(const char *message);
#endif
#endif

@ -0,0 +1,9 @@
#include "sd_journal.h"
#ifdef JOURNALD_NATIVE_SYSTEMD_JOURNAL_DUMMY
int sd_journal_print(int priority, const char *format, ...) { return 0; }
int sd_journal_sendv(const struct iovec *iov, int n) { return 0; }
int sd_journal_perror(const char *message) { return 0; }
#endif

@ -1,5 +1,5 @@
module Journald
module Native
VERSION = '1.0.2'
VERSION = '1.0.3'
end
end

Loading…
Cancel
Save