LL2_READ_ALL(3)

πŸ’… LL2_READ_ALL(3) β€” like, the Programmers Manual page, but make it make sense ✨

okay bestie, gather round 🫢 this is ll2_read_all(3) from section 3 (that's the Programmers Manual, iykyk), and it's genuinely one of the cutest little functions in liblastlog2. you're gonna love her. no cap.


🌸 NAME 🌸

ll2_read_all β€” reads all the entries out of the database and hits up your callback function for each one. every single one. she does not skip. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <lastlog2.h> int ll2_read_all (struct ll2_context *context, int
(*callback)(const char *user, int64_t ll_time, const char *tty, const
char *rhost, const char *pam_service, const char *cb_error), char
**error);

like yes she's a long one, she's that girl, we respect her πŸ’–


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the vibe: ll2_read_all reads all the entries from the database that's defined in context, and calls the callback function callback for each entry. one by one. every time. 🎯

and bestie, if context is NULL? no stress β€” she'll just take the default database, the one defined in LL2_DEFAULT_DATABASE. slay. πŸ‘‘

here's the little example so you can see her in action, and yes i'm keeping it exactly as-is because she's iconic:

char  *error = NULL;
const char *user = "root";

static int
callback (const char *res_user, int64_t ll_time, const char *res_tty,
          const char *res_rhost, const char *res_service, const char *cb_error)
{
   /* returning != 0 if no further entry has to be handled by the callback */
   return 0;
}

int ret = ll2_read_all (NULL, callback, &error);
🫢 quick thing to notice in that comment up there: returning != 0 means no further entry has to be handled by the callback. so your return value is literally the "ok i'm done" button. main character energy.

⭐ RETURN VALUE ⭐

okay so what comes back:

  • 0 on success β€” we love a clean win πŸ’š
  • -ENOMEM β€” or -1 on other failure 😭

error contains an error string if the return value is -1. but heads up, bestie β€” error is not guaranteed to contain an error string, it could also be NULL. don't come for her, that's just how she is πŸ™ˆ

also: error should be freed by the caller. that's you. you're the caller. free it. 🧚

and one more lil detail that matters: if the lastlog2 database does not exist at all, the errno ENOENT is set and you can check for it. periodt. πŸ’€


πŸ‘‘ AUTHORS πŸ‘‘

Thorsten Kukuk <kukuk@suse.de> β€” the icon, the legend, the moment 🌟


🌈 SEE ALSO 🌈

go read these next, they're all friends of hers:


πŸ”₯ REPORTING BUGS πŸ”₯

found something sus? πŸ› for bug reports, use the issue tracker at <https://github.com/util-linux/util-linux/issues>. be nice to the maintainers, they're doing great πŸ’œ


πŸ“ AVAILABILITY πŸ“

the liblastlog2 library is part of the util-linux package since version 2.40. you can download it from the Linux Kernel Archive at <https://www.kernel.org/pub/linux/utils/util-linux/>. go get her ✨


and that's the whole page, bestie β€” this cutie is page LL2_READ_ALL(3), shipped as part of util-linux 2.41.6, dated 2026-08-31. mwah πŸ’‹ go read all the entries, you absolute legend πŸ«ΆπŸ’–

πŸ“¦ where this page comes from