mirror of
https://github.com/systemd/systemd.git
synced 2024-12-26 03:22:00 +03:00
Mark *data and *userdata params to specifier_printf() as const
It would be very wrong if any of the specfier printf calls modified any of the objects or data being printed. Let's mark all arguments as const (primarily to make it easier for the reader to see where modifications cannot occur).
This commit is contained in:
parent
9be3c60570
commit
303ee60151
@ -1491,7 +1491,7 @@ static const char *migrate_callback(CGroupMask mask, void *userdata) {
|
||||
return unit_get_realized_cgroup_path(userdata, mask);
|
||||
}
|
||||
|
||||
char *unit_default_cgroup_path(Unit *u) {
|
||||
char *unit_default_cgroup_path(const Unit *u) {
|
||||
_cleanup_free_ char *escaped = NULL, *slice = NULL;
|
||||
int r;
|
||||
|
||||
|
@ -164,7 +164,7 @@ void unit_invalidate_cgroup_members_masks(Unit *u);
|
||||
void unit_add_to_cgroup_realize_queue(Unit *u);
|
||||
|
||||
const char *unit_get_realized_cgroup_path(Unit *u, CGroupMask mask);
|
||||
char *unit_default_cgroup_path(Unit *u);
|
||||
char *unit_default_cgroup_path(const Unit *u);
|
||||
int unit_set_cgroup_path(Unit *u, const char *path);
|
||||
int unit_pick_cgroup_path(Unit *u);
|
||||
|
||||
|
@ -12,25 +12,25 @@
|
||||
#include "unit.h"
|
||||
#include "user-util.h"
|
||||
|
||||
static int specifier_prefix_and_instance(char specifier, void *data, void *userdata, char **ret) {
|
||||
Unit *u = userdata;
|
||||
static int specifier_prefix_and_instance(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
const Unit *u = userdata;
|
||||
|
||||
assert(u);
|
||||
|
||||
return unit_name_to_prefix_and_instance(u->id, ret);
|
||||
}
|
||||
|
||||
static int specifier_prefix(char specifier, void *data, void *userdata, char **ret) {
|
||||
Unit *u = userdata;
|
||||
static int specifier_prefix(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
const Unit *u = userdata;
|
||||
|
||||
assert(u);
|
||||
|
||||
return unit_name_to_prefix(u->id, ret);
|
||||
}
|
||||
|
||||
static int specifier_prefix_unescaped(char specifier, void *data, void *userdata, char **ret) {
|
||||
static int specifier_prefix_unescaped(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
Unit *u = userdata;
|
||||
const Unit *u = userdata;
|
||||
int r;
|
||||
|
||||
assert(u);
|
||||
@ -42,16 +42,16 @@ static int specifier_prefix_unescaped(char specifier, void *data, void *userdata
|
||||
return unit_name_unescape(p, ret);
|
||||
}
|
||||
|
||||
static int specifier_instance_unescaped(char specifier, void *data, void *userdata, char **ret) {
|
||||
Unit *u = userdata;
|
||||
static int specifier_instance_unescaped(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
const Unit *u = userdata;
|
||||
|
||||
assert(u);
|
||||
|
||||
return unit_name_unescape(strempty(u->instance), ret);
|
||||
}
|
||||
|
||||
static int specifier_last_component(char specifier, void *data, void *userdata, char **ret) {
|
||||
Unit *u = userdata;
|
||||
static int specifier_last_component(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
const Unit *u = userdata;
|
||||
_cleanup_free_ char *prefix = NULL;
|
||||
char *dash;
|
||||
int r;
|
||||
@ -70,7 +70,7 @@ static int specifier_last_component(char specifier, void *data, void *userdata,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int specifier_last_component_unescaped(char specifier, void *data, void *userdata, char **ret) {
|
||||
static int specifier_last_component_unescaped(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
int r;
|
||||
|
||||
@ -81,8 +81,8 @@ static int specifier_last_component_unescaped(char specifier, void *data, void *
|
||||
return unit_name_unescape(p, ret);
|
||||
}
|
||||
|
||||
static int specifier_filename(char specifier, void *data, void *userdata, char **ret) {
|
||||
Unit *u = userdata;
|
||||
static int specifier_filename(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
const Unit *u = userdata;
|
||||
|
||||
assert(u);
|
||||
|
||||
@ -92,12 +92,12 @@ static int specifier_filename(char specifier, void *data, void *userdata, char *
|
||||
return unit_name_to_path(u->id, ret);
|
||||
}
|
||||
|
||||
static void bad_specifier(Unit *u, char specifier) {
|
||||
static void bad_specifier(const Unit *u, char specifier) {
|
||||
log_unit_warning(u, "Specifier '%%%c' used in unit configuration, which is deprecated. Please update your unit file, as it does not work as intended.", specifier);
|
||||
}
|
||||
|
||||
static int specifier_cgroup(char specifier, void *data, void *userdata, char **ret) {
|
||||
Unit *u = userdata;
|
||||
static int specifier_cgroup(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
const Unit *u = userdata;
|
||||
char *n;
|
||||
|
||||
assert(u);
|
||||
@ -115,8 +115,8 @@ static int specifier_cgroup(char specifier, void *data, void *userdata, char **r
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int specifier_cgroup_root(char specifier, void *data, void *userdata, char **ret) {
|
||||
Unit *u = userdata;
|
||||
static int specifier_cgroup_root(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
const Unit *u = userdata;
|
||||
char *n;
|
||||
|
||||
assert(u);
|
||||
@ -131,8 +131,8 @@ static int specifier_cgroup_root(char specifier, void *data, void *userdata, cha
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int specifier_cgroup_slice(char specifier, void *data, void *userdata, char **ret) {
|
||||
Unit *u = userdata;
|
||||
static int specifier_cgroup_slice(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
const Unit *u = userdata;
|
||||
char *n;
|
||||
|
||||
assert(u);
|
||||
@ -140,7 +140,7 @@ static int specifier_cgroup_slice(char specifier, void *data, void *userdata, ch
|
||||
bad_specifier(u, specifier);
|
||||
|
||||
if (UNIT_ISSET(u->slice)) {
|
||||
Unit *slice;
|
||||
const Unit *slice;
|
||||
|
||||
slice = UNIT_DEREF(u->slice);
|
||||
|
||||
@ -157,8 +157,8 @@ static int specifier_cgroup_slice(char specifier, void *data, void *userdata, ch
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int specifier_special_directory(char specifier, void *data, void *userdata, char **ret) {
|
||||
Unit *u = userdata;
|
||||
static int specifier_special_directory(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
const Unit *u = userdata;
|
||||
char *n = NULL;
|
||||
|
||||
assert(u);
|
||||
|
@ -132,7 +132,7 @@ int unit_new_for_name(Manager *m, size_t size, const char *name, Unit **ret) {
|
||||
return r;
|
||||
}
|
||||
|
||||
bool unit_has_name(Unit *u, const char *name) {
|
||||
bool unit_has_name(const Unit *u, const char *name) {
|
||||
assert(u);
|
||||
assert(name);
|
||||
|
||||
|
@ -648,7 +648,7 @@ int unit_set_default_slice(Unit *u);
|
||||
|
||||
const char *unit_description(Unit *u) _pure_;
|
||||
|
||||
bool unit_has_name(Unit *u, const char *name);
|
||||
bool unit_has_name(const Unit *u, const char *name);
|
||||
|
||||
UnitActiveState unit_active_state(Unit *u);
|
||||
|
||||
|
@ -141,7 +141,7 @@ static int dnssd_service_load(Manager *manager, const char *filename) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int specifier_dnssd_host_name(char specifier, void *data, void *userdata, char **ret) {
|
||||
static int specifier_dnssd_host_name(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
DnssdService *s = (DnssdService *) userdata;
|
||||
char *n;
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "unit-name.h"
|
||||
#include "user-util.h"
|
||||
|
||||
static int specifier_prefix_and_instance(char specifier, void *data, void *userdata, char **ret) {
|
||||
static int specifier_prefix_and_instance(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
const UnitFileInstallInfo *i = userdata;
|
||||
_cleanup_free_ char *prefix = NULL;
|
||||
int r;
|
||||
@ -38,7 +38,7 @@ static int specifier_prefix_and_instance(char specifier, void *data, void *userd
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int specifier_name(char specifier, void *data, void *userdata, char **ret) {
|
||||
static int specifier_name(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
const UnitFileInstallInfo *i = userdata;
|
||||
char *ans;
|
||||
|
||||
@ -54,7 +54,7 @@ static int specifier_name(char specifier, void *data, void *userdata, char **ret
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int specifier_prefix(char specifier, void *data, void *userdata, char **ret) {
|
||||
static int specifier_prefix(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
const UnitFileInstallInfo *i = userdata;
|
||||
|
||||
assert(i);
|
||||
@ -62,7 +62,7 @@ static int specifier_prefix(char specifier, void *data, void *userdata, char **r
|
||||
return unit_name_to_prefix(i->name, ret);
|
||||
}
|
||||
|
||||
static int specifier_instance(char specifier, void *data, void *userdata, char **ret) {
|
||||
static int specifier_instance(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
const UnitFileInstallInfo *i = userdata;
|
||||
char *instance;
|
||||
int r;
|
||||
@ -83,7 +83,7 @@ static int specifier_instance(char specifier, void *data, void *userdata, char *
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int specifier_last_component(char specifier, void *data, void *userdata, char **ret) {
|
||||
static int specifier_last_component(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
_cleanup_free_ char *prefix = NULL;
|
||||
char *dash;
|
||||
int r;
|
||||
@ -104,8 +104,7 @@ static int specifier_last_component(char specifier, void *data, void *userdata,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int install_full_printf(UnitFileInstallInfo *i, const char *format, char **ret) {
|
||||
|
||||
int install_full_printf(const UnitFileInstallInfo *i, const char *format, char **ret) {
|
||||
/* This is similar to unit_full_printf() but does not support
|
||||
* anything path-related.
|
||||
*
|
||||
|
@ -3,4 +3,4 @@
|
||||
|
||||
#include "install.h"
|
||||
|
||||
int install_full_printf(UnitFileInstallInfo *i, const char *format, char **ret);
|
||||
int install_full_printf(const UnitFileInstallInfo *i, const char *format, char **ret);
|
||||
|
@ -27,7 +27,7 @@
|
||||
* and "%" used for escaping. */
|
||||
#define POSSIBLE_SPECIFIERS ALPHANUMERICAL "%"
|
||||
|
||||
int specifier_printf(const char *text, const Specifier table[], void *userdata, char **_ret) {
|
||||
int specifier_printf(const char *text, const Specifier table[], const void *userdata, char **_ret) {
|
||||
size_t l, allocated = 0;
|
||||
_cleanup_free_ char *ret = NULL;
|
||||
char *t;
|
||||
@ -102,7 +102,7 @@ int specifier_printf(const char *text, const Specifier table[], void *userdata,
|
||||
|
||||
/* Generic handler for simple string replacements */
|
||||
|
||||
int specifier_string(char specifier, void *data, void *userdata, char **ret) {
|
||||
int specifier_string(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
char *n;
|
||||
|
||||
n = strdup(strempty(data));
|
||||
@ -113,7 +113,7 @@ int specifier_string(char specifier, void *data, void *userdata, char **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int specifier_machine_id(char specifier, void *data, void *userdata, char **ret) {
|
||||
int specifier_machine_id(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
sd_id128_t id;
|
||||
char *n;
|
||||
int r;
|
||||
@ -130,7 +130,7 @@ int specifier_machine_id(char specifier, void *data, void *userdata, char **ret)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int specifier_boot_id(char specifier, void *data, void *userdata, char **ret) {
|
||||
int specifier_boot_id(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
sd_id128_t id;
|
||||
char *n;
|
||||
int r;
|
||||
@ -147,7 +147,7 @@ int specifier_boot_id(char specifier, void *data, void *userdata, char **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int specifier_host_name(char specifier, void *data, void *userdata, char **ret) {
|
||||
int specifier_host_name(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
char *n;
|
||||
|
||||
n = gethostname_malloc();
|
||||
@ -158,7 +158,7 @@ int specifier_host_name(char specifier, void *data, void *userdata, char **ret)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int specifier_kernel_release(char specifier, void *data, void *userdata, char **ret) {
|
||||
int specifier_kernel_release(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
struct utsname uts;
|
||||
char *n;
|
||||
int r;
|
||||
@ -175,7 +175,7 @@ int specifier_kernel_release(char specifier, void *data, void *userdata, char **
|
||||
return 0;
|
||||
}
|
||||
|
||||
int specifier_group_name(char specifier, void *data, void *userdata, char **ret) {
|
||||
int specifier_group_name(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
char *t;
|
||||
|
||||
t = gid_to_name(getgid());
|
||||
@ -186,14 +186,14 @@ int specifier_group_name(char specifier, void *data, void *userdata, char **ret)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int specifier_group_id(char specifier, void *data, void *userdata, char **ret) {
|
||||
int specifier_group_id(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
if (asprintf(ret, UID_FMT, getgid()) < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int specifier_user_name(char specifier, void *data, void *userdata, char **ret) {
|
||||
int specifier_user_name(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
char *t;
|
||||
|
||||
/* If we are UID 0 (root), this will not result in NSS, otherwise it might. This is good, as we want to be able
|
||||
@ -211,7 +211,7 @@ int specifier_user_name(char specifier, void *data, void *userdata, char **ret)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int specifier_user_id(char specifier, void *data, void *userdata, char **ret) {
|
||||
int specifier_user_id(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
|
||||
if (asprintf(ret, UID_FMT, getuid()) < 0)
|
||||
return -ENOMEM;
|
||||
@ -219,7 +219,7 @@ int specifier_user_id(char specifier, void *data, void *userdata, char **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int specifier_user_home(char specifier, void *data, void *userdata, char **ret) {
|
||||
int specifier_user_home(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
|
||||
/* On PID 1 (which runs as root) this will not result in NSS,
|
||||
* which is good. See above */
|
||||
@ -227,7 +227,7 @@ int specifier_user_home(char specifier, void *data, void *userdata, char **ret)
|
||||
return get_home_dir(ret);
|
||||
}
|
||||
|
||||
int specifier_user_shell(char specifier, void *data, void *userdata, char **ret) {
|
||||
int specifier_user_shell(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
|
||||
/* On PID 1 (which runs as root) this will not result in NSS,
|
||||
* which is good. See above */
|
||||
@ -235,7 +235,7 @@ int specifier_user_shell(char specifier, void *data, void *userdata, char **ret)
|
||||
return get_shell(ret);
|
||||
}
|
||||
|
||||
int specifier_tmp_dir(char specifier, void *data, void *userdata, char **ret) {
|
||||
int specifier_tmp_dir(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
const char *p;
|
||||
char *copy;
|
||||
int r;
|
||||
@ -252,7 +252,7 @@ int specifier_tmp_dir(char specifier, void *data, void *userdata, char **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int specifier_var_tmp_dir(char specifier, void *data, void *userdata, char **ret) {
|
||||
int specifier_var_tmp_dir(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
const char *p;
|
||||
char *copy;
|
||||
int r;
|
||||
|
@ -3,32 +3,32 @@
|
||||
|
||||
#include "string-util.h"
|
||||
|
||||
typedef int (*SpecifierCallback)(char specifier, void *data, void *userdata, char **ret);
|
||||
typedef int (*SpecifierCallback)(char specifier, const void *data, const void *userdata, char **ret);
|
||||
|
||||
typedef struct Specifier {
|
||||
const char specifier;
|
||||
const SpecifierCallback lookup;
|
||||
void *data;
|
||||
const void *data;
|
||||
} Specifier;
|
||||
|
||||
int specifier_printf(const char *text, const Specifier table[], void *userdata, char **ret);
|
||||
int specifier_printf(const char *text, const Specifier table[], const void *userdata, char **ret);
|
||||
|
||||
int specifier_string(char specifier, void *data, void *userdata, char **ret);
|
||||
int specifier_string(char specifier, const void *data, const void *userdata, char **ret);
|
||||
|
||||
int specifier_machine_id(char specifier, void *data, void *userdata, char **ret);
|
||||
int specifier_boot_id(char specifier, void *data, void *userdata, char **ret);
|
||||
int specifier_host_name(char specifier, void *data, void *userdata, char **ret);
|
||||
int specifier_kernel_release(char specifier, void *data, void *userdata, char **ret);
|
||||
int specifier_machine_id(char specifier, const void *data, const void *userdata, char **ret);
|
||||
int specifier_boot_id(char specifier, const void *data, const void *userdata, char **ret);
|
||||
int specifier_host_name(char specifier, const void *data, const void *userdata, char **ret);
|
||||
int specifier_kernel_release(char specifier, const void *data, const void *userdata, char **ret);
|
||||
|
||||
int specifier_group_name(char specifier, void *data, void *userdata, char **ret);
|
||||
int specifier_group_id(char specifier, void *data, void *userdata, char **ret);
|
||||
int specifier_user_name(char specifier, void *data, void *userdata, char **ret);
|
||||
int specifier_user_id(char specifier, void *data, void *userdata, char **ret);
|
||||
int specifier_user_home(char specifier, void *data, void *userdata, char **ret);
|
||||
int specifier_user_shell(char specifier, void *data, void *userdata, char **ret);
|
||||
int specifier_group_name(char specifier, const void *data, const void *userdata, char **ret);
|
||||
int specifier_group_id(char specifier, const void *data, const void *userdata, char **ret);
|
||||
int specifier_user_name(char specifier, const void *data, const void *userdata, char **ret);
|
||||
int specifier_user_id(char specifier, const void *data, const void *userdata, char **ret);
|
||||
int specifier_user_home(char specifier, const void *data, const void *userdata, char **ret);
|
||||
int specifier_user_shell(char specifier, const void *data, const void *userdata, char **ret);
|
||||
|
||||
int specifier_tmp_dir(char specifier, void *data, void *userdata, char **ret);
|
||||
int specifier_var_tmp_dir(char specifier, void *data, void *userdata, char **ret);
|
||||
int specifier_tmp_dir(char specifier, const void *data, const void *userdata, char **ret);
|
||||
int specifier_var_tmp_dir(char specifier, const void *data, const void *userdata, char **ret);
|
||||
|
||||
static inline char* specifier_escape(const char *string) {
|
||||
return strreplace(string, "%", "%%");
|
||||
|
@ -180,8 +180,8 @@ STATIC_DESTRUCTOR_REGISTER(arg_include_prefixes, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_exclude_prefixes, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
|
||||
|
||||
static int specifier_machine_id_safe(char specifier, void *data, void *userdata, char **ret);
|
||||
static int specifier_directory(char specifier, void *data, void *userdata, char **ret);
|
||||
static int specifier_machine_id_safe(char specifier, const void *data, const void *userdata, char **ret);
|
||||
static int specifier_directory(char specifier, const void *data, const void *userdata, char **ret);
|
||||
|
||||
static const Specifier specifier_table[] = {
|
||||
{ 'm', specifier_machine_id_safe, NULL },
|
||||
@ -204,7 +204,7 @@ static const Specifier specifier_table[] = {
|
||||
{}
|
||||
};
|
||||
|
||||
static int specifier_machine_id_safe(char specifier, void *data, void *userdata, char **ret) {
|
||||
static int specifier_machine_id_safe(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
int r;
|
||||
|
||||
/* If /etc/machine_id is missing or empty (e.g. in a chroot environment)
|
||||
@ -218,7 +218,7 @@ static int specifier_machine_id_safe(char specifier, void *data, void *userdata,
|
||||
return r;
|
||||
}
|
||||
|
||||
static int specifier_directory(char specifier, void *data, void *userdata, char **ret) {
|
||||
static int specifier_directory(char specifier, const void *data, const void *userdata, char **ret) {
|
||||
struct table_entry {
|
||||
uint64_t type;
|
||||
const char *suffix;
|
||||
|
Loading…
Reference in New Issue
Block a user