sd-path: drop "-dir" and "-path" suffixes from path enums

Clean up the naming of the sd-path enums. Previously, the more recently
added fields where named in the form SD_PATH_xyz_DIR and
SD_PATH_xyz_PATH, while the older fields where called just SD_PATH_xyz
and SD_PATH_SEARCH_xyz. Let's clean this up, to come to a more unified
way how we name this stuff.

I opted to stick to the old naming, i.e. dropthe suffixes. It's a bit of
a bike-shedding question of course, but I think there's a good reason to
avoid the additional DIR and PATH suffixes: the enum prefix contains
"PATH" anyway (i.e. "SD_PATH_"), so including PATH twice in each name is
redundant. Moreover, the key difference between the enums with the "dir"
and the "path" in the name is that the latter are *seach* paths, and I
think this is better emphasized by sticking to the "SEARCH" in the name.

Moreover dropping the suffixes makes the identifiers a lot shorter, in
particular in the "systemd-path" list output. And that's always good.

This means the naming pkgconfig file and in sd-path slightly deviate
(though the mapping is very simple), but I think that's OK, given that
this is developer facing and not user facing.
This commit is contained in:
Lennart Poettering 2020-05-28 09:28:28 +02:00
parent 4a56315a99
commit ccdf03b9c7
4 changed files with 136 additions and 131 deletions

View File

@ -76,30 +76,30 @@
<constant>SD_PATH_SEARCH_STATE_FACTORY</constant>,
<constant>SD_PATH_SEARCH_CONFIGURATION</constant>,
<constant>SD_PATH_SYSTEMD_UTIL_DIR</constant>,
<constant>SD_PATH_SYSTEMD_SYSTEM_UNIT_DIR</constant>,
<constant>SD_PATH_SYSTEMD_SYSTEM_PRESET_DIR</constant>,
<constant>SD_PATH_SYSTEMD_USER_UNIT_DIR</constant>,
<constant>SD_PATH_SYSTEMD_USER_PRESET_DIR</constant>,
<constant>SD_PATH_SYSTEMD_SYSTEM_CONF_DIR</constant>,
<constant>SD_PATH_SYSTEMD_USER_CONF_DIR</constant>,
<constant>SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH</constant>,
<constant>SD_PATH_SYSTEMD_USER_UNIT_PATH</constant>,
<constant>SD_PATH_SYSTEMD_SYSTEM_GENERATOR_DIR</constant>,
<constant>SD_PATH_SYSTEMD_USER_GENERATOR_DIR</constant>,
<constant>SD_PATH_SYSTEMD_SYSTEM_GENERATOR_PATH</constant>,
<constant>SD_PATH_SYSTEMD_USER_GENERATOR_PATH</constant>,
<constant>SD_PATH_SYSTEMD_SLEEP_DIR</constant>,
<constant>SD_PATH_SYSTEMD_SHUTDOWN_DIR</constant>,
<constant>SD_PATH_SYSTEMD_UTIL</constant>,
<constant>SD_PATH_SYSTEMD_SYSTEM_UNIT</constant>,
<constant>SD_PATH_SYSTEMD_SYSTEM_PRESET</constant>,
<constant>SD_PATH_SYSTEMD_USER_UNIT</constant>,
<constant>SD_PATH_SYSTEMD_USER_PRESET</constant>,
<constant>SD_PATH_SYSTEMD_SYSTEM_CONF</constant>,
<constant>SD_PATH_SYSTEMD_USER_CONF</constant>,
<constant>SD_PATH_SYSTEMD_SEARCH_SYSTEM_UNIT</constant>,
<constant>SD_PATH_SYSTEMD_SEARCH_USER_UNIT</constant>,
<constant>SD_PATH_SYSTEMD_SYSTEM_GENERATOR</constant>,
<constant>SD_PATH_SYSTEMD_USER_GENERATOR</constant>,
<constant>SD_PATH_SYSTEMD_SEARCH_SYSTEM_GENERATOR</constant>,
<constant>SD_PATH_SYSTEMD_SEARCH_USER_GENERATOR</constant>,
<constant>SD_PATH_SYSTEMD_SLEEP</constant>,
<constant>SD_PATH_SYSTEMD_SHUTDOWN</constant>,
<constant>SD_PATH_TMPFILES_DIR</constant>,
<constant>SD_PATH_SYSUSERS_DIR</constant>,
<constant>SD_PATH_SYSCTL_DIR</constant>,
<constant>SD_PATH_BINFMT_DIR</constant>,
<constant>SD_PATH_MODULES_LOAD_DIR</constant>,
<constant>SD_PATH_CATALOG_DIR</constant>,
<constant>SD_PATH_TMPFILES</constant>,
<constant>SD_PATH_SYSUSERS</constant>,
<constant>SD_PATH_SYSCTL</constant>,
<constant>SD_PATH_BINFMT</constant>,
<constant>SD_PATH_MODULES_LOAD</constant>,
<constant>SD_PATH_CATALOG</constant>,
<constant>SD_PATH_SYSTEMD_NETWORK_PATH</constant>,
<constant>SD_PATH_SYSTEMD_SEARCH_NETWORK</constant>,
};</funcsynopsisinfo>
<funcprototype>

View File

@ -320,73 +320,73 @@ static int get_path(uint64_t type, char **buffer, const char **ret) {
case SD_PATH_USER_DESKTOP:
return from_user_dir("XDG_DESKTOP_DIR", buffer, ret);
case SD_PATH_SYSTEMD_UTIL_DIR:
case SD_PATH_SYSTEMD_UTIL:
*ret = ROOTPREFIX "/lib/systemd";
return 0;
case SD_PATH_SYSTEMD_SYSTEM_UNIT_DIR:
case SD_PATH_SYSTEMD_SYSTEM_UNIT:
*ret = SYSTEM_DATA_UNIT_PATH;
return 0;
case SD_PATH_SYSTEMD_SYSTEM_PRESET_DIR:
case SD_PATH_SYSTEMD_SYSTEM_PRESET:
*ret = ROOTPREFIX "/lib/systemd/system-preset";
return 0;
case SD_PATH_SYSTEMD_USER_UNIT_DIR:
case SD_PATH_SYSTEMD_USER_UNIT:
*ret = USER_DATA_UNIT_DIR;
return 0;
case SD_PATH_SYSTEMD_USER_PRESET_DIR:
case SD_PATH_SYSTEMD_USER_PRESET:
*ret = ROOTPREFIX "/lib/systemd/user-preset";
return 0;
case SD_PATH_SYSTEMD_SYSTEM_CONF_DIR:
case SD_PATH_SYSTEMD_SYSTEM_CONF:
*ret = SYSTEM_CONFIG_UNIT_DIR;
return 0;
case SD_PATH_SYSTEMD_USER_CONF_DIR:
case SD_PATH_SYSTEMD_USER_CONF:
*ret = USER_CONFIG_UNIT_DIR;
return 0;
case SD_PATH_SYSTEMD_SYSTEM_GENERATOR_DIR:
case SD_PATH_SYSTEMD_SYSTEM_GENERATOR:
*ret = SYSTEM_GENERATOR_DIR;
return 0;
case SD_PATH_SYSTEMD_USER_GENERATOR_DIR:
case SD_PATH_SYSTEMD_USER_GENERATOR:
*ret = USER_GENERATOR_DIR;
return 0;
case SD_PATH_SYSTEMD_SLEEP_DIR:
case SD_PATH_SYSTEMD_SLEEP:
*ret = ROOTPREFIX "/lib/systemd/system-sleep";
return 0;
case SD_PATH_SYSTEMD_SHUTDOWN_DIR:
case SD_PATH_SYSTEMD_SHUTDOWN:
*ret = ROOTPREFIX "/lib/systemd/system-shutdown";
return 0;
/* FIXME: systemd.pc uses ${prefix}, but CONF_PATHS_NULSTR doesn't.
* Should ${prefix} use in systemd.pc be removed? */
case SD_PATH_TMPFILES_DIR:
case SD_PATH_TMPFILES:
*ret = "/usr/lib/tmpfiles.d";
return 0;
case SD_PATH_SYSUSERS_DIR:
case SD_PATH_SYSUSERS:
*ret = ROOTPREFIX "/lib/sysusers.d";
return 0;
case SD_PATH_SYSCTL_DIR:
case SD_PATH_SYSCTL:
*ret = ROOTPREFIX "/lib/sysctl.d";
return 0;
case SD_PATH_BINFMT_DIR:
case SD_PATH_BINFMT:
*ret = ROOTPREFIX "/lib/binfmt.d";
return 0;
case SD_PATH_MODULES_LOAD_DIR:
case SD_PATH_MODULES_LOAD:
*ret = ROOTPREFIX "/lib/modules-load.d";
return 0;
case SD_PATH_CATALOG_DIR:
case SD_PATH_CATALOG:
*ret = "/usr/lib/systemd/catalog";
return 0;
}
@ -607,10 +607,10 @@ static int get_search(uint64_t type, char ***list) {
case SD_PATH_SEARCH_BINARIES_DEFAULT:
return strv_from_nulstr(list, DEFAULT_PATH_NULSTR);
case SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH:
case SD_PATH_SYSTEMD_USER_UNIT_PATH: {
case SD_PATH_SYSTEMD_SEARCH_SYSTEM_UNIT:
case SD_PATH_SYSTEMD_SEARCH_USER_UNIT: {
_cleanup_(lookup_paths_free) LookupPaths lp = {};
const UnitFileScope scope = type == SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH ?
const UnitFileScope scope = type == SD_PATH_SYSTEMD_SEARCH_SYSTEM_UNIT ?
UNIT_FILE_SYSTEM : UNIT_FILE_USER;
r = lookup_paths_init(&lp, scope, 0, NULL);
@ -621,10 +621,10 @@ static int get_search(uint64_t type, char ***list) {
return 0;
}
case SD_PATH_SYSTEMD_SYSTEM_GENERATOR_PATH:
case SD_PATH_SYSTEMD_USER_GENERATOR_PATH: {
case SD_PATH_SYSTEMD_SEARCH_SYSTEM_GENERATOR:
case SD_PATH_SYSTEMD_SEARCH_USER_GENERATOR: {
char **t;
const UnitFileScope scope = type == SD_PATH_SYSTEMD_SYSTEM_GENERATOR_PATH ?
const UnitFileScope scope = type == SD_PATH_SYSTEMD_SEARCH_SYSTEM_GENERATOR ?
UNIT_FILE_SYSTEM : UNIT_FILE_USER;
t = generator_binary_paths(scope);
@ -635,7 +635,7 @@ static int get_search(uint64_t type, char ***list) {
return 0;
}
case SD_PATH_SYSTEMD_NETWORK_PATH:
case SD_PATH_SYSTEMD_SEARCH_NETWORK:
return strv_from_nulstr(list, NETWORK_DIRS_NULSTR);
}

View File

@ -18,71 +18,71 @@
static const char *arg_suffix = NULL;
static const char* const path_table[_SD_PATH_MAX] = {
[SD_PATH_TEMPORARY] = "temporary",
[SD_PATH_TEMPORARY_LARGE] = "temporary-large",
[SD_PATH_SYSTEM_BINARIES] = "system-binaries",
[SD_PATH_SYSTEM_INCLUDE] = "system-include",
[SD_PATH_SYSTEM_LIBRARY_PRIVATE] = "system-library-private",
[SD_PATH_SYSTEM_LIBRARY_ARCH] = "system-library-arch",
[SD_PATH_SYSTEM_SHARED] = "system-shared",
[SD_PATH_SYSTEM_CONFIGURATION_FACTORY] = "system-configuration-factory",
[SD_PATH_SYSTEM_STATE_FACTORY] = "system-state-factory",
[SD_PATH_SYSTEM_CONFIGURATION] = "system-configuration",
[SD_PATH_SYSTEM_RUNTIME] = "system-runtime",
[SD_PATH_SYSTEM_RUNTIME_LOGS] = "system-runtime-logs",
[SD_PATH_SYSTEM_STATE_PRIVATE] = "system-state-private",
[SD_PATH_SYSTEM_STATE_LOGS] = "system-state-logs",
[SD_PATH_SYSTEM_STATE_CACHE] = "system-state-cache",
[SD_PATH_SYSTEM_STATE_SPOOL] = "system-state-spool",
[SD_PATH_USER_BINARIES] = "user-binaries",
[SD_PATH_USER_LIBRARY_PRIVATE] = "user-library-private",
[SD_PATH_USER_LIBRARY_ARCH] = "user-library-arch",
[SD_PATH_USER_SHARED] = "user-shared",
[SD_PATH_USER_CONFIGURATION] = "user-configuration",
[SD_PATH_USER_RUNTIME] = "user-runtime",
[SD_PATH_USER_STATE_CACHE] = "user-state-cache",
[SD_PATH_USER] = "user",
[SD_PATH_USER_DOCUMENTS] = "user-documents",
[SD_PATH_USER_MUSIC] = "user-music",
[SD_PATH_USER_PICTURES] = "user-pictures",
[SD_PATH_USER_VIDEOS] = "user-videos",
[SD_PATH_USER_DOWNLOAD] = "user-download",
[SD_PATH_USER_PUBLIC] = "user-public",
[SD_PATH_USER_TEMPLATES] = "user-templates",
[SD_PATH_USER_DESKTOP] = "user-desktop",
[SD_PATH_SEARCH_BINARIES] = "search-binaries",
[SD_PATH_SEARCH_BINARIES_DEFAULT] = "search-binaries-default",
[SD_PATH_SEARCH_LIBRARY_PRIVATE] = "search-library-private",
[SD_PATH_SEARCH_LIBRARY_ARCH] = "search-library-arch",
[SD_PATH_SEARCH_SHARED] = "search-shared",
[SD_PATH_SEARCH_CONFIGURATION_FACTORY] = "search-configuration-factory",
[SD_PATH_SEARCH_STATE_FACTORY] = "search-state-factory",
[SD_PATH_SEARCH_CONFIGURATION] = "search-configuration",
[SD_PATH_TEMPORARY] = "temporary",
[SD_PATH_TEMPORARY_LARGE] = "temporary-large",
[SD_PATH_SYSTEM_BINARIES] = "system-binaries",
[SD_PATH_SYSTEM_INCLUDE] = "system-include",
[SD_PATH_SYSTEM_LIBRARY_PRIVATE] = "system-library-private",
[SD_PATH_SYSTEM_LIBRARY_ARCH] = "system-library-arch",
[SD_PATH_SYSTEM_SHARED] = "system-shared",
[SD_PATH_SYSTEM_CONFIGURATION_FACTORY] = "system-configuration-factory",
[SD_PATH_SYSTEM_STATE_FACTORY] = "system-state-factory",
[SD_PATH_SYSTEM_CONFIGURATION] = "system-configuration",
[SD_PATH_SYSTEM_RUNTIME] = "system-runtime",
[SD_PATH_SYSTEM_RUNTIME_LOGS] = "system-runtime-logs",
[SD_PATH_SYSTEM_STATE_PRIVATE] = "system-state-private",
[SD_PATH_SYSTEM_STATE_LOGS] = "system-state-logs",
[SD_PATH_SYSTEM_STATE_CACHE] = "system-state-cache",
[SD_PATH_SYSTEM_STATE_SPOOL] = "system-state-spool",
[SD_PATH_USER_BINARIES] = "user-binaries",
[SD_PATH_USER_LIBRARY_PRIVATE] = "user-library-private",
[SD_PATH_USER_LIBRARY_ARCH] = "user-library-arch",
[SD_PATH_USER_SHARED] = "user-shared",
[SD_PATH_USER_CONFIGURATION] = "user-configuration",
[SD_PATH_USER_RUNTIME] = "user-runtime",
[SD_PATH_USER_STATE_CACHE] = "user-state-cache",
[SD_PATH_USER] = "user",
[SD_PATH_USER_DOCUMENTS] = "user-documents",
[SD_PATH_USER_MUSIC] = "user-music",
[SD_PATH_USER_PICTURES] = "user-pictures",
[SD_PATH_USER_VIDEOS] = "user-videos",
[SD_PATH_USER_DOWNLOAD] = "user-download",
[SD_PATH_USER_PUBLIC] = "user-public",
[SD_PATH_USER_TEMPLATES] = "user-templates",
[SD_PATH_USER_DESKTOP] = "user-desktop",
[SD_PATH_SEARCH_BINARIES] = "search-binaries",
[SD_PATH_SEARCH_BINARIES_DEFAULT] = "search-binaries-default",
[SD_PATH_SEARCH_LIBRARY_PRIVATE] = "search-library-private",
[SD_PATH_SEARCH_LIBRARY_ARCH] = "search-library-arch",
[SD_PATH_SEARCH_SHARED] = "search-shared",
[SD_PATH_SEARCH_CONFIGURATION_FACTORY] = "search-configuration-factory",
[SD_PATH_SEARCH_STATE_FACTORY] = "search-state-factory",
[SD_PATH_SEARCH_CONFIGURATION] = "search-configuration",
[SD_PATH_SYSTEMD_UTIL_DIR] = "systemd-util-dir",
[SD_PATH_SYSTEMD_SYSTEM_UNIT_DIR] = "systemd-system-unit-dir",
[SD_PATH_SYSTEMD_SYSTEM_PRESET_DIR] = "systemd-system-preset-dir",
[SD_PATH_SYSTEMD_USER_UNIT_DIR] = "systemd-user-unit-dir",
[SD_PATH_SYSTEMD_USER_PRESET_DIR] = "systemd-user-preset-dir",
[SD_PATH_SYSTEMD_SYSTEM_CONF_DIR] = "systemd-system-conf-dir",
[SD_PATH_SYSTEMD_USER_CONF_DIR] = "systemd-user-conf-dir",
[SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH] = "systemd-system-unit-path",
[SD_PATH_SYSTEMD_USER_UNIT_PATH] = "systemd-user-unit-path",
[SD_PATH_SYSTEMD_SYSTEM_GENERATOR_DIR] = "systemd-system-generator-dir",
[SD_PATH_SYSTEMD_USER_GENERATOR_DIR] = "systemd-user-generator-dir",
[SD_PATH_SYSTEMD_SYSTEM_GENERATOR_PATH] = "systemd-system-generator-path",
[SD_PATH_SYSTEMD_USER_GENERATOR_PATH] = "systemd-user-generator-path",
[SD_PATH_SYSTEMD_SLEEP_DIR] = "systemd-sleep-dir",
[SD_PATH_SYSTEMD_SHUTDOWN_DIR] = "systemd-shutdown-dir",
[SD_PATH_SYSTEMD_UTIL] = "systemd-util",
[SD_PATH_SYSTEMD_SYSTEM_UNIT] = "systemd-system-unit",
[SD_PATH_SYSTEMD_SYSTEM_PRESET] = "systemd-system-preset",
[SD_PATH_SYSTEMD_SYSTEM_CONF] = "systemd-system-conf",
[SD_PATH_SYSTEMD_SEARCH_SYSTEM_UNIT] = "systemd-system-unit",
[SD_PATH_SYSTEMD_SYSTEM_GENERATOR] = "systemd-system-generator",
[SD_PATH_SYSTEMD_SEARCH_SYSTEM_GENERATOR] = "systemd-system-generator",
[SD_PATH_SYSTEMD_USER_UNIT] = "systemd-user-unit",
[SD_PATH_SYSTEMD_USER_PRESET] = "systemd-user-preset",
[SD_PATH_SYSTEMD_USER_CONF] = "systemd-user-conf",
[SD_PATH_SYSTEMD_SEARCH_USER_UNIT] = "systemd-user-unit",
[SD_PATH_SYSTEMD_SEARCH_USER_GENERATOR] = "systemd-user-generator",
[SD_PATH_SYSTEMD_USER_GENERATOR] = "systemd-user-generator",
[SD_PATH_SYSTEMD_SLEEP] = "systemd-sleep",
[SD_PATH_SYSTEMD_SHUTDOWN] = "systemd-shutdown",
[SD_PATH_TMPFILES_DIR] = "tmpfiles-dir",
[SD_PATH_SYSUSERS_DIR] = "sysusers-dir",
[SD_PATH_SYSCTL_DIR] = "sysctl-dir",
[SD_PATH_BINFMT_DIR] = "binfmt-dir",
[SD_PATH_MODULES_LOAD_DIR] = "modules-load-dir",
[SD_PATH_CATALOG_DIR] = "catalog-dir",
[SD_PATH_TMPFILES] = "tmpfiles",
[SD_PATH_SYSUSERS] = "sysusers",
[SD_PATH_SYSCTL] = "sysctl",
[SD_PATH_BINFMT] = "binfmt",
[SD_PATH_MODULES_LOAD] = "modules-load",
[SD_PATH_CATALOG] = "catalog",
[SD_PATH_SYSTEMD_NETWORK_PATH] = "systemd-network-path",
[SD_PATH_SYSTEMD_SEARCH_NETWORK] = "systemd-search-network",
};
static int list_homes(void) {

View File

@ -78,32 +78,37 @@ enum {
SD_PATH_SEARCH_STATE_FACTORY,
SD_PATH_SEARCH_CONFIGURATION,
/* Various systemd paths, generally mirroring systemd.pc */
SD_PATH_SYSTEMD_UTIL_DIR,
SD_PATH_SYSTEMD_SYSTEM_UNIT_DIR,
SD_PATH_SYSTEMD_SYSTEM_PRESET_DIR,
SD_PATH_SYSTEMD_USER_UNIT_DIR,
SD_PATH_SYSTEMD_USER_PRESET_DIR,
SD_PATH_SYSTEMD_SYSTEM_CONF_DIR,
SD_PATH_SYSTEMD_USER_CONF_DIR,
SD_PATH_SYSTEMD_SYSTEM_UNIT_PATH,
SD_PATH_SYSTEMD_USER_UNIT_PATH,
SD_PATH_SYSTEMD_SYSTEM_GENERATOR_DIR,
SD_PATH_SYSTEMD_USER_GENERATOR_DIR,
SD_PATH_SYSTEMD_SYSTEM_GENERATOR_PATH,
SD_PATH_SYSTEMD_USER_GENERATOR_PATH,
SD_PATH_SYSTEMD_SLEEP_DIR,
SD_PATH_SYSTEMD_SHUTDOWN_DIR,
/* Various systemd paths, generally mirroring systemd.pc — Except we drop the "dir" suffix (and
* replaces "path" by "search"), since this API is about dirs/paths anyway, and contains "path"
* already in the prefix */
SD_PATH_SYSTEMD_UTIL,
SD_PATH_SYSTEMD_SYSTEM_UNIT,
SD_PATH_SYSTEMD_SYSTEM_PRESET,
SD_PATH_SYSTEMD_SYSTEM_CONF,
SD_PATH_SYSTEMD_USER_UNIT,
SD_PATH_SYSTEMD_USER_PRESET,
SD_PATH_SYSTEMD_USER_CONF,
SD_PATH_TMPFILES_DIR,
SD_PATH_SYSUSERS_DIR,
SD_PATH_SYSCTL_DIR,
SD_PATH_BINFMT_DIR,
SD_PATH_MODULES_LOAD_DIR,
SD_PATH_CATALOG_DIR,
SD_PATH_SYSTEMD_SEARCH_SYSTEM_UNIT,
SD_PATH_SYSTEMD_SEARCH_USER_UNIT,
SD_PATH_SYSTEMD_SYSTEM_GENERATOR,
SD_PATH_SYSTEMD_USER_GENERATOR,
SD_PATH_SYSTEMD_SEARCH_SYSTEM_GENERATOR,
SD_PATH_SYSTEMD_SEARCH_USER_GENERATOR,
SD_PATH_SYSTEMD_SLEEP,
SD_PATH_SYSTEMD_SHUTDOWN,
SD_PATH_TMPFILES,
SD_PATH_SYSUSERS,
SD_PATH_SYSCTL,
SD_PATH_BINFMT,
SD_PATH_MODULES_LOAD,
SD_PATH_CATALOG,
/* systemd-networkd search paths */
SD_PATH_SYSTEMD_NETWORK_PATH,
SD_PATH_SYSTEMD_SEARCH_NETWORK,
_SD_PATH_MAX,
};