systemd-journal 1.1.1 → 1.1.2

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: 2c6739b242c00d225c300175bcbe918d55f7f0d8
4
- data.tar.gz: e25c7e9a75c02bc848de55610f63e34460ab179a
3
+ metadata.gz: 3f3143bd56943aac2825763f571d4be96938850d
4
+ data.tar.gz: da9dfeb9e238db9d1a3f2133a067d1f3e3027497
5
5
  SHA512:
6
- metadata.gz: 545d435b72630e2c39da338a36fade67e7ebfef43771587c46913ed1013830a721b207d47b530c7af82a51ed126c9c6bc38c446c9d880b15e47e47d2e4a16250
7
- data.tar.gz: 6fe063ad1eadbaaa2396374655d89b4e95375bb6405a14ce627ce7363c50040c5989d2318fd5b42134715154ae4988558990caddbb521d1de7e9a638884ede23
6
+ metadata.gz: b2728e14303118f0f34a1c25aa5f973f8dd22089d4798f36e29e9036bbfbf0052f1196e14a14915469361519a8751224a3f73c8ece7b7e20ee513663a1a83ed9
7
+ data.tar.gz: f2700281ac8a85099630790dda239d8cae0419fd5193ca9b28679ec8249a77e1e4547a21cfd0c0db44961b4f4ebb6a5b9b0e65398f2c7ee1de7debeb09e486ea
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.0.0
5
+ - 1.9.3
data/README.md CHANGED
@@ -22,16 +22,7 @@ thing.
22
22
 
23
23
  Obviously you will need to have
24
24
  [systemd](http://www.freedesktop.org/wiki/Software/systemd/) installed on your
25
- system in order to use the gem.
26
-
27
- __systemd 208__:
28
-
29
- * `libsystemd-journal`
30
- * `libsystemd-id128`
31
-
32
- __systemd 209+__:
33
-
34
- * `libsystemd`
25
+ system in order to use the gem. Currently we support systemd 208 or higher.
35
26
 
36
27
  ## Usage
37
28
 
@@ -114,5 +105,3 @@ If you run into problems or have questions, please open an
114
105
  4. Push to the branch
115
106
  5. Create new Pull Request, targeting the __develop__ branch.
116
107
  6. Wipe hands on pants, you're done!
117
-
118
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/ledbettj/systemd-journal/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
@@ -1,3 +1,4 @@
1
+ require 'systemd/journal/version'
1
2
  require 'systemd/journal/native'
2
3
  require 'systemd/journal/flags'
3
4
  require 'systemd/journal/writable'
@@ -29,9 +30,14 @@ module Systemd
29
30
  # @option opts [Integer] :flags a set of bitwise OR-ed
30
31
  # {Systemd::Journal::Flags} which control what journal files are opened.
31
32
  # Defaults to `0`, meaning all journals avaiable to the current user.
32
- # @option opts [String] :path if provided, open the journal files living
33
- # in the provided directory only. Any provided flags will be ignored per
33
+ # @option opts [String] :path if provided, open the journal files living
34
+ # in the provided directory only. Any provided flags will be ignored
34
35
  # since sd_journal_open_directory does not currently accept any flags.
36
+ # @option opts [Array] :files if provided, open the provided journal files
37
+ # only. Any provided flags will be ignored since sd_journal_open_files
38
+ # does not currently accept any flags.
39
+ # @option opts [String] :container if provided, open the journal files from
40
+ # the container with the provided machine name only.
35
41
  # @example Read only system journal entries
36
42
  # j = Systemd::Journal.new(flags: Systemd::Journal::Flags::SYSTEM_ONLY)
37
43
  # @example Directly open a journal directory
@@ -39,12 +45,18 @@ module Systemd
39
45
  # path: '/var/log/journal/5f5777e46c5f4131bd9b71cbed6b9abf'
40
46
  # )
41
47
  def initialize(opts = {})
48
+ validate_options!(opts)
49
+
42
50
  flags = opts[:flags] || 0
43
- path = opts[:path]
44
51
  ptr = FFI::MemoryPointer.new(:pointer, 1)
45
52
 
46
- rc = if path
47
- Native.sd_journal_open_directory(ptr, path, 0)
53
+ rc = case
54
+ when opts[:path]
55
+ Native.sd_journal_open_directory(ptr, opts[:path], 0)
56
+ when opts[:files]
57
+ Native.sd_journal_open_files(ptr, array_to_ptrs(opts[:files]), 0)
58
+ when opts[:container]
59
+ Native.sd_journal_open_container(ptr, opts[:container], flags)
48
60
  else
49
61
  Native.sd_journal_open(ptr, flags)
50
62
  end
@@ -194,6 +206,23 @@ module Systemd
194
206
 
195
207
  private
196
208
 
209
+ def array_to_ptrs(strings)
210
+ ptr = FFI::MemoryPointer.new(:pointer, strings.length + 1)
211
+ strings.each_with_index do |s, i|
212
+ ptr[i].put_pointer(0, FFI::MemoryPointer.from_string(s))
213
+ end
214
+ ptr[strings.length].put_pointer(0, nil)
215
+ ptr
216
+ end
217
+
218
+ def validate_options!(opts)
219
+ exclusive = [:path, :files, :container]
220
+ provided = (opts.keys & exclusive)
221
+ if provided.length > 1
222
+ raise ArgumentError.new("#{provided} are conflicting options")
223
+ end
224
+ end
225
+
197
226
  def self.finalize(ptr)
198
227
  proc { Native.sd_journal_close(ptr) unless ptr.nil? }
199
228
  end
@@ -16,6 +16,9 @@ module Systemd
16
16
  attach_function :sd_journal_open_directory, [:pointer, :string, :int], :int
17
17
  attach_function :sd_journal_close, [:pointer], :void
18
18
 
19
+ attach_function :sd_journal_open_files, [:pointer, :pointer, :int], :int
20
+ attach_function :sd_journal_open_container, [:pointer, :string, :int], :int
21
+
19
22
  # navigation
20
23
  attach_function :sd_journal_next, [:pointer], :int
21
24
  attach_function :sd_journal_next_skip, [:pointer, :uint64], :int
@@ -1,6 +1,6 @@
1
1
  module Systemd
2
2
  class Journal
3
3
  # The version of the systemd-journal gem.
4
- VERSION = '1.1.1'
4
+ VERSION = '1.1.2'
5
5
  end
6
6
  end
data/spec/spec_helper.rb CHANGED
@@ -15,8 +15,9 @@ RSpec.configure do |config|
15
15
  0
16
16
  end
17
17
 
18
- Systemd::Journal::Native.stub(:sd_journal_open, &dummy_open)
19
- Systemd::Journal::Native.stub(:sd_journal_open_directory, &dummy_open)
18
+ ['', '_directory', '_files', '_container'].each do |suffix|
19
+ Systemd::Journal::Native.stub(:"sd_journal_open#{suffix}", &dummy_open)
20
+ end
20
21
  Systemd::Journal::Native.stub(:sd_journal_close).and_return(0)
21
22
 
22
23
  # Raise an exception if any native calls are actually called
@@ -25,7 +26,8 @@ RSpec.configure do |config|
25
26
  end
26
27
 
27
28
  native_calls -= [
28
- :sd_journal_open, :sd_journal_open_directory, :sd_journal_close
29
+ :sd_journal_open, :sd_journal_open_directory, :sd_journal_close,
30
+ :sd_journal_open_files, :sd_journal_open_container
29
31
  ]
30
32
 
31
33
  build_err_proc = ->(method_name) do
@@ -16,10 +16,29 @@ describe Systemd::Journal do
16
16
  Systemd::Journal.new(flags: 1234)
17
17
  end
18
18
 
19
+ it 'accepts a files argument to open specific files' do
20
+ Systemd::Journal::Native.should_receive(:sd_journal_open_files)
21
+ Systemd::Journal.new(files: ['/path/to/journal/1', '/path/to/journal/2'])
22
+ end
23
+
24
+ it 'accepts a machine name to open a container' do
25
+ Systemd::Journal::Native.should_receive(:sd_journal_open_container)
26
+ Systemd::Journal.new(container: 'bobs-machine')
27
+ end
28
+
19
29
  it 'raises a Journal Error if a native call fails' do
20
30
  Systemd::Journal::Native.should_receive(:sd_journal_open).and_return(-1)
21
31
  expect { Systemd::Journal.new }.to raise_error(Systemd::JournalError)
22
32
  end
33
+
34
+ it 'raises an argument error if conflicting options are passed' do
35
+ expect do
36
+ Systemd::Journal.new(path: 'p', files: %w{a b})
37
+ end.to raise_error(ArgumentError)
38
+ expect do
39
+ Systemd::Journal.new(container: 'c', files: %w{a b})
40
+ end.to raise_error(ArgumentError)
41
+ end
23
42
  end
24
43
 
25
44
  describe '#move' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: systemd-journal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Ledbetter
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-20 00:00:00.000000000 Z
12
+ date: 2014-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -63,6 +63,7 @@ extra_rdoc_files: []
63
63
  files:
64
64
  - ".gitignore"
65
65
  - ".rubocop.yml"
66
+ - ".travis.yml"
66
67
  - Gemfile
67
68
  - LICENSE.txt
68
69
  - README.md
@@ -109,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
110
  version: '0'
110
111
  requirements: []
111
112
  rubyforge_project:
112
- rubygems_version: 2.2.0
113
+ rubygems_version: 2.2.2
113
114
  signing_key:
114
115
  specification_version: 4
115
116
  summary: Ruby bindings to libsystemd-journal