KEYCTL_SET_TIMEOUT(2const)

✨ KEYCTL_SET_TIMEOUT ✨

okay so bestie, we're in the Linux manual pages, section 2const (that's the const-y corner of syscalls), and today's hyperfixation is KEYCTL_SET_TIMEOUT β€” literally just set the expiration timer on a key. putting an alarm clock on your key. giving it a bedtime. iconic behavior honestly πŸŽ€


πŸ“š LIBRARY

Standard C library (libc, -lc) β€” the classic, the blueprint, the moment πŸ’…


πŸ¦‹ SYNOPSIS

#include <linux/keyctl.h>  /* Definition of KEY* constants */
#include <sys/syscall.h>   /* Definition of SYS_* constants */
#include <unistd.h>

long syscall(SYS_keyctl, KEYCTL_SET_TIMEOUT, key_serial_t key, time_t t);

like yes we're doing the raw syscall dance, no shame in it 🫢


πŸ’– DESCRIPTION

So. You set a timeout on a key. That's the whole vibe. Let's break it down fr fr.

  • The ID of the key goes in key.
  • The timeout value, counted in seconds from the current time, goes in t.
  • The timeout is measured against the realtime clock ⏰ β€” so yes, the wall-clock one, the one that jumps when your laptop syncs time, that one.

Now the fun part: if you pass the timeout value as 0, it clears any existing timeout on the key. poof. gone. not a timeout anymore, it's a free spirit 🌈

Wanna know how much time a key has left? The /proc/keys file displays the remaining time until each key will expire. and lowkey that's the only method of discovering the timeout on a key β€” there is no other way bestie, that's the whole pipeline πŸ‘‘

Permission check moment: the caller must either have the setattr permission on the key or hold an instantiation authorization token for the key (see request_key(2)). no permission, no timer, no service πŸ’€

Once that timeout expires, the key and any links to the key will be automatically garbage collected. like, swept up. and then any subsequent attempts to access the key will fail with the error EKEYEXPIRED. it's giving ghosted 😭

⚠️ HEADS UP: this operation cannot be used to set timeouts on revoked, expired, or negatively instantiated keys. not happening. do not try it. the key said no βœ‹

πŸ”₯ RETURN VALUE

  • On success, 0 is returned. slay ✨
  • On error, -1 is returned, and errno is set to indicate the error. rude but informative πŸ™ˆ

🌸 VERSIONS

A wrapper is provided in the libkeyutils library: keyctl_set_timeout(3). so if you'd rather not raw-dog the syscall, there's a whole library waiting for you πŸ’œ


πŸ‘‘ STANDARDS

Linux. (obviously. we're built different here.)


⭐ HISTORY

Linux 2.6.16. vintage but still ate πŸ’…


πŸŽ€ SEE ALSO


mwah πŸ’‹ that's the page, bestie β€” go forth and schedule your keys' little deaths. source vibes: Linux man-pages 6.20, dated 2026-02-08, from the KEYCTL_SET_TIMEOUT(2const) page itself. no cap, every word was already there. I just made it cute. πŸ¦‹

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms