Skip to content

Commit 7fd063b

Browse files
committed
uptime: fix issue in licence, formatting, spell and ci
1 parent 9803d3a commit 7fd063b

File tree

11 files changed

+84
-69
lines changed

11 files changed

+84
-69
lines changed

.github/workflows/CICD.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ jobs:
5858
- uses: actions/checkout@v4
5959
with:
6060
persist-credentials: false
61+
- if: ${{ contains(matrix.job.os, 'ubuntu') }}
62+
run: |
63+
sudo apt-get update -y
64+
sudo apt-get -yq --no-install-suggests --no-install-recommends install libsystemd-dev
6165
- uses: dtolnay/rust-toolchain@nightly
6266
## note: requires 'nightly' toolchain b/c `cargo-udeps` uses the `rustc` '-Z save-analysis' option
6367
## * ... ref: <https://github.com/est31/cargo-udeps/issues/73>
@@ -112,6 +116,10 @@ jobs:
112116
- uses: actions/checkout@v4
113117
with:
114118
persist-credentials: false
119+
- if: ${{ contains(matrix.job.os, 'ubuntu') }}
120+
run: |
121+
sudo apt-get update -y
122+
sudo apt-get -yq --no-install-suggests --no-install-recommends install libsystemd-dev
115123
- uses: dtolnay/rust-toolchain@master
116124
with:
117125
toolchain: stable
@@ -171,6 +179,10 @@ jobs:
171179
- uses: actions/checkout@v4
172180
with:
173181
persist-credentials: false
182+
- if: ${{ contains(matrix.job.os, 'ubuntu') }}
183+
run: |
184+
sudo apt-get update -y
185+
sudo apt-get -yq --no-install-suggests --no-install-recommends install libsystemd-dev
174186
- uses: dtolnay/rust-toolchain@master
175187
with:
176188
toolchain: ${{ env.RUST_MIN_SRV }}
@@ -264,7 +276,7 @@ jobs:
264276
- uses: actions/checkout@v4
265277
with:
266278
persist-credentials: false
267-
- if: ${{ contains(matrix.os, 'ubuntu') }}
279+
- if: ${{ contains(matrix.job.os, 'ubuntu') }}
268280
run: |
269281
sudo apt-get update -y
270282
sudo apt-get -yq --no-install-suggests --no-install-recommends install libsystemd-dev
@@ -324,7 +336,7 @@ jobs:
324336
- uses: actions/checkout@v4
325337
with:
326338
persist-credentials: false
327-
- if: ${{ contains(matrix.os, 'ubuntu') }}
339+
- if: ${{ contains(matrix.job.os, 'ubuntu') }}
328340
run: |
329341
sudo apt-get update -y
330342
sudo apt-get -yq --no-install-suggests --no-install-recommends install libsystemd-dev
@@ -357,7 +369,7 @@ jobs:
357369
- uses: actions/checkout@v4
358370
with:
359371
persist-credentials: false
360-
- if: ${{ contains(matrix.os, 'ubuntu') }}
372+
- if: ${{ contains(matrix.job.os, 'ubuntu') }}
361373
run: |
362374
sudo apt-get update -y
363375
sudo apt-get -yq --no-install-suggests --no-install-recommends install libsystemd-dev
@@ -519,7 +531,7 @@ jobs:
519531
- uses: actions/checkout@v4
520532
with:
521533
persist-credentials: false
522-
- if: ${{ contains(matrix.os, 'ubuntu') }}
534+
- if: ${{ contains(matrix.job.os, 'ubuntu') }}
523535
run: |
524536
sudo apt-get update -y
525537
sudo apt-get -yq --no-install-suggests --no-install-recommends install libsystemd-dev
@@ -820,6 +832,10 @@ jobs:
820832
- uses: actions/checkout@v4
821833
with:
822834
persist-credentials: false
835+
- if: ${{ contains(matrix.job.os, 'ubuntu') }}
836+
run: |
837+
sudo apt-get update -y
838+
sudo apt-get -yq --no-install-suggests --no-install-recommends install libsystemd-dev
823839
- uses: Swatinem/rust-cache@v2
824840
- name: Run sccache-cache
825841
uses: mozilla-actions/[email protected]
@@ -902,6 +918,10 @@ jobs:
902918
- uses: actions/checkout@v4
903919
with:
904920
persist-credentials: false
921+
- if: ${{ contains(matrix.job.os, 'ubuntu') }}
922+
run: |
923+
sudo apt-get update -y
924+
sudo apt-get -yq --no-install-suggests --no-install-recommends install libsystemd-dev
905925
- uses: dtolnay/rust-toolchain@master
906926
with:
907927
toolchain: ${{ env.RUST_MIN_SRV }}

.github/workflows/code-quality.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ jobs:
7979
- uses: actions/checkout@v4
8080
with:
8181
persist-credentials: false
82+
- if: ${{ contains(matrix.job.os, 'ubuntu') }}
83+
run: |
84+
sudo apt-get update -y
85+
sudo apt-get -yq --no-install-suggests --no-install-recommends install libsystemd-dev
8286
- uses: dtolnay/rust-toolchain@master
8387
with:
8488
toolchain: stable

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ iana-time-zone = "0.1.57"
302302
indicatif = "0.17.8"
303303
itertools = "0.14.0"
304304
libc = "0.2.153"
305-
libsystemd-sys = "0.9.3"
306305
lscolors = { version = "0.20.0", default-features = false, features = [
307306
"gnu_legacy",
308307
] }
@@ -317,6 +316,7 @@ num-traits = "0.2.19"
317316
number_prefix = "0.4"
318317
once_cell = "1.19.0"
319318
onig = { version = "~6.4", default-features = false }
319+
pkg-config = "0.3.31"
320320
parse_datetime = "0.7.0"
321321
phf = "0.11.2"
322322
phf_codegen = "0.11.2"

src/uu/uptime/Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@ path = "src/uptime.rs"
1919
[dependencies]
2020
chrono = { workspace = true }
2121
clap = { workspace = true }
22-
uucore = { workspace = true, features = ["libc", "utmpx", "uptime"] }
2322
thiserror = { workspace = true }
24-
25-
[target.'cfg(target_os="linux")'.dependencies]
26-
libsystemd-sys = { workspace = true }
23+
uucore = { workspace = true, features = ["libc", "utmpx", "uptime"] }
2724

2825
[target.'cfg(target_os = "openbsd")'.dependencies]
2926
utmp-classic = { workspace = true }
3027

3128
[target.'cfg(target_os="windows")'.dependencies]
32-
windows-sys = {workspace = true, features = ["Win32_System_RemoteDesktop", "Wdk_System_SystemInformation"]}
29+
windows-sys = { workspace = true, features = ["Win32_System_RemoteDesktop", "Wdk_System_SystemInformation"] }
3330

3431
[[bin]]
3532
name = "uptime"

src/uu/uptime/src/uptime.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55

6-
// spell-checker:ignore getloadavg behaviour loadavg uptime upsecs updays upmins uphours boottime nusers utmpxname gettime clockid
6+
// spell-checker:ignore getloadavg behaviour loadavg uptime upsecs updays upmins uphours boottime nusers utmpxname gettime clockid formated
77

88
use chrono::{Local, TimeZone, Utc};
99
use clap::ArgMatches;
@@ -294,7 +294,3 @@ fn print_uptime(boot_time: Option<time_t>) -> UResult<()> {
294294
print!("up {}, ", get_formated_uptime(boot_time)?);
295295
Ok(())
296296
}
297-
298-
299-
300-

src/uucore/Cargo.toml

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ lazy_static = "1.4.0"
3636
itertools = { workspace = true, optional = true }
3737
thiserror = { workspace = true, optional = true }
3838
time = { workspace = true, optional = true, features = [
39-
"formatting",
40-
"local-offset",
41-
"macros",
39+
"formatting",
40+
"local-offset",
41+
"macros",
4242
] }
4343
# * "problem" dependencies (pinned)
4444
data-encoding = { version = "2.6", optional = true }
@@ -71,19 +71,19 @@ clap = { workspace = true }
7171
once_cell = { workspace = true }
7272
tempfile = { workspace = true }
7373

74+
[build-dependencies]
75+
pkg-config = { workspace = true }
76+
7477
[target.'cfg(target_os = "windows")'.dependencies]
7578
winapi-util = { workspace = true, optional = true }
7679
windows-sys = { workspace = true, optional = true, default-features = false, features = [
77-
"Wdk_System_SystemInformation",
78-
"Win32_Storage_FileSystem",
79-
"Win32_Foundation",
80-
"Win32_System_RemoteDesktop",
81-
"Win32_System_WindowsProgramming",
80+
"Wdk_System_SystemInformation",
81+
"Win32_Storage_FileSystem",
82+
"Win32_Foundation",
83+
"Win32_System_RemoteDesktop",
84+
"Win32_System_WindowsProgramming",
8285
] }
8386

84-
[target.'cfg(target_os="linux")'.dependencies]
85-
libsystemd-sys = { workspace = true, optional = true }
86-
8787
[target.'cfg(target_os = "openbsd")'.dependencies]
8888
utmp-classic = { workspace = true, optional = true }
8989

@@ -111,17 +111,17 @@ ranges = []
111111
ringbuffer = []
112112
signals = []
113113
sum = [
114-
"digest",
115-
"hex",
116-
"memchr",
117-
"md-5",
118-
"sha1",
119-
"sha2",
120-
"sha3",
121-
"blake2b_simd",
122-
"blake3",
123-
"sm3",
124-
"crc32fast",
114+
"digest",
115+
"hex",
116+
"memchr",
117+
"md-5",
118+
"sha1",
119+
"sha2",
120+
"sha3",
121+
"blake2b_simd",
122+
"blake3",
123+
"sm3",
124+
"crc32fast",
125125
]
126126
update-control = []
127127
utf8 = []
@@ -130,4 +130,4 @@ version-cmp = []
130130
wide = []
131131
custom-tz-fmt = []
132132
tty = []
133-
uptime = ["libc", "windows-sys", "utmpx", "libsystemd-sys", "utmp-classic"]
133+
uptime = ["libc", "windows-sys", "utmpx", "utmp-classic"]

src/uucore/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// spell-checker:ignore libsystemd
2+
fn main() {
3+
#[cfg(target_os = "linux")]
4+
#[cfg(feature = "uptime")]
5+
pkg_config::find_library("libsystemd").unwrap();
6+
}

src/uucore/src/lib/features.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ pub mod ringbuffer;
3434
pub mod sum;
3535
#[cfg(feature = "update-control")]
3636
pub mod update_control;
37+
#[cfg(feature = "uptime")]
38+
pub mod uptime;
3739
#[cfg(feature = "version-cmp")]
3840
pub mod version_cmp;
3941

@@ -72,6 +74,4 @@ pub mod signals;
7274
pub mod utmpx;
7375
// ** windows-only
7476
#[cfg(all(windows, feature = "wide"))]
75-
pub mod wide;
76-
#[cfg(feature = "uptime")]
77-
pub mod uptime;
77+
pub mod wide;

src/uucore/src/lib/features/uptime.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1+
// spell-checker:ignore gettime BOOTTIME clockid boottime formated nusers loadavg getloadavg
2+
13
use crate::error::{UResult, USimpleError};
24
use chrono::Local;
35
use libc::time_t;
46

7+
#[cfg(target_os = "linux")]
8+
extern "C" {
9+
pub fn sd_booted() -> libc::c_int;
10+
pub fn sd_get_sessions(sessions: *mut *mut *mut libc::c_char) -> libc::c_int;
11+
pub fn sd_session_get_class(
12+
session: *const libc::c_char,
13+
class: *mut *mut libc::c_char,
14+
) -> libc::c_int;
15+
}
16+
517
pub fn get_formatted_time() -> String {
618
Local::now().time().format("%H:%M:%S").to_string()
719
}
@@ -108,15 +120,13 @@ pub fn get_formated_uptime(boot_time: Option<time_t>) -> UResult<String> {
108120
}
109121
}
110122

111-
/// Returns the number of logged users from systemd, and return `-1` if unavailable.
112123
#[cfg(target_os = "linux")]
113124
pub fn get_nusers_systemd() -> UResult<usize> {
125+
use crate::libc::*;
126+
use std::ffi::CStr;
127+
use std::ptr;
128+
114129
unsafe {
115-
use crate::libc::free;
116-
use libsystemd_sys::daemon::sd_booted;
117-
use libsystemd_sys::login::{sd_get_sessions, sd_session_get_class};
118-
use std::ffi::{c_char, c_void, CStr};
119-
use std::ptr;
120130
// systemd
121131
if sd_booted() > 0 {
122132
let mut sessions_list: *mut *mut c_char = ptr::null_mut();

src/uucore/src/lib/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ pub use crate::features::ranges;
6464
pub use crate::features::ringbuffer;
6565
#[cfg(feature = "sum")]
6666
pub use crate::features::sum;
67-
#[cfg(feature = "uptime")]
68-
pub use crate::features::uptime;
6967
#[cfg(feature = "update-control")]
7068
pub use crate::features::update_control;
69+
#[cfg(feature = "uptime")]
70+
pub use crate::features::uptime;
7171
#[cfg(feature = "version-cmp")]
7272
pub use crate::features::version_cmp;
7373

0 commit comments

Comments
 (0)