From 2a371001f8d23533a339a150eeffa3215773058d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 25 Apr 2013 20:53:29 -0400 Subject: [PATCH] Use attribute(unused) in PROTECT_ERRNO MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit clang emits warnings about unused attribute _saved_errno_, which drown out other—potentially useful—warnings. gcc documentation is not exactly verbose about the effects of __attribute__((unused)) on variables, but let's assume that it works if the unit test passes. --- src/shared/cgroup-util.c | 1 - src/shared/util.h | 2 +- src/test/test-util.c | 11 +++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c index b79a24a49..46a8128eb 100644 --- a/src/shared/cgroup-util.c +++ b/src/shared/cgroup-util.c @@ -1208,7 +1208,6 @@ int cg_pid_get_path_shifted(pid_t pid, char **root, char **cgroup) { } int cg_path_decode_unit(const char *cgroup, char **unit){ - _cleanup_free_ char *unescaped = NULL; char *p, *e, *c, *s, *k; assert(cgroup); diff --git a/src/shared/util.h b/src/shared/util.h index 68e87da7c..e3fc87685 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -644,7 +644,7 @@ static inline void _reset_errno_(int *saved_errno) { errno = *saved_errno; } -#define PROTECT_ERRNO _cleanup_(_reset_errno_) int _saved_errno_ = errno +#define PROTECT_ERRNO _cleanup_(_reset_errno_) __attribute__((unused)) int _saved_errno_ = errno struct _umask_struct_ { mode_t mask; diff --git a/src/test/test-util.c b/src/test/test-util.c index 66a10ead4..4c3a8a6b8 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "util.h" @@ -429,6 +430,15 @@ static void test_get_process_comm(void) { log_info("pid1 $PATH: '%s'", strna(i)); } +static void test_protect_errno(void) { + errno = 12; + { + PROTECT_ERRNO; + errno = 11; + } + assert(errno == 12); +} + int main(int argc, char *argv[]) { test_streq_ptr(); test_first_word(); @@ -456,6 +466,7 @@ int main(int argc, char *argv[]) { test_hostname_is_valid(); test_u64log2(); test_get_process_comm(); + test_protect_errno(); return 0; } -- 2.30.2