KaisarCode

init.c

init.c - Persistent Startup Registration

init.c provides a small C library and CLI for registering named commands as persistent startup entries using only classic OS startup filesystem primitives. Applications can register a command under a name, execute it immediately, list registrations, and remove them.

On POSIX, init.c writes executable scripts to /etc/init.d/ and creates S99 symlinks in /etc/rc{2,3,4,5}.d/. On Windows, it creates .cmd launchers in the user Startup folder and optionally adds a HKCU\...\Run registry entry. Registration metadata is stored under ~/.local/share/init/ on Linux and %APPDATA%\init\ on Windows. The CLI is implemented on top of libinit.


CLI

Examples

Register a startup command:

init myapp /usr/local/bin/myapp --daemon

Execute the registered command immediately:

init myapp

List all registrations:

init --list

List one registration:

init myapp --list

Remove a registration:

init myapp --delete

Parameters

Command/FlagDescription
<name> <cmd>Register or replace a startup entry.
<name> -d, <name> --deleteRemove a registration if it exists.
<name> -l, <name> --listList one registration if it exists.
-l, --listList all registrations as name<TAB>path.
<name>Execute the registered command immediately.
-h, --helpShow help and usage.
-v, --versionShow version.

Public API

#include "init.h"

kc_init_options_t opts = kc_init_options_default();
kc_init_options_load_env(&opts);

kc_init_t *ctx = kc_init_open(&opts);

kc_init_update(ctx, "app", "/usr/local/bin/app --daemon");
kc_init_list(ctx, "app");
kc_init_exec(ctx, "app");
kc_init_delete(ctx, "app");

kc_init_close(ctx);
kc_init_options_free(&opts);

Lifecycle

  • kc_init_options_default() - creates default init options.
  • kc_init_options_load_env() - applies KC_INIT_* environment overrides.
  • kc_init_options_free() - releases option resources.
  • kc_init_open() - resolves metadata state and returns a context owned by the caller.
  • kc_init_update() - registers or replaces a named startup command.
  • kc_init_exec() - executes the registered command immediately.
  • kc_init_list() - lists all registrations or one named registration.
  • kc_init_delete() - removes a named registration and its startup artifacts.
  • kc_init_path() - returns the resolved metadata directory for diagnostics.
  • kc_init_close() - releases the context.

Environment

VariableDescription
KC_INIT_DIRMetadata directory path.
KC_INIT_BACKENDPOSIX backend override: systemd, runit, openrc, or sysv.

Notes

  • kc_init_update requires write access to /etc/init.d/ and /etc/rc*.d/ on Linux, which typically requires root.
  • kc_init_exec reads from the user metadata directory and does not require root.
  • No service managers, PID1 replacements, or external dependencies are used.

Build

Compiled artifacts are generated under bin/{arch}/{platform}/ for the host architecture running the build.

make clean && make

Multiarch Builds

The project is prepared to build artifacts for multiple architectures under bin/{arch}/{platform}/. A plain make builds only the current host architecture, while the targets below build the full matrix or a specific target.

make all
make x86_64/linux
make x86_64/windows
make i686/linux
make i686/windows
make aarch64/linux
make aarch64/android
make armv7/linux
make armv7/android
make armv7hf/linux
make riscv64/linux
make powerpc64le/linux
make mips/linux
make mipsel/linux
make mips64el/linux
make s390x/linux
make loongarch64/linux

Beta Notice

This is a beta project tested only on Debian x86_64. It was created out of a personal need for these libraries, but no guarantees are provided regarding its stability or future support. You are free to test it, use it, and modify it as you please.

If you'd like to reach out, you can send an email to [email protected]. Please note that I do not accept pull requests; the goal is to avoid long-term dependency on platforms like GitHub, and I do not maintain fixed infrastructure to guarantee long-term stability for these projects.


Repo

You can download the repository and read the most up-to-date documentation directly from its official source.

GitHub: kaisarcode/init.c

License

GPLv3

This project is distributed under the GNU General Public License version 3 (GPLv3).