LIBTRACEFS(3)

πŸ’– LIBTRACEFS(3) β€” the tracefs error log trilogy πŸ’–

okay so bestie, welcome to the libtracefs manual page, section 3 of your fave library docs 🫢 this one's all about the tracefs error log and the three little functions that let you peek at it and wipe it clean ✨


🌸 NAME 🌸

tracefs_error_last, tracefs_error_all, tracefs_error_clear β€” the trio of functions that read and clear the tracefs error log, periodt πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

like, here's the vibe in code form:

#include <tracefs.h>

char *tracefs_error_last(struct tracefs_instance *instance);
char *tracefs_error_all(struct tracefs_instance *instance);
int tracefs_error_clear(struct tracefs_instance *instance);

πŸ¦‹ DESCRIPTION πŸ¦‹

so tracefs_error_last() hands you back the last error message sitting in the tracefs error log πŸ’Œ ngl, a bunch of actions that need proper syntax written into the tracefs file system can produce error messages in that log β€” messy, ik β€” and this function shows you the most recent one. main character of the error log, honestly πŸ‘‘

then there's tracefs_error_all(), which returns all the messages saved in the error log πŸ—‚οΈ but bestie, heads up β€” this may not be every message that was ever produced, because the kernel only keeps a limited amount of messages and older ones may get discarded by the kernel 😭 so it's giving "what's still in the group chat, not the whole history."

and tracefs_error_clear()? yeah, that one just clears the error log. poof, gone, clean slate ✨🧼


⭐ RETURN VALUE ⭐

both tracefs_error_last() and tracefs_error_all() will return an allocated string when an error exists in the log β€” otherwise you get NULL, no cap πŸ™ˆ and if an error occurs, errno will be set; but if there are no error messages to display, then errno is not touched. leave her alone fr πŸ’…

tracefs_error_clear() returns 0 on success or -1 on error. simple as that πŸŽ€


πŸ”₯ EXAMPLE πŸ”₯

here's the whole example, verbatim, because we do not play with code around here:

#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

#include <tracefs.h>

int main (int argc, char **argv, char **env)
{
        struct tracefs_dynevent *kevent;
        char *system = NULL;
        char *kprobe;
        char *format;
        char *addr;
        int arg = 1;
        int ret;

        if (argc < 4) {
                printf("usage: %s [system] kprobe addr fmt\n", argv[0]);
                exit(-1);
        }

        if (argc > 5)
                system = argv[arg++];

        kprobe = argv[arg++];
        addr = argv[arg++];
        format = argv[arg++];

        tracefs_error_clear(NULL);
        kevent = tracefs_dynevent_get(TRACEFS_DYNEVENT_KPROBE, system, kprobe);
        if (kevent) {
                tracefs_dynevent_destroy(kevent, true);
                tracefs_dynevent_free(kevent);
        }

        ret = tracefs_kprobe_raw(system, kprobe, addr, format);
        if (ret < 0) {
                char *err;

                perror("Failed creating kprobe");
                errno = 0;
                err = tracefs_error_last(NULL);
                if (err)
                        fprintf(stderr, "%s\n", err);
                else if (errno)
                        perror("Failed reading error log");
                free(err);
        }

        exit(ret);
}

🌈 FILES 🌈

  • tracefs.h β€” the header file you include so you can have access to the library APIs 🫢
  • -ltracefs β€” the linker switch you add when building a program that uses the library πŸ”§

πŸ’œ SEE ALSO πŸ’œ

libtracefs(3), libtraceevent(3), trace-cmd(1) β€” go read those too, iykyk πŸ“šβœ¨


πŸ‘‘ AUTHOR πŸ‘‘

  • Steven Rostedt <rostedt@goodmis.org[1]>
  • Tzvetomir Stoyanov <tz.stoyanov@gmail.com[2]>

πŸ™ˆ REPORTING BUGS πŸ™ˆ

report bugs to <linux-trace-devel@vger.kernel.org[3]> β€” they wanna hear from you fr πŸ“¬


🧚 LICENSE 🧚

libtracefs is Free Software licensed under the GNU LGPL 2.1 βš–οΈ slay


πŸ“ RESOURCES πŸ“

https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/


πŸ’€ COPYING πŸ’€

Copyright (C) 2020 VMware, Inc. Free use of this software is granted under the terms of the GNU Public License (GPL). πŸ“œ


🌸 NOTES 🌸

  1. rostedt@goodmis.org mailto:rostedt@goodmis.org
  2. tz.stoyanov@gmail.com mailto:tz.stoyanov@gmail.com
  3. linux-trace-devel@vger.kernel.org mailto:linux-trace-devel@vger.kernel.org

aaaand that's the whole page bestie πŸ’– this was libtracefs 1.8.4, dated 10/21/2026, section 3 of the manual β€” go forth and debug your tracefs errors like the icon you are πŸŽ€βœ¨πŸ’…

πŸ“¦ where this page comes from