AUPLUGIN_FGETS(3)

πŸ“¦
version 4.2.1 Β· 2 versions
, in arch rolling, centos-stream 10, fedora 43, fedora 44, nixpkgs unstable

✨ 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 it
  • MEM_MMAP β€” user-supplied mmap buffer; fgets munmaps it
  • MEM_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_fgets returns -1 on error, 0 when no data is available, or the number of characters copied otherwise.
  • auplugin_fgets_more and auplugin_fgets_eof return 1 for true and 0 for false.
  • auplugin_fgets_clear returns no value.
  • auplugin_setvbuf returns 0 on success and 1 on 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 πŸ‘‘πŸ’œ