Skip to content

kaisarcode/init.c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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/Flag Description
<name> <cmd> Register or replace a startup entry.
<name> -d, <name> --delete Remove a registration if it exists.
<name> -l, <name> --list List one registration if it exists.
-l, --list List all registrations as name<TAB>path.
<name> Execute the registered command immediately.
-h, --help Show help and usage.
-v, --version Show version.

Public API

#include "init.h"

kc_init_t *ctx = kc_init_open();

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);

Lifecycle

  • 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.

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

License

GPLv3

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

About

Persistent Startup Registration

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors