X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Faudit.c;h=4701c0a8de856548d1eb7b8e0d31dd9304636872;hb=b5884878a2874447b2a9f07f324a7cd909d96d48;hp=f101050825384ff43e5b8e1f711dfc6c93f21e09;hpb=f841a154efbb3162d2a732936f031ac7a6b0d4cf;p=elogind.git diff --git a/src/shared/audit.c b/src/shared/audit.c index f10105082..4701c0a8d 100644 --- a/src/shared/audit.c +++ b/src/shared/audit.c @@ -80,3 +80,21 @@ int audit_loginuid_from_pid(pid_t pid, uid_t *uid) { *uid = (uid_t) u; return 0; } + +bool use_audit(void) { + static int cached_use = -1; + + if (cached_use < 0) { + int fd; + + fd = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_AUDIT); + if (fd < 0) + cached_use = errno != EAFNOSUPPORT && errno != EPROTONOSUPPORT; + else { + cached_use = true; + safe_close(fd); + } + } + + return cached_use; +}