fixup! Add daemon support to init(8).

This commit is contained in:
Jonas 'Sortie' Termansen 2022-01-12 22:51:24 +01:00
parent 613cddd0ae
commit 5c90e6589f
2 changed files with 20 additions and 5 deletions

View File

@ -118,6 +118,7 @@ struct dependency
enum log_method
{
LOG_METHOD_NONE,
LOG_METHOD_APPEND,
LOG_METHOD_ROTATE,
};
@ -430,6 +431,8 @@ static void log_close(struct log* log)
static bool log_open(struct log* log)
{
if ( log->method == LOG_METHOD_NONE )
return true;
int logflags = O_CREAT | O_WRONLY | O_APPEND | O_NOFOLLOW;
if ( log->method == LOG_METHOD_APPEND && log->rotate_on_start )
logflags |= O_TRUNC;
@ -463,6 +466,8 @@ static bool log_open(struct log* log)
static bool log_rotate(struct log* log)
{
if ( log->method == LOG_METHOD_NONE )
return true;
if ( 0 <= log->fd )
{
close(log->fd);
@ -539,6 +544,8 @@ static bool log_rotate(struct log* log)
static bool log_begin(struct log* log)
{
if ( log->method == LOG_METHOD_NONE )
return true;
if ( log->method == LOG_METHOD_ROTATE && log->rotate_on_start )
return log_rotate(log);
return log_open(log);
@ -572,6 +579,8 @@ static bool log_initialize(struct log* log,
static void log_data(struct log* log, const char* data, size_t length)
{
if ( log->method == LOG_METHOD_NONE )
return;
// TODO: Support for infinitely sized chunks / OFF_MAX chunks?
// TODO: Ensure log->max_line_size <= log->max_size.
const off_t chunk_cut_offset = log->max_size - log->max_line_size;

View File

@ -272,8 +272,10 @@ When using the
.Sy pipe
log method, start the log process using this program and arguments.
.\" TODO: The name of the daemon should be inserted as an argument?
.It Sy log-format
Selects the format of the log:
.It Sy log-format Ar format
Selects the
.Ar format
of the log:
.Bl -tag -width "nanoseconds"
.It Sy none
The log is exactly as written by the daemon with no additional formatting.
@ -316,10 +318,11 @@ log method, log files are cut at newlines if the lines don't exceed
bytes.
.Pp
The default value is 4096 bytes.
.It Sy log-method Oo Sy append "|" rotate "|" pipe Oc
Selects the method for logging (the default is
.Sy rotate ) :
.It Sy log-method Oo Sy none "|" append "|" rotate "|" pipe Oc
Selects the method for logging:
.Bl -tag -width "12345678"
.It Sy none
Disable logging.
.It Sy append
Always append the log data to the log file without any rotation.
.Pp
@ -375,6 +378,9 @@ daemon will stop with a failure if the log process fails.
This method does not lose log data, always forwarding it to the spawned process,
but the spawned process might of course lose it.
.El
.Pp
The default format is
.Sy rotate .
.It Sy log-rotate-on-start Oo Sy false "|" true Oc
When starting the daemon, rotate the logs (when using the
.Sy rotate