Thank you for your interest in contributing to systemd-netlogd! This document provides guidelines and instructions for contributing to the project.
- Code of Conduct
- Getting Started
- Development Setup
- Making Changes
- Coding Standards
- Testing
- Submitting Changes
- Review Process
This project follows the systemd Code of Conduct. Please be respectful and constructive in all interactions.
- C compiler (GCC or Clang)
- systemd development libraries (>= 230)
- meson build system (>= 0.51)
- pkg-config
- gperf
- libcap development libraries
- OpenSSL development libraries (>= 1.1.0)
- cmocka (for testing)
-
Fork and Clone
git clone https://github.com/YOUR-USERNAME/systemd-netlogd.git cd systemd-netlogd -
Add Upstream Remote
git remote add upstream https://github.com/systemd/systemd-netlogd.git
-
Install Dependencies
Fedora/RHEL/CentOS:
sudo dnf install gcc meson pkg-config gperf libcap-devel systemd-devel \ openssl-devel libcmocka-devel python3-sphinxDebian/Ubuntu:
sudo apt install build-essential meson pkg-config gperf libcap-dev \ libsystemd-dev libssl-dev libcmocka-dev python3-sphinx -
Build the Project
meson setup build meson compile -C build
-
Run Tests
meson test -C build -v
Configure the build with custom options:
# Debug build
meson setup build --buildtype=debug
# Release build with optimizations
meson setup build --buildtype=release
# Custom installation prefix
meson setup build --prefix=/usr
# Disable OpenSSL (no TLS/DTLS support)
meson setup build -Dopenssl=disabledrm -rf build/
meson setup build- Check Existing Issues: Look for existing issues or discussions related to your change
- Create an Issue: For significant changes, create an issue first to discuss the approach
- Create a Branch: Use descriptive branch names
git checkout -b feature/add-compression-support
git checkout -b fix/connection-retry-bug
git checkout -b docs/improve-tls-examplesWe welcome:
- Bug fixes: Fix incorrect behavior or crashes
- Features: Add new functionality (discuss in issue first)
- Documentation: Improve or add documentation
- Tests: Add test coverage
- Performance: Optimize existing code
- Code cleanup: Refactoring without behavior changes
This project follows systemd coding conventions:
-
Indentation: 8 spaces (no tabs)
-
Line Length: Maximum 109 characters
-
Braces: K&R style
if (condition) { /* code */ } else { /* code */ }
-
Variable Names: snake_case
int connection_retry_count; Manager *manager;
-
Function Names: snake_case
int manager_connect(Manager *m); void tls_disconnect(TLSManager *m);
-
Constants: UPPER_CASE
#define DEFAULT_CONNECTION_RETRY_USEC (30 * USEC_PER_SEC)
-
Header Guards: Use
#pragma once -
Includes Order:
- System headers
- Library headers
- Local headers
#include <stdio.h> #include <systemd/sd-journal.h> #include "netlog-manager.h"
-
SPDX License: Every file must start with:
/* SPDX-License-Identifier: LGPL-2.1-or-later */ -
Function Documentation: Document complex functions
/* Connects to the remote syslog server * Returns: 0 on success, negative errno on failure */ int manager_connect(Manager *m);
-
Use negative errno values for errors
if (fd < 0) return log_error_errno(errno, "Failed to open socket: %m");
-
Use cleanup macros for resource management
_cleanup_free_ char *buffer = NULL; _cleanup_close_ int fd = -1;
-
Check all allocations
m = new(Manager, 1); if (!m) return log_oom();
- Use cleanup functions when possible
- Initialize pointers to NULL
- Use TAKE_PTR() for ownership transfer
- Free resources in reverse allocation order
Use appropriate log levels:
log_debug("Connection attempt to %s", address);
log_info("Network configuration changed");
log_warning("Certificate validation disabled");
log_error("Failed to connect to remote server");# Run all tests
meson test -C build -v
# Run specific test
meson test -C build test-protocol -v
# Run tests with address sanitizer
meson setup build -Db_sanitize=address
meson test -C build -v- Use cmocka framework
- Test file naming:
test-<module>.c - Test function naming:
test_<feature>()
Example test structure:
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
static void test_my_feature(void **state) {
int result = my_function();
assert_int_equal(result, EXPECTED_VALUE);
}
int main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_my_feature),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}Aim for:
- All new functions should have tests
- Edge cases and error conditions
- Protocol compliance (RFC 5424, RFC 3339)
Follow the Conventional Commits format:
<type>: <short description>
<detailed description>
<footer>
Types:
feat: New featurefix: Bug fixdocs: Documentation changestest: Adding or updating testsrefactor: Code refactoringperf: Performance improvementschore: Build system, dependencies
Example:
feat: Add exponential backoff for connection retries
Implements exponential backoff starting at 1s and capping at 5min
to better handle temporary network outages. This reduces load on
failing servers while maintaining responsiveness.
Fixes #42
- Code follows style guidelines
- Tests pass locally
- New tests added for new functionality
- Documentation updated if needed
- Commit message is clear and descriptive
- No compiler warnings
- License headers present
-
Update your branch
git fetch upstream git rebase upstream/main
-
Push to your fork
git push origin feature/my-feature
-
Create Pull Request
- Use a clear, descriptive title
- Reference related issues
- Describe what changed and why
- Include test results if applicable
-
PR Template
## Description Brief description of changes ## Motivation Why is this change needed? ## Changes - List of changes ## Testing How was this tested? ## Checklist - [ ] Tests pass - [ ] Documentation updated - [ ] Follows coding standards
- Initial Review: Maintainers review within a few days
- Feedback: Suggestions for improvements
- Iteration: Make requested changes
- Approval: At least one maintainer approval required
- Merge: Maintainer will merge approved PRs
- Be open to suggestions
- Ask for clarification if needed
- Make requested changes in new commits (don't force push during review)
- Mark conversations as resolved when addressed
Reviewers check for:
- Correctness and functionality
- Code quality and style
- Test coverage
- Documentation
- Performance implications
- Security considerations
- Backward compatibility
# Run with debug logging
SYSTEMD_LOG_LEVEL=debug ./build/systemd-netlogd
# Use GDB
gdb --args ./build/systemd-netlogd
# Check for memory leaks
valgrind --leak-check=full ./build/systemd-netlogd# Enable compiler warnings
meson setup build -Dwarning_level=3
# Use clang-tidy
clang-tidy src/netlog/*.c# Profile with perf
perf record -g ./build/systemd-netlogd
perf report- systemd Coding Style
- RFC 5424 - Syslog Protocol
- RFC 3339 - Date and Time on the Internet
- systemd Journal API
- Issues: Create an issue for bugs or feature requests
- Discussions: Use GitHub Discussions for questions
- IRC: #systemd on irc.libera.chat (for systemd-related questions)
Contributors are listed in the project's commit history. Significant contributions will be acknowledged in release notes.
Thank you for contributing to systemd-netlogd!