File: auplugin_fgets.3

package info (click to toggle)
audit 1%3A4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,468 kB
  • sloc: ansic: 61,684; makefile: 1,664; python: 1,647; sh: 417; sed: 32
file content (87 lines) | stat: -rw-r--r-- 2,877 bytes parent folder | download
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
.TH "AUPLUGIN_FGETS" "3" "June 2025" "Red Hat" "Linux Audit API"
.SH NAME
auplugin_fgets, auplugin_fgets_more, auplugin_fgets_eof, auplugin_fgets_clear, auplugin_setvbuf, auplugin_setvbuf_r \- buffered line reader helpers
.SH SYNOPSIS
.B #include <auplugin.h>
.sp
.BI "int auplugin_fgets(char *" buf ", size_t " blen ", int " fd ");"
.br
.BI "int auplugin_fgets_more(size_t " blen ");"
.br
.BI "int auplugin_fgets_eof(void);"
.br
.B void auplugin_fgets_clear(void);
.br
.BI "int auplugin_setvbuf(void *" buf ", size_t buff_size, enum auplugin_mem " how ");"
.br
.BI "int auplugin_setvbuf_r(auplugin_fgets_state_t *" st ", void *" buf ", size_t buff_size, enum auplugin_mem " how ");"
.SH DESCRIPTION
.B auplugin_fgets
reads from
.I fd
into
.I buf
up to
.I blen
bytes or through the next newline. Text is accumulated across calls in an internal buffer so that complete lines can be returned. The string is NUL terminated.
.PP
.B auplugin_fgets_more
checks whether the buffer holds a newline or at least
.I blen - 1
bytes.
.PP
.B auplugin_fgets_eof
indicates whether end of file was reached on
.I fd
.
.PP
.B auplugin_fgets_clear
resets the internal buffer and EOF state, discarding any stored text. When the memory type is
.B MEM_MMAP_FILE
, the buffer is rewound to the beginning making the entire file available again.
.PP
.B auplugin_setvbuf
points the internal buffer at
.I buf
and sets how it will be released when
.B auplugin_fgets_destroy
is called. The
.I how
parameter should be one of
.B MEM_SELF_MANAGED,
.B MEM_MALLOC,
.B MEM_MMAP,
or
.B MEM_MMAP_FILE.
The default is
.B MEM_SELF_MANAGED
which means no action is taken on the memory block.
When
.B MEM_MMAP_FILE
is used, the buffer is treated as a preloaded buffer (the entire file) and no reads will be performed on the descriptor provided to
.BR auplugin_fgets_r .
The reentrant form
.B auplugin_setvbuf_r
operates on an explicit state handle.
.PP
These functions maintain static state and are therefore not thread safe.
.SH RETURN VALUE
.B auplugin_fgets
returns -1 on error, 0 when no data is available, or the number of characters copied otherwise.
.PP
.B auplugin_fgets_more
and
.B auplugin_fgets_eof
return 1 for true and 0 for false.
.PP
.B auplugin_fgets_clear
returns no value.
.PP
.B auplugin_setvbuf
returns 0 on success and 1 on failure.
.SH BACKGROUND
 The reason that this family of functions was created is because in  auditd plugins, the event stream is stdin, which is  descriptor 0.  A typical pattern is to call select, poll, or epoll to wait for a  record to arrive. As soon as it does, you need to read it. If you  use fgets, you will wind up with big problems because you cannot mix  low level descriptors with high level constructs like struct FILE.  This family of functions allows you to correctly work only using descriptors but with the convenience of fgets.

.SH SEE ALSO
.BR fgets (3)