journald-native 1.0.2 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +7 -6
- data/ext/journald_native/extconf.rb +22 -6
- data/ext/journald_native/journald_native.c +13 -39
- data/ext/journald_native/sd_journal.h +55 -0
- data/ext/journald_native/sd_journal_dummy.h +23 -0
- data/lib/journald/native/version.rb +1 -1
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4020a007bf01dcb53dde8935a7772ab71e28c882
|
4
|
+
data.tar.gz: b95b33ae4d6014cf76c0b1b6e138829274f3d433
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ab72f2d53e00b60be3489609ee7065e293bef46c13145c14cfae7eae4adddbb465e1a4a785ba05930a50f1b97fa5de809a20f0b2d628a9073d7655c82dd3f74
|
7
|
+
data.tar.gz: 3983b62b9f1dc7367013048cab266f2adc71b5c0ed14ae9ad77bafe214866d6310c5d7b70f672d10636319815d7d815b4cab5a1078cbf672909d69c8659ebbef
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# journald-native
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/journald-native.svg)](http://badge.fury.io/rb/journald-native)
|
4
|
+
[![Reference Status](https://www.versioneye.com/ruby/journald-native/reference_badge.svg)](https://www.versioneye.com/ruby/journald-native/references)
|
4
5
|
|
5
6
|
A systemd-journal native logging lib wrapper.
|
6
7
|
[See sd-journal help for more info](http://www.freedesktop.org/software/systemd/man/sd_journal_print.html)
|
@@ -29,13 +30,13 @@ Journald::LOG_DEBUG # debug-level messages
|
|
29
30
|
```
|
30
31
|
|
31
32
|
systemd-journal uses syslog constants to denote level therefore they are equal to those of the Syslog module,
|
32
|
-
e.g. ```Journald::LOG_WARNING == Syslog::LOG_WARNING```.
|
33
|
+
e.g. ```Journald::LOG_WARNING == Syslog::LOG_WARNING```.
|
33
34
|
[See syslog man page for more info](http://man7.org/linux/man-pages/man3/syslog.3.html)
|
34
35
|
|
35
36
|
### Methods
|
36
37
|
|
37
|
-
Methods of Journald::Native class wrap systemd-journal calls.
|
38
|
-
[See sd-journal help for more info](http://www.freedesktop.org/software/systemd/man/sd_journal_print.html)
|
38
|
+
Methods of Journald::Native class wrap systemd-journal calls.
|
39
|
+
[See sd-journal help for more info](http://www.freedesktop.org/software/systemd/man/sd_journal_print.html)
|
39
40
|
|
40
41
|
```ruby
|
41
42
|
Journald::Native.send "MESSAGE=message", "PRIORITY=#{Journald::LOG_WARNING}"
|
@@ -43,9 +44,9 @@ Journald::Native.print Journald::LOG_WARNING, "message"
|
|
43
44
|
Journald::Native.perror "message"
|
44
45
|
```
|
45
46
|
|
46
|
-
It is not recommended to use ```print``` and ```perror``` as you may
|
47
|
-
C zero-terminated string format
|
48
|
-
|
47
|
+
It is not recommended to use ```print``` and ```perror``` as you may get exception if your string contains
|
48
|
+
```'\0'``` byte due to C zero-terminated string format. On the contrary ```send``` uses binary buffers and
|
49
|
+
does not have this shortcoming.
|
49
50
|
|
50
51
|
### License
|
51
52
|
|
@@ -4,17 +4,33 @@ LIBDIR = RbConfig::CONFIG['libdir']
|
|
4
4
|
INCLUDEDIR = RbConfig::CONFIG['includedir']
|
5
5
|
|
6
6
|
HEADER_DIRS = [INCLUDEDIR]
|
7
|
-
|
8
|
-
LIB_DIRS = [LIBDIR]
|
7
|
+
LIB_DIRS = [LIBDIR]
|
9
8
|
|
10
9
|
dir_config('systemd', HEADER_DIRS, LIB_DIRS)
|
11
10
|
|
11
|
+
$CFLAGS = '-std=c99'
|
12
|
+
|
13
|
+
def have_funcs
|
14
|
+
have_funcs = true
|
15
|
+
|
16
|
+
# check functions. redefine const list in sd_journal.h if changed
|
17
|
+
%w(sd_journal_print sd_journal_sendv sd_journal_perror).each do |func|
|
18
|
+
have_funcs &&= have_func(func)
|
19
|
+
end
|
20
|
+
|
21
|
+
have_funcs
|
22
|
+
end
|
23
|
+
|
12
24
|
# check headers
|
13
|
-
|
25
|
+
have_header('systemd/sd-journal.h')
|
26
|
+
|
27
|
+
# first try to find funcs in systemd
|
28
|
+
have_library('systemd')
|
14
29
|
|
15
|
-
|
16
|
-
|
17
|
-
|
30
|
+
unless have_funcs
|
31
|
+
have_library('systemd-journal') # try to fall back to systemd-journal if older systemd
|
32
|
+
have_funcs
|
18
33
|
end
|
19
34
|
|
35
|
+
create_header
|
20
36
|
create_makefile('journald_native')
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#define SD_JOURNAL_SUPPRESS_LOCATION
|
3
3
|
|
4
4
|
#include <ruby.h>
|
5
|
-
#include
|
5
|
+
#include "sd_journal.h"
|
6
6
|
|
7
7
|
void Init_journald_native();
|
8
8
|
|
@@ -15,9 +15,7 @@ static void jdl_init_methods();
|
|
15
15
|
static VALUE jdl_native_print(VALUE self, VALUE priority, VALUE message);
|
16
16
|
static VALUE jdl_native_send(int argc, VALUE* argv, VALUE self);
|
17
17
|
static VALUE jdl_native_perror(VALUE self, VALUE message);
|
18
|
-
|
19
|
-
/* aux */
|
20
|
-
static char * jdl_alloc_safe_string(VALUE string);
|
18
|
+
static VALUE jdl_native_is_dummy();
|
21
19
|
|
22
20
|
/* globals */
|
23
21
|
static VALUE mJournald;
|
@@ -46,6 +44,9 @@ static void jdl_init_constants()
|
|
46
44
|
rb_define_const(mJournald, "LOG_NOTICE", INT2NUM(LOG_NOTICE)); /* normal but significant condition */
|
47
45
|
rb_define_const(mJournald, "LOG_INFO", INT2NUM(LOG_INFO)); /* informational */
|
48
46
|
rb_define_const(mJournald, "LOG_DEBUG", INT2NUM(LOG_DEBUG)); /* debug-level messages */
|
47
|
+
|
48
|
+
// dummy detection const
|
49
|
+
rb_define_const(mNative, "IS_DUMMY", jdl_native_is_dummy());
|
49
50
|
}
|
50
51
|
|
51
52
|
static void jdl_init_methods()
|
@@ -53,6 +54,9 @@ static void jdl_init_methods()
|
|
53
54
|
rb_define_singleton_method(mNative, "print", jdl_native_print, 2);
|
54
55
|
rb_define_singleton_method(mNative, "send", jdl_native_send, -1); /* -1 to pass as C array */
|
55
56
|
rb_define_singleton_method(mNative, "perror", jdl_native_perror, 1);
|
57
|
+
|
58
|
+
// dummy detection method
|
59
|
+
rb_define_singleton_method(mNative, "dummy?", jdl_native_is_dummy, 0);
|
56
60
|
}
|
57
61
|
|
58
62
|
static VALUE jdl_native_print(VALUE v_self, VALUE v_priority, VALUE v_message)
|
@@ -61,19 +65,17 @@ static VALUE jdl_native_print(VALUE v_self, VALUE v_priority, VALUE v_message)
|
|
61
65
|
char *message;
|
62
66
|
|
63
67
|
priority = NUM2INT(v_priority);
|
64
|
-
message =
|
68
|
+
message = StringValueCStr(v_message);
|
65
69
|
|
66
70
|
result = sd_journal_print(priority, "%s", message);
|
67
71
|
|
68
|
-
free(message);
|
69
|
-
|
70
72
|
return INT2NUM(result);
|
71
73
|
}
|
72
74
|
|
73
75
|
static VALUE jdl_native_send(int argc, VALUE* argv, VALUE self)
|
74
76
|
{
|
75
77
|
struct iovec *msgs;
|
76
|
-
|
78
|
+
int i;
|
77
79
|
int result;
|
78
80
|
|
79
81
|
/* first check everything is a string / convertable to string */
|
@@ -102,42 +104,14 @@ static VALUE jdl_native_perror(VALUE v_self, VALUE v_message)
|
|
102
104
|
int result;
|
103
105
|
char *message;
|
104
106
|
|
105
|
-
message =
|
107
|
+
message = StringValueCStr(v_message);
|
106
108
|
|
107
109
|
result = sd_journal_perror(message);
|
108
110
|
|
109
|
-
free(message);
|
110
|
-
|
111
111
|
return INT2NUM(result);
|
112
112
|
}
|
113
113
|
|
114
|
-
|
115
|
-
* Remove zeros from string and ensure it's zero-terminated
|
116
|
-
*/
|
117
|
-
static char * jdl_alloc_safe_string(VALUE v_string)
|
114
|
+
static VALUE jdl_native_is_dummy()
|
118
115
|
{
|
119
|
-
|
120
|
-
size_t len;
|
121
|
-
|
122
|
-
char *newstr,
|
123
|
-
*ptr;
|
124
|
-
size_t i;
|
125
|
-
|
126
|
-
/* convert to string */
|
127
|
-
StringValue(v_string);
|
128
|
-
|
129
|
-
str = RSTRING_PTR(v_string);
|
130
|
-
len = RSTRING_LEN(v_string);
|
131
|
-
|
132
|
-
newstr = calloc(len + 1, sizeof(char));
|
133
|
-
|
134
|
-
for (i = 0, ptr = newstr; i < len; i++) {
|
135
|
-
if (str[i]) {
|
136
|
-
*(ptr++) = str[i];
|
137
|
-
}
|
138
|
-
}
|
139
|
-
|
140
|
-
*ptr = '\0';
|
141
|
-
|
142
|
-
return newstr;
|
116
|
+
return JOURNALD_NATIVE_SD_JOURNAL_DUMMY ? Qtrue : Qfalse;
|
143
117
|
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#include <stdbool.h>
|
2
|
+
|
3
|
+
#ifdef __cplusplus
|
4
|
+
extern "C" {
|
5
|
+
#endif
|
6
|
+
|
7
|
+
#ifndef JOURNALD_NATIVE_SD_JOURNAL_H
|
8
|
+
#define JOURNALD_NATIVE_SD_JOURNAL_H
|
9
|
+
|
10
|
+
#ifdef __linux__
|
11
|
+
|
12
|
+
#define JOURNALD_NATIVE_SD_JOURNAL_DUMMY false
|
13
|
+
|
14
|
+
/* do the real stuff */
|
15
|
+
|
16
|
+
#include "extconf.h"
|
17
|
+
|
18
|
+
/* check for extconf results */
|
19
|
+
|
20
|
+
#ifndef HAVE_SYSTEMD_SD_JOURNAL_H
|
21
|
+
#error Cannot include <systemd/sd-journal.h>. Please use linux version with systemd-journal installed
|
22
|
+
#endif
|
23
|
+
|
24
|
+
#ifndef HAVE_SD_JOURNAL_PRINT
|
25
|
+
#error Required function sd_journal_print is missing
|
26
|
+
#endif
|
27
|
+
|
28
|
+
#ifndef HAVE_SD_JOURNAL_SENDV
|
29
|
+
#error Required function sd_journal_sendv is missing
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#ifndef HAVE_SD_JOURNAL_PERROR
|
33
|
+
#error Required function sd_journal_perror is missing
|
34
|
+
#endif
|
35
|
+
|
36
|
+
/* Do not add C line and file to the log messages */
|
37
|
+
#define SD_JOURNAL_SUPPRESS_LOCATION
|
38
|
+
/* include systemd-journal headers */
|
39
|
+
#include <systemd/sd-journal.h>
|
40
|
+
|
41
|
+
#else
|
42
|
+
|
43
|
+
#define JOURNALD_NATIVE_SD_JOURNAL_DUMMY true
|
44
|
+
|
45
|
+
#warning Compiling dummy version of the gem for non-Linux OS
|
46
|
+
|
47
|
+
#include "sd_journal_dummy.h"
|
48
|
+
|
49
|
+
#endif
|
50
|
+
|
51
|
+
#ifdef __cplusplus
|
52
|
+
}
|
53
|
+
#endif
|
54
|
+
|
55
|
+
#endif // JOURNALD_NATIVE_SD_JOURNAL_H
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/* dummy code to be used in sd_journal.h on non-linux system */
|
2
|
+
|
3
|
+
#include <stdlib.h>
|
4
|
+
|
5
|
+
/* syslog constants */
|
6
|
+
#define LOG_EMERG 0
|
7
|
+
#define LOG_ALERT 1
|
8
|
+
#define LOG_CRIT 2
|
9
|
+
#define LOG_ERR 3
|
10
|
+
#define LOG_WARNING 4
|
11
|
+
#define LOG_NOTICE 5
|
12
|
+
#define LOG_INFO 6
|
13
|
+
#define LOG_DEBUG 7
|
14
|
+
|
15
|
+
/* iovec */
|
16
|
+
struct iovec {
|
17
|
+
void *iov_base; /* Starting address */
|
18
|
+
size_t iov_len; /* Number of bytes to transfer */
|
19
|
+
};
|
20
|
+
|
21
|
+
inline int sd_journal_print(int priority, const char *format, ...) { return 0; }
|
22
|
+
inline int sd_journal_sendv(const struct iovec *iov, int n) { return 0; }
|
23
|
+
inline int sd_journal_perror(const char *message) { return 0; }
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: journald-native
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Smirnov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake-compiler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description:
|
@@ -60,13 +60,15 @@ extensions:
|
|
60
60
|
- ext/journald_native/extconf.rb
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
-
- .gitignore
|
63
|
+
- ".gitignore"
|
64
64
|
- Gemfile
|
65
65
|
- LICENSE.txt
|
66
66
|
- README.md
|
67
67
|
- Rakefile
|
68
68
|
- ext/journald_native/extconf.rb
|
69
69
|
- ext/journald_native/journald_native.c
|
70
|
+
- ext/journald_native/sd_journal.h
|
71
|
+
- ext/journald_native/sd_journal_dummy.h
|
70
72
|
- journald-native.gemspec
|
71
73
|
- lib/journald/native.rb
|
72
74
|
- lib/journald/native/version.rb
|
@@ -80,19 +82,18 @@ require_paths:
|
|
80
82
|
- lib
|
81
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
84
|
requirements:
|
83
|
-
- -
|
85
|
+
- - ">="
|
84
86
|
- !ruby/object:Gem::Version
|
85
87
|
version: 1.9.2
|
86
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
89
|
requirements:
|
88
|
-
- -
|
90
|
+
- - ">="
|
89
91
|
- !ruby/object:Gem::Version
|
90
92
|
version: '0'
|
91
93
|
requirements: []
|
92
94
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.4.5
|
94
96
|
signing_key:
|
95
97
|
specification_version: 4
|
96
98
|
summary: systemd-journal logging native lib wrapper
|
97
99
|
test_files: []
|
98
|
-
has_rdoc:
|