summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-07-27 12:27:28 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-08-03 10:05:10 +0200
commit04499a70fbff3f6b798028473f5c9234a53eaa2d (patch)
treeec7a851e163ee20ba5211c16a86f1c251543e0a7 /src/basic
parentc7cfde640d2b32ff1eb893d1fcd291c25cd421e7 (diff)
downloadsystemd-04499a70fbff3f6b798028473f5c9234a53eaa2d.tar.gz
Drop the text argument from assert_not_reached()
In general we almost never hit those asserts in production code, so users see them very rarely, if ever. But either way, we just need something that users can pass to the developers. We have quite a few of those asserts, and some have fairly nice messages, but many are like "WTF?" or "???" or "unexpected something". The error that is printed includes the file location, and function name. In almost all functions there's at most one assert, so the function name alone is enough to identify the failure for a developer. So we don't get much extra from the message, and we might just as well drop them. Dropping them makes our code a tiny bit smaller, and most importantly, improves development experience by making it easy to insert such an assert in the code without thinking how to phrase the argument.
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/architecture.c2
-rw-r--r--src/basic/hashmap.c6
-rw-r--r--src/basic/in-addr-util.c2
-rw-r--r--src/basic/log.c5
-rw-r--r--src/basic/log.h1
-rw-r--r--src/basic/macro.h4
-rw-r--r--src/basic/path-lookup.c8
-rw-r--r--src/basic/socket-util.h2
-rw-r--r--src/basic/stdio-util.h2
9 files changed, 15 insertions, 17 deletions
diff --git a/src/basic/architecture.c b/src/basic/architecture.c
index 409632c3f4..e5dafb9814 100644
--- a/src/basic/architecture.c
+++ b/src/basic/architecture.c
@@ -136,7 +136,7 @@ int uname_architecture(void) {
if (streq(arch_map[i].machine, u.machine))
return cached = arch_map[i].arch;
- assert_not_reached("Couldn't identify architecture. You need to patch systemd.");
+ assert_not_reached();
return _ARCHITECTURE_INVALID;
}
diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c
index 0decbb04e1..b51d70bc87 100644
--- a/src/basic/hashmap.c
+++ b/src/basic/hashmap.c
@@ -401,7 +401,7 @@ static struct hashmap_base_entry* bucket_at_virtual(HashmapBase *h, struct swap_
if (idx < _IDX_SWAP_END)
return &bucket_at_swap(swap, idx)->p.b;
- assert_not_reached("Invalid index");
+ assert_not_reached();
}
static dib_raw_t* dib_raw_ptr(HashmapBase *h) {
@@ -513,7 +513,7 @@ static void* entry_value(HashmapBase *h, struct hashmap_base_entry *e) {
return (void*) e->key;
default:
- assert_not_reached("Unknown hashmap type");
+ assert_not_reached();
}
}
@@ -1747,7 +1747,7 @@ HashmapBase* _hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS) {
r = set_merge((Set*)copy, (Set*)h);
break;
default:
- assert_not_reached("Unknown hashmap type");
+ assert_not_reached();
}
if (r < 0)
diff --git a/src/basic/in-addr-util.c b/src/basic/in-addr-util.c
index 9cc92a1c76..2187bd0cba 100644
--- a/src/basic/in-addr-util.c
+++ b/src/basic/in-addr-util.c
@@ -794,7 +794,7 @@ int in_addr_prefix_from_string_auto_internal(
k = 0;
break;
default:
- assert_not_reached("Invalid prefixlen mode");
+ assert_not_reached();
}
if (ret_family)
diff --git a/src/basic/log.c b/src/basic/log.c
index fb183ea9e7..bbc12a1cfb 100644
--- a/src/basic/log.c
+++ b/src/basic/log.c
@@ -863,12 +863,11 @@ _noreturn_ void log_assert_failed(
}
_noreturn_ void log_assert_failed_unreachable(
- const char *text,
const char *file,
int line,
const char *func) {
- log_assert(LOG_CRIT, text, file, line, func,
- "Code should not be reached '%s' at %s:%u, function %s(). Aborting.");
+ log_assert(LOG_CRIT, "Code should not be reached", file, line, func,
+ "%s at %s:%u, function %s(). Aborting.");
abort();
}
diff --git a/src/basic/log.h b/src/basic/log.h
index 738c181070..9a17cd6c3d 100644
--- a/src/basic/log.h
+++ b/src/basic/log.h
@@ -174,7 +174,6 @@ _noreturn_ void log_assert_failed(
const char *func);
_noreturn_ void log_assert_failed_unreachable(
- const char *text,
const char *file,
int line,
const char *func);
diff --git a/src/basic/macro.h b/src/basic/macro.h
index 90f4e02d19..92498b0f20 100644
--- a/src/basic/macro.h
+++ b/src/basic/macro.h
@@ -282,8 +282,8 @@ static inline int __coverity_check_and_return__(int condition) {
#define assert(expr) assert_message_se(expr, #expr)
#endif
-#define assert_not_reached(t) \
- log_assert_failed_unreachable(t, PROJECT_FILE, __LINE__, __PRETTY_FUNCTION__)
+#define assert_not_reached() \
+ log_assert_failed_unreachable(PROJECT_FILE, __LINE__, __PRETTY_FUNCTION__)
#define assert_return(expr, r) \
do { \
diff --git a/src/basic/path-lookup.c b/src/basic/path-lookup.c
index 05eb17d66c..987834b0d5 100644
--- a/src/basic/path-lookup.c
+++ b/src/basic/path-lookup.c
@@ -347,7 +347,7 @@ static int acquire_config_dirs(UnitFileScope scope, char **persistent, char **ru
return 0;
default:
- assert_not_reached("Hmm, unexpected scope value.");
+ assert_not_reached();
}
if (!a || !b)
@@ -405,7 +405,7 @@ static int acquire_control_dirs(UnitFileScope scope, char **persistent, char **r
return -EOPNOTSUPP;
default:
- assert_not_reached("Hmm, unexpected scope value.");
+ assert_not_reached();
}
*persistent = TAKE_PTR(a);
@@ -657,7 +657,7 @@ int lookup_paths_init(
break;
default:
- assert_not_reached("Hmm, unexpected scope?");
+ assert_not_reached();
}
if (!add)
@@ -807,7 +807,7 @@ char **generator_binary_paths(UnitFileScope scope) {
break;
default:
- assert_not_reached("Hmm, unexpected scope.");
+ assert_not_reached();
}
if (!add)
diff --git a/src/basic/socket-util.h b/src/basic/socket-util.h
index f92e425fd6..e857ae4341 100644
--- a/src/basic/socket-util.h
+++ b/src/basic/socket-util.h
@@ -245,7 +245,7 @@ struct cmsghdr* cmsg_find(struct msghdr *mh, int level, int type, socklen_t leng
_len = sizeof(struct sockaddr_vm); \
break; \
default: \
- assert_not_reached("invalid socket family"); \
+ assert_not_reached(); \
} \
_len; \
})
diff --git a/src/basic/stdio-util.h b/src/basic/stdio-util.h
index 6dc1e72312..0ed48b3fd4 100644
--- a/src/basic/stdio-util.h
+++ b/src/basic/stdio-util.h
@@ -58,7 +58,7 @@ do { \
(void) va_arg(ap, long double); \
break; \
default: \
- assert_not_reached("Unknown format string argument."); \
+ assert_not_reached(); \
} \
} \
} while (false)