systemd-journal 1.0.0 → 1.0.1

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: 871a098e73eadfe6cd53fc8066537c37e1a1681b
4
- data.tar.gz: cb944399a1624c724b469ca41b13a3ccb4bddcb0
3
+ metadata.gz: cb7ad77b556c438d61a805803ce3ea525aae200f
4
+ data.tar.gz: 135d9669a414f246f1b75e060ba8b6d719bdea2f
5
5
  SHA512:
6
- metadata.gz: a399b0ddb5e9eb60bb305b631bb531588352f0015a1ac0b64880fa289877a716c44eaa34d887461a17144af21f5c520a6d759c8030c315538c117160ead48724
7
- data.tar.gz: af798df9d31d0cc9e742104de505964bf1e07f94dfb74918407cdce0996cde716a96b440482614c57050afabc56c62aa82d218edc53fb20f3685e29ec5c1d719
6
+ metadata.gz: 063fc619fbc6436e72381812dcb0c3905a3b17d260e8d0223df0dec95b51a8219cbf6ee1c02a3eff3f0f548e474ca8df77ed2f6a97adfe12de90c87018b0a5dd
7
+ data.tar.gz: 1175078fb9650d9bf12c5bbbd612b87ddb5b5bf5c44974d49fdc4a9344ee1e1f4934a92f35b1f9c8c5a4fbfe5b2d4408b9a1f17a58bff2ebf0ce0bff30c051d4
data/README.md CHANGED
@@ -16,10 +16,10 @@ And then execute:
16
16
 
17
17
  ## Usage
18
18
 
19
+ require 'systemd/journal'
20
+
19
21
  Print all messages as they occur:
20
22
 
21
- require 'systemd/journal'
22
-
23
23
  j = Systemd::Journal.new
24
24
  j.seek(:tail)
25
25
 
@@ -27,20 +27,36 @@ Print all messages as they occur:
27
27
  puts entry.message
28
28
  end
29
29
 
30
- Filter messages included in the journal:
31
-
32
- require 'systemd/journal'
30
+ Filter events and iterate:
33
31
 
34
32
  j = Systemd::Journal.new
35
-
33
+
36
34
  # only display entries from SSHD with priority 6.
37
- j.add_match(:priority, 6)
38
- j.add_match(:_exe, '/usr/bin/sshd')
39
-
40
- while j.move_next
41
- puts j.current_entry.message
35
+ j.filter(priority: 6, _exe: '/usr/bin/sshd')
36
+ j.each do |entry|
37
+ puts entry.message
42
38
  end
39
+
40
+ Moving around the journal:
41
+
42
+ j = Systemd::Journal.new
43
+
44
+ j.seek(:head) # move to the start of journal
45
+ j.move(10) # move forward by 10 entries
46
+ c = j.cursor # get a reference to this entry
47
+ j.move(-5) # move back 5 entries
48
+ j.seek(c) # move to the saved cursor
49
+ j.cursor?(c) # verify that we're at the correct entry
50
+ j.seek(:tail) # move to end of the journal
51
+ j.move_previous # move back
52
+ j.move_next # move forward
53
+
54
+ j.current_entry # get the entry we're currently positioned at
55
+
56
+ # seek the entry that occured closest to this time
57
+ j.seek(Time.parse("2013-10-31T12:00:00+04:00:00"))
43
58
 
59
+
44
60
  See the documentation for more examples.
45
61
 
46
62
  ## Contributing
@@ -406,7 +406,7 @@ module Systemd
406
406
  raise JournalError.new(rc)
407
407
  end
408
408
 
409
- out_ptr.read_pointer.read_string
409
+ read_and_free_outstr(out_ptr.read_pointer)
410
410
  end
411
411
 
412
412
  # Check if the read position is currently at the entry represented by the
@@ -428,5 +428,14 @@ module Systemd
428
428
  proc{ Native::sd_journal_close(ptr) unless ptr.nil? }
429
429
  end
430
430
 
431
+ # some sd_journal_* functions return strings that we're expected to free
432
+ # ourselves. This function copies the string from a char* to a ruby string,
433
+ # frees the char*, and returns the ruby string.
434
+ def read_and_free_outstr(ptr)
435
+ str = ptr.read_string
436
+ LibC.free(ptr)
437
+ str
438
+ end
439
+
431
440
  end
432
441
  end
@@ -62,4 +62,13 @@ module Systemd
62
62
  end
63
63
 
64
64
  end unless $NO_FFI_SPEC
65
+
66
+ module LibC
67
+ require 'ffi'
68
+ extend FFI::Library
69
+ ffi_lib FFI::Library::LIBC
70
+
71
+ attach_function :free, [:pointer], :void
72
+ end
73
+
65
74
  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.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
6
6
  end
@@ -429,8 +429,14 @@ describe Systemd::Journal do
429
429
  describe '#cursor' do
430
430
  it 'returns the current cursor' do
431
431
  j = Systemd::Journal.new
432
+
432
433
  Systemd::Journal::Native.should_receive(:sd_journal_get_cursor) do |ptr, out_ptr|
433
- out_ptr.write_pointer(FFI::MemoryPointer.from_string("5678"))
434
+ # this memory will be manually freed. not setting autorelease to false
435
+ # would cause a double free.
436
+ str = FFI::MemoryPointer.from_string("5678")
437
+ str.autorelease = false
438
+
439
+ out_ptr.write_pointer(str)
434
440
  0
435
441
  end
436
442
  j.cursor.should eq("5678")
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.0.0
4
+ version: 1.0.1
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: 2013-11-09 00:00:00.000000000 Z
12
+ date: 2013-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  version: '0'
106
106
  requirements: []
107
107
  rubyforge_project:
108
- rubygems_version: 2.0.3
108
+ rubygems_version: 2.0.7
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: Ruby bindings to libsystemd-journal