Project 3: Socket-Activated Echo Server

A service that doesn’t run until someone connects to its port. systemd holds the socket, and when a connection arrives, systemd spawns your service and hands over the file descriptor.

Quick Reference

Attribute Value
Primary Language C
Alternative Languages Python, Rust, Go
Difficulty Level 2: Intermediate
Time Estimate Weekend
Knowledge Area Systems Programming / Networking
Tooling Systemd Socket Activation
Prerequisites Basic socket programming, C or any language with systemd bindings

What You Will Build

A service that doesn’t run until someone connects to its port. systemd holds the socket, and when a connection arrives, systemd spawns your service and hands over the file descriptor.

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Writing a .socket unit that defines the listening socket (maps to socket units)
  • Writing a matching .service that receives the socket (maps to unit relationships)
  • Using `sd_listen_fds()` or environment variables to receive passed FDs (maps to sd-daemon API)
  • Understanding the socket/service activation dance (maps to systemd architecture)

Key Concepts

  • Socket programming: “The Linux Programming Interface” Ch. 56-61 by Michael Kerrisk
  • File descriptor passing: “TCP/IP Sockets in C” Ch. 6 by Donahoo & Calvert
  • Socket activation: `man sd_listen_fds`, systemd.socket(5) man page

Real-World Outcome

Deliver a working demo with observable output that proves the feature is correct.


Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: SYSTEMD_LEARNING_PROJECTS.md
  • “The Linux Programming Interface” by Michael Kerrisk