summaryrefslogtreecommitdiffstats
path: root/src/systemctl
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-05-19 23:22:44 +0200
committerGitHub <noreply@github.com>2021-05-19 23:22:44 +0200
commited056c560b47f84a0aa0289151f4ec91f786d24a (patch)
treea6090ba19eae10a48a8bf0e446b991f16aa872c3 /src/systemctl
parentMerge pull request #19603 from yuwata/network-link-get-by-name (diff)
parentalloc-util: simplify GREEDY_REALLOC() logic by relying on malloc_usable_size() (diff)
downloadsystemd-ed056c560b47f84a0aa0289151f4ec91f786d24a.tar.xz
systemd-ed056c560b47f84a0aa0289151f4ec91f786d24a.zip
Merge pull request #19653 from poettering/greedy-realloc-more
malloc_usable_size() tweaks
Diffstat (limited to 'src/systemctl')
-rw-r--r--src/systemctl/systemctl-list-jobs.c3
-rw-r--r--src/systemctl/systemctl-list-machines.c5
-rw-r--r--src/systemctl/systemctl-list-unit-files.c3
-rw-r--r--src/systemctl/systemctl-list-units.c6
-rw-r--r--src/systemctl/systemctl-util.c8
5 files changed, 9 insertions, 16 deletions
diff --git a/src/systemctl/systemctl-list-jobs.c b/src/systemctl/systemctl-list-jobs.c
index 7ac0496382..a050e09c17 100644
--- a/src/systemctl/systemctl-list-jobs.c
+++ b/src/systemctl/systemctl-list-jobs.c
@@ -131,7 +131,6 @@ int list_jobs(int argc, char *argv[], void *userdata) {
_cleanup_free_ struct job_info *jobs = NULL;
const char *name, *type, *state;
bool skipped = false;
- size_t size = 0;
unsigned c = 0;
sd_bus *bus;
uint32_t id;
@@ -157,7 +156,7 @@ int list_jobs(int argc, char *argv[], void *userdata) {
continue;
}
- if (!GREEDY_REALLOC(jobs, size, c + 1))
+ if (!GREEDY_REALLOC(jobs, c + 1))
return log_oom();
jobs[c++] = job;
diff --git a/src/systemctl/systemctl-list-machines.c b/src/systemctl/systemctl-list-machines.c
index 2e891b103c..1a2f2d7153 100644
--- a/src/systemctl/systemctl-list-machines.c
+++ b/src/systemctl/systemctl-list-machines.c
@@ -93,7 +93,6 @@ static int get_machine_list(
struct machine_info *machine_infos = NULL;
_cleanup_strv_free_ char **m = NULL;
_cleanup_free_ char *hn = NULL;
- size_t sz = 0;
char **i;
int c = 0, r;
@@ -102,7 +101,7 @@ static int get_machine_list(
return log_oom();
if (output_show_machine(hn, patterns)) {
- if (!GREEDY_REALLOC0(machine_infos, sz, c+1))
+ if (!GREEDY_REALLOC0(machine_infos, c+1))
return log_oom();
machine_infos[c].is_host = true;
@@ -126,7 +125,7 @@ static int get_machine_list(
if (!streq_ptr(class, "container"))
continue;
- if (!GREEDY_REALLOC0(machine_infos, sz, c+1)) {
+ if (!GREEDY_REALLOC0(machine_infos, c+1)) {
free_machines_list(machine_infos, c);
return log_oom();
}
diff --git a/src/systemctl/systemctl-list-unit-files.c b/src/systemctl/systemctl-list-unit-files.c
index 1bf2fc18f3..fd10e7965b 100644
--- a/src/systemctl/systemctl-list-unit-files.c
+++ b/src/systemctl/systemctl-list-unit-files.c
@@ -136,7 +136,6 @@ static int output_unit_file_list(const UnitFileList *units, unsigned c) {
int list_unit_files(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_free_ UnitFileList *units = NULL;
- size_t size = 0;
unsigned c = 0;
const char *state;
char *path;
@@ -234,7 +233,7 @@ int list_unit_files(int argc, char *argv[], void *userdata) {
while ((r = sd_bus_message_read(reply, "(ss)", &path, &state)) > 0) {
- if (!GREEDY_REALLOC(units, size, c + 1))
+ if (!GREEDY_REALLOC(units, c + 1))
return log_oom();
units[c] = (struct UnitFileList) {
diff --git a/src/systemctl/systemctl-list-units.c b/src/systemctl/systemctl-list-units.c
index 135d8388a3..1efb569971 100644
--- a/src/systemctl/systemctl-list-units.c
+++ b/src/systemctl/systemctl-list-units.c
@@ -432,7 +432,6 @@ int list_sockets(int argc, char *argv[], void *userdata) {
_cleanup_free_ UnitInfo *unit_infos = NULL;
_cleanup_free_ struct socket_info *socket_infos = NULL;
unsigned cs = 0;
- size_t size = 0;
int r, n;
sd_bus *bus;
@@ -468,7 +467,7 @@ int list_sockets(int argc, char *argv[], void *userdata) {
goto cleanup;
}
- if (!GREEDY_REALLOC(socket_infos, size, cs + c)) {
+ if (!GREEDY_REALLOC(socket_infos, cs + c)) {
r = log_oom();
goto cleanup;
}
@@ -695,7 +694,6 @@ int list_timers(int argc, char *argv[], void *userdata) {
_cleanup_strv_free_ char **timers_with_suffix = NULL;
_cleanup_free_ struct timer_info *timer_infos = NULL;
_cleanup_free_ UnitInfo *unit_infos = NULL;
- size_t size = 0;
int n, c = 0;
dual_timestamp nw;
sd_bus *bus;
@@ -736,7 +734,7 @@ int list_timers(int argc, char *argv[], void *userdata) {
get_last_trigger(bus, u->unit_path, &last);
- if (!GREEDY_REALLOC(timer_infos, size, c+1)) {
+ if (!GREEDY_REALLOC(timer_infos, c+1)) {
r = log_oom();
goto cleanup;
}
diff --git a/src/systemctl/systemctl-util.c b/src/systemctl/systemctl-util.c
index d1490c906d..99f1394bcf 100644
--- a/src/systemctl/systemctl-util.c
+++ b/src/systemctl/systemctl-util.c
@@ -158,7 +158,6 @@ int get_unit_list(
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
- size_t size = c;
int r;
bool fallback = false;
@@ -218,7 +217,7 @@ int get_unit_list(
if (!output_show_unit(&u, fallback ? patterns : NULL))
continue;
- if (!GREEDY_REALLOC(*unit_infos, size, c+1))
+ if (!GREEDY_REALLOC(*unit_infos, c+1))
return log_oom();
(*unit_infos)[c++] = u;
@@ -261,17 +260,16 @@ int expand_unit_names(sd_bus *bus, char **names, const char* suffix, char ***ret
if (expanded) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_free_ UnitInfo *unit_infos = NULL;
- size_t allocated, n;
+ size_t n;
r = get_unit_list(bus, NULL, globs, &unit_infos, 0, &reply);
if (r < 0)
return r;
n = strv_length(mangled);
- allocated = n + 1;
for (int i = 0; i < r; i++) {
- if (!GREEDY_REALLOC(mangled, allocated, n+2))
+ if (!GREEDY_REALLOC(mangled, n+2))
return log_oom();
mangled[n] = strdup(unit_infos[i].id);