myxce/src/worker
Rongsong Shen 5df33e69d9
fix(worker): xcecd's fixed /tmp files never follow planted links (bug-1869)
xcecd runs as root and kept files at fixed names in world-writable /tmp,
opened by path:

- main.c created <logdir or /tmp>/xcecd_worker.log and then chmod(path,
  0666)'d it: a symlink planted there made root chmod 0666 any file
  (e.g. /etc/shadow).
- process_worker_manager.c appended xcecd_worker's stdout/stderr to
  /tmp/xcecd_worker.log through any planted symlink/hardlink.
- xcecd_prepare_restart() created /tmp/.xcecd.restarting through a
  dangling symlink (an empty root-owned file anywhere), and
  xcecd_check_restart_type() trusted access() on it, so any user could make
  an unplanned restart look planned.

xcecd_tmpfile.h:
- xcecd_open_owned_file(): reuses an existing file only if it is our own
  regular single-link file (so a legitimate log keeps being appended to);
  otherwise unlinks whatever is there and creates a fresh file with
  O_EXCL|O_NOFOLLOW. O_NONBLOCK so a planted FIFO cannot hang startup.
- xcecd_owned_file_exists(): lstat-based; only our own regular file counts
  as the restart flag. Anything else at the name is removed and ignored.
- The worker log's 0666 mode is now set with fchmod() on the fd.

New test_xcecd_tmpfile.c (7 tests; with the old behaviour the symlink,
dangling-symlink and hardlink cases FAIL and the FIFO case hangs);
worker suite 12/12. Sequential HA soak (5 rounds, xcecd_virtual) PASS.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 08:13:24 +00:00
..
include fix(worker): xcecd's fixed /tmp files never follow planted links (bug-1869) 2026-09-26 08:13:24 +00:00
scripts import worker code 2025-11-24 15:53:31 +08:00
src fix(worker): xcecd's fixed /tmp files never follow planted links (bug-1869) 2026-09-26 08:13:24 +00:00
testsuite fix(worker): xcecd's fixed /tmp files never follow planted links (bug-1869) 2026-09-26 08:13:24 +00:00
CLAUDE.md update documents 2026-08-10 17:51:51 +08:00
meson.build feat(worker-rejoin-resync): task 4.3 - wire query receipt and post-join gate 2026-09-01 18:01:03 +00:00
README.md import worker code 2025-11-24 15:53:31 +08:00

Cross-Platform Xcecd Process

This is a cross-platform process manager implementation in C that supports both Linux and Windows platforms. The xcecd provides the following features:

  • Sending status to the remote controller module at port 6789 and receive job requests
  • Maintains a configurable thread pool for request processing
  • Periodically collects and updates system resource status
  • Manages child processes spawned from received commands
  • Caches job status information
  • Uses Unix Domain Sockets for communication between the main process and worker processes

Building

Prerequisites

  • C compiler with C11 support
  • Windows: Visual Studio
  • Linux: GCC and development tools

Build Instructions

On Linux

make

On Windows

nmake

Configuration

The xcecd can be configured through the following parameters in main.c:

  • thread_pool_size: Number of threads in the thread pool (default: 4)
  • resource_update_interval: Interval for updating system resource status in seconds (default: 1)
  • job_status_update_interval: Interval for updating job status in seconds (default: 1)
  • port: Port number to listen on (default: 7869)
  • acct_file_path: Path to the accounting file (default: /tmp/xcecd.acct)
  • log_file_path: Path to the log file (default: /tmp/xcecd.log)
  • domain_sock_path: Path to the Unix Domain Socket file (default: /tmp/xcecd.sock)
  • remote_host: Remote server address (default: lchen02)
  • remote_port: Remote server port (default: 6789)
  • update_interval: Interval for sending status updates to the remote server (default: 1 second)

Usage

Starting the Xcecd

On Windows:

xcecd.exe

On Linux:

./xcecd

Features

  1. Cross-Platform Support

    • Works on both Windows and Linux
    • Abstracts platform-specific implementations
  2. Thread Pool

    • Configurable number of worker threads
    • Efficient request handling
  3. System Monitoring

    • CPU usage monitoring
    • Memory usage monitoring
    • Disk space monitoring
  4. Process Management

    • Spawns child processes for received commands
    • Tracks process status
    • Manages process lifecycle
  5. Network Communication

    • TCP socket-based communication
    • Simple text-based protocol
  6. Unix Domain Socket Communication

    • Uses Unix Domain Sockets for communication between the main process and worker processes

Architecture

The xcecd is composed of several key components:

  • Main Process: Coordinates all components and manages the lifecycle
  • Thread Pool: Handles concurrent request processing
  • System Monitor: Collects and updates system resource information
  • Process Manager: Manages child processes and their status
  • Network Handler: Handles network communication and request receiving
  • Resource Sync: Synchronizes and aggregates resource collection thread, system monitor, and job information

Contributing

Feel free to submit issues and enhancement requests!