mirror of
https://github.com/pygos/init.git
synced 2024-06-02 02:08:44 +02:00
David Oberhollenzer
87a524d931
- exec_t belongs to service.h, the main place where it is used/needed - code for executing exec_t is moved to runsvc for the same reason - what is left are NORETURN and ARRAY_SIZE - the former can be replaced with direct attribute usage since the only relevant compilers all support the attribute. - the later is only used in 3 places and can be trivially replaced with direct usage of sizeof(). Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
50 lines
837 B
C
50 lines
837 B
C
/* SPDX-License-Identifier: ISC */
|
|
#include <string.h>
|
|
#include "service.h"
|
|
|
|
static const char *type_map[] = {
|
|
"once",
|
|
"wait",
|
|
"respawn",
|
|
};
|
|
|
|
static const char *target_map[] = {
|
|
"boot",
|
|
"shutdown",
|
|
"reboot",
|
|
};
|
|
|
|
const char *svc_type_to_string(int type)
|
|
{
|
|
return type >= 0 && type < SVC_MAX ? type_map[type] : NULL;
|
|
}
|
|
|
|
int svc_type_from_string(const char *type)
|
|
{
|
|
size_t i;
|
|
|
|
for (i = 0; i < sizeof(type_map) / sizeof(type_map[0]); ++i) {
|
|
if (strcmp(type_map[i], type) == 0)
|
|
return i;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
const char *svc_target_to_string(int target)
|
|
{
|
|
return target >= 0 && target < TGT_MAX ? target_map[target] : NULL;
|
|
}
|
|
|
|
int svc_target_from_string(const char *target)
|
|
{
|
|
size_t i;
|
|
|
|
for (i = 0; i < sizeof(target_map) / sizeof(target_map[0]); ++i) {
|
|
if (strcmp(target_map[i], target) == 0)
|
|
return i;
|
|
}
|
|
|
|
return -1;
|
|
}
|