2018-11-23 13:13:23 +01:00
|
|
|
/* SPDX-License-Identifier: ISC */
|
2018-11-23 14:13:52 +01:00
|
|
|
#include <string.h>
|
2018-03-25 01:55:08 +01:00
|
|
|
#include "service.h"
|
|
|
|
|
2018-11-23 14:13:52 +01:00
|
|
|
static const char *type_map[] = {
|
|
|
|
"once",
|
|
|
|
"wait",
|
|
|
|
"respawn",
|
2018-03-25 01:55:08 +01:00
|
|
|
};
|
|
|
|
|
2018-11-23 14:13:52 +01:00
|
|
|
static const char *target_map[] = {
|
|
|
|
"boot",
|
|
|
|
"shutdown",
|
|
|
|
"reboot",
|
2018-03-25 01:55:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const char *svc_type_to_string(int type)
|
|
|
|
{
|
2018-11-23 14:13:52 +01:00
|
|
|
return type >= 0 && type < SVC_MAX ? type_map[type] : NULL;
|
2018-03-25 01:55:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int svc_type_from_string(const char *type)
|
|
|
|
{
|
2018-11-23 14:13:52 +01:00
|
|
|
size_t i;
|
2018-03-25 01:55:08 +01:00
|
|
|
|
2020-03-31 18:19:27 +02:00
|
|
|
for (i = 0; i < sizeof(type_map) / sizeof(type_map[0]); ++i) {
|
2018-11-23 14:13:52 +01:00
|
|
|
if (strcmp(type_map[i], type) == 0)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2018-03-25 01:55:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *svc_target_to_string(int target)
|
|
|
|
{
|
2018-11-23 14:13:52 +01:00
|
|
|
return target >= 0 && target < TGT_MAX ? target_map[target] : NULL;
|
2018-03-25 01:55:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int svc_target_from_string(const char *target)
|
|
|
|
{
|
2018-11-23 14:13:52 +01:00
|
|
|
size_t i;
|
|
|
|
|
2020-03-31 18:19:27 +02:00
|
|
|
for (i = 0; i < sizeof(target_map) / sizeof(target_map[0]); ++i) {
|
2018-11-23 14:13:52 +01:00
|
|
|
if (strcmp(target_map[i], target) == 0)
|
|
|
|
return i;
|
|
|
|
}
|
2018-03-25 01:55:08 +01:00
|
|
|
|
2018-11-23 14:13:52 +01:00
|
|
|
return -1;
|
2018-03-25 01:55:08 +01:00
|
|
|
}
|