xref: /aosp_15_r20/external/libtracefs/Documentation/libtracefs-error.txt (revision 287e80b3a36113050663245e7f2c00d274188f18)
1libtracefs(3)
2=============
3
4NAME
5----
6tracefs_error_last, tracefs_error_all, tracefs_error_clear -
7functions to read and clear the tracefs error log.
8
9SYNOPSIS
10--------
11[verse]
12--
13*#include <tracefs.h>*
14
15char pass:[*]*tracefs_error_last*(struct tracefs_instance pass:[*]_instance_);
16char pass:[*]*tracefs_error_all*(struct tracefs_instance pass:[*]_instance_);
17int *tracefs_error_clear*(struct tracefs_instance pass:[*]_instance_);
18--
19
20DESCRIPTION
21-----------
22The *tracefs_error_last*() returns the last error message in the tracefs
23error log. Several actions that require proper syntax written into the
24tracefs file system may produce error messages in the error log. This
25function will show the most recent error in the error log.
26
27The *tracefs_error_all*() returns all messages saved in the error log.
28Note, this may not be all messages that were ever produced, as the kernel
29only keeps a limited amount of messages, and older ones may be discarded
30by the kernel.
31
32The *tracefs_error_clear*() will clear the error log.
33
34RETURN VALUE
35------------
36Both *tracefs_error_last*() and *tracefs_error_all*() will return an allocated
37string an error exists in the log, otherwise NULL is returned. If an error
38occurs, errno will be set, otherwise if there is no error messages to display
39then errno is not touched.
40
41*tracefs_error_clear*() returns 0 on success or -1 on error.
42
43EXAMPLE
44-------
45[source,c]
46--
47#include <stdlib.h>
48#include <unistd.h>
49#include <errno.h>
50
51#include <tracefs.h>
52
53int main (int argc, char **argv, char **env)
54{
55	struct tracefs_dynevent *kevent;
56	char *system = NULL;
57	char *kprobe;
58	char *format;
59	char *addr;
60	int arg = 1;
61	int ret;
62
63	if (argc < 4) {
64		printf("usage: %s [system] kprobe addr fmt\n", argv[0]);
65		exit(-1);
66	}
67
68	if (argc > 5)
69		system = argv[arg++];
70
71	kprobe = argv[arg++];
72	addr = argv[arg++];
73	format = argv[arg++];
74
75	tracefs_error_clear(NULL);
76	kevent = tracefs_dynevent_get(TRACEFS_DYNEVENT_KPROBE, system, kprobe);
77	if (kevent) {
78		tracefs_dynevent_destroy(kevent, true);
79		tracefs_dynevent_free(kevent);
80	}
81
82	ret = tracefs_kprobe_raw(system, kprobe, addr, format);
83	if (ret < 0) {
84		char *err;
85
86		perror("Failed creating kprobe");
87		errno = 0;
88		err = tracefs_error_last(NULL);
89		if (err)
90			fprintf(stderr, "%s\n", err);
91		else if (errno)
92			perror("Failed reading error log");
93		free(err);
94	}
95
96	exit(ret);
97}
98--
99FILES
100-----
101[verse]
102--
103*tracefs.h*
104	Header file to include in order to have access to the library APIs.
105*-ltracefs*
106	Linker switch to add when building a program that uses the library.
107--
108
109SEE ALSO
110--------
111*libtracefs*(3),
112*libtraceevent*(3),
113*trace-cmd*(1)
114
115AUTHOR
116------
117[verse]
118--
119*Steven Rostedt* <[email protected]>
120*Tzvetomir Stoyanov* <[email protected]>
121--
122REPORTING BUGS
123--------------
124Report bugs to  <[email protected]>
125
126LICENSE
127-------
128libtracefs is Free Software licensed under the GNU LGPL 2.1
129
130RESOURCES
131---------
132https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/
133
134COPYING
135-------
136Copyright \(C) 2020 VMware, Inc. Free use of this software is granted under
137the terms of the GNU Public License (GPL).
138