AUPLUGIN_FGETS(3)
β¨ auplugin_fgets β the buffered line reader squad β¨
okay bestie, listen up π this is the Linux Audit API page for auplugin_fgets(3) and honestly? it's giving "we fixed a genuinely cursed problem" energy. these functions are your buffered line reader helpers β a whole little family of them, and you're gonna meet all of them, no cap.
πΈ NAME πΈ
auplugin_fgets, auplugin_fgets_more, auplugin_fgets_eof, auplugin_fgets_clear, auplugin_setvbuf, auplugin_setvbuf_r β buffered line reader helpers. yes that's six (6) icons in one friend group, and yes they all pull their weight π
π SYNOPSIS π
#include <auplugin.h>
int auplugin_fgets(char *buf, size_t blen, int fd);
int auplugin_fgets_more(size_t blen);
int auplugin_fgets_eof(void);
void auplugin_fgets_clear(void);
int auplugin_setvbuf(void *buf, size_t buff_size, enum auplugin_mem how);
int auplugin_setvbuf_r(auplugin_fgets_state_t *st, void *buf, size_t buff_size, enum auplugin_mem how);
π¦ DESCRIPTION π¦
auplugin_fgets reads from fd into buf up to blen bytes, or all the way through the next newline β whichever comes first, like it's not gonna overstay its welcome. here's the cute part: the text gets accumulated across calls in an internal buffer, so complete lines can actually be returned to you. and the string is NUL terminated, because of course it is, we're not monsters π«Ά
auplugin_fgets_more does a little vibe check π β it checks whether the buffer holds a newline or at least blen - 1 bytes.
auplugin_fgets_eof tells you whether end of file was reached on fd. that's it, that's the whole job, and it does it flawlessly π
auplugin_fgets_clear resets the internal buffer and the EOF state, discarding any stored text like it never happened π and here's the spicy detail: when the memory type is MEM_MMAP_FILE, the buffer gets rewound to the beginning, making the entire file available again. it's giving time travel honestly β
auplugin_setvbuf points the internal buffer at buf and sets how it will be released when auplugin_fgets_destroy is called. the how parameter should be one of these, bestie β memorize them:
MEM_SELF_MANAGEDβ internal buffer owned by fgets πMEM_MALLOCβ user-supplied malloc buffer; fgets frees itMEM_MMAPβ user-supplied mmap buffer; fgets munmaps itMEM_MMAP_FILEβ read-only mmap file data
the default is MEM_SELF_MANAGED, which means its lifecycle is automatically handled. you don't gotta do a thing, it's self-sufficient, main character energy β¨ when MEM_MMAP_FILE is used, the buffer is treated as a preloaded buffer (the entire file, yes, the whole thing) and no reads will be performed on the descriptor provided to auplugin_fgets_r. the reentrant form auplugin_setvbuf_r operates on an explicit state handle, for when you're feeling multi-threaded and fancy π§
β οΈ okay important warning time, no skipping: these functions maintain static state and are therefore not thread safe. for thread-safety, use the re-entrant variants. periodt. π
π RETURN VALUE π
auplugin_fgetsreturns-1on error,0when no data is available, or the number of characters copied otherwise.auplugin_fgets_moreandauplugin_fgets_eofreturn1for true and0for false.auplugin_fgets_clearreturns no value.auplugin_setvbufreturns0on success and1on failure.
π BACKGROUND π
okay so here's the lore, and it's actually iconic π
the reason this whole family of functions exists 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.
and here's where it goes wrong: 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. it's giving oil and water. it's giving incompatible situationship. π
this family of functions lets you correctly work only using descriptors, but with the convenience of fgets. best of both worlds, we ate and left no crumbs π
β SEE ALSO β
and that's the whole page, bestie β you're officially fluent in auplugin_fgets(3) π
this lil masterpiece came from Red Hat, dated June 2025 β go forth and read your lines responsibly ππ
π¦ where this page comes from
- arch rolling: audit 4.2.1-1 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- centos-stream 10: audit-libs-devel 4.2.1-3.el10 Β· LGPL-2.0-or-later
- fedora 43: audit-libs-devel 4.2.1-1.fc43 Β· LGPL-2.0-or-later
- fedora 43: audit-libs-devel 4.2.1-1.fc43 Β· LGPL-2.0-or-later
- fedora 44: audit-libs-devel 4.1.4-1.fc44 Β· LGPL-2.0-or-later
- fedora 44: audit-libs-devel 4.1.4-1.fc44 Β· LGPL-2.0-or-later
- fedora 44: audit-libs-devel 4.2.1-1.fc44 Β· LGPL-2.0-or-later
- fedora 44: audit-libs-devel 4.2.1-1.fc44 Β· LGPL-2.0-or-later
- nixpkgs unstable: audit 4.2.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms