tracefs_error_last(3) — Linux manual page

NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | EXAMPLE | FILES | SEE ALSO | AUTHOR | REPORTING BUGS | LICENSE | RESOURCES | COPYING | NOTES | COLOPHON

LIBTRACEFS(3)               libtracefs Manual              LIBTRACEFS(3)

NAME         top

       tracefs_error_last, tracefs_error_all, tracefs_error_clear -
       functions to read and clear the tracefs error log.

SYNOPSIS         top

       #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         top

       The tracefs_error_last() returns the last error message in the
       tracefs error log. Several actions that require proper syntax
       written into the tracefs file system may produce error messages
       in the error log. This function will show the most recent error
       in the error log.

       The tracefs_error_all() returns all messages saved in the error
       log. Note, this may not be all messages that were ever produced,
       as the kernel only keeps a limited amount of messages, and older
       ones may be discarded by the kernel.

       The tracefs_error_clear() will clear the error log.

RETURN VALUE         top

       Both tracefs_error_last() and tracefs_error_all() will return an
       allocated string an error exists in the log, otherwise NULL is
       returned. If an error occurs, errno will be set, otherwise if
       there is no error messages to display then errno is not touched.

       tracefs_error_clear() returns 0 on success or -1 on error.

EXAMPLE         top

           #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         top

           tracefs.h
                   Header file to include in order to have access to the library APIs.
           -ltracefs
                   Linker switch to add when building a program that uses the library.

SEE ALSO         top

       libtracefs(3), libtraceevent(3), trace-cmd(1)

AUTHOR         top

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

REPORTING BUGS         top

       Report bugs to <linux-trace-devel@vger.kernel.org[3]>

LICENSE         top

       libtracefs is Free Software licensed under the GNU LGPL 2.1

RESOURCES         top

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

COPYING         top

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

NOTES         top

        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

COLOPHON         top

       This page is part of the libtracefs (Linux kernel trace file
       system library) project.  Information about the project can be
       found at ⟨https://www.trace-cmd.org/⟩.  If you have a bug report
       for this manual page, see ⟨https://www.trace-cmd.org/⟩.  This
       page was obtained from the project's upstream Git repository
       ⟨https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git⟩ on
       2024-06-14.  (At that time, the date of the most recent commit
       that was found in the repository was 2024-05-17.)  If you
       discover any rendering problems in this HTML version of the page,
       or you believe there is a better or more up-to-date source for
       the page, or you have corrections or improvements to the
       information in this COLOPHON (which is not part of the original
       manual page), send a mail to man-pages@man7.org

libtracefs 1.7.0               12/22/2023                  LIBTRACEFS(3)

Pages that refer to this page: tracefs_dynevent_create(3)tracefs_kprobe_alloc(3)