aboutsummaryrefslogtreecommitdiff
path: root/lib/init/svcmap.c
blob: de45914cbb30682305bbd5944be16e8a61f5cf35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* 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;
}