systemd-journal 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72e715f4febf59e80e5b3ee18156f408e896001c
4
- data.tar.gz: 9dc1f0c4921b88568469259e56db12c5db850e78
3
+ metadata.gz: 0438540edec22fbae63e8415a028a3811efe665d
4
+ data.tar.gz: 33fd5a5c73b159830d8e545be1ea9b5fde0b0250
5
5
  SHA512:
6
- metadata.gz: 7528d93f609d6e9abcb39fd52cb1b9572760ac2d09cd8ada74ae1ec18722fd4829a6625996d10757f7d5180e951af8e3e6db5e42dbb21f1665adb32fa4972aeb
7
- data.tar.gz: 1466d24d65ab955ecea3b833d054df7b97a20456d26f54d33b1e564d9496bcfc1c5dba8be9c8c624c2789db49dec5b36139aae831527c3b9f93ea73a595480f2
6
+ metadata.gz: a236ee7822df8302c33e32b2a2d14ee0a359bf0ea0bccfc9e46645583cad6e8f0889c3761b63351ff770bf461d4e6308cc9ca945765e2eea4a1acc72e372dfaa
7
+ data.tar.gz: f347074030ae403b3093dd73c4931a41aefee52c4d18b38576c5105fa4bbf5fd606f2579f273cfed68b2c712186149dd4eb20049c9957c6ebfc68ec322ed7860
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ z�'��!�~�D�Z�>rt]��33/�$
2
+ "E��L���Ec�����9O}�K�� �85j��XX-�p,��Ȉ�0�g3��}�G��u�7-҅K2a$��P�@�f���"2>E=u�')e��C��gor�.�Op��a��KxW ;��2��..aO��#Aұ&R�JS�7�
data/.rubocop.yml CHANGED
@@ -2,7 +2,7 @@ SignalException:
2
2
  Enabled: false
3
3
 
4
4
  RaiseArgs:
5
- Enabled: false
5
+ Enabled: true
6
6
 
7
7
  SpaceInsideBlockBraces:
8
8
  Enabled: true
data/.travis.yml CHANGED
@@ -1,9 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.2
3
+ - 2.3.0
4
4
  - 1.9.3
5
5
  - jruby-19mode
6
-
6
+ before_install:
7
+ - gem install bundler
7
8
  before_script:
8
9
  - export PREV_DIR=$(pwd)
9
10
  - sudo apt-get update -qq
data/Gemfile CHANGED
@@ -3,3 +3,6 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in systemd-journal.gemspec
4
4
  gemspec
5
5
 
6
+ group :test do
7
+ gem 'codeclimate-test-reporter', require: nil
8
+ end
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 John Ledbetter
1
+ Copyright (c) 2013-2016 John Ledbetter
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -9,14 +9,29 @@ Ruby bindings for reading from the systemd journal.
9
9
 
10
10
  Add this line to your application's Gemfile:
11
11
 
12
- gem 'systemd-journal', '~> 1.2.0'
12
+ ```ruby
13
+ gem 'systemd-journal', '~> 1.2.0'
14
+ ```
13
15
 
14
16
  And then execute:
15
17
 
16
- bundle install
18
+ ```sh
19
+ bundle install
20
+ ```
17
21
 
18
- Or just `gem install systemd-journal` if you're not into that whole bundler
19
- thing.
22
+ If you have trust issues, fear not:
23
+
24
+ ```sh
25
+ wget https://raw.githubusercontent.com/ledbettj/systemd-journal/master/certs/john@throttle.io.pem
26
+ gem cert --add john@throttle.io.pem
27
+ ```
28
+
29
+ You can then verify the signature at install time with either `gem` or `bundler`:
30
+
31
+ ```sh
32
+ gem install systemd-journal -P HighSecurity
33
+ bundle install --trust-policy HighSecurity
34
+ ```
20
35
 
21
36
  ## Dependencies
22
37
 
@@ -27,73 +42,119 @@ use the gem. Currently we support systemd 208 or higher.
27
42
 
28
43
  ## Usage
29
44
 
30
- require 'systemd/journal'
45
+ ```ruby
46
+ require 'systemd/journal'
47
+ ```
31
48
 
32
49
  Print all messages as they occur:
33
50
 
34
- j = Systemd::Journal.new
35
- j.seek(:tail)
51
+ ```ruby
52
+ j = Systemd::Journal.new
53
+ j.seek(:tail)
36
54
 
37
- j.watch do |entry|
38
- puts entry.message
39
- end
55
+ # watch() does not return
56
+ j.watch do |entry|
57
+ puts entry.message
58
+ end
59
+ ```
40
60
 
41
61
  Filter events and iterate:
42
62
 
43
- j = Systemd::Journal.new
63
+ ```ruby
64
+ j = Systemd::Journal.new
44
65
 
45
- # only display entries from SSHD with priority 6.
46
- j.filter(priority: 6, _exe: '/usr/bin/sshd')
47
- j.each do |entry|
48
- puts entry.message
49
- end
66
+ # only display entries from SSHD with priority 6.
67
+ j.filter(priority: 6, _exe: '/usr/bin/sshd')
68
+ j.each do |entry|
69
+ puts entry.message
70
+ end
71
+ ```
50
72
 
51
73
  Moving around the journal:
52
74
 
53
- j = Systemd::Journal.new
75
+ ```ruby
76
+ j = Systemd::Journal.new
54
77
 
55
- j.seek(:head) # move to the start of journal
56
- j.move(10) # move forward by 10 entries
57
- c = j.cursor # get a reference to this entry
58
- j.move(-5) # move back 5 entries
59
- j.seek(c) # move to the saved cursor
60
- j.cursor?(c) # verify that we're at the correct entry
61
- j.seek(:tail) # move to end of the journal
62
- j.move_previous # move back
63
- j.move_next # move forward
78
+ j.seek(:head) # move to the start of journal
79
+ j.move(10) # move forward by 10 entries
80
+ c = j.cursor # get a reference to this entry
81
+ j.move(-5) # move back 5 entries
82
+ j.seek(c) # move to the saved cursor
83
+ j.cursor?(c) # verify that we're at the correct entry
84
+ j.seek(:tail) # move to end of the journal
85
+ j.move_previous # move back
86
+ j.move_next # move forward
64
87
 
65
- j.current_entry # get the entry we're currently positioned at
88
+ j.current_entry # get the entry we're currently positioned at
66
89
 
67
- # seek the entry that occured closest to this time
68
- j.seek(Time.parse("2013-10-31T12:00:00+04:00:00"))
90
+ # seek the entry that occured closest to this time
91
+ j.seek(Time.parse('2013-10-31T12:00:00+04:00:00'))
92
+ ```
69
93
 
70
94
  Waiting for things to happen:
71
95
 
72
- j = Systemd::Journal.new
73
- j.seek(:tail)
74
- # wait up to one second for something to happen
75
- if j.wait(1_000_000)
76
- puts 'something changed!'
77
- # same as above, but can be interrupted with Control+C.
78
- if j.wait(1_000_000, select: true)
79
- puts 'something changed!'
96
+ ```ruby
97
+ j = Systemd::Journal.new
98
+ j.seek(:tail)
99
+ # wait up to one second for something to happen
100
+ if j.wait(1_000_000)
101
+ puts 'something changed!'
102
+ # same as above, but can be interrupted with Control+C.
103
+ if j.wait(1_000_000, select: true)
104
+ puts 'something changed!'
105
+ ```
80
106
 
81
107
  Accessing the catalog:
82
108
 
83
- j = Systemd::Journal.new
84
- j.move_next
85
- j.move_next while !j.current_entry.catalog?
109
+ ```ruby
110
+ j = Systemd::Journal.new
111
+ j.move_next
112
+ j.move_next until j.current_entry.catalog?
113
+
114
+ puts j.current_entry.catalog
115
+ # or if you have a message id:
116
+ puts Systemd::Journal.catalog_for(j.current_entry.message_id)
117
+ ```
118
+
119
+ Writing to the journal:
120
+
121
+ ```ruby
122
+ # write a simple message
123
+ Systemd::Journal.print(Systemd::Journal::LOG_INFO, 'Something happened')
86
124
 
87
- puts j.current_entry.catalog
88
- # or if you have a message id:
89
- puts Systemd::Journal.catalog_for(j.current_entry.message_id)
125
+ # write custom fields
126
+ Systemd::Journal.message(
127
+ message: 'Something bad happened',
128
+ priority: Systemd::Journal::LOG_ERR,
129
+ my_custom_field: 'foo was nil!'
130
+ )
131
+ ```
90
132
 
91
133
  See the documentation for more examples.
92
134
 
135
+ ## Troubleshooting
136
+
137
+ ### I get 'Cannot assign requested address' when trying to read an entry!
138
+
139
+ After calling one of the below, the Journal read pointer might not point at
140
+ a valid entry:
141
+
142
+ Journal#filter
143
+ Journal#clear_filters
144
+ Journal#seek(:head)
145
+ Journal#seek(:tail)
146
+
147
+ The solution is to always call one of `move`, `move_next`, `move_previous` and
148
+ friends before reading after issuing one of the above calls.
149
+
93
150
  ## Issues?
94
151
 
95
- This gem has been tested primarily on Arch Linux running systemd 208. Please
96
- let me know if you have issues on other distributions.
152
+ This gem has been tested primarily on MRI and Arch Linux running systemd version
153
+ 208 and up. Please let me know if you have issues with other versions or
154
+ distributions.
155
+
156
+ The gem will run under JRuby, although some features which rely on native file
157
+ descriptor support will not work.
97
158
 
98
159
  If you run into problems or have questions, please open an
99
160
  [Issue](https://github.com/ledbettj/systemd-journal/issues) or Pull Request.
@@ -104,5 +165,5 @@ If you run into problems or have questions, please open an
104
165
  2. Create your feature branch
105
166
  3. Commit your changes
106
167
  4. Push to the branch
107
- 5. Create new Pull Request, targeting the __develop__ branch.
168
+ 5. Create new Pull Request, targeting the __master__ branch.
108
169
  6. Wipe hands on pants, you're done!
@@ -0,0 +1,21 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDaDCCAlCgAwIBAgIBATANBgkqhkiG9w0BAQUFADA9MQ0wCwYDVQQDDARqb2hu
3
+ MRgwFgYKCZImiZPyLGQBGRYIdGhyb3R0bGUxEjAQBgoJkiaJk/IsZAEZFgJpbzAe
4
+ Fw0xNjAxMTcxNjEyNDlaFw0xNzAxMTYxNjEyNDlaMD0xDTALBgNVBAMMBGpvaG4x
5
+ GDAWBgoJkiaJk/IsZAEZFgh0aHJvdHRsZTESMBAGCgmSJomT8ixkARkWAmlvMIIB
6
+ IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsKoOAl3GjhyD0ijDTrgKRdN2
7
+ LgFc59HUFYKLfPnCxH3LLxyFEQWMyxmqwetUAQ2SALKNM2U+rr4Dvv39sqEjvYHn
8
+ prWK8+XuvvBYHeH2E5K0uQjwZ5yIo8wsqc0ae46cBZoRjvlWFo3ha6vo5KU1i80K
9
+ wY1bk5NykKBUIgblDCIjsh6h6lflje1MNpBW0IaHinIBeU2ZLDVi46kssptHos2q
10
+ HQLHR+wqTtaSy22jzLHf5yYDagPHyjCC6CGoApY2qE+DRiCHBE0mTB8sRrlu5aln
11
+ 3aoLT+z5iCfNrS20ycEKCg73WDdVs2gYK+yHh6GBWL0n1UhfPrOj6XIAtZTKtQID
12
+ AQABo3MwcTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU5yrYSRUD
13
+ 85vV8/Gecelpz5p3qt4wGwYDVR0RBBQwEoEQam9obkB0aHJvdHRsZS5pbzAbBgNV
14
+ HRIEFDASgRBqb2huQHRocm90dGxlLmlvMA0GCSqGSIb3DQEBBQUAA4IBAQAwUOPx
15
+ qQlrazrqAIGKMSBs7sTnyxAiirElMQLsaJbqsNmup7fDnAPaQBViL8uv2n08F7ZV
16
+ wAeItgtQxTVUkaQLh/x0OqjEc7z1P0XMXReL1Et6ep8vBOhLRHIXAdZ8Q2ESTtBM
17
+ JnHwNiSbojxBFwn7OkUuisaXr9cu6CDH/VpiGT/GxJ7cRT1WgH/ZAPt+oCY6jcs9
18
+ 3jCu+Q6KtUcFxFdXr7L2+p9Z1HkKECa1CuBsLQa8ENcqblazSJ3k7jh1nRC+PjNU
19
+ GqIHnd4cKMcoFxN3l2KjrTS2rabk/yf6nWrkVGPkN41hSRf9reteYiI08RAi3peY
20
+ 7eGf9eghUTYEt1pJ
21
+ -----END CERTIFICATE-----
@@ -12,7 +12,7 @@ class FFI::MemoryPointer
12
12
  method_defined?("read_#{name}") if t == type
13
13
  end
14
14
 
15
- raise RuntimeError, "Unable to patch in reader/writer for #{which}" if type.nil?
15
+ raise "Unable to patch in reader/writer for #{which}" if type.nil?
16
16
 
17
17
  alias_method "read_#{which}", "read_#{type}"
18
18
  alias_method "write_#{which}", "write_#{type}"
data/lib/systemd/id128.rb CHANGED
@@ -37,7 +37,7 @@ module Systemd
37
37
  def self.read_id128(func)
38
38
  ptr = FFI::MemoryPointer.new(Native::Id128, 1)
39
39
  rc = Native.send(func, ptr)
40
- raise JournalError.new(rc) if rc < 0
40
+ raise JournalError, rc if rc < 0
41
41
  Native::Id128.new(ptr).to_s
42
42
  end
43
43
 
@@ -45,14 +45,11 @@ module Systemd
45
45
  # path: '/var/log/journal/5f5777e46c5f4131bd9b71cbed6b9abf'
46
46
  # )
47
47
  def initialize(opts = {})
48
- validate_options!(opts)
48
+ open_type, flags = validate_options!(opts)
49
+ ptr = FFI::MemoryPointer.new(:pointer, 1)
49
50
 
50
- flags = opts[:flags] || 0
51
- ptr = FFI::MemoryPointer.new(:pointer, 1)
52
- opts[:files] = opts[:file] if opts[:file]
53
-
54
- rc = open_journal(ptr, opts, flags)
55
- raise JournalError.new(rc) if rc < 0
51
+ rc = open_journal(open_type, ptr, opts, flags)
52
+ raise JournalError, rc if rc < 0
56
53
 
57
54
  @ptr = ptr.read_pointer
58
55
  ObjectSpace.define_finalizer(self, self.class.finalize(@ptr))
@@ -84,7 +81,7 @@ module Systemd
84
81
  field = field.to_s.upcase
85
82
  rc = Native.sd_journal_get_data(@ptr, field, out_ptr, len_ptr)
86
83
 
87
- raise JournalError.new(rc) if rc < 0
84
+ raise JournalError, rc if rc < 0
88
85
 
89
86
  len = len_ptr.read_size_t
90
87
  string_from_out_ptr(out_ptr, len).split('=', 2).last
@@ -123,7 +120,7 @@ module Systemd
123
120
  out_ptr = FFI::MemoryPointer.new(:pointer, 1)
124
121
 
125
122
  rc = Native.sd_journal_get_catalog(@ptr, out_ptr)
126
- raise JournalError.new(rc) if rc < 0
123
+ raise JournalError, rc if rc < 0
127
124
 
128
125
  Journal.read_and_free_outstr(out_ptr.read_pointer)
129
126
  end
@@ -135,7 +132,7 @@ module Systemd
135
132
  Systemd::Id128::Native::Id128.from_s(message_id),
136
133
  out_ptr
137
134
  )
138
- raise JournalError.new(rc) if rc < 0
135
+ raise JournalError, rc if rc < 0
139
136
 
140
137
  read_and_free_outstr(out_ptr.read_pointer)
141
138
  end
@@ -152,7 +149,7 @@ module Systemd
152
149
  Native.sd_journal_restart_unique(@ptr)
153
150
 
154
151
  rc = Native.sd_journal_query_unique(@ptr, field.to_s.upcase)
155
- raise JournalError.new(rc) if rc < 0
152
+ raise JournalError, rc if rc < 0
156
153
 
157
154
  while (kvpair = enumerate_helper(:sd_journal_enumerate_unique))
158
155
  results << kvpair.last
@@ -170,7 +167,7 @@ module Systemd
170
167
  size_ptr = FFI::MemoryPointer.new(:uint64)
171
168
  rc = Native.sd_journal_get_usage(@ptr, size_ptr)
172
169
 
173
- raise JournalError.new(rc) if rc < 0
170
+ raise JournalError, rc if rc < 0
174
171
  size_ptr.read_uint64
175
172
  end
176
173
 
@@ -180,7 +177,7 @@ module Systemd
180
177
  def data_threshold
181
178
  size_ptr = FFI::MemoryPointer.new(:size_t, 1)
182
179
  if (rc = Native.sd_journal_get_data_threshold(@ptr, size_ptr)) < 0
183
- raise JournalError.new(rc)
180
+ raise JournalError, rc
184
181
  end
185
182
 
186
183
  size_ptr.read_size_t
@@ -190,7 +187,7 @@ module Systemd
190
187
  # Fields longer than this will be truncated.
191
188
  def data_threshold=(threshold)
192
189
  if (rc = Native.sd_journal_set_data_threshold(@ptr, threshold)) < 0
193
- raise JournalError.new(rc)
190
+ raise JournalError, rc
194
191
  end
195
192
  end
196
193
 
@@ -207,33 +204,32 @@ module Systemd
207
204
 
208
205
  private
209
206
 
210
- def open_journal(ptr, opts, flags)
211
- @open_flags = 0
207
+ def open_journal(type, ptr, opts, flags)
208
+ @open_flags = flags
212
209
 
213
- case
214
- when opts[:path]
210
+ case type
211
+ when :path
215
212
  @open_target = "path:#{opts[:path]}"
216
213
  Native.sd_journal_open_directory(ptr, opts[:path], 0)
217
- when opts[:files]
218
- files = Array(opts[:files])
214
+ when :files, :file
215
+ files = Array(opts[type])
219
216
  @open_target = "file#{files.one? ? '' : 's'}:#{files.join(',')}"
220
217
  Native.sd_journal_open_files(ptr, array_to_ptrs(files), 0)
221
- when opts[:container]
222
- raise ArgumentError.new('This libsystemd-journal version does not support sd_journal_open_container') unless Native.open_container?
223
- @open_flags = flags
218
+ when :container
224
219
  @open_target = "container:#{opts[:container]}"
225
220
  Native.sd_journal_open_container(ptr, opts[:container], flags)
226
- else
227
- @open_flags = flags
221
+ when :local
228
222
  @open_target = 'journal:local'
229
223
  Native.sd_journal_open(ptr, flags)
224
+ else
225
+ raise ArgumentError, "Unknown open type: #{type}"
230
226
  end
231
227
  end
232
228
 
233
229
  def read_realtime
234
230
  out = FFI::MemoryPointer.new(:uint64, 1)
235
231
  rc = Native.sd_journal_get_realtime_usec(@ptr, out)
236
- raise JournalError.new(rc) if rc < 0
232
+ raise JournalError, rc if rc < 0
237
233
 
238
234
  out.read_uint64
239
235
  end
@@ -243,7 +239,7 @@ module Systemd
243
239
  boot = FFI::MemoryPointer.new(Systemd::Id128::Native::Id128, 1)
244
240
 
245
241
  rc = Native.sd_journal_get_monotonic_usec(@ptr, out, boot)
246
- raise JournalError.new(rc) if rc < 0
242
+ raise JournalError, rc if rc < 0
247
243
 
248
244
  [out.read_uint64, Systemd::Id128::Native::Id128.new(boot).to_s]
249
245
  end
@@ -259,10 +255,21 @@ module Systemd
259
255
 
260
256
  def validate_options!(opts)
261
257
  exclusive = [:path, :files, :container, :file]
262
- provided = (opts.keys & exclusive)
263
- if provided.length > 1
264
- raise ArgumentError.new("#{provided} are conflicting options")
258
+ given = (opts.keys & exclusive)
259
+
260
+ raise ArgumentError, "conflicting options: #{given}" if given.length > 1
261
+
262
+ type = given.first || :local
263
+
264
+ if type == :container && !Native.open_container?
265
+ raise ArgumentError,
266
+ 'This native library version does not support opening containers'
265
267
  end
268
+
269
+ flags = opts[:flags] if [:local, :container].include?(type)
270
+ flags ||= 0
271
+
272
+ [type, flags]
266
273
  end
267
274
 
268
275
  def self.finalize(ptr)
@@ -274,7 +281,7 @@ module Systemd
274
281
  out_ptr = FFI::MemoryPointer.new(:pointer, 1)
275
282
 
276
283
  rc = Native.send(enum_function, @ptr, out_ptr, len_ptr)
277
- raise JournalError.new(rc) if rc < 0
284
+ raise JournalError, rc if rc < 0
278
285
  return nil if rc == 0
279
286
 
280
287
  len = len_ptr.read_size_t
@@ -38,7 +38,7 @@ module Systemd
38
38
  def add_filter(field, value)
39
39
  match = "#{field.to_s.upcase}=#{value}"
40
40
  rc = Native.sd_journal_add_match(@ptr, match, match.length)
41
- raise JournalError.new(rc) if rc < 0
41
+ raise JournalError, rc if rc < 0
42
42
  end
43
43
 
44
44
  # Add a set of filters to the journal, such that only entries where the
@@ -71,7 +71,7 @@ module Systemd
71
71
  # end
72
72
  def add_disjunction
73
73
  rc = Native.sd_journal_add_disjunction(@ptr)
74
- raise JournalError.new(rc) if rc < 0
74
+ raise JournalError, rc if rc < 0
75
75
  end
76
76
 
77
77
  # Add an AND condition to the filter. All previously added terms will be
@@ -89,7 +89,7 @@ module Systemd
89
89
  # end
90
90
  def add_conjunction
91
91
  rc = Native.sd_journal_add_conjunction(@ptr)
92
- raise JournalError.new(rc) if rc < 0
92
+ raise JournalError, rc if rc < 0
93
93
  end
94
94
 
95
95
  # Remove all filters and conjunctions/disjunctions.
@@ -11,10 +11,10 @@ module Systemd
11
11
  ffi_lib %w( libsystemd.so.0 libsystemd.so
12
12
  libsystemd-journal.so.0 libsystemd-journal.so)
13
13
 
14
- @@has_open_container = true
14
+ @has_open_container = true
15
15
 
16
16
  def self.open_container?
17
- @@has_open_container
17
+ @has_open_container
18
18
  end
19
19
 
20
20
  # setup/teardown
@@ -28,7 +28,7 @@ module Systemd
28
28
  begin
29
29
  attach_function :sd_journal_open_container, [:pointer, :string, :int], :int
30
30
  rescue FFI::NotFoundError
31
- @@has_open_container = false
31
+ @has_open_container = false
32
32
  end
33
33
 
34
34
  # navigation
@@ -7,7 +7,7 @@ module Systemd
7
7
  def cursor
8
8
  out_ptr = FFI::MemoryPointer.new(:pointer, 1)
9
9
  if (rc = Native.sd_journal_get_cursor(@ptr, out_ptr)) < 0
10
- raise JournalError.new(rc)
10
+ raise JournalError, rc
11
11
  end
12
12
 
13
13
  Journal.read_and_free_outstr(out_ptr.read_pointer)
@@ -20,7 +20,7 @@ module Systemd
20
20
  # provided cursor, False otherwise.
21
21
  def cursor?(c)
22
22
  if (rc = Native.sd_journal_test_cursor(@ptr, c)) < 0
23
- raise JournalError.new(rc)
23
+ raise JournalError, rc
24
24
  end
25
25
 
26
26
  rc > 0
@@ -41,7 +41,7 @@ module Systemd
41
41
  # that the pointer has reached the end of the journal.
42
42
  def move_next
43
43
  rc = Native.sd_journal_next(@ptr)
44
- raise JournalError.new(rc) if rc < 0
44
+ raise JournalError, rc if rc < 0
45
45
  rc > 0
46
46
  end
47
47
 
@@ -51,7 +51,7 @@ module Systemd
51
51
  # pointer has reached the end of the journal.
52
52
  def move_next_skip(amount)
53
53
  rc = Native.sd_journal_next_skip(@ptr, amount)
54
- raise JournalError.new(rc) if rc < 0
54
+ raise JournalError, rc if rc < 0
55
55
  rc
56
56
  end
57
57
 
@@ -61,7 +61,7 @@ module Systemd
61
61
  # indicating that the pointer has reached the beginning of the journal.
62
62
  def move_previous
63
63
  rc = Native.sd_journal_previous(@ptr)
64
- raise JournalError.new(rc) if rc < 0
64
+ raise JournalError, rc if rc < 0
65
65
  rc > 0
66
66
  end
67
67
 
@@ -71,7 +71,7 @@ module Systemd
71
71
  # read pointer has reached the beginning of the journal.
72
72
  def move_previous_skip(amount)
73
73
  rc = Native.sd_journal_previous_skip(@ptr, amount)
74
- raise JournalError.new(rc) if rc < 0
74
+ raise JournalError, rc if rc < 0
75
75
  rc
76
76
  end
77
77
 
@@ -94,16 +94,16 @@ module Systemd
94
94
  Native.sd_journal_seek_tail(@ptr)
95
95
  when where.is_a?(Time)
96
96
  Native.sd_journal_seek_realtime_usec(
97
- @ptr,
98
- where.to_i * 1_000_000
97
+ @ptr,
98
+ where.to_i * 1_000_000
99
99
  )
100
100
  when where.is_a?(String)
101
101
  Native.sd_journal_seek_cursor(@ptr, where)
102
102
  else
103
- raise ArgumentError.new("Unknown seek type: #{where.class}")
103
+ raise ArgumentError, "Unknown seek type: #{where.class}"
104
104
  end
105
105
 
106
- raise JournalError.new(rc) if rc < 0
106
+ raise JournalError, rc if rc < 0
107
107
 
108
108
  true
109
109
  end
@@ -1,6 +1,6 @@
1
1
  module Systemd
2
2
  class Journal
3
3
  # The version of the systemd-journal gem.
4
- VERSION = '1.2.2'
4
+ VERSION = '1.2.3'
5
5
  end
6
6
  end
@@ -20,7 +20,7 @@ module Systemd
20
20
  wait_select(timeout_usec)
21
21
  else
22
22
  rc = Native.sd_journal_wait(@ptr, timeout_usec)
23
- raise JournalError.new(rc) if rc.is_a?(Fixnum) && rc < 0
23
+ raise JournalError, rc if rc.is_a?(Fixnum) && rc < 0
24
24
  rc == :nop ? nil : rc
25
25
  end
26
26
  end
@@ -61,13 +61,13 @@ module Systemd
61
61
 
62
62
  def file_descriptor
63
63
  fd = Native.sd_journal_get_fd(@ptr)
64
- raise JournalError.new(rc) if fd < 0
64
+ raise JournalError, rc if fd < 0
65
65
  fd
66
66
  end
67
67
 
68
68
  def reason_for_wakeup
69
69
  rc = Native.sd_journal_process(@ptr)
70
- raise JournalError.new(rc) if rc.is_a?(Fixnum) && rc < 0
70
+ raise JournalError, rc if rc.is_a?(Fixnum) && rc < 0
71
71
  rc == :nop ? nil : rc
72
72
  end
73
73
  end
@@ -48,7 +48,7 @@ module Systemd
48
48
  priority,
49
49
  !opts[:prefix].nil?
50
50
  )
51
- raise JournalError.new(fd) if fd < 0
51
+ raise JournalError, fd if fd < 0
52
52
 
53
53
  IO.new(fd, File::WRONLY, encoding: Encoding::UTF_8)
54
54
  end
@@ -58,7 +58,7 @@ module Systemd
58
58
  # @param [String] message the text to prefix the error message with.
59
59
  def perror(message)
60
60
  rc = Native.sd_journal_perror(message)
61
- raise JournalError.new(rc) if rc < 0
61
+ raise JournalError, rc if rc < 0
62
62
  end
63
63
 
64
64
  # write a simple message to the systemd journal.
@@ -67,7 +67,7 @@ module Systemd
67
67
  # @param [String] message the content of the message to write.
68
68
  def print(level, message)
69
69
  rc = Native.sd_journal_print(level, message)
70
- raise JournalError.new(rc) if rc < 0
70
+ raise JournalError, rc if rc < 0
71
71
  end
72
72
 
73
73
  # write an event to the systemd journal.
@@ -79,7 +79,7 @@ module Systemd
79
79
  # add a null pointer to terminate the varargs
80
80
  items += [:string, nil]
81
81
  rc = Native.sd_journal_send(*items)
82
- raise JournalError.new(rc) if rc < 0
82
+ raise JournalError, rc if rc < 0
83
83
  end
84
84
  end
85
85
  end
data/spec/spec_helper.rb CHANGED
@@ -26,7 +26,6 @@ end
26
26
  require 'systemd/journal'
27
27
 
28
28
  RSpec.configure do |config|
29
-
30
29
  config.disable_monkey_patching!
31
30
  config.include SpecHelper
32
31
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe Systemd::Id128 do
4
- subject(:id128){ Systemd::Id128 }
4
+ subject(:id128) { Systemd::Id128 }
5
5
 
6
6
  describe 'machine_id' do
7
7
  it 'should be a 128 bit hexadecimal string' do
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe Systemd::Journal do
4
4
  subject(:j) do
5
- Systemd::Journal.new(file: journal_file).tap do |j|
6
- j.seek(:head)
7
- j.move_next
5
+ Systemd::Journal.new(file: journal_file).tap do |journal|
6
+ journal.seek(:head)
7
+ journal.move_next
8
8
  end
9
9
  end
10
10
 
@@ -17,8 +17,10 @@ RSpec.describe Systemd::Journal do
17
17
  expect { j.new(container: '', path: '/') }.to raise_error(ArgumentError)
18
18
  end
19
19
 
20
- it 'throws an ArgumentError when attempting to open a container without support' do
21
- allow(Systemd::Journal::Native).to receive(:open_container?).and_return(false)
20
+ it 'raises ArgumentError on attempt to open a container without support' do
21
+ allow(Systemd::Journal::Native).to receive(:open_container?)
22
+ .and_return(false)
23
+
22
24
  expect { j.new(container: 'test') }.to raise_error(ArgumentError)
23
25
  end
24
26
  end
@@ -145,7 +147,7 @@ RSpec.describe Systemd::Journal do
145
147
 
146
148
  it 'returns the correct catalog entry' do
147
149
  cat = Systemd::Journal.catalog_for(msg_id)
148
- expect(cat).to start_with(msg_text)
150
+ expect(cat.downcase).to start_with(msg_text.downcase)
149
151
  end
150
152
  end
151
153
 
@@ -162,7 +164,7 @@ RSpec.describe Systemd::Journal do
162
164
  # find first entry with a catalog
163
165
  j.move_next until j.current_entry.catalog?
164
166
 
165
- expect(j.current_catalog).to start_with(msg_text)
167
+ expect(j.current_catalog.downcase).to start_with(msg_text.downcase)
166
168
  end
167
169
  end
168
170
  end
@@ -359,13 +361,13 @@ RSpec.describe Systemd::Journal do
359
361
  end
360
362
 
361
363
  it 'can use select' do
362
- pending "not available on JRUBY" if Systemd::Journal::IS_JRUBY
364
+ pending 'not available on JRUBY' if Systemd::Journal::IS_JRUBY
363
365
  expect(Systemd::Journal::Native).to_not receive(:sd_journal_wait)
364
366
  j.wait(1, select: true)
365
367
  end
366
368
 
367
369
  it 'ignores request to use select on JRuby' do
368
- pending "not necessary on MRI" unless Systemd::Journal::IS_JRUBY
370
+ pending 'not necessary on MRI' unless Systemd::Journal::IS_JRUBY
369
371
  expect(Systemd::Journal::Native).to receive(:sd_journal_wait)
370
372
  j.wait(1, select: true)
371
373
  end
@@ -380,5 +382,4 @@ RSpec.describe Systemd::Journal do
380
382
  expect([true, false]).to include(j.wait_select_reliable?)
381
383
  end
382
384
  end
383
-
384
385
  end
data/spec/systemd_spec.rb CHANGED
@@ -14,5 +14,4 @@ RSpec.describe Systemd do
14
14
  Systemd.boot_id
15
15
  end
16
16
  end
17
-
18
17
  end
@@ -9,23 +9,30 @@ Gem::Specification.new do |gem|
9
9
  gem.license = 'MIT'
10
10
  gem.authors = ['John Ledbetter', 'Daniel Mack']
11
11
  gem.email = ['john@throttle.io']
12
- gem.description = %q{Provides the ability to navigate and read entries from the systemd journal in ruby, as well as write events to the journal.}
13
- gem.summary = %q{Ruby bindings to libsystemd-journal}
12
+ gem.description = 'Provides the ability to navigate and read entries from the systemd journal in ruby, as well as write events to the journal.'
13
+ gem.summary = 'Ruby bindings to libsystemd-journal'
14
14
  gem.homepage = 'https://github.com/ledbettj/systemd-journal'
15
15
 
16
+ gem.cert_chain = Dir['certs/*']
17
+
18
+ if $PROGRAM_NAME.end_with?('gem')
19
+ gem.signing_key = ENV['GEM_SIGNING_KEY']
20
+ raise ArgumentError, 'Please set GEM_SIGNING_KEY' if gem.signing_key.nil?
21
+ end
22
+
16
23
  gem.files = `git ls-files`.split($/)
17
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
24
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
18
25
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
26
  gem.require_paths = ['lib']
20
27
 
21
28
  gem.required_ruby_version = '>= 1.9.3'
22
29
 
23
- gem.add_runtime_dependency 'ffi', '~> 1.9.0'
30
+ gem.add_runtime_dependency 'ffi', '~> 1.9'
24
31
 
25
- gem.add_development_dependency 'rspec', '~> 3.1'
32
+ gem.add_development_dependency 'rspec', '~> 3.4'
26
33
  gem.add_development_dependency 'simplecov', '~> 0.9'
27
34
  gem.add_development_dependency 'rubocop', '~> 0.26'
28
35
  gem.add_development_dependency 'rake', '~> 10.3'
29
- gem.add_development_dependency 'yard', '~> 0.8.7'
36
+ gem.add_development_dependency 'yard', '~> 0.8'
30
37
  gem.add_development_dependency 'pry', '~> 0.10'
31
38
  end
metadata CHANGED
@@ -1,15 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: systemd-journal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Ledbetter
8
8
  - Daniel Mack
9
9
  autorequire:
10
10
  bindir: bin
11
- cert_chain: []
12
- date: 2014-12-10 00:00:00.000000000 Z
11
+ cert_chain:
12
+ - |
13
+ -----BEGIN CERTIFICATE-----
14
+ MIIDaDCCAlCgAwIBAgIBATANBgkqhkiG9w0BAQUFADA9MQ0wCwYDVQQDDARqb2hu
15
+ MRgwFgYKCZImiZPyLGQBGRYIdGhyb3R0bGUxEjAQBgoJkiaJk/IsZAEZFgJpbzAe
16
+ Fw0xNjAxMTcxNjEyNDlaFw0xNzAxMTYxNjEyNDlaMD0xDTALBgNVBAMMBGpvaG4x
17
+ GDAWBgoJkiaJk/IsZAEZFgh0aHJvdHRsZTESMBAGCgmSJomT8ixkARkWAmlvMIIB
18
+ IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsKoOAl3GjhyD0ijDTrgKRdN2
19
+ LgFc59HUFYKLfPnCxH3LLxyFEQWMyxmqwetUAQ2SALKNM2U+rr4Dvv39sqEjvYHn
20
+ prWK8+XuvvBYHeH2E5K0uQjwZ5yIo8wsqc0ae46cBZoRjvlWFo3ha6vo5KU1i80K
21
+ wY1bk5NykKBUIgblDCIjsh6h6lflje1MNpBW0IaHinIBeU2ZLDVi46kssptHos2q
22
+ HQLHR+wqTtaSy22jzLHf5yYDagPHyjCC6CGoApY2qE+DRiCHBE0mTB8sRrlu5aln
23
+ 3aoLT+z5iCfNrS20ycEKCg73WDdVs2gYK+yHh6GBWL0n1UhfPrOj6XIAtZTKtQID
24
+ AQABo3MwcTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU5yrYSRUD
25
+ 85vV8/Gecelpz5p3qt4wGwYDVR0RBBQwEoEQam9obkB0aHJvdHRsZS5pbzAbBgNV
26
+ HRIEFDASgRBqb2huQHRocm90dGxlLmlvMA0GCSqGSIb3DQEBBQUAA4IBAQAwUOPx
27
+ qQlrazrqAIGKMSBs7sTnyxAiirElMQLsaJbqsNmup7fDnAPaQBViL8uv2n08F7ZV
28
+ wAeItgtQxTVUkaQLh/x0OqjEc7z1P0XMXReL1Et6ep8vBOhLRHIXAdZ8Q2ESTtBM
29
+ JnHwNiSbojxBFwn7OkUuisaXr9cu6CDH/VpiGT/GxJ7cRT1WgH/ZAPt+oCY6jcs9
30
+ 3jCu+Q6KtUcFxFdXr7L2+p9Z1HkKECa1CuBsLQa8ENcqblazSJ3k7jh1nRC+PjNU
31
+ GqIHnd4cKMcoFxN3l2KjrTS2rabk/yf6nWrkVGPkN41hSRf9reteYiI08RAi3peY
32
+ 7eGf9eghUTYEt1pJ
33
+ -----END CERTIFICATE-----
34
+ date: 2016-09-17 00:00:00.000000000 Z
13
35
  dependencies:
14
36
  - !ruby/object:Gem::Dependency
15
37
  name: ffi
@@ -17,28 +39,28 @@ dependencies:
17
39
  requirements:
18
40
  - - "~>"
19
41
  - !ruby/object:Gem::Version
20
- version: 1.9.0
42
+ version: '1.9'
21
43
  type: :runtime
22
44
  prerelease: false
23
45
  version_requirements: !ruby/object:Gem::Requirement
24
46
  requirements:
25
47
  - - "~>"
26
48
  - !ruby/object:Gem::Version
27
- version: 1.9.0
49
+ version: '1.9'
28
50
  - !ruby/object:Gem::Dependency
29
51
  name: rspec
30
52
  requirement: !ruby/object:Gem::Requirement
31
53
  requirements:
32
54
  - - "~>"
33
55
  - !ruby/object:Gem::Version
34
- version: '3.1'
56
+ version: '3.4'
35
57
  type: :development
36
58
  prerelease: false
37
59
  version_requirements: !ruby/object:Gem::Requirement
38
60
  requirements:
39
61
  - - "~>"
40
62
  - !ruby/object:Gem::Version
41
- version: '3.1'
63
+ version: '3.4'
42
64
  - !ruby/object:Gem::Dependency
43
65
  name: simplecov
44
66
  requirement: !ruby/object:Gem::Requirement
@@ -87,14 +109,14 @@ dependencies:
87
109
  requirements:
88
110
  - - "~>"
89
111
  - !ruby/object:Gem::Version
90
- version: 0.8.7
112
+ version: '0.8'
91
113
  type: :development
92
114
  prerelease: false
93
115
  version_requirements: !ruby/object:Gem::Requirement
94
116
  requirements:
95
117
  - - "~>"
96
118
  - !ruby/object:Gem::Version
97
- version: 0.8.7
119
+ version: '0.8'
98
120
  - !ruby/object:Gem::Dependency
99
121
  name: pry
100
122
  requirement: !ruby/object:Gem::Requirement
@@ -124,6 +146,7 @@ files:
124
146
  - LICENSE.txt
125
147
  - README.md
126
148
  - Rakefile
149
+ - certs/john@throttle.io.pem
127
150
  - examples/journal_directory.rb
128
151
  - examples/ssh_watcher.rb
129
152
  - lib/systemd-journal.rb
@@ -169,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
192
  version: '0'
170
193
  requirements: []
171
194
  rubyforge_project:
172
- rubygems_version: 2.2.2
195
+ rubygems_version: 2.5.1
173
196
  signing_key:
174
197
  specification_version: 4
175
198
  summary: Ruby bindings to libsystemd-journal
metadata.gz.sig ADDED
Binary file