Crinit -- Configurable Rootfs Init
crinit-ctl.c File Reference

(2023-08-02, commit: 9434b31)

Implementation of the crinit-ctl service program using the crinit-client library. More...

#include <getopt.h>
#include <libgen.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "common.h"
#include "crinit-client.h"
#include "logio.h"
#include "version.h"
Include dependency graph for crinit-ctl.c:

Functions

static void crinitPrintUsage (char *prgmPath)
 
static void crinitPrintVersion (void)
 
static const char * crinitTaskStateToStr (crinitTaskState_t s)
 
int main (int argc, char *argv[])
 

Detailed Description

Implementation of the crinit-ctl service program using the crinit-client library.

Example implementation of the machine-id-gen service program.

Program usage info:

USAGE: crinit-ctl <ACTION> [OPTIONS] <PARAMETER> [PARAMETERS...]
where ACTION must be exactly one of (including specific options/parameters):
addtask [-f/--overwrite] [-i/--ignore-deps] [-d/--override-deps "depA:eventA depB:eventB [...]"] <PATH>
- Will add a task defined in the task configuration file at <PATH> (absolute) to Crinit's task database.
'-f/--overwrite' - Lets Crinit know it is fine to overwrite if it has already loaded a task
with the same name.
'-d/--override-deps <dependency-list>' - Will override the DEPENDS field of the config file
with what is given as the parameter.
'-i/--ignore-deps' - Shortcut for '--override-deps ""'.
addseries [-f/--overwrite] <PATH>
- Will load a series file from <PATH>. Options set in the new series file take precedence over
current settings.
'-f/--overwrite' - Lets Crinit know it is fine to overwrite if it has already loaded tasks
with the same name as those in the new series file.
enable <TASK_NAME>
- Removes dependency '@ctl:enable' from the dependency list of <TASK_NAME> if it is present.
disable <TASK_NAME>
- Adds dependency '@ctl:enable' to the dependency list of <TASK_NAME>.
stop <TASK_NAME>
- Sends SIGTERM to the PID of <TASK_NAME> if the PID is currently known.
kill <TASK_NAME>
- Sends SIGKILL to the PID of <TASK_NAME> if the PID is currently known.
restart <TASK_NAME>
- Resets the status bits of <TASK_NAME> if it is DONE or FAILED.
status <TASK_NAME>
- Queries status bits and PID of <TASK_NAME>.
notify <TASK_NAME> <"SD_NOTIFY_STRING">
- Will send an sd_notify-style status report to Crinit. Only MAINPID and READY are
implemented. See the sd_notify documentation for their meaning.
list
- Print the list of loaded tasks and their status.
reboot
- Will request Crinit to perform a graceful system reboot. crinit-ctl can be symlinked to
reboot as a shortcut which will invoke this command automatically.
poweroff
- Will request Crinit to perform a graceful system shutdown. crinit-ctl can be symlinked to
poweroff as a shortcut which will invoke this command automatically.
General Options:
--verbose/-v - Be verbose.
--help/-h - Print this help.
--version/-V - Print version information about crinit-ctl, the crinit-client library,
and -- if connection is successful -- the crinit daemon.

In a production system, the implementation is customer-defined to offer flexibility. The general requirement for this program is to write a system-unique identifier (in any format, i.e. unique arbitrary data) to /etc/machine-id. The identifier shall not have a random component as it may not be persisted to disk (in order to support read-only file- systems).

Program usage info:

This program shall be called without additional arguments through a Crinit task. It will generate an appropriate
/etc/machine-id file if it is either run on S32G or the Kernel command line contains a value for systemd.machine_id.
The latter will take precedence over the S32G ROM serial number if set.

Function Documentation

◆ crinitPrintUsage()

static void crinitPrintUsage ( char *  prgmPath)
static

Print usage information.

Parameters
prgmPathThe path to the program, usually found in argv[0].

◆ crinitPrintVersion()

static void crinitPrintVersion ( void  )
static

Prints a message indicating the versions of crinit-ctl, the client library, and (if connection is successful) the Crinit daemon to stderr.

◆ crinitTaskStateToStr()

static const char * crinitTaskStateToStr ( crinitTaskState_t  s)
static

Convert a task state code to a string.

Parameters
sThe task state code to convert.
Returns
a string representing the given task status code.

◆ main()

int main ( int  argc,
char *  argv[] 
)