journald-native 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 434d6c7409f38d0c734102b165c7422774b4b765
4
- data.tar.gz: dbb1a39c162a253430a5ddf497a7b6ecc8c71ee5
3
+ metadata.gz: 40cc80f310e9a40ca958130fae646a2498d50876
4
+ data.tar.gz: 742cc24381ddf5eaddba2baf430ef332f6030a2e
5
5
  SHA512:
6
- metadata.gz: 53b67e58815b34992d37b8a39339372e2d27393bbefe533d37375aac7fd4ef9386fd35fecece27ee7c9b201f56488d12fed26d22d24a1b17bb00e72fdad67473
7
- data.tar.gz: ec9ac27fa92aeb99b0258780342ebdbf34805f90db345990f5e650db5bf9a4ffd8e738f8a64612b7612a03bd4f540ab8091a4a74e8635b234f5caec24d503f68
6
+ metadata.gz: 6a0254aae671f1b71835ccb8ae0a22fed7827ad195643f1192dc930587b2c906723ecc2254d9c7fb59229a39ba8566b5039dbe1c04a6349e34170ec602109936
7
+ data.tar.gz: 3eaf04c61e3a201c86a430c03abed4da16ec7daccfc9c6d90e9b0c22ce1fbee34ba3c2d3d4758f4f23762eeaa93b6fb0d21b4e655f8fe7b11f289569c36b8b81
data/.gitignore CHANGED
@@ -25,3 +25,4 @@ Makefile
25
25
  *.ipr
26
26
  *.iws
27
27
  .rakeTasks
28
+ .idea
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # journald-native
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/journald-native.svg)](http://badge.fury.io/rb/journald-native)
4
+
3
5
  A systemd-journal native logging lib wrapper.
4
6
  [See sd-journal help for more info](http://www.freedesktop.org/software/systemd/man/sd_journal_print.html)
5
7
 
6
8
  ## Usage
7
9
 
8
10
  ```ruby
9
- require 'journald/native'
11
+ require 'journald/native'
10
12
  ```
11
13
 
12
14
  ### Constants
@@ -16,14 +18,14 @@ Constants are used to denote a log level
16
18
  Available constants:
17
19
 
18
20
  ```ruby
19
- Journald::LOG_EMERG # system is unusable
20
- Journald::LOG_ALERT # action must be taken immediately
21
- Journald::LOG_CRIT # critical conditions
22
- Journald::LOG_ERR # error conditions
23
- Journald::LOG_WARNING # warning conditions
24
- Journald::LOG_NOTICE # normal but significant condition
25
- Journald::LOG_INFO # informational
26
- Journald::LOG_DEBUG # debug-level messages
21
+ Journald::LOG_EMERG # system is unusable
22
+ Journald::LOG_ALERT # action must be taken immediately
23
+ Journald::LOG_CRIT # critical conditions
24
+ Journald::LOG_ERR # error conditions
25
+ Journald::LOG_WARNING # warning conditions
26
+ Journald::LOG_NOTICE # normal but significant condition
27
+ Journald::LOG_INFO # informational
28
+ Journald::LOG_DEBUG # debug-level messages
27
29
  ```
28
30
 
29
31
  systemd-journal uses syslog constants to denote level therefore they are equal to those of the Syslog module,
@@ -36,14 +38,14 @@ Methods of Journald::Native class wrap systemd-journal calls.
36
38
  [See sd-journal help for more info](http://www.freedesktop.org/software/systemd/man/sd_journal_print.html)
37
39
 
38
40
  ```ruby
39
- Journald::Native.send "MESSAGE=message", "PRIORITY=#{Journald::LOG_WARNING}"
40
- Journald::Native.print Journald::LOG_WARNING, "message"
41
- Journald::Native.perror "message"
41
+ Journald::Native.send "MESSAGE=message", "PRIORITY=#{Journald::LOG_WARNING}"
42
+ Journald::Native.print Journald::LOG_WARNING, "message"
43
+ Journald::Native.perror "message"
42
44
  ```
43
45
 
44
46
  It is not recommended to use ```print``` and ```perror``` as you may lose ```'\0'``` byte in your string due to
45
47
  C zero-terminated string format (all zero bytes in the middle will be removed) On the contrary ```send``` uses
46
- binary buffers and does not have such shortcoming.
48
+ binary buffers and does not have this shortcoming.
47
49
 
48
50
  ### License
49
51
 
@@ -51,7 +51,7 @@ static void jdl_init_constants()
51
51
  static void jdl_init_methods()
52
52
  {
53
53
  rb_define_singleton_method(mNative, "print", jdl_native_print, 2);
54
- rb_define_singleton_method(mNative, "send", jdl_native_send, -1); // -1 to pass as C array
54
+ rb_define_singleton_method(mNative, "send", jdl_native_send, -1); /* -1 to pass as C array */
55
55
  rb_define_singleton_method(mNative, "perror", jdl_native_perror, 1);
56
56
  }
57
57
 
@@ -72,16 +72,20 @@ static VALUE jdl_native_print(VALUE v_self, VALUE v_priority, VALUE v_message)
72
72
 
73
73
  static VALUE jdl_native_send(int argc, VALUE* argv, VALUE self)
74
74
  {
75
- //const char * fmt = "%s";
76
75
  struct iovec *msgs;
77
76
  size_t i;
78
77
  int result;
79
78
 
79
+ /* first check everything is a string / convertable to string */
80
+ for (i = 0; i < argc; i++) {
81
+ StringValue(argv[i]); /* you may get a ruby exception here */
82
+ }
83
+
84
+ /* allocate memory after all checks to avoid possible memory leak */
80
85
  msgs = calloc(argc, sizeof(struct iovec));
81
86
 
82
87
  for (i = 0; i < argc; i++) {
83
88
  VALUE v = argv[i];
84
- StringValue(v);
85
89
  msgs[i].iov_base = RSTRING_PTR(v);
86
90
  msgs[i].iov_len = RSTRING_LEN(v);
87
91
  }
@@ -119,7 +123,7 @@ static char * jdl_alloc_safe_string(VALUE v_string)
119
123
  *ptr;
120
124
  size_t i;
121
125
 
122
- /* convert tos sring */
126
+ /* convert to string */
123
127
  StringValue(v_string);
124
128
 
125
129
  str = RSTRING_PTR(v_string);
@@ -1,5 +1,5 @@
1
1
  module Journald
2
2
  module Native
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: journald-native
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Smirnov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-30 00:00:00.000000000 Z
11
+ date: 2014-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler