xref: /OK3568_Linux_fs/buildroot/package/netplug/0003-remove-assert-fail.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593SmuzhiyunRemove __assert_fail()
2*4882a593Smuzhiyun
3*4882a593SmuzhiyunThe netplug code uses the assert() macro in various places. In glibc
4*4882a593Smuzhiyuninternally, assert() uses a function called __assert_fail() to print a
5*4882a593Smuzhiyunmessage and abort. Relying on internal glibc details, netplug
6*4882a593Smuzhiyunre-defines __assert_fail() in the hope that it will get called instead
7*4882a593Smuzhiyunof glibc internal version.
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunThis attempt:
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun * Doesn't work with uClibc, which doesn't use any __assert_fail()
12*4882a593Smuzhiyun   function at all. It doesn't fail to build, but it is entirely
13*4882a593Smuzhiyun   useless.
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun * Fails to build with musl, which also defines __assert_fail(), but
16*4882a593Smuzhiyun   with a different prototype.
17*4882a593Smuzhiyun
18*4882a593SmuzhiyunWe simply remove the __assert_fail() implementation, so that the C
19*4882a593Smuzhiyunlibrary implementation of assert() just does its normal work. The only
20*4882a593Smuzhiyunfunctionality lost is that the message is displayed on the standard
21*4882a593Smuzhiyunoutput rather than in netplug's logs (and this was only working with
22*4882a593Smuzhiyunglibc anyway).
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunSigned-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunIndex: b/lib.c
27*4882a593Smuzhiyun===================================================================
28*4882a593Smuzhiyun--- a/lib.c
29*4882a593Smuzhiyun+++ b/lib.c
30*4882a593Smuzhiyun@@ -199,21 +199,6 @@
31*4882a593Smuzhiyun     return x;
32*4882a593Smuzhiyun }
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun-
35*4882a593Smuzhiyun-void
36*4882a593Smuzhiyun-__assert_fail(const char *assertion, const char *file,
37*4882a593Smuzhiyun-              unsigned int line, const char *function)
38*4882a593Smuzhiyun-{
39*4882a593Smuzhiyun-    do_log(LOG_CRIT, "%s:%u: %s%sAssertion `%s' failed",
40*4882a593Smuzhiyun-           file, line,
41*4882a593Smuzhiyun-           function ? function : "",
42*4882a593Smuzhiyun-           function ? ": " : "",
43*4882a593Smuzhiyun-           assertion);
44*4882a593Smuzhiyun-
45*4882a593Smuzhiyun-    abort();
46*4882a593Smuzhiyun-}
47*4882a593Smuzhiyun-
48*4882a593Smuzhiyun-
49*4882a593Smuzhiyun /*
50*4882a593Smuzhiyun  * Local variables:
51*4882a593Smuzhiyun  * c-file-style: "stroustrup"
52