KLDUNLOAD(2)

✨ KLDUNLOAD β€” bestie's guide to yeeting kernel modules ✨

okay so real talk, this is the kldunload / kldunloadf manual page, and it's giving unload kld files energy πŸ’– if you're here, you're the kind of girl who loads a kernel module and then goes "…actually no" and that is VALID.


πŸ“š LIBRARY

Standard C Library (libc, -lc) πŸŽ€ like obviously, she lives in libc, that's her home.


✨ SYNOPSIS

#include <sys/param.h>
#include <sys/linker.h>

int
kldunload(int fileid);

int
kldunloadf(int fileid, int flags);

look at her. two little functions. so demure. so mindful. πŸ¦‹


πŸ’… DESCRIPTION

okay so the kldunload() system call unloads a kld file from the kernel that was previously linked via kldload(2). basically it's the "undo" button for modules, and no cap, we love a reversible decision 🫢

the kldunloadf() system call is the same girl but she takes an additional flags argument, and that flags can be one of these two:

  • LINKER_UNLOAD_NORMAL β€” gives you the exact same behavior as kldunload(), i.e. the classic. the OG. the default vibe. ✨
  • LINKER_UNLOAD_FORCE β€” this one causes the unload to ignore a failure to quiesce the module. yes bestie she said what she said, she's not waiting for the module to calm down, she's just leaving πŸ’€

🫢 RETURN VALUES

upon successful completion, the value 0 is returned. otherwise the value -1 is returned and the global variable errno is set to indicate the error. so like. 0 = slay, -1 = check errno, periodt. πŸ‘‘


😭 ERRORS

the file referred to by fileid is unloaded unless one of these happens (and if one happens, bestie, she is NOT unloading):

  • [EPERM] β€” you do not have access to unlink the file from the kernel. not your module, not your business πŸ™ˆ
  • [ENOENT] β€” the file was not found. she's not there. she never was. ghosted fr fr.
  • [EBUSY] β€” you attempted to unload a file linked by the kernel. nope. the kernel is holding on with both hands. πŸ’€
  • [EINVAL] β€” the kldunloadf() system call was passed invalid flags. you handed her something she doesn't recognize and she's judging you (gently, lovingly) πŸŽ€

πŸ‘€ SEE ALSO

kldfind(2), kldfirstmod(2), kldload(2), kldnext(2), kldstat(2), kldsym(2), modfind(2), modfnext(2), modnext(2), modstat(2), kld(4), kldunload(8) β€” the whole friend group, go say hi, they're all iconic in their own way 🌈


🌸 HISTORY

the kld interface first appeared in FreeBSD 3.0. she's a legacy queen and she's been serving since day one πŸ‘‘


πŸ’‘ friendly reminder bestie: unload responsibly. LINKER_UNLOAD_FORCE is right there and it does exactly what it sounds like it does.

and that's the whole page!! this came from the Debian edition, dated December 25, 2008 β€” a lil Christmas gift of a manpage 🎁 β€” and honestly? she ate. mwah. πŸ’…πŸ’–βœ¨

πŸ“¦ where this page comes from