Skip to content

Commit

Permalink
Add klogctl to linux and android
Browse files Browse the repository at this point in the history
For android, we also add the `KLOG_*` constants. For linux, they are
defined in source but not exported to user space.

(backport <rust-lang#3777>)
(cherry picked from commit ece907b)
  • Loading branch information
sgasse authored and tgross35 committed Aug 17, 2024
1 parent 3f102f3 commit 3280331
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,7 @@ fn test_android(target: &str) {
"sys/fsuid.h",
"sys/inotify.h",
"sys/ioctl.h",
"sys/klog.h",
"sys/mman.h",
"sys/mount.h",
"sys/personality.h",
Expand Down Expand Up @@ -3433,6 +3434,7 @@ fn test_linux(target: &str) {
"sys/eventfd.h",
"sys/file.h",
"sys/fsuid.h",
"sys/klog.h",
"sys/inotify.h",
"sys/ioctl.h",
"sys/ipc.h",
Expand Down
12 changes: 12 additions & 0 deletions libc-test/semver/android.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,17 @@ KEXEC_ON_CRASH
KEXEC_PRESERVE_CONTEXT
KEY_CNT
KEY_MAX
KLOG_CLOSE
KLOG_OPEN
KLOG_READ
KLOG_READ_ALL
KLOG_READ_CLEAR
KLOG_CLEAR
KLOG_CONSOLE_OFF
KLOG_CONSOLE_ON
KLOG_CONSOLE_LEVEL
KLOG_SIZE_UNREAD
KLOG_SIZE_BUFFER
LC_ADDRESS
LC_ADDRESS_MASK
LC_ALL
Expand Down Expand Up @@ -3341,6 +3352,7 @@ itimerval
key_t
kill
killpg
klogctl
lastlog
lchown
lconv
Expand Down
1 change: 1 addition & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3562,6 +3562,7 @@ j1939_filter
jrand48
key_t
killpg
klogctl
labs
lcong48
lgetxattr
Expand Down
14 changes: 14 additions & 0 deletions src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3523,6 +3523,18 @@ pub const PF_MEMALLOC_PIN: ::c_int = 0x10000000;

pub const PF_SUSPEND_TASK: ::c_int = 0x80000000;

pub const KLOG_CLOSE: ::c_int = 0;
pub const KLOG_OPEN: ::c_int = 1;
pub const KLOG_READ: ::c_int = 2;
pub const KLOG_READ_ALL: ::c_int = 3;
pub const KLOG_READ_CLEAR: ::c_int = 4;
pub const KLOG_CLEAR: ::c_int = 5;
pub const KLOG_CONSOLE_OFF: ::c_int = 6;
pub const KLOG_CONSOLE_ON: ::c_int = 7;
pub const KLOG_CONSOLE_LEVEL: ::c_int = 8;
pub const KLOG_SIZE_UNREAD: ::c_int = 9;
pub const KLOG_SIZE_BUFFER: ::c_int = 10;

// Most `*_SUPER_MAGIC` constants are defined at the `linux_like` level; the
// following are only available on newer Linux versions than the versions
// currently used in CI in some configurations, so we define them here.
Expand Down Expand Up @@ -4095,6 +4107,8 @@ extern "C" {
) -> ::size_t;
pub fn fflush_unlocked(stream: *mut ::FILE) -> ::c_int;
pub fn fgets_unlocked(buf: *mut ::c_char, size: ::c_int, stream: *mut ::FILE) -> *mut ::c_char;

pub fn klogctl(syslog_type: ::c_int, bufp: *mut ::c_char, len: ::c_int) -> ::c_int;
}

cfg_if! {
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5626,6 +5626,8 @@ extern "C" {
len: ::size_t,
flags: ::c_uint,
) -> ::ssize_t;

pub fn klogctl(syslog_type: ::c_int, bufp: *mut ::c_char, len: ::c_int) -> ::c_int;
}

// LFS64 extensions
Expand Down

0 comments on commit 3280331

Please sign in to comment.