summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-10-11 19:34:17 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-10-13 17:56:54 -0400
commit872c8faaf2009422a91d227ae0b5c6f04c9d2c69 (patch)
treea6b03abbcd801638098ec591f48873b39f6a0dcd
parent51d122af23533b0b8318911c4fc8b128ad8eafb7 (diff)
Fix write-only use of a few variables
Since the invention of read-only memory, write-only memory has been considered deprecated. Where appropriate, either make use of the value, or avoid writing it, to make it clear that it is not used.
-rw-r--r--src/analyze/systemd-analyze.c12
-rw-r--r--src/bootchart/bootchart.c2
-rw-r--r--src/bootchart/svg.c18
-rw-r--r--src/hostname/hostnamectl.c2
-rw-r--r--src/journal/coredump.c12
-rw-r--r--src/libsystemd-bus/test-bus-memfd.c2
-rw-r--r--src/login/logind-dbus.c2
-rw-r--r--src/systemctl/systemctl.c2
-rw-r--r--src/test/test-libudev.c4
-rw-r--r--src/udev/udevadm-hwdb.c2
10 files changed, 27 insertions, 31 deletions
diff --git a/src/analyze/systemd-analyze.c b/src/analyze/systemd-analyze.c
index a4f15eb646..26769d6c37 100644
--- a/src/analyze/systemd-analyze.c
+++ b/src/analyze/systemd-analyze.c
@@ -384,9 +384,9 @@ static int pretty_boot_time(DBusConnection *bus, char **_buf) {
size = strpcpyf(&ptr, size, "%s (userspace) ", format_timespan(ts, sizeof(ts), t->finish_time - t->userspace_time, USEC_PER_MSEC));
if (t->kernel_time > 0)
- size = strpcpyf(&ptr, size, "= %s", format_timespan(ts, sizeof(ts), t->firmware_time + t->finish_time, USEC_PER_MSEC));
+ strpcpyf(&ptr, size, "= %s", format_timespan(ts, sizeof(ts), t->firmware_time + t->finish_time, USEC_PER_MSEC));
else
- size = strpcpyf(&ptr, size, "= %s", format_timespan(ts, sizeof(ts), t->finish_time - t->userspace_time, USEC_PER_MSEC));
+ strpcpyf(&ptr, size, "= %s", format_timespan(ts, sizeof(ts), t->finish_time - t->userspace_time, USEC_PER_MSEC));
ptr = strdup(buf);
if (!ptr)
@@ -818,18 +818,18 @@ static int list_dependencies_one(DBusConnection *bus, const char *name, unsigned
if (strv_contains(*units, *c)) {
r = list_dependencies_print("...", level + 1, (branches << 1) | (to_print ? 1 : 0),
true, NULL, boot);
+ if (r < 0)
+ return r;
continue;
}
r = list_dependencies_one(bus, *c, level + 1, units,
(branches << 1) | (to_print ? 1 : 0));
- if(r < 0)
+ if (r < 0)
return r;
-
- if(!to_print)
+ if (!to_print)
break;
-
}
return 0;
}
diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c
index 14ccd3efe5..edbd3815cd 100644
--- a/src/bootchart/bootchart.c
+++ b/src/bootchart/bootchart.c
@@ -254,7 +254,7 @@ static void do_journal_append(char *file)
p = malloc(9 + BOOTCHART_MAX);
if (!p) {
- r = log_oom();
+ log_oom();
return;
}
diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c
index 5eee2d1987..7ac0138a2b 100644
--- a/src/bootchart/svg.c
+++ b/src/bootchart/svg.c
@@ -420,13 +420,10 @@ static void svg_pss_graph(void) {
i = 1;
LIST_FOREACH_BEFORE(link, sampledata, head) {
int bottom;
- int top;
+ int top = 0;
struct ps_sched_struct *prev_sample;
struct ps_sched_struct *cross_place;
- bottom = 0;
- top = 0;
-
/* put all the small pss blocks into the bottom */
ps = ps_first->next_ps;
while (ps->next_ps) {
@@ -533,8 +530,8 @@ static void svg_io_bi_bar(void) {
int max_here = 0;
int i;
int k;
- struct list_sample_data *start_sampledata = sampledata;
- struct list_sample_data *stop_sampledata = sampledata;
+ struct list_sample_data *start_sampledata;
+ struct list_sample_data *stop_sampledata;
svg("<!-- IO utilization graph - In -->\n");
@@ -599,10 +596,7 @@ static void svg_io_bi_bar(void) {
int stop;
int diff;
double tot;
- double pbi;
-
- tot = 0;
- pbi = 0;
+ double pbi = 0;
start = MAX(i - ((range / 2) - 1), 0);
stop = MIN(i + (range / 2), samples);
@@ -647,8 +641,8 @@ static void svg_io_bo_bar(void) {
int max_here = 0;
int i;
int k;
- struct list_sample_data *start_sampledata = sampledata;
- struct list_sample_data *stop_sampledata = sampledata;
+ struct list_sample_data *start_sampledata;
+ struct list_sample_data *stop_sampledata;
svg("<!-- IO utilization graph - out -->\n");
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
index 66015c2f4c..c6d72b5417 100644
--- a/src/hostname/hostnamectl.c
+++ b/src/hostname/hostnamectl.c
@@ -110,6 +110,8 @@ static void print_status_info(StatusInfo *i) {
"PRETTY_NAME", &pretty_name,
"CPE_NAME", &cpe_name,
NULL);
+ if (r < 0)
+ log_warning("Failed to read /etc/os-release: %s", strerror(-r));
if (!isempty(pretty_name))
printf(" Operating System: %s\n", pretty_name);
diff --git a/src/journal/coredump.c b/src/journal/coredump.c
index 68c353fe83..733373b307 100644
--- a/src/journal/coredump.c
+++ b/src/journal/coredump.c
@@ -240,7 +240,7 @@ int main(int argc, char* argv[]) {
coredump_bufsize = COREDUMP_MIN_START;
coredump_data = malloc(coredump_bufsize);
if (!coredump_data) {
- r = log_oom();
+ log_warning("Failed to allocate memory for core, core will not be stored.");
goto finalize;
}
@@ -251,7 +251,7 @@ int main(int argc, char* argv[]) {
n = loop_read(STDIN_FILENO, coredump_data + coredump_size,
coredump_bufsize - coredump_size, false);
if (n < 0) {
- log_error("Failed to read core dump data: %s", strerror(-n));
+ log_error("Failed to read core data: %s", strerror(-n));
r = (int) n;
goto finish;
} else if (n == 0)
@@ -259,13 +259,13 @@ int main(int argc, char* argv[]) {
coredump_size += n;
- if(coredump_size > COREDUMP_MAX) {
- log_error("Coredump too large, ignoring");
+ if (coredump_size > COREDUMP_MAX) {
+ log_error("Core too large, core will not be stored.");
goto finalize;
}
if (!GREEDY_REALLOC(coredump_data, coredump_bufsize, coredump_size + 1)) {
- r = log_oom();
+ log_warning("Failed to allocate memory for core, core will not be stored.");
goto finalize;
}
}
@@ -277,7 +277,7 @@ int main(int argc, char* argv[]) {
finalize:
r = sd_journal_sendv(iovec, j);
if (r < 0)
- log_error("Failed to send coredump: %s", strerror(-r));
+ log_error("Failed to log coredump: %s", strerror(-r));
finish:
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
diff --git a/src/libsystemd-bus/test-bus-memfd.c b/src/libsystemd-bus/test-bus-memfd.c
index 05ef555f0d..b9d6a250c3 100644
--- a/src/libsystemd-bus/test-bus-memfd.c
+++ b/src/libsystemd-bus/test-bus-memfd.c
@@ -102,7 +102,7 @@ int main(int argc, char *argv[]) {
/* we did truncate it to 6 */
r = sd_memfd_get_size(m, &sz);
- assert_se(sz == 6);
+ assert_se(r >= 0 && sz == 6);
/* map it, check content */
r = sd_memfd_map(m, 0, 12, (void **)&s);
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index bb85c7d4af..890c5c6b1d 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -484,7 +484,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message) {
return -EINVAL;
}
- r = manager_get_session_by_pid(m, leader, &session);
+ manager_get_session_by_pid(m, leader, &session);
if (session) {
_cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
_cleanup_free_ char *path = NULL;
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 036828b5dd..a8a86edd1f 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -748,7 +748,7 @@ static int list_sockets(DBusConnection *bus, char **args) {
}
free(socket_infos);
- return 0;
+ return r;
}
static int compare_unit_file_list(const void *a, const void *b) {
diff --git a/src/test/test-libudev.c b/src/test/test-libudev.c
index 716767ba5f..f79d20cbfb 100644
--- a/src/test/test-libudev.c
+++ b/src/test/test-libudev.c
@@ -429,7 +429,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem)
return 0;
}
-static int test_hwdb(struct udev *udev, const char *modalias) {
+static void test_hwdb(struct udev *udev, const char *modalias) {
struct udev_hwdb *hwdb;
struct udev_list_entry *entry;
@@ -440,7 +440,7 @@ static int test_hwdb(struct udev *udev, const char *modalias) {
printf("\n");
hwdb = udev_hwdb_unref(hwdb);
- return 0;
+ assert(hwdb == NULL);
}
int main(int argc, char *argv[])
diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c
index d9dc73bfc1..d0cce84859 100644
--- a/src/udev/udevadm-hwdb.c
+++ b/src/udev/udevadm-hwdb.c
@@ -648,7 +648,7 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
udev_list_entry_foreach(entry, udev_hwdb_get_properties_list_entry(hwdb, test, 0))
printf("%s=%s\n", udev_list_entry_get_name(entry), udev_list_entry_get_value(entry));
- hwdb = udev_hwdb_unref(hwdb);
+ udev_hwdb_unref(hwdb);
}
}
out: