Skip to content

Commit 5488a93

Browse files
bors[bot]codyps
andauthored
Merge #154
154: journal: adjust open() mechanisms to use a builder pattern r=jmesmon a=jmesmon - `JournalFiles` doesn't properly cover all inclusions/exclusions - The various boolean arguments were leading to "boolean blindness" (ie: lack of clarity in what `open()` call options meant). - `OpenOptions`, `OpenFileOptions`, and `OpenDirectoryOptions` are added. These are patterned after `std::fs::OpenOptions`. - I've marked the commonly used `Journal::open()` as deprecated (and was somewhat annoyed by rust-lang/rust#47219). - I've removed `Journal::open_directory` and `Journal::open_files` entirely. They'll need to use the new `journal::OpenFileOptions` and `journal::OpenDirectoryOptions`. Co-authored-by: Cody P Schafer <[email protected]>
2 parents f1d28dc + 05802e1 commit 5488a93

File tree

11 files changed

+369
-105
lines changed

11 files changed

+369
-105
lines changed
File renamed without changes.

.github/workflows/features.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
on:
2+
push:
3+
branches-ignore:
4+
- '**.tmp'
5+
6+
name: features-check
7+
8+
jobs:
9+
check:
10+
runs-on: ubuntu-20.04
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- uses: actions-rs/toolchain@v1
16+
with:
17+
profile: minimal
18+
toolchain: beta
19+
override: true
20+
21+
- name: Install libsystemd-dev
22+
run: sudo apt-get install libsystemd-dev
23+
24+
- name: Check with no-default-features
25+
uses: actions-rs/cargo@v1
26+
with:
27+
command: check
28+
args: --all --no-default-features
29+
30+
- name: Check with only bus
31+
uses: actions-rs/cargo@v1
32+
with:
33+
command: check
34+
args: --all --no-default-features --features bus
35+
36+
- name: Check with only journal
37+
uses: actions-rs/cargo@v1
38+
with:
39+
command: check
40+
args: --all --no-default-features --features journal

Cargo.lock

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ memchr = "2.3.4"
2222
utf8-cstr = "~0.1"
2323
cstr-argument = "~0.1"
2424
foreign-types = "0.5.0"
25-
serde = { version = "1.0", default-features = false, features=["derive"], optional = true}
2625
#enumflags2 = "^0.5"
2726
#enumflags2_derive = "^0.5"
2827

bors.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
status = [
22
"continuous-integration/travis-ci/push",
3-
"check"
3+
"check",
4+
"features-check",
45
]
56
cut_body_after = "---"
67
delete_merged_branches = true

examples/journal-logger.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod x {
55
//! Follow future journal log messages and print up to 100 of them.
66
use std::io::ErrorKind;
77

8-
use systemd::journal::{Journal, JournalFiles, JournalRecord, JournalSeek};
8+
use systemd::journal::{self, JournalRecord, JournalSeek};
99
use systemd::Error;
1010

1111
const KEY_UNIT: &str = "_SYSTEMD_UNIT";
@@ -17,9 +17,8 @@ mod x {
1717
println!("Starting journal-logger");
1818

1919
// Open the journal
20-
let runtime_only = false;
21-
let local_only = false;
22-
let mut reader = Journal::open(JournalFiles::All, runtime_only, local_only)
20+
let mut reader = journal::OpenOptions::default()
21+
.open()
2322
.expect("Could not open journal");
2423

2524
// Seek to end of current log to prevent old messages from being printed

examples/journal-reader.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#[cfg(feature = "journal")]
44
mod x {
55
//! Follow future journal log messages and print up to 100 of them.
6-
use systemd::journal::{Journal, JournalFiles, JournalSeek};
6+
use systemd::journal::{self, JournalSeek};
77

88
const KEY_UNIT: &str = "_SYSTEMD_UNIT";
99
const KEY_MESSAGE: &str = "MESSAGE";
@@ -14,9 +14,8 @@ mod x {
1414
println!("Starting journal-logger");
1515

1616
// Open the journal
17-
let runtime_only = false;
18-
let local_only = false;
19-
let mut reader = Journal::open(JournalFiles::All, runtime_only, local_only)
17+
let mut reader = journal::OpenOptions::default()
18+
.open()
2019
.expect("Could not open journal");
2120

2221
// Seek to end of current log to prevent old messages from being printed

libsystemd-sys/src/journal.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ use super::const_iovec;
44
use super::size_t;
55
use super::{c_char, c_int, c_void};
66

7-
pub const SD_JOURNAL_LOCAL_ONLY: c_int = 1;
8-
pub const SD_JOURNAL_RUNTIME_ONLY: c_int = 2;
9-
pub const SD_JOURNAL_SYSTEM: c_int = 4;
10-
pub const SD_JOURNAL_CURRENT_USER: c_int = 8;
11-
pub const SD_JOURNAL_OS_ROOT: c_int = 16;
7+
pub const SD_JOURNAL_LOCAL_ONLY: c_int = 1 << 0;
8+
pub const SD_JOURNAL_RUNTIME_ONLY: c_int = 1 << 1;
9+
pub const SD_JOURNAL_SYSTEM: c_int = 1 << 2;
10+
pub const SD_JOURNAL_CURRENT_USER: c_int = 1 << 3;
11+
pub const SD_JOURNAL_OS_ROOT: c_int = 1 << 4;
12+
pub const SD_JOURNAL_ALL_NAMESPACES: c_int = 1 << 5;
13+
pub const SD_JOURNAL_INCLUDE_DEFAULT_NAMESPACE: c_int = 1 << 6;
1214

1315
// Wakeup event types
1416
pub const SD_JOURNAL_NOP: c_int = 0;
@@ -25,6 +27,11 @@ extern "C" {
2527
// (we don't need to do c-style format strings)
2628

2729
pub fn sd_journal_open(ret: *mut *mut sd_journal, flags: c_int) -> c_int;
30+
pub fn sd_journal_open_namespace(
31+
ret: *mut *mut sd_journal,
32+
namespace: *const c_char,
33+
flags: c_int,
34+
) -> c_int;
2835
pub fn sd_journal_open_directory(
2936
ret: *mut *mut sd_journal,
3037
path: *const c_char,

0 commit comments

Comments
 (0)