[systemd-commits] 8 commits - TODO man/systemctl.xml src/core src/shared src/systemctl
Lennart Poettering
lennart at kemper.freedesktop.org
Tue Jul 10 09:06:28 PDT 2012
TODO | 4 ++++
man/systemctl.xml | 28 ++++++++++++++++++++--------
src/core/automount.c | 1 -
src/core/device.c | 1 -
src/core/manager.c | 2 +-
src/core/mount.c | 1 -
src/core/path.c | 1 -
src/core/service.c | 1 -
src/core/snapshot.c | 1 -
src/core/socket.c | 1 -
src/core/swap.c | 1 -
src/core/target.c | 1 -
src/core/timer.c | 1 -
src/core/unit.c | 32 --------------------------------
src/core/unit.h | 35 +----------------------------------
src/shared/install.c | 18 +++++++++---------
src/shared/unit-name.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
src/shared/unit-name.h | 38 +++++++++++++++++++++++++++++++++++++-
src/systemctl/systemctl.c | 19 +++++++++++++++----
19 files changed, 129 insertions(+), 101 deletions(-)
New commits:
commit a9f55579e8cae256b91dfec9f775622698b1a605
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Jul 10 18:06:06 2012 +0200
update TODO
diff --git a/TODO b/TODO
index ecdde83..96db4a5 100644
--- a/TODO
+++ b/TODO
@@ -22,6 +22,8 @@ Bugfixes:
Features:
+* switch-root add extra safety check
+
* switch-root: reopen /dev/console before switching root
* switch-root: sockets need relabelling
commit c147dc42f8b3383a3ced69aaa75e21df4fe75a96
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Tue Jul 10 18:03:03 2012 +0200
systemctl: filter shown units by their load state
E.g. systemctl --all -t masked gives the list of masked units.
The -t/--type option is reused. This is possible because unit types
and unit load states are called differently, so it is possible to
distinguish what the user meant. Using the same option also means that
the interface is user for the user: less options to remember.
diff --git a/man/systemctl.xml b/man/systemctl.xml
index e3d22a7..bf31b61 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -87,14 +87,26 @@
<term><option>--type=</option></term>
<term><option>-t</option></term>
- <listitem><para>When listing units,
- limit display to certain unit
- types. If not specified units of all
- types will be shown. The argument
- should be a unit type name such as
- <option>service</option>,
- <option>socket</option> and
- similar.</para></listitem>
+ <listitem><para>The argument should
+ be a unit type name such as
+ <option>service</option> and
+ <option>socket</option>,
+ or a unit load state such as
+ <option>loaded</option> and
+ <option>masked</option>.
+ </para>
+
+ <para>If the argument is a unit type,
+ when listing units, limit display to
+ certain unit types. If not specified
+ units of all types will be shown.</para>
+
+ <para>If the argument is a unit load state,
+ when listing units, limit display to
+ certain unit types. If not specified
+ units of in all load states will be
+ shown.</para>
+ </listitem>
</varlistentry>
<varlistentry>
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index a968179..6ab92ce 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -65,6 +65,7 @@
#include "path-util.h"
static const char *arg_type = NULL;
+static const char *arg_load_state = NULL;
static char **arg_property = NULL;
static bool arg_all = false;
static const char *arg_job_mode = "replace";
@@ -337,7 +338,9 @@ static bool output_show_unit(const struct unit_info *u) {
return (!arg_type || ((dot = strrchr(u->id, '.')) &&
streq(dot+1, arg_type))) &&
- (arg_all || !(streq(u->active_state, "inactive") || u->following[0]) || u->job_id > 0);
+ (!arg_load_state || streq(u->load_state, arg_load_state)) &&
+ (arg_all || !(streq(u->active_state, "inactive")
+ || u->following[0]) || u->job_id > 0);
}
static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
@@ -4650,13 +4653,17 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
return 0;
case 't':
- if (unit_type_from_string(optarg) < 0) {
- log_error("Invalid unit type '%s'.", optarg);
- return -EINVAL;
+ if (unit_type_from_string(optarg) >= 0) {
+ arg_type = optarg;
+ break;
}
- arg_type = optarg;
- break;
-
+ if (unit_load_state_from_string(optarg) >= 0) {
+ arg_load_state = optarg;
+ break;
+ }
+ log_error("Unkown unit type or load state '%s'.",
+ optarg);
+ return -EINVAL;
case 'p': {
char **l;
commit f69614f811b133ececad4394e88f9549a017bd4e
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Tue Jul 10 17:18:09 2012 +0200
unit: Move UnitLoadState definitions from core/unit.c to shared/unit-name.c
This makes it possible to use them from systemctl without linking
against the core.
diff --git a/src/core/unit.c b/src/core/unit.c
index 2d18976..37711af 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2746,16 +2746,6 @@ int unit_add_mount_links(Unit *u) {
return 0;
}
-static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
- [UNIT_STUB] = "stub",
- [UNIT_LOADED] = "loaded",
- [UNIT_ERROR] = "error",
- [UNIT_MERGED] = "merged",
- [UNIT_MASKED] = "masked"
-};
-
-DEFINE_STRING_TABLE_LOOKUP(unit_load_state, UnitLoadState);
-
static const char* const unit_active_state_table[_UNIT_ACTIVE_STATE_MAX] = {
[UNIT_ACTIVE] = "active",
[UNIT_RELOADING] = "reloading",
diff --git a/src/core/unit.h b/src/core/unit.h
index b0aa02f..0e1e72e 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -28,7 +28,6 @@
typedef struct Unit Unit;
typedef struct UnitVTable UnitVTable;
typedef enum UnitType UnitType;
-typedef enum UnitLoadState UnitLoadState;
typedef enum UnitActiveState UnitActiveState;
typedef enum UnitDependency UnitDependency;
typedef struct UnitRef UnitRef;
@@ -43,16 +42,6 @@ typedef struct UnitStatusMessageFormats UnitStatusMessageFormats;
#include "install.h"
#include "unit-name.h"
-enum UnitLoadState {
- UNIT_STUB,
- UNIT_LOADED,
- UNIT_ERROR,
- UNIT_MERGED,
- UNIT_MASKED,
- _UNIT_LOAD_STATE_MAX,
- _UNIT_LOAD_STATE_INVALID = -1
-};
-
enum UnitActiveState {
UNIT_ACTIVE,
UNIT_RELOADING,
@@ -549,9 +538,6 @@ void unit_ref_unset(UnitRef *ref);
int unit_add_one_mount_link(Unit *u, Mount *m);
int unit_add_mount_links(Unit *u);
-const char *unit_load_state_to_string(UnitLoadState i);
-UnitLoadState unit_load_state_from_string(const char *s);
-
const char *unit_active_state_to_string(UnitActiveState i);
UnitActiveState unit_active_state_from_string(const char *s);
diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c
index cbe0b05..3e437b7 100644
--- a/src/shared/unit-name.c
+++ b/src/shared/unit-name.c
@@ -48,6 +48,16 @@ static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);
+static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
+ [UNIT_STUB] = "stub",
+ [UNIT_LOADED] = "loaded",
+ [UNIT_ERROR] = "error",
+ [UNIT_MERGED] = "merged",
+ [UNIT_MASKED] = "masked"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(unit_load_state, UnitLoadState);
+
bool unit_name_is_valid(const char *n, bool template_ok) {
const char *e, *i, *at;
diff --git a/src/shared/unit-name.h b/src/shared/unit-name.h
index cd30d65..c6c09dd 100644
--- a/src/shared/unit-name.h
+++ b/src/shared/unit-name.h
@@ -27,6 +27,7 @@
#define UNIT_NAME_MAX 256
typedef enum UnitType UnitType;
+typedef enum UnitLoadState UnitLoadState;
enum UnitType {
UNIT_SERVICE = 0,
@@ -43,9 +44,22 @@ enum UnitType {
_UNIT_TYPE_INVALID = -1
};
+enum UnitLoadState {
+ UNIT_STUB,
+ UNIT_LOADED,
+ UNIT_ERROR,
+ UNIT_MERGED,
+ UNIT_MASKED,
+ _UNIT_LOAD_STATE_MAX,
+ _UNIT_LOAD_STATE_INVALID = -1
+};
+
const char *unit_type_to_string(UnitType i);
UnitType unit_type_from_string(const char *s);
+const char *unit_load_state_to_string(UnitLoadState i);
+UnitLoadState unit_load_state_from_string(const char *s);
+
int unit_name_to_instance(const char *n, char **instance);
char* unit_name_to_prefix(const char *n);
char* unit_name_to_prefix_and_instance(const char *n);
commit bcbe497e5a73d889e8799f8a3680c303afede347
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Jul 10 17:04:42 2012 +0200
unit: get rid of UnitVTable.suffix, which is now unused
diff --git a/src/core/automount.c b/src/core/automount.c
index 697dfa1..91162c2 100644
--- a/src/core/automount.c
+++ b/src/core/automount.c
@@ -846,7 +846,6 @@ static const char* const automount_result_table[_AUTOMOUNT_RESULT_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(automount_result, AutomountResult);
const UnitVTable automount_vtable = {
- .suffix = ".automount",
.object_size = sizeof(Automount),
.sections =
"Unit\0"
diff --git a/src/core/device.c b/src/core/device.c
index f4c59b3..5307341 100644
--- a/src/core/device.c
+++ b/src/core/device.c
@@ -587,7 +587,6 @@ static const char* const device_state_table[_DEVICE_STATE_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(device_state, DeviceState);
const UnitVTable device_vtable = {
- .suffix = ".device",
.object_size = sizeof(Device),
.sections =
"Unit\0"
diff --git a/src/core/mount.c b/src/core/mount.c
index 3d513a0..69cb6e2 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -1785,7 +1785,6 @@ static const char* const mount_result_table[_MOUNT_RESULT_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(mount_result, MountResult);
const UnitVTable mount_vtable = {
- .suffix = ".mount",
.object_size = sizeof(Mount),
.sections =
"Unit\0"
diff --git a/src/core/path.c b/src/core/path.c
index 6cf03ad..42dd5da 100644
--- a/src/core/path.c
+++ b/src/core/path.c
@@ -738,7 +738,6 @@ static const char* const path_result_table[_PATH_RESULT_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(path_result, PathResult);
const UnitVTable path_vtable = {
- .suffix = ".path",
.object_size = sizeof(Path),
.sections =
"Unit\0"
diff --git a/src/core/service.c b/src/core/service.c
index 0c29d4a..e57b0e9 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -3798,7 +3798,6 @@ static const char* const start_limit_action_table[_SERVICE_START_LIMIT_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(start_limit_action, StartLimitAction);
const UnitVTable service_vtable = {
- .suffix = ".service",
.object_size = sizeof(Service),
.sections =
"Unit\0"
diff --git a/src/core/snapshot.c b/src/core/snapshot.c
index 5bb3c4a..5c2a319 100644
--- a/src/core/snapshot.c
+++ b/src/core/snapshot.c
@@ -281,7 +281,6 @@ static const char* const snapshot_state_table[_SNAPSHOT_STATE_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(snapshot_state, SnapshotState);
const UnitVTable snapshot_vtable = {
- .suffix = ".snapshot",
.object_size = sizeof(Snapshot),
.no_alias = true,
diff --git a/src/core/socket.c b/src/core/socket.c
index ea24f4b..3613e84 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -2185,7 +2185,6 @@ static const char* const socket_result_table[_SOCKET_RESULT_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(socket_result, SocketResult);
const UnitVTable socket_vtable = {
- .suffix = ".socket",
.object_size = sizeof(Socket),
.sections =
"Unit\0"
diff --git a/src/core/swap.c b/src/core/swap.c
index f3c7fa3..aeb8bda 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -1335,7 +1335,6 @@ static const char* const swap_result_table[_SWAP_RESULT_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(swap_result, SwapResult);
const UnitVTable swap_vtable = {
- .suffix = ".swap",
.object_size = sizeof(Swap),
.sections =
"Unit\0"
diff --git a/src/core/target.c b/src/core/target.c
index a912f44..092b206 100644
--- a/src/core/target.c
+++ b/src/core/target.c
@@ -198,7 +198,6 @@ static const char* const target_state_table[_TARGET_STATE_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(target_state, TargetState);
const UnitVTable target_vtable = {
- .suffix = ".target",
.object_size = sizeof(Target),
.sections =
"Unit\0"
diff --git a/src/core/timer.c b/src/core/timer.c
index 6bd4cc3..0b3c5ce 100644
--- a/src/core/timer.c
+++ b/src/core/timer.c
@@ -486,7 +486,6 @@ static const char* const timer_result_table[_TIMER_RESULT_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(timer_result, TimerResult);
const UnitVTable timer_vtable = {
- .suffix = ".timer",
.object_size = sizeof(Timer),
.sections =
"Unit\0"
diff --git a/src/core/unit.h b/src/core/unit.h
index c20c532..b0aa02f 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -274,8 +274,6 @@ struct UnitStatusMessageFormats {
#include "path.h"
struct UnitVTable {
- const char *suffix;
-
/* How much memory does an object of this unit type need */
size_t object_size;
commit 5f73969991fa765f2826975c0fc5e47438b5e9ea
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Jul 10 17:03:11 2012 +0200
unit-name: remove unit_name_is_valid_no_type() and move unit_name_is_valid() to unit-name.h
diff --git a/src/core/manager.c b/src/core/manager.c
index f07d26e..7bd484b 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -796,7 +796,7 @@ int manager_load_unit_prepare(Manager *m, const char *name, const char *path, DB
t = unit_name_to_type(name);
- if (t == _UNIT_TYPE_INVALID || !unit_name_is_valid_no_type(name, false)) {
+ if (t == _UNIT_TYPE_INVALID || !unit_name_is_valid(name, false)) {
dbus_set_error(e, BUS_ERROR_INVALID_NAME, "Unit name %s is not valid.", name);
return -EINVAL;
}
diff --git a/src/core/unit.c b/src/core/unit.c
index 64e26b7..2d18976 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2647,28 +2647,6 @@ bool unit_pending_active(Unit *u) {
return false;
}
-UnitType unit_name_to_type(const char *n) {
- UnitType t;
-
- assert(n);
-
- for (t = 0; t < _UNIT_TYPE_MAX; t++)
- if (endswith(n, unit_vtable[t]->suffix))
- return t;
-
- return _UNIT_TYPE_INVALID;
-}
-
-bool unit_name_is_valid(const char *n, bool template_ok) {
- UnitType t;
-
- t = unit_name_to_type(n);
- if (t < 0 || t >= _UNIT_TYPE_MAX)
- return false;
-
- return unit_name_is_valid_no_type(n, template_ok);
-}
-
int unit_kill(Unit *u, KillWho w, KillMode m, int signo, DBusError *error) {
assert(u);
assert(w >= 0 && w < _KILL_WHO_MAX);
diff --git a/src/core/unit.h b/src/core/unit.h
index 049b1db..c20c532 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -537,9 +537,6 @@ int unit_add_default_target_dependency(Unit *u, Unit *target);
int unit_following_set(Unit *u, Set **s);
-UnitType unit_name_to_type(const char *n);
-bool unit_name_is_valid(const char *n, bool template_ok);
-
void unit_trigger_on_failure(Unit *u);
bool unit_condition_test(Unit *u);
diff --git a/src/shared/install.c b/src/shared/install.c
index 13ae9a9..a3b7524 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -608,7 +608,7 @@ int unit_file_mask(
STRV_FOREACH(i, files) {
char *path;
- if (!unit_name_is_valid_no_type(*i, true)) {
+ if (!unit_name_is_valid(*i, true)) {
if (r == 0)
r = -EINVAL;
continue;
@@ -684,7 +684,7 @@ int unit_file_unmask(
STRV_FOREACH(i, files) {
char *path;
- if (!unit_name_is_valid_no_type(*i, true)) {
+ if (!unit_name_is_valid(*i, true)) {
if (r == 0)
r = -EINVAL;
continue;
@@ -760,7 +760,7 @@ int unit_file_link(
fn = path_get_file_name(*i);
if (!path_is_absolute(*i) ||
- !unit_name_is_valid_no_type(fn, true)) {
+ !unit_name_is_valid(fn, true)) {
if (r == 0)
r = -EINVAL;
continue;
@@ -923,7 +923,7 @@ static int install_info_add(
if (!name)
name = path_get_file_name(path);
- if (!unit_name_is_valid_no_type(name, true))
+ if (!unit_name_is_valid(name, true))
return -EINVAL;
if (hashmap_get(c->have_installed, name) ||
@@ -1233,7 +1233,7 @@ static int install_info_symlink_wants(
STRV_FOREACH(s, i->wanted_by) {
char *path;
- if (!unit_name_is_valid_no_type(*s, true)) {
+ if (!unit_name_is_valid(*s, true)) {
r = -EINVAL;
continue;
}
@@ -1267,7 +1267,7 @@ static int install_info_symlink_requires(
STRV_FOREACH(s, i->required_by) {
char *path;
- if (!unit_name_is_valid_no_type(*s, true)) {
+ if (!unit_name_is_valid(*s, true)) {
r = -EINVAL;
continue;
}
@@ -1598,7 +1598,7 @@ UnitFileState unit_file_get_state(
if (root_dir && scope != UNIT_FILE_SYSTEM)
return -EINVAL;
- if (!unit_name_is_valid_no_type(name, true))
+ if (!unit_name_is_valid(name, true))
return -EINVAL;
r = lookup_paths_init_from_scope(&paths, scope);
@@ -1793,7 +1793,7 @@ int unit_file_preset(
STRV_FOREACH(i, files) {
- if (!unit_name_is_valid_no_type(*i, true)) {
+ if (!unit_name_is_valid(*i, true)) {
r = -EINVAL;
goto finish;
}
@@ -1898,7 +1898,7 @@ int unit_file_get_list(
if (ignore_file(de->d_name))
continue;
- if (!unit_name_is_valid_no_type(de->d_name, true))
+ if (!unit_name_is_valid(de->d_name, true))
continue;
if (hashmap_get(h, de->d_name))
diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c
index 67a760a..cbe0b05 100644
--- a/src/shared/unit-name.c
+++ b/src/shared/unit-name.c
@@ -48,7 +48,7 @@ static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);
-bool unit_name_is_valid_no_type(const char *n, bool template_ok) {
+bool unit_name_is_valid(const char *n, bool template_ok) {
const char *e, *i, *at;
/* Valid formats:
@@ -66,6 +66,9 @@ bool unit_name_is_valid_no_type(const char *n, bool template_ok) {
if (!e || e == n)
return false;
+ if (unit_type_from_string(e + 1) < 0)
+ return false;
+
for (i = n, at = NULL; i < e; i++) {
if (*i == '@' && !at)
@@ -169,7 +172,7 @@ char *unit_name_change_suffix(const char *n, const char *suffix) {
size_t a, b;
assert(n);
- assert(unit_name_is_valid_no_type(n, true));
+ assert(unit_name_is_valid(n, true));
assert(suffix);
assert_se(e = strrchr(n, '.'));
@@ -485,3 +488,15 @@ char *unit_name_mangle(const char *name) {
return r;
}
+
+UnitType unit_name_to_type(const char *n) {
+ const char *e;
+
+ assert(n);
+
+ e = strrchr(n, '.');
+ if (!e)
+ return _UNIT_TYPE_INVALID;
+
+ return unit_type_from_string(e + 1);
+}
diff --git a/src/shared/unit-name.h b/src/shared/unit-name.h
index 4c793c5..cd30d65 100644
--- a/src/shared/unit-name.h
+++ b/src/shared/unit-name.h
@@ -50,10 +50,12 @@ int unit_name_to_instance(const char *n, char **instance);
char* unit_name_to_prefix(const char *n);
char* unit_name_to_prefix_and_instance(const char *n);
-bool unit_name_is_valid_no_type(const char *n, bool template_ok);
+bool unit_name_is_valid(const char *n, bool template_ok);
bool unit_prefix_is_valid(const char *p);
bool unit_instance_is_valid(const char *i);
+UnitType unit_name_to_type(const char *n);
+
char *unit_name_change_suffix(const char *n, const char *suffix);
char *unit_name_build(const char *prefix, const char *instance, const char *suffix);
commit 0bf07cb5e4db097fcc25784b491fc4311d20fff2
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Jul 10 16:54:08 2012 +0200
update TODO
diff --git a/TODO b/TODO
index b41c4f6..ecdde83 100644
--- a/TODO
+++ b/TODO
@@ -22,6 +22,8 @@ Bugfixes:
Features:
+* switch-root: reopen /dev/console before switching root
+
* switch-root: sockets need relabelling
* switch-root: handle journald restart
commit 6d97280899a766ad7b4a6b07cc803709a08b364b
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Wed Jun 6 16:56:19 2012 +0200
systemctl: check the argument to -t for invalid values
Systemctl accepted anything as the argument for -t, and simply said '0
units found'. It is better to catch this user error early.
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index c89920b..a968179 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4650,6 +4650,10 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
return 0;
case 't':
+ if (unit_type_from_string(optarg) < 0) {
+ log_error("Invalid unit type '%s'.", optarg);
+ return -EINVAL;
+ }
arg_type = optarg;
break;
commit 0a9f8ed00c8f323d5bf24a9a11149a9342c0e1aa
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Wed Jun 6 16:56:18 2012 +0200
unit: Move UnitType definitions from core/unit.c to shared/unit-name.c
This makes it possible to use them from systemctl without linking
against the core. A string->enum lookup table is added.
diff --git a/src/core/unit.h b/src/core/unit.h
index cfb38d0..049b1db 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -41,21 +41,7 @@ typedef struct UnitStatusMessageFormats UnitStatusMessageFormats;
#include "execute.h"
#include "condition.h"
#include "install.h"
-
-enum UnitType {
- UNIT_SERVICE = 0,
- UNIT_SOCKET,
- UNIT_TARGET,
- UNIT_DEVICE,
- UNIT_MOUNT,
- UNIT_AUTOMOUNT,
- UNIT_SNAPSHOT,
- UNIT_TIMER,
- UNIT_SWAP,
- UNIT_PATH,
- _UNIT_TYPE_MAX,
- _UNIT_TYPE_INVALID = -1
-};
+#include "unit-name.h"
enum UnitLoadState {
UNIT_STUB,
diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c
index 4b52f7b..67a760a 100644
--- a/src/shared/unit-name.c
+++ b/src/shared/unit-name.c
@@ -33,6 +33,21 @@
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
":-_.\\"
+static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
+ [UNIT_SERVICE] = "service",
+ [UNIT_SOCKET] = "socket",
+ [UNIT_TARGET] = "target",
+ [UNIT_DEVICE] = "device",
+ [UNIT_MOUNT] = "mount",
+ [UNIT_AUTOMOUNT] = "automount",
+ [UNIT_SNAPSHOT] = "snapshot",
+ [UNIT_TIMER] = "timer",
+ [UNIT_SWAP] = "swap",
+ [UNIT_PATH] = "path",
+};
+
+DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);
+
bool unit_name_is_valid_no_type(const char *n, bool template_ok) {
const char *e, *i, *at;
diff --git a/src/shared/unit-name.h b/src/shared/unit-name.h
index 13665c5..4c793c5 100644
--- a/src/shared/unit-name.h
+++ b/src/shared/unit-name.h
@@ -26,6 +26,26 @@
#define UNIT_NAME_MAX 256
+typedef enum UnitType UnitType;
+
+enum UnitType {
+ UNIT_SERVICE = 0,
+ UNIT_SOCKET,
+ UNIT_TARGET,
+ UNIT_DEVICE,
+ UNIT_MOUNT,
+ UNIT_AUTOMOUNT,
+ UNIT_SNAPSHOT,
+ UNIT_TIMER,
+ UNIT_SWAP,
+ UNIT_PATH,
+ _UNIT_TYPE_MAX,
+ _UNIT_TYPE_INVALID = -1
+};
+
+const char *unit_type_to_string(UnitType i);
+UnitType unit_type_from_string(const char *s);
+
int unit_name_to_instance(const char *n, char **instance);
char* unit_name_to_prefix(const char *n);
char* unit_name_to_prefix_and_instance(const char *n);
More information about the systemd-commits
mailing list