Skip to content

Conversation

@MSScaleXiaohei
Copy link

Pull Request Description

Summary

This PR adds a new example chmodsnoop to the BCC project, demonstrating how to trace chmod() system calls using BCC and eBPF.

Changes

  • examples/tracing/chmodsnoop.py: Main example script that traces chmod() syscalls
  • examples/tracing/chmodsnoop_example.txt: Example usage documentation

Features

The example demonstrates:

  • Tracing system calls using kprobes/kretprobes
  • Extracting string arguments from user space
  • Filtering by PID (-p option)
  • Showing only failed calls (-x option)
  • Including timestamps (-T option)
  • Formatting file permissions (mode) in octal format

Example Usage

# Trace all chmod() syscalls
sudo ./chmodsnoop

# Include timestamps
sudo ./chmodsnoop -T

# Only show failed calls
sudo ./chmodsnoop -x

# Filter by PID
sudo ./chmodsnoop -p 181

Testing

The code follows the same pattern as other tracing examples (e.g., statsnoop, opensnoop) and has been checked for:

  • ✅ Code style compliance
  • ✅ No linter errors
  • ✅ Follows project conventions
  • ✅ Proper documentation

Type of Change

  • New example (examples directory)
  • Bug fix
  • Performance improvement
  • Documentation update

Checklist

  • Code follows project style guidelines
  • Code is properly commented
  • Example documentation included
  • No breaking changes
  • Tested locally (basic syntax check)

Note: This is a simple example for the examples directory, focusing on demonstrating BCC capabilities rather than production use.

Add a simple example demonstrating how to trace chmod() system calls
using BCC and eBPF. This example shows:
- Tracing system calls with kprobes/kretprobes
- Extracting string arguments from user space
- Filtering by PID
- Handling syscall errors
- Formatting file permissions

The example includes:
- chmodsnoop.py: Main example script
- chmodsnoop_example.txt: Example usage documentation

This follows the same pattern as other tracing examples like
statsnoop and opensnoop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant