chiark / gitweb /
Use attribute(unused) in PROTECT_ERRNO
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 26 Apr 2013 00:53:29 +0000 (20:53 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 26 Apr 2013 01:50:48 +0000 (21:50 -0400)
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
src/shared/util.h
src/test/test-util.c

index b79a24a495e6f6ddccf8e09d6c1e144df01af113..46a8128eb4030d8373da43a54b2b419b1c7a9e8c 100644 (file)
@@ -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);
index 68e87da7cd4213ed35f1e755d8a83dbdd7e37dfa..e3fc876857876f3a5e9f8b4cc9b8b9b71d2d22ed 100644 (file)
@@ -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;
index 66a10ead461489cc628fb070dd42c7b8e0ef1975..4c3a8a6b88d46d6c07c6e7f5de3cfe2c373492fc 100644 (file)
@@ -24,6 +24,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <locale.h>
+#include <errno.h>
 
 #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;
 }