First off, thank you for considering contributing to hwmonitor! It's people like you that make open source tools great.
This document provides a set of guidelines for contributing to the repository.
By participating in this project, you agree to maintain a respectful, inclusive, and harassment-free environment for everyone. Please be kind and professional in all interactions.
- A Linux environment (the tool relies heavily on Linux-specific filesystems like
sysfsandprocfs). gccandmakeinstalled.- Familiarity with C11.
- Fork the repository on GitHub.
- Clone your fork locally with submodules:
git clone --recursive https://github.com/your-username/hwmonitor.git
- Create a new branch for your feature or bug fix:
git checkout -b feature/my-new-feature
hwmonitor is built with extreme performance, modularity, and memory safety in mind. Please adhere to the following when writing code:
- No Shell Commands: Do not use
system(),popen(), or execute external binaries (likelspciordmidecode). All hardware discovery must be done by parsing standard Linux interfaces (/sys/,/proc/, etc.). - Modularity: Keep hardware logic separated. If you add a new hardware type (e.g.,
disk.c), ensure it has its own header and doesn't tightly couple with other hardware modules. - Minimal Dependencies: We aim to keep dependencies to an absolute minimum to maintain a tiny footprint. We currently use
cJSON(via git submodule) for serialization, andlibcurlfor AI network requests. Please discuss before adding any new system-wide dependencies. - Separation of Concerns: Keep hardware discovery logic in
src/linux/separate from external API integrations insrc/api/.
This project strongly adheres to the Linux kernel coding style conventions:
- Indentation: Use 2 spaces for indentation.
- Braces: Single-statement
if/for/whileblocks must not use braces.// Bad if (!ptr) { return -1; } // Good if (!ptr) return -1;
- Null Checks: Use
!ptrinstead ofptr == NULL. - Pointers: Bind the asterisk to the type, not the variable (e.g.,
char* str, notchar *str).
- This project has a zero-leak policy.
- Every allocated struct must have a corresponding deep-free function (e.g.,
free_cpu(),free_battery()). - Ensure all dynamically allocated strings inside structs are freed before the struct itself is freed.
- Test your changes: Run
make clean && makeand ensure the binary builds without errors or warnings. - Verify memory: Use tools like
valgrindto ensure your new features do not introduce memory leaks (test both standard and API paths).valgrind ./build/hwmonitor.o --all # and if testing AI features: valgrind ./build/hwmonitor.o --cpu --ai "Test prompt"
- Commit: Write clear, concise commit messages.
- Push: Push your branch to your fork.
- Pull Request: Open a Pull Request against the
masterbranch. Provide a detailed description of what your PR does and why it is necessary.
We look forward to reviewing your contributions!