-
Notifications
You must be signed in to change notification settings - Fork 1
/
fixedstruct.rs
6118 lines (5675 loc) · 243 KB
/
fixedstruct.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// src/data/fixedstruct.rs
//! Implement [`FixedStruct`] to represent Unix record-keeping C structs.
//! This includes [`acct`], [`lastlog`], [`lastlogx`],
//! [`utmp`], and [`utmpx`] formats for various operating systems and
//! architectures.
//!
//! [`acct`]: https://www.man7.org/linux/man-pages/man5/acct.5.html
//! [`lastlog`]: https://man7.org/linux/man-pages/man8/lastlog.8.html
//! [`lastlogx`]: https://man.netbsd.org/lastlogx.5
//! [`utmp`]: https://www.man7.org/linux/man-pages/man5/utmp.5.html
//! [`utmpx`]: https://man.netbsd.org/utmpx.5
#![allow(clippy::tabs_in_doc_comments)]
#[doc(hidden)]
use crate::{de_err, de_wrn, debug_panic};
#[doc(hidden)]
use crate::common::{
FileOffset,
FileSz,
FixedStructFileType,
max16,
min16,
};
use crate::data::datetime::{
DateTimeL,
FixedOffset,
LocalResult,
TimeZone,
};
use crate::readers::blockreader::{
BlockOffset,
BlockReader,
BlockSz,
};
use crate::readers::helpers::is_empty;
#[cfg(any(debug_assertions, test))]
use crate::debug::printers::byte_to_char_noraw;
use core::panic;
use std::collections::HashMap;
use std::ffi::CStr;
use std::fmt;
use std::io::{Error, ErrorKind};
#[allow(unused_imports)]
use ::more_asserts::{
assert_ge,
assert_gt,
assert_le,
assert_lt,
debug_assert_ge,
debug_assert_gt,
debug_assert_le,
debug_assert_lt,
};
use numtoa::NumToA; // adds `numtoa` method to numbers
#[allow(unused_imports)]
use ::si_trace_print::{defn, defo, defx, defñ, den, deo, dex, deñ};
use ::static_assertions::const_assert;
/// size of the `[u8]` buffer used for `numtoa` conversions
/// good up to `i64::MAX` or `i64::MIN` plus a little "just in case" head room
pub const NUMTOA_BUF_SZ: usize = 22;
/// A scoring system for the quality of the data in a [`FixedStruct`]. A higher score
/// means the data is more likely to be the [`FixedStructType`] expected.
pub type Score = i32;
/// Helper to [`FixedStructType::tv_pair_from_buffer`].
macro_rules! buffer_to_timeval {
($timeval_type:ty, $timeval_sz:expr, $buffer:ident, $tv_sec:ident, $tv_usec:ident) => ({{
// ut_tv
let size: usize = $timeval_sz;
defo!("size {:?}", size);
debug_assert_eq!($buffer.len(), size);
let time_val: $timeval_type = unsafe {
*($buffer.as_ptr() as *const $timeval_type)
};
// XXX: copy to local variable to avoid alignment warning
// see #82523 <https://github.com/rust-lang/rust/issues/82523>
let _tv_sec = time_val.tv_sec;
let _tv_usec = time_val.tv_usec;
defo!("time_val.tv_sec {:?} .tv_usec {:?}", _tv_sec, _tv_usec);
// ut_tv.tv_sec
$tv_sec = match time_val.tv_sec.try_into() {
Ok(val) => val,
Err(_) => {
debug_panic!("tv_sec overflow: {:?}", _tv_sec);
return None;
}
};
defo!("tv_sec {:?}", $tv_sec);
// ut_tv.tv_usec
$tv_usec = match time_val.tv_usec.try_into() {
Ok(val) => val,
Err(_) => {
debug_panic!("tv_usec overflow: {:?}", _tv_usec);
0
}
};
defo!("tv_usec {:?}", $tv_usec);
}})
}
macro_rules! buffer_to_time_t {
($ll_time_t:ty, $ll_time_sz:expr, $buffer:ident, $tv_sec:ident) => ({{
let size: usize = $ll_time_sz;
defo!("size {:?}", size);
debug_assert_eq!($buffer.len(), size);
let ll_time: $ll_time_t = unsafe {
*($buffer.as_ptr() as *const $ll_time_t)
};
defo!("ll_time {:?}", ll_time);
$tv_sec = match ll_time.try_into() {
Ok(val) => val,
Err(_) => {
debug_panic!("tv_sec overflow from ll_time {:?}", ll_time);
return None;
}
};
defo!("tv_sec {:?}", $tv_sec);
}})
}
/// Helper to [`FixedStructType::tv_pair_from_buffer`].
/// Debug print the `DateTimeL` conversion of a `tv_pair`.
macro_rules! defo_tv_pair {
($tv_sec:ident, $tv_usec:ident) => ({{
#[cfg(any(debug_assertions, test))]
{
let tz_offset: FixedOffset = FixedOffset::east_opt(0).unwrap();
let tv_pair = tv_pair_type($tv_sec, $tv_usec);
match convert_tvpair_to_datetime(tv_pair, &tz_offset) {
Ok(_dt) => {
defo!("dt: {:?}", _dt);
}
Err(err) => {
de_err!("{:?}", err);
panic!(
"convert_tvpair_to_datetime({:?}) returned an error; {}",
tv_pair, err
);
}
}
}
}})
}
/// FixedStruct Implementation Type (name `FixedStructType` is taken).
///
/// The specific implementation of the FixedStruct. Each implementation of,
/// for example, a `utmp` struct, differs in fields and sizes among Operating
/// Systems FreeBsd, Linux, OpenBSD, and NetBSD. and also differ per CPU
/// architecture, e.g. x86_64 vs. i386 vs. ARM7
#[allow(non_camel_case_types)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum FixedStructType {
// FreeBSD x86_64 (amd64), x86_32 (i686)
/// corresponds to [`freebsd_x8664::utmpx`]
#[allow(non_camel_case_types)]
Fs_Freebsd_x8664_Utmpx,
// Linux
// Linux ARM64 (aarch64)
/// corresponds to [`linux_arm64aarch64::lastlog`]
#[allow(non_camel_case_types)]
Fs_Linux_Arm64Aarch64_Lastlog,
/// corresponds to [`linux_arm64aarch64::utmpx`]
#[allow(non_camel_case_types)]
Fs_Linux_Arm64Aarch64_Utmpx,
// Linux x86
/// corresponds to [`linux_x86::acct`]
#[allow(non_camel_case_types)]
Fs_Linux_x86_Acct,
/// corresponds to [`linux_x86::acct_v3`]
#[allow(non_camel_case_types)]
Fs_Linux_x86_Acct_v3,
/// corresponds to [`linux_x86::lastlog`]
#[allow(non_camel_case_types)]
Fs_Linux_x86_Lastlog,
/// corresponds to [`linux_x86::utmpx`]
#[allow(non_camel_case_types)]
Fs_Linux_x86_Utmpx,
// NetBSD
// NetBSD 9 x86_32 (i686)
/// corresponds to [`netbsd_x8632::acct`]
#[allow(non_camel_case_types)]
Fs_Netbsd_x8632_Acct,
/// corresponds to [`netbsd_x8632::lastlogx`]
#[allow(non_camel_case_types)]
Fs_Netbsd_x8632_Lastlogx,
/// corresponds to [`netbsd_x8632::utmpx`]
#[allow(non_camel_case_types)]
Fs_Netbsd_x8632_Utmpx,
// NetBSD 9 x86_64 (AMD64)
/// corresponds to [`netbsd_x8664::lastlog`]
#[allow(non_camel_case_types)]
Fs_Netbsd_x8664_Lastlog,
/// corresponds to [`netbsd_x8664::lastlogx`]
#[allow(non_camel_case_types)]
Fs_Netbsd_x8664_Lastlogx,
/// corresponds to [`netbsd_x8664::utmp`]
#[allow(non_camel_case_types)]
Fs_Netbsd_x8664_Utmp,
/// corresponds to [`netbsd_x8664::utmpx`]
#[allow(non_camel_case_types)]
Fs_Netbsd_x8664_Utmpx,
// OpenBSD x86_32, x86_64
/// corresponds to [`openbsd_x86::lastlog`]
#[allow(non_camel_case_types)]
Fs_Openbsd_x86_Lastlog,
/// corresponds to [`openbsd_x86::utmp`]
#[allow(non_camel_case_types)]
Fs_Openbsd_x86_Utmp,
}
impl FixedStructType {
/// return the associated `FixedStructType`'s `SZ` value (size in bytes).
pub const fn size(&self) -> usize {
match self {
FixedStructType::Fs_Freebsd_x8664_Utmpx => freebsd_x8664::UTMPX_SZ,
FixedStructType::Fs_Linux_Arm64Aarch64_Lastlog => linux_arm64aarch64::LASTLOG_SZ,
FixedStructType::Fs_Linux_Arm64Aarch64_Utmpx => linux_arm64aarch64::UTMPX_SZ,
FixedStructType::Fs_Linux_x86_Acct => linux_x86::ACCT_SZ,
FixedStructType::Fs_Linux_x86_Acct_v3 => linux_x86::ACCT_V3_SZ,
FixedStructType::Fs_Linux_x86_Lastlog => linux_x86::LASTLOG_SZ,
FixedStructType::Fs_Linux_x86_Utmpx => linux_x86::UTMPX_SZ,
FixedStructType::Fs_Netbsd_x8632_Acct => netbsd_x8632::ACCT_SZ,
FixedStructType::Fs_Netbsd_x8632_Lastlogx => netbsd_x8632::LASTLOGX_SZ,
FixedStructType::Fs_Netbsd_x8632_Utmpx => netbsd_x8632::UTMPX_SZ,
FixedStructType::Fs_Netbsd_x8664_Lastlog => netbsd_x8664::LASTLOG_SZ,
FixedStructType::Fs_Netbsd_x8664_Lastlogx => netbsd_x8664::LASTLOGX_SZ,
FixedStructType::Fs_Netbsd_x8664_Utmp => netbsd_x8664::UTMP_SZ,
FixedStructType::Fs_Netbsd_x8664_Utmpx => netbsd_x8664::UTMPX_SZ,
FixedStructType::Fs_Openbsd_x86_Lastlog => openbsd_x86::LASTLOG_SZ,
FixedStructType::Fs_Openbsd_x86_Utmp => openbsd_x86::UTMP_SZ,
}
}
/// return the associated `FixedStructType`'s offset to it's ***t***ime
/// ***v***alue field
pub const fn offset_tv(&self) -> usize {
match self {
FixedStructType::Fs_Freebsd_x8664_Utmpx => freebsd_x8664::UTMPX_TIMEVALUE_OFFSET,
FixedStructType::Fs_Linux_Arm64Aarch64_Lastlog => linux_arm64aarch64::LASTLOG_TIMEVALUE_OFFSET,
FixedStructType::Fs_Linux_Arm64Aarch64_Utmpx => linux_arm64aarch64::UTMPX_TIMEVALUE_OFFSET,
FixedStructType::Fs_Linux_x86_Acct => linux_x86::ACCT_TIMEVALUE_OFFSET,
FixedStructType::Fs_Linux_x86_Acct_v3 => linux_x86::ACCT_V3_TIMEVALUE_OFFSET,
FixedStructType::Fs_Linux_x86_Lastlog => linux_x86::LASTLOG_TIMEVALUE_OFFSET,
FixedStructType::Fs_Linux_x86_Utmpx => linux_x86::UTMPX_TIMEVALUE_OFFSET,
FixedStructType::Fs_Netbsd_x8632_Acct => netbsd_x8632::ACCT_TIMEVALUE_OFFSET,
FixedStructType::Fs_Netbsd_x8632_Lastlogx => netbsd_x8632::LASTLOGX_TIMEVALUE_OFFSET,
FixedStructType::Fs_Netbsd_x8632_Utmpx => netbsd_x8632::UTMPX_TIMEVALUE_OFFSET,
FixedStructType::Fs_Netbsd_x8664_Lastlog => netbsd_x8664::LASTLOG_TIMEVALUE_OFFSET,
FixedStructType::Fs_Netbsd_x8664_Lastlogx => netbsd_x8664::LASTLOGX_TIMEVALUE_OFFSET,
FixedStructType::Fs_Netbsd_x8664_Utmp => netbsd_x8664::UTMP_TIMEVALUE_OFFSET,
FixedStructType::Fs_Netbsd_x8664_Utmpx => netbsd_x8664::UTMPX_TIMEVALUE_OFFSET,
FixedStructType::Fs_Openbsd_x86_Lastlog => openbsd_x86::LASTLOG_TIMEVALUE_OFFSET,
FixedStructType::Fs_Openbsd_x86_Utmp => openbsd_x86::UTMP_TIMEVALUE_OFFSET,
}
}
/// return the associated `FixedStructType`'s size of it's
/// ***t***ime ***v***alue in bytes
pub const fn size_tv(&self) -> usize {
match self {
FixedStructType::Fs_Freebsd_x8664_Utmpx => freebsd_x8664::UTMPX_TIMEVALUE_SZ,
FixedStructType::Fs_Linux_Arm64Aarch64_Lastlog => linux_arm64aarch64::LASTLOG_TIMEVALUE_SZ,
FixedStructType::Fs_Linux_Arm64Aarch64_Utmpx => linux_arm64aarch64::UTMPX_TIMEVALUE_SZ,
FixedStructType::Fs_Linux_x86_Acct => linux_x86::ACCT_TIMEVALUE_SZ,
FixedStructType::Fs_Linux_x86_Acct_v3 => linux_x86::ACCT_V3_TIMEVALUE_SZ,
FixedStructType::Fs_Linux_x86_Lastlog => linux_x86::LASTLOG_TIMEVALUE_SZ,
FixedStructType::Fs_Linux_x86_Utmpx => linux_x86::UTMPX_TIMEVALUE_SZ,
FixedStructType::Fs_Netbsd_x8632_Acct => netbsd_x8632::ACCT_TIMEVALUE_SZ,
FixedStructType::Fs_Netbsd_x8632_Lastlogx => netbsd_x8632::LASTLOGX_TIMEVALUE_SZ,
FixedStructType::Fs_Netbsd_x8632_Utmpx => netbsd_x8632::UTMPX_TIMEVALUE_SZ,
FixedStructType::Fs_Netbsd_x8664_Lastlog => netbsd_x8664::LASTLOG_TIMEVALUE_SZ,
FixedStructType::Fs_Netbsd_x8664_Lastlogx => netbsd_x8664::LASTLOGX_TIMEVALUE_SZ,
FixedStructType::Fs_Netbsd_x8664_Utmp => netbsd_x8664::UTMP_TIMEVALUE_SZ,
FixedStructType::Fs_Netbsd_x8664_Utmpx => netbsd_x8664::UTMPX_TIMEVALUE_SZ,
FixedStructType::Fs_Openbsd_x86_Lastlog => openbsd_x86::LASTLOG_TIMEVALUE_SZ,
FixedStructType::Fs_Openbsd_x86_Utmp => openbsd_x86::UTMP_TIMEVALUE_SZ,
}
}
/// the datetime field as a pair of seconds and microseconds taken from
/// raw bytes
pub fn tv_pair_from_buffer(&self, buffer: &[u8]) -> Option<tv_pair_type> {
defn!("type {:?}", self);
let tv_sec: tv_sec_type;
let tv_usec: tv_usec_type;
let size = self.size_tv();
match self {
FixedStructType::Fs_Freebsd_x8664_Utmpx => {
buffer_to_timeval!(freebsd_x8664::timeval, size, buffer, tv_sec, tv_usec);
defo_tv_pair!(tv_sec, tv_usec);
}
FixedStructType::Fs_Linux_Arm64Aarch64_Lastlog => {
buffer_to_time_t!(linux_arm64aarch64::ll_time_t, size, buffer, tv_sec);
tv_usec = 0;
defo_tv_pair!(tv_sec, tv_usec);
}
FixedStructType::Fs_Linux_Arm64Aarch64_Utmpx => {
buffer_to_timeval!(linux_arm64aarch64::timeval, size, buffer, tv_sec, tv_usec);
defo_tv_pair!(tv_sec, tv_usec);
}
FixedStructType::Fs_Linux_x86_Acct => {
buffer_to_time_t!(linux_x86::b_time_t, size, buffer, tv_sec);
tv_usec = 0;
defo_tv_pair!(tv_sec, tv_usec);
}
FixedStructType::Fs_Linux_x86_Acct_v3 => {
buffer_to_time_t!(linux_x86::b_time_t, size, buffer, tv_sec);
tv_usec = 0;
defo_tv_pair!(tv_sec, tv_usec);
}
FixedStructType::Fs_Linux_x86_Lastlog => {
buffer_to_time_t!(linux_x86::ll_time_t, size, buffer, tv_sec);
tv_usec = 0;
defo_tv_pair!(tv_sec, tv_usec);
}
FixedStructType::Fs_Linux_x86_Utmpx => {
buffer_to_timeval!(linux_x86::__timeval, size, buffer, tv_sec, tv_usec);
defo_tv_pair!(tv_sec, tv_usec);
}
FixedStructType::Fs_Netbsd_x8632_Acct => {
buffer_to_time_t!(netbsd_x8632::time_t, size, buffer, tv_sec);
tv_usec = 0;
defo_tv_pair!(tv_sec, tv_usec);
}
FixedStructType::Fs_Netbsd_x8632_Lastlogx => {
buffer_to_timeval!(netbsd_x8632::timeval, size, buffer, tv_sec, tv_usec);
defo_tv_pair!(tv_sec, tv_usec);
}
FixedStructType::Fs_Netbsd_x8632_Utmpx => {
buffer_to_timeval!(netbsd_x8632::timeval, size, buffer, tv_sec, tv_usec);
defo_tv_pair!(tv_sec, tv_usec);
}
FixedStructType::Fs_Netbsd_x8664_Lastlog => {
buffer_to_time_t!(netbsd_x8664::time_t, size, buffer, tv_sec);
tv_usec = 0;
defo_tv_pair!(tv_sec, tv_usec);
}
FixedStructType::Fs_Netbsd_x8664_Lastlogx => {
buffer_to_timeval!(netbsd_x8664::timeval, size, buffer, tv_sec, tv_usec);
defo_tv_pair!(tv_sec, tv_usec);
}
FixedStructType::Fs_Netbsd_x8664_Utmp => {
buffer_to_time_t!(netbsd_x8664::time_t, size, buffer, tv_sec);
tv_usec = 0;
defo_tv_pair!(tv_sec, tv_usec);
}
FixedStructType::Fs_Netbsd_x8664_Utmpx => {
buffer_to_timeval!(netbsd_x8664::timeval, size, buffer, tv_sec, tv_usec);
defo_tv_pair!(tv_sec, tv_usec);
}
FixedStructType::Fs_Openbsd_x86_Lastlog => {
buffer_to_time_t!(openbsd_x86::time_t, size, buffer, tv_sec);
tv_usec = 0;
defo_tv_pair!(tv_sec, tv_usec);
}
FixedStructType::Fs_Openbsd_x86_Utmp => {
buffer_to_time_t!(openbsd_x86::time_t, size, buffer, tv_sec);
tv_usec = 0;
defo_tv_pair!(tv_sec, tv_usec);
}
}
let tv_pair = tv_pair_type(tv_sec, tv_usec);
defx!("return Some({:?})", tv_pair);
Some(tv_pair)
}
}
// listing of specific FixedStruct implementations
// all listings should be in alphabetical order
// BUG: [2024/03/10] the `&CStr` wrappers do not protect against no
// null-termination in the underlying buffer.
// e.g. `freebsd_x8664::utmpx::ut_user()` may include the following field
// `freebsd_x8664::utmpx::ut_line`.
// This only affects debug printing and tests.
// freebsd_x8664
/// FixedStruct definitions found on FreeBSD 14.0 amd64 and FreeBSD 13.1 amd64
/// (x86_64).
#[allow(non_camel_case_types, unused)]
pub mod freebsd_x8664 {
use crate::common::FileOffset;
use std::ffi::CStr;
use std::mem::size_of;
use ::memoffset::offset_of;
use ::static_assertions::const_assert_eq;
pub type subseconds_t = std::ffi::c_longlong;
// XXX: use `i64` to satisfy various cross-compilation targets
pub type time_t = i64;
// utmpx
/// From [`/usr/include/sys/_timeval.h`]
///
/// ```C
/// struct timeval {
/// time_t tv_sec; /* seconds */
/// suseconds_t tv_usec; /* and microseconds */
/// };
/// ```
///
/// [`/usr/include/sys/_timeval.h`]: https://github.com/freebsd/freebsd-src/blob/release/12.4.0/sys/sys/_timeval.h#L46-L52
#[derive(Clone, Copy)]
#[repr(C, align(8))]
#[allow(non_camel_case_types)]
pub struct timeval {
pub tv_sec: time_t,
pub tv_usec: subseconds_t,
}
pub const TIMEVAL_SZ: usize = size_of::<timeval>();
const_assert_eq!(TIMEVAL_SZ, 16);
const_assert_eq!(offset_of!(timeval, tv_sec), 0);
const_assert_eq!(offset_of!(timeval, tv_usec), 8);
pub const UT_IDSIZE: usize = 8;
pub const UT_USERSIZE: usize = 32;
pub const UT_LINESIZE: usize = 16;
pub const UT_HOSTSIZE: usize = 128;
pub type c_char = std::ffi::c_char;
pub type c_short = std::ffi::c_short;
pub type c_ushort = std::ffi::c_ushort;
pub type pid_t = std::ffi::c_int;
/// From [`/usr/src/include/utmpx.h`] on FreeBSD 14.0 amd64
///
/// ```C
/// struct utmpx {
/// short ut_type; /* Type of entry. */
/// struct timeval ut_tv; /* Time entry was made. */
/// char ut_id[8]; /* Record identifier. */
/// pid_t ut_pid; /* Process ID. */
/// char ut_user[32]; /* User login name. */
/// char ut_line[16]; /* Device name. */
/// #if __BSD_VISIBLE
/// char ut_host[128]; /* Remote hostname. */
/// #else
/// char __ut_host[128];
/// #endif
/// char __ut_spare[64];
/// };
/// ```
///
/// Also see [FreeBSD 12.4 `utmpx.h`].
/// Also see [_Replacing utmp.h with utmpx.h_].
///
/// ---
///
///
/// ```text
/// timeval sizeof 16
/// timeval.tv_sec @ 0 sizeof 8
/// timeval.tv_usec @ 8 sizeof 8
///
/// utmpx sizeof 280
/// utmpx.ut_type @ 0 sizeof 2
/// utmpx.ut_tv @ 8 sizeof 16
/// utmpx.ut_tv.tv_sec @ 8 sizeof 8
/// utmpx.ut_tv.tv_usec@ 16 sizeof 8
/// utmpx.ut_id @ 24 sizeof 8
/// utmpx.ut_pid @ 32 sizeof 4
/// utmpx.ut_user @ 36 sizeof 32
/// utmpx.ut_line @ 68 sizeof 16
/// utmpx.ut_host @ 84 sizeof 128
/// ```
///
/// [`/usr/src/include/utmpx.h`]: https://cgit.freebsd.org/src/tree/include/utmpx.h?h=stable/14
/// [FreeBSD 12.4 `utmpx.h`]: https://github.com/freebsd/freebsd-src/blob/release/12.4.0/include/utmpx.h#L43-L56
/// [_Replacing utmp.h with utmpx.h_]: https://lists.freebsd.org/pipermail/freebsd-arch/2010-January/009816.html
#[derive(Clone, Copy)]
#[allow(non_camel_case_types)]
#[repr(C, align(8))]
pub struct utmpx {
pub ut_type: c_short,
pub __gap1: [u8; 6],
pub ut_tv: timeval,
pub ut_id: [c_char; UT_IDSIZE],
pub ut_pid: pid_t,
pub ut_user: [c_char; UT_USERSIZE],
pub ut_line: [c_char; UT_LINESIZE],
pub ut_host: [c_char; UT_HOSTSIZE],
pub __ut_spare: [c_char; 64],
}
pub const UTMPX_SZ: usize = size_of::<utmpx>();
pub const UTMPX_SZ_FO: FileOffset = UTMPX_SZ as FileOffset;
pub const UTMPX_TIMEVALUE_OFFSET: usize = offset_of!(utmpx, ut_tv);
pub const UTMPX_TIMEVALUE_SZ: usize = TIMEVAL_SZ;
pub const UTMPX_TIMEVALUE_OFFSET_TV_SEC: usize = UTMPX_TIMEVALUE_OFFSET + offset_of!(timeval, tv_sec);
pub const UTMPX_TIMEVALUE_OFFSET_TV_USEC: usize = UTMPX_TIMEVALUE_OFFSET + offset_of!(timeval, tv_usec);
const_assert_eq!(UTMPX_SZ, 280);
const_assert_eq!(offset_of!(utmpx, ut_type), 0);
const_assert_eq!(offset_of!(utmpx, __gap1), 2);
const_assert_eq!(offset_of!(utmpx, ut_tv), 8);
const_assert_eq!(offset_of!(utmpx, ut_id), 24);
const_assert_eq!(offset_of!(utmpx, ut_pid), 32);
const_assert_eq!(offset_of!(utmpx, ut_user), 36);
const_assert_eq!(offset_of!(utmpx, ut_line), 68);
const_assert_eq!(offset_of!(utmpx, ut_host), 84);
const_assert_eq!(offset_of!(utmpx, __ut_spare), 212);
/// Helpers for use in `fmt::Debug` trait.
impl utmpx {
pub fn ut_id(&self) -> &CStr {
unsafe { CStr::from_ptr(self.ut_id[..UT_IDSIZE].as_ptr()) }
}
pub fn ut_user(&self) -> &CStr {
unsafe { CStr::from_ptr(self.ut_user[..UT_USERSIZE].as_ptr()) }
}
pub fn ut_line(&self) -> &CStr {
unsafe { CStr::from_ptr(self.ut_line[..UT_LINESIZE].as_ptr()) }
}
pub fn ut_host(&self) -> &CStr {
unsafe { CStr::from_ptr(self.ut_host[..UT_HOSTSIZE].as_ptr()) }
}
}
/// From [`include/utmpx.h`], FreeBSD 12.4
/// ```C
/// #define EMPTY 0 /* No valid user accounting information. */
/// #define BOOT_TIME 1 /* Time of system boot. */
/// #define OLD_TIME 2 /* Time when system clock changed. */
/// #define NEW_TIME 3 /* Time after system clock changed. */
/// #define USER_PROCESS 4 /* A process. */
/// #define INIT_PROCESS 5 /* A process spawned by the init process. */
/// #define LOGIN_PROCESS 6 /* The session leader of a logged-in user. */
/// #define DEAD_PROCESS 7 /* A session leader who has exited. */
/// #if __BSD_VISIBLE
/// #define SHUTDOWN_TIME 8 /* Time of system shutdown. */
/// #endif
///
/// #if __BSD_VISIBLE
/// #define UTXDB_ACTIVE 0 /* Active login sessions. */
/// #define UTXDB_LASTLOGIN 1 /* Last login sessions. */
/// #define UTXDB_LOG 2 /* Log indexed by time. */
/// #endif
/// ```
///
/// [`include/utmpx.h`]: https://github.com/freebsd/freebsd-src/blob/release/12.4.0/include/utmpx.h#L58C1-L74C7
pub const UT_TYPES: [c_short; 9] = [
0, 1, 2, 3, 4, 5, 6, 7, 8
];
}
/// FixedStruct definitions found on Linux running on ARM64 (aarch64)
/// architecture.
#[allow(non_camel_case_types)]
pub mod linux_arm64aarch64 {
use crate::common::FileOffset;
use std::ffi::CStr;
use std::mem::size_of;
use ::static_assertions::const_assert_eq;
use ::memoffset::offset_of;
pub type c_char = std::ffi::c_char;
pub type c_short = std::ffi::c_short;
pub type ll_time_t = std::ffi::c_longlong;
pub type pid_t = std::ffi::c_int;
pub type suseconds_t = std::ffi::c_longlong;
// timeval
/// ```text
/// timeval sizeof 16
/// timeval.tv_sec @ 0 sizeof 8
/// timeval.tv_usec @ 8 sizeof 8
/// ```
#[derive(Clone, Copy)]
#[repr(C, align(8))]
#[allow(non_camel_case_types)]
pub struct timeval {
pub tv_sec: i64,
pub tv_usec: i64,
}
pub const TIMEVAL_SZ: usize = size_of::<timeval>();
const_assert_eq!(TIMEVAL_SZ, 16);
const_assert_eq!(offset_of!(timeval, tv_sec), 0);
const_assert_eq!(offset_of!(timeval, tv_usec), 8);
pub const UT_LINESIZE: usize = 32;
pub const UT_IDSIZE: usize = 4;
pub const UT_NAMESIZE: usize = 32;
pub const UT_USERSIZE: usize = 32;
pub const UT_HOSTSIZE: usize = 256;
// lastlog
/// ```text
/// lastlog sizeof 296
/// lastlog.ll_time @ 0 sizeof 8
/// lastlog.ll_line @ 8 sizeof 32
/// lastlog.ll_host @ 40 sizeof 256
/// ```
#[derive(Clone, Copy)]
#[repr(C, align(8))]
#[allow(non_camel_case_types)]
pub struct lastlog {
pub ll_time: ll_time_t,
pub ll_line: [c_char; UT_LINESIZE],
pub ll_host: [c_char; UT_HOSTSIZE],
}
impl lastlog {
pub fn ll_line(&self) -> &CStr {
unsafe { CStr::from_ptr(self.ll_line.as_ptr()) }
}
pub fn ll_host(&self) -> &CStr {
unsafe { CStr::from_ptr(self.ll_host.as_ptr()) }
}
}
pub const LASTLOG_SZ: usize = size_of::<lastlog>();
pub const LASTLOG_SZ_FO: FileOffset = LASTLOG_SZ as FileOffset;
pub const LASTLOG_TIMEVALUE_OFFSET: usize = offset_of!(lastlog, ll_time);
pub const LASTLOG_TIMEVALUE_SZ: usize = size_of::<ll_time_t>();
const_assert_eq!(LASTLOG_SZ, 296);
const_assert_eq!(offset_of!(lastlog, ll_time), 0);
const_assert_eq!(offset_of!(lastlog, ll_line), 8);
const_assert_eq!(offset_of!(lastlog, ll_host), 40);
// utmp == utmpx
/// From [`man utmpx`]
///
/// ```C
/// /* Values for ut_type field, below */
///
/// #define EMPTY 0 /* Record does not contain valid info
/// (formerly known as UT_UNKNOWN on Linux) */
/// #define RUN_LVL 1 /* Change in system run-level (see
/// init(8)) */
/// #define BOOT_TIME 2 /* Time of system boot (in ut_tv) */
/// #define NEW_TIME 3 /* Time after system clock change
/// (in ut_tv) */
/// #define OLD_TIME 4 /* Time before system clock change
/// (in ut_tv) */
/// #define INIT_PROCESS 5 /* Process spawned by init(8) */
/// #define LOGIN_PROCESS 6 /* Session leader process for user login */
/// #define USER_PROCESS 7 /* Normal process */
/// #define DEAD_PROCESS 8 /* Terminated process */
/// #define ACCOUNTING 9 /* Not implemented */
///
/// #define UT_LINESIZE 32
/// #define UT_NAMESIZE 32
/// #define UT_HOSTSIZE 256
///
/// struct exit_status { /* Type for ut_exit, below */
/// short int e_termination; /* Process termination status */
/// short int e_exit; /* Process exit status */
/// };
///
/// struct utmp {
/// short ut_type; /* Type of record */
/// pid_t ut_pid; /* PID of login process */
/// char ut_line[UT_LINESIZE]; /* Device name of tty - "/dev/" */
/// char ut_id[4]; /* Terminal name suffix,
/// or inittab(5) ID */
/// char ut_user[UT_NAMESIZE]; /* Username */
/// char ut_host[UT_HOSTSIZE]; /* Hostname for remote login, or
/// kernel version for run-level
/// messages */
/// struct exit_status ut_exit; /* Exit status of a process
/// marked as DEAD_PROCESS; not
/// used by Linux init(8) */
/// /* The ut_session and ut_tv fields must be the same size when
/// compiled 32- and 64-bit. This allows data files and shared
/// memory to be shared between 32- and 64-bit applications. */
/// #if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32
/// int32_t ut_session; /* Session ID (getsid(2)),
/// used for windowing */
/// struct {
/// int32_t tv_sec; /* Seconds */
/// int32_t tv_usec; /* Microseconds */
/// } ut_tv; /* Time entry was made */
/// #else
/// long ut_session; /* Session ID */
/// struct timeval ut_tv; /* Time entry was made */
/// #endif
///
/// int32_t ut_addr_v6[4]; /* Internet address of remote
/// host; IPv4 address uses
/// just ut_addr_v6[0] */
/// char __unused[20]; /* Reserved for future use */
/// };
///
/// /* Backward compatibility hacks */
/// #define ut_name ut_user
/// #ifndef _NO_UT_TIME
/// #define ut_time ut_tv.tv_sec
/// #endif
/// #define ut_xtime ut_tv.tv_sec
/// #define ut_addr ut_addr_v6[0]
/// ```
///
/// ---
///
/// ```text
/// utmpx sizeof 400
/// utmpx.ut_type @ 0 sizeof 2
/// utmpx.ut_pid @ 4 sizeof 4
/// utmpx.ut_line @ 8 sizeof 32
/// utmpx.ut_id @ 40 sizeof 4
/// utmpx.ut_user @ 44 sizeof 32
/// utmpx.ut_host @ 76 sizeof 256
/// utmpx.ut_exit @332 sizeof 4
/// utmpx.ut_session @336 sizeof 8
/// utmpx.ut_tv @344 sizeof 16
/// utmpx.ut_tv.tv_sec @344 sizeof 8
/// utmpx.ut_tv.tv_usec@352 sizeof 8
/// utmpx.ut_addr @360 sizeof 4
/// utmpx.ut_addr_v6 @360 sizeof 16
/// ```
///
/// [`man utmpx`]: https://linux.die.net/man/5/utmpx
#[derive(Clone, Copy)]
#[repr(C, align(4))]
#[allow(non_camel_case_types)]
pub struct utmpx {
pub ut_type: c_short,
pub ut_pid: pid_t,
pub ut_line: [c_char; UT_LINESIZE],
pub ut_id: [c_char; UT_IDSIZE],
pub ut_user: [c_char; UT_NAMESIZE],
pub ut_host: [c_char; UT_HOSTSIZE],
pub ut_exit: i32,
pub ut_session: i64,
pub ut_tv: timeval,
pub ut_addr_v6: [i32; 4],
pub __glibc_reserved: [c_char; 20],
}
impl utmpx {
pub fn ut_line(&self) -> &CStr {
unsafe { CStr::from_ptr(self.ut_line.as_ptr()) }
}
pub fn ut_id(&self) -> &CStr {
unsafe { CStr::from_ptr(self.ut_id.as_ptr()) }
}
pub fn ut_user(&self) -> &CStr {
unsafe { CStr::from_ptr(self.ut_user.as_ptr()) }
}
pub fn ut_host(&self) -> &CStr {
unsafe { CStr::from_ptr(self.ut_host.as_ptr()) }
}
}
pub const UTMPX_SZ: usize = size_of::<utmpx>();
pub const UTMPX_SZ_FO: FileOffset = UTMPX_SZ as FileOffset;
pub const UTMPX_TIMEVALUE_OFFSET: usize = offset_of!(utmpx, ut_tv);
pub const UTMPX_TIMEVALUE_SZ: usize = TIMEVAL_SZ;
const_assert_eq!(UTMPX_SZ, 400);
const_assert_eq!(offset_of!(utmpx, ut_type), 0);
const_assert_eq!(offset_of!(utmpx, ut_pid), 4);
const_assert_eq!(offset_of!(utmpx, ut_line), 8);
const_assert_eq!(offset_of!(utmpx, ut_id), 40);
const_assert_eq!(offset_of!(utmpx, ut_user), 44);
const_assert_eq!(offset_of!(utmpx, ut_host), 76);
const_assert_eq!(offset_of!(utmpx, ut_exit), 332);
const_assert_eq!(offset_of!(utmpx, ut_session), 336);
const_assert_eq!(offset_of!(utmpx, ut_tv), 344);
const_assert_eq!(offset_of!(utmpx, ut_addr_v6), 360);
const_assert_eq!(offset_of!(utmpx, __glibc_reserved), 376);
/// From [`utmpx.h`], Linux 6.1
/// ```C
/// #define EMPTY 0
/// #define RUN_LVL 1
/// #define BOOT_TIME 2
/// #define NEW_TIME 3
/// #define OLD_TIME 4
/// #define INIT_PROCESS 5
/// #define LOGIN_PROCESS 6
/// #define USER_PROCESS 7
/// #define DEAD_PROCESS 8
/// ```
///
/// [`utmpx.h`]: https://elixir.bootlin.com/musl/latest/source/include/utmpx.h
pub const UT_TYPES: [c_short; 9] = [
0, 1, 2, 3, 4, 5, 6, 7, 8
];
}
/// FixedStruct definitions found in `lastlog.h`, `utmp.h`, `utmpx.h`
/// from GNU glibc for Linux, architectures amd64 (x86_64), i686 (x86_32),
/// ARM6 (aarch64), and RISC-V (riscv64).
///
/// Found on Ubuntu 22.04 amd64 (x86_64) Linux 5.15, in files:
/// * `/usr/include/lastlog.h`
/// * `/usr/include/utmp.h`
/// * `/usr/include/utmpx.h`
/// * `/usr/include/x86_64-linux-gnu/bits/utmp.h`
/// * `/usr/include/x86_64-linux-gnu/bits/utmpx.h`
///
/// Confirmed the sizes and offsets are the same on:
/// * CentOS 7 amd64 (x86_64) Linux 3.10
/// * Ubuntu 16 i686 (x86_32) Linux 4.4
/// * Debian 11 ARM6 (aarch64) Linux 6.1
/// * Debian 13 RISC-V (riscv64) Linux 6.1
///
/// However, `struct timeval` differs on in size on x86_64/32 and ARM6. Yet the
/// `utmpx.ut_tv`, which is sometimes defined in-place and sometimes typed as a
/// `struct timeval` or `struct __timeval`, is the same size on both.
/// From the [code comment in `utmpx.h`]:
/// ```C
/// /* The fields ut_session and ut_tv must be the same size when compiled
/// 32- and 64-bit. This allows files and shared memory to be shared
/// between 32- and 64-bit applications. */
/// ```
///
/// The `utmp` struct is exactly the same as the `utmpx` struct except for a few
/// different names. This mod defines `utmpx` and not `utmp`.
///
/// [code comment in `utmpx.h`]: https://elixir.bootlin.com/glibc/latest/source/sysdeps/gnu/bits/utmpx.h
#[allow(non_camel_case_types)]
pub mod linux_x86 {
use crate::common::FileOffset;
use std::ffi::CStr;
use std::mem::size_of;
use ::memoffset::offset_of;
use ::static_assertions::const_assert_eq;
pub type b_time_t = std::ffi::c_uint;
pub type c_char = std::ffi::c_char;
pub type c_short = std::ffi::c_short;
pub type comp_t = std::ffi::c_ushort;
pub type ll_time_t = std::ffi::c_int;
pub type pid_t = std::ffi::c_int;
pub type suseconds_t = std::ffi::c_longlong;
pub type uint16_t = std::ffi::c_ushort;
pub const PATH_ACCT: &str = "/var/log/account/acct";
pub const PATH_PACCT: &str = "/var/log/account/pacct";
pub const ACCT_COMM: usize = 16;
pub const AFORK: c_char = 0x01;
pub const ASU: c_char = 0x02;
pub const ACOMPAT: c_char = 0x04;
pub const ACORE: c_char = 0x08;
pub const AXSIG: c_char = 0x10;
pub const AC_FLAGS_MASK: c_char = AFORK | ASU | ACOMPAT | ACORE | AXSIG;
/// from [`/usr/include/uapi/linux/acct.h`] on Ubuntu 22.04
///
/// [`/usr/include/uapi/linux/acct.h`]: https://github.com/torvalds/linux/blob/v5.15/include/uapi/linux/acct.h#L75-L101
///
/// ```C
/// struct acct
/// {
/// char ac_flag; /* Flags. */
/// uint16_t ac_uid; /* Real user ID. */
/// uint16_t ac_gid; /* Real group ID. */
/// uint16_t ac_tty; /* Controlling terminal. */
/// uint32_t ac_btime; /* Beginning time. */
/// comp_t ac_utime; /* User time. */
/// comp_t ac_stime; /* System time. */
/// comp_t ac_etime; /* Elapsed time. */
/// comp_t ac_mem; /* Average memory usage. */
/// comp_t ac_io; /* Chars transferred. */
/// comp_t ac_rw; /* Blocks read or written. */
/// comp_t ac_minflt; /* Minor pagefaults. */
/// comp_t ac_majflt; /* Major pagefaults. */
/// comp_t ac_swaps; /* Number of swaps. */
/// uint32_t ac_exitcode; /* Process exitcode. */
/// char ac_comm[ACCT_COMM+1]; /* Command name. */
/// char ac_pad[10]; /* Padding bytes. */
/// };
///
/// #define AFORK 0x01 /* ... executed fork, but did not exec */
/// #define ASU 0x02 /* ... used super-user privileges */
/// #define ACOMPAT 0x04 /* ... used compatibility mode (VAX only not used) */
/// #define ACORE 0x08 /* ... dumped core */
/// #define AXSIG 0x10 /* ... was killed by a signal */
/// ```
///
/// ---
///
/// ```text
/// acct sizeof 64
/// acct.ac_flag @ 0 sizeof 1
/// acct.ac_uid @ 2 sizeof 2
/// acct.ac_gid @ 4 sizeof 2
/// acct.ac_tty @ 6 sizeof 2
/// acct.ac_btime @ 8 sizeof 4
/// acct.ac_utime @ 12 sizeof 2
/// acct.ac_stime @ 14 sizeof 2
/// acct.ac_etime @ 16 sizeof 2
/// acct.ac_mem @ 18 sizeof 2
/// acct.ac_io @ 20 sizeof 2
/// acct.ac_rw @ 22 sizeof 2
/// acct.ac_exitcode@ 32 sizeof 4
/// acct.ac_comm @ 36 sizeof 17
/// ```
#[derive(Clone, Copy)]
#[repr(C, align(2))]
#[allow(non_camel_case_types)]
pub struct acct {
pub ac_flag: c_char,
pub ac_uid: uint16_t,
pub ac_gid: uint16_t,
pub ac_tty: uint16_t,
pub ac_btime: b_time_t,
pub ac_utime: comp_t,
pub ac_stime: comp_t,
pub ac_etime: comp_t,
pub ac_mem: comp_t,
pub ac_io: comp_t,
pub ac_rw: comp_t,
pub ac_minflt: comp_t,
pub ac_majflt: comp_t,
pub ac_swaps: comp_t,
pub ac_exitcode: u32,
pub ac_comm: [c_char; ACCT_COMM + 1],
pub ac_pad: [c_char; 10],
}
pub const ACCT_SZ: usize = size_of::<acct>();
pub const ACCT_SZ_FO: FileOffset = ACCT_SZ as FileOffset;
pub const ACCT_TIMEVALUE_OFFSET: usize = offset_of!(acct, ac_btime);
pub const ACCT_TIMEVALUE_SZ: usize = size_of::<b_time_t>();
const_assert_eq!(ACCT_SZ, 64);
const_assert_eq!(offset_of!(acct, ac_flag), 0);
const_assert_eq!(offset_of!(acct, ac_uid), 2);
const_assert_eq!(offset_of!(acct, ac_gid), 4);
const_assert_eq!(offset_of!(acct, ac_tty), 6);
const_assert_eq!(offset_of!(acct, ac_btime), 8);
const_assert_eq!(offset_of!(acct, ac_utime), 12);
const_assert_eq!(offset_of!(acct, ac_stime), 14);
const_assert_eq!(offset_of!(acct, ac_etime), 16);
const_assert_eq!(offset_of!(acct, ac_mem), 18);
const_assert_eq!(offset_of!(acct, ac_io), 20);
const_assert_eq!(offset_of!(acct, ac_rw), 22);
const_assert_eq!(offset_of!(acct, ac_minflt), 24);
const_assert_eq!(offset_of!(acct, ac_majflt), 26);
const_assert_eq!(offset_of!(acct, ac_swaps), 28);
const_assert_eq!(offset_of!(acct, ac_exitcode), 32);
const_assert_eq!(offset_of!(acct, ac_comm), 36);
const_assert_eq!(offset_of!(acct, ac_pad), 53);
impl acct {
pub fn ac_comm(&self) -> &CStr {
unsafe { CStr::from_ptr(self.ac_comm.as_ptr()) }
}
}
/// From [`/usr/include/uapi/linux/acct.h`] on Ubuntu 22.04
///
/// [`/usr/include/uapi/linux/acct.h`]: https://github.com/torvalds/linux/blob/v5.15/include/uapi/linux/acct.h#L75-L101
///
/// ```C
/// struct acct_v3
/// {
/// char ac_flag; /* Flags */
/// char ac_version; /* Always set to ACCT_VERSION */
/// __u16 ac_tty; /* Control Terminal */
/// __u32 ac_exitcode; /* Exitcode */
/// __u32 ac_uid; /* Real User ID */
/// __u32 ac_gid; /* Real Group ID */
/// __u32 ac_pid; /* Process ID */
/// __u32 ac_ppid; /* Parent Process ID */