tools/bpf/bpftool/tracelog.c
Source file repositories/reference/linux-study-clean/tools/bpf/bpftool/tracelog.c
File Facts
- System
- Linux kernel
- Corpus path
tools/bpf/bpftool/tracelog.c- Extension
.c- Size
- 3242 bytes
- Lines
- 160
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hlimits.hsignal.hstdio.hstring.hunistd.hlinux/magic.hfcntl.hsys/vfs.hmain.h
Detected Declarations
function validate_tracefs_mntfunction find_tracefs_mnt_singlefunction get_tracefs_pipefunction exit_tracelogfunction do_tracelog
Annotated Snippet
if (strcmp(type, fstype) == 0) {
found = true;
break;
}
fclose(fp);
/* The string from fscanf() might be truncated, check mnt is valid */
if (found && validate_tracefs_mnt(mnt, TRACEFS_MAGIC))
goto exit_found;
if (block_mount)
return false;
p_info("could not find tracefs, attempting to mount it now");
strcpy(mnt, known_mnts[0]);
if (mount_tracefs(mnt))
return false;
exit_found:
strcat(mnt, pipe_name);
return true;
}
static void exit_tracelog(int signum)
{
fclose(trace_pipe_fd);
free(buff);
if (json_output) {
jsonw_end_array(json_wtr);
jsonw_destroy(&json_wtr);
}
exit(0);
}
int do_tracelog(int argc, char **argv)
{
const struct sigaction act = {
.sa_handler = exit_tracelog
};
char trace_pipe[PATH_MAX];
size_t buff_len = 0;
if (json_output)
jsonw_start_array(json_wtr);
if (!get_tracefs_pipe(trace_pipe))
return -1;
trace_pipe_fd = fopen(trace_pipe, "r");
if (!trace_pipe_fd) {
p_err("could not open trace pipe: %s", strerror(errno));
return -1;
}
sigaction(SIGHUP, &act, NULL);
sigaction(SIGINT, &act, NULL);
sigaction(SIGTERM, &act, NULL);
while (1) {
ssize_t ret;
ret = getline(&buff, &buff_len, trace_pipe_fd);
if (ret <= 0) {
p_err("failed to read content from trace pipe: %s",
strerror(errno));
break;
}
if (json_output)
jsonw_string(json_wtr, buff);
else
printf("%s", buff);
}
fclose(trace_pipe_fd);
free(buff);
return -1;
}
Annotation
- Immediate include surface: `errno.h`, `limits.h`, `signal.h`, `stdio.h`, `string.h`, `unistd.h`, `linux/magic.h`, `fcntl.h`.
- Detected declarations: `function validate_tracefs_mnt`, `function find_tracefs_mnt_single`, `function get_tracefs_pipe`, `function exit_tracelog`, `function do_tracelog`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.