Use attribute(unused) in PROTECT_ERRNO

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.
parent e0a974b4
...@@ -1208,7 +1208,6 @@ int cg_pid_get_path_shifted(pid_t pid, char **root, char **cgroup) { ...@@ -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){ int cg_path_decode_unit(const char *cgroup, char **unit){
_cleanup_free_ char *unescaped = NULL;
char *p, *e, *c, *s, *k; char *p, *e, *c, *s, *k;
assert(cgroup); assert(cgroup);
......
...@@ -644,7 +644,7 @@ static inline void _reset_errno_(int *saved_errno) { ...@@ -644,7 +644,7 @@ static inline void _reset_errno_(int *saved_errno) {
errno = *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_ { struct _umask_struct_ {
mode_t mask; mode_t mask;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <locale.h> #include <locale.h>
#include <errno.h>
#include "util.h" #include "util.h"
...@@ -429,6 +430,15 @@ static void test_get_process_comm(void) { ...@@ -429,6 +430,15 @@ static void test_get_process_comm(void) {
log_info("pid1 $PATH: '%s'", strna(i)); 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[]) { int main(int argc, char *argv[]) {
test_streq_ptr(); test_streq_ptr();
test_first_word(); test_first_word();
...@@ -456,6 +466,7 @@ int main(int argc, char *argv[]) { ...@@ -456,6 +466,7 @@ int main(int argc, char *argv[]) {
test_hostname_is_valid(); test_hostname_is_valid();
test_u64log2(); test_u64log2();
test_get_process_comm(); test_get_process_comm();
test_protect_errno();
return 0; return 0;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment