This repository was archived by the owner on Mar 7, 2021. It is now read-only.
File tree 2 files changed +84
-0
lines changed
2 files changed +84
-0
lines changed Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " json-sysctl"
3
+ version = " 0.1.0"
4
+ authors = [
" Alex Gaynor <[email protected] " ,
" Geoffrey Thomas <[email protected] >" ]
5
+ edition = " 2018"
6
+
7
+ [lib ]
8
+ crate-type = [" staticlib" ]
9
+
10
+ [dependencies ]
11
+ linux-kernel-module = { path = " ../.." }
12
+ serde = { version = " *" , default-features = false , features = [" derive" ] }
13
+ serde-json-core = { git = " https://github.com/japaric/serde-json-core" }
14
+ typenum = " *"
15
+
16
+ [patch .crates-io ]
17
+ byteorder = { path = " /root/byteorder" }
Original file line number Diff line number Diff line change
1
+ #![ no_std]
2
+ #![ feature( const_str_as_bytes) ]
3
+
4
+ use core:: sync:: atomic:: { AtomicBool , Ordering } ;
5
+
6
+ use serde:: Serialize ;
7
+ use serde_json_core;
8
+
9
+ use linux_kernel_module:: sysctl:: Sysctl ;
10
+ use linux_kernel_module:: Mode ;
11
+ use linux_kernel_module:: println;
12
+
13
+ struct JsonSysctlModule {
14
+ a : Sysctl < AtomicBool > ,
15
+ b : Sysctl < AtomicBool > ,
16
+ c : Sysctl < AtomicBool > ,
17
+ }
18
+
19
+ #[ derive( Serialize ) ]
20
+ struct Output {
21
+ a : bool ,
22
+ b : bool ,
23
+ c : bool ,
24
+ }
25
+
26
+ impl linux_kernel_module:: KernelModule for JsonSysctlModule {
27
+ fn init ( ) -> linux_kernel_module:: KernelResult < Self > {
28
+ Ok ( JsonSysctlModule {
29
+ a : Sysctl :: register (
30
+ "json-sysctl\x00 " ,
31
+ "a\x00 " ,
32
+ AtomicBool :: new ( false ) ,
33
+ Mode :: from_int ( 0o666 ) ,
34
+ ) ?,
35
+ b : Sysctl :: register (
36
+ "json-sysctl\x00 " ,
37
+ "b\x00 " ,
38
+ AtomicBool :: new ( false ) ,
39
+ Mode :: from_int ( 0o666 ) ,
40
+ ) ?,
41
+ c : Sysctl :: register (
42
+ "json-sysctl\x00 " ,
43
+ "c\x00 " ,
44
+ AtomicBool :: new ( false ) ,
45
+ Mode :: from_int ( 0o666 ) ,
46
+ ) ?,
47
+ } )
48
+ }
49
+ }
50
+
51
+ impl Drop for JsonSysctlModule {
52
+ fn drop ( & mut self ) {
53
+ let o = Output {
54
+ a : self . a . get ( ) . load ( Ordering :: Relaxed ) ,
55
+ b : self . b . get ( ) . load ( Ordering :: Relaxed ) ,
56
+ c : self . c . get ( ) . load ( Ordering :: Relaxed ) ,
57
+ } ;
58
+ println ! ( "{}" , serde_json_core:: to_string:: <typenum:: U32 , _>( & o) . unwrap( ) ) ;
59
+ }
60
+ }
61
+
62
+ linux_kernel_module:: kernel_module!(
63
+ JsonSysctlModule ,
64
+ author: "Alex Gaynor and Geoffrey Thomas" ,
65
+ description: "Use JSON serialization in kernelspace" ,
66
+ license: "GPL"
67
+ ) ;
You can’t perform that action at this time.
0 commit comments