Thread 106166723 - /g/ [Archived: 303 hours ago]

Anonymous
8/6/2025, 10:24:20 PM No.106166723
123
123
md5: bf3f9e2edeb9de5d98ff2839ccf7a7ad🔍
I found the weirdest bug in Linux today.
Some 'if' statements may randomly return true or false.
I was banging my head thinking I was doing something wrong, but no.
If you put a boolean expression in a constantly running while loop, it may randomly switch between true and false.
How is this unacceptable?
Replies: >>106166743 >>106166744 >>106166761 >>106166864 >>106166907 >>106167073 >>106167122
Anonymous
8/6/2025, 10:25:51 PM No.106166743
>>106166723 (OP)
works on my machine
Anonymous
8/6/2025, 10:25:56 PM No.106166744
>>106166723 (OP)
Buy a CPU that has in-built error correction from space radiation, dumbass.
Anonymous
8/6/2025, 10:28:21 PM No.106166761
>>106166723 (OP)
What's your shell?
Replies: >>106166805
Anonymous
8/6/2025, 10:30:26 PM No.106166779
what? you should probably run memtest86
Replies: >>106166805
Anonymous
8/6/2025, 10:33:29 PM No.106166805
321
321
md5: c274036772425e65b445669f5353b302🔍
>>106166761
bash

>>106166779
I found the cause of this, it's clearly a software bug. It takes about 1 second to switch to false lol
Replies: >>106166862 >>106166864
Anonymous
8/6/2025, 10:38:39 PM No.106166862
>>106166805
..........whats the cause then? why are you showing us how long it takes?
Anonymous
8/6/2025, 10:38:47 PM No.106166864
>>106166723 (OP)
>>106166805
Post your code, anon. Anyone can echo TRUE 30 times and then echo FALSE.
Anonymous
8/6/2025, 10:43:14 PM No.106166907
>>106166723 (OP)
all of that stupid screenshot and 0 actual code. you're a troll until you prove it with code.
Replies: >>106166951
Anonymous
8/6/2025, 10:46:31 PM No.106166951
>>106166907

#!/bin/bash

set -euo pipefail

{
while true; do
if ! ldconfig -p | grep -q 'libc.so.6'; then
echo "FALSE"
exit 1
else
echo "TRUE"
fi
done
}
Replies: >>106167074 >>106167090 >>106167122 >>106167132 >>106167176 >>106167804 >>106171645 >>106173454
Anonymous
8/6/2025, 10:52:45 PM No.106167022
Wonder how old this bug is
Anonymous
8/6/2025, 10:58:39 PM No.106167073
>>106166723 (OP)
(you) issue
Anonymous
8/6/2025, 10:58:43 PM No.106167074
>>106166951
Oh shit. Use it to get root, anon.
Anonymous
8/6/2025, 11:01:21 PM No.106167090
>>106166951
It must be a scheduling error that causes IO clobber or grep/ldconfig failing. One test ran for 400 iterations another 83
Anonymous
8/6/2025, 11:03:48 PM No.106167113
it's this
>ldconfig -p | grep -q 'libc.so.6'
you can use a different shell and get the same exit. it's not bash and you can strip the program to a basic loop with no tests and still get the result.
Replies: >>106167133
Anonymous
8/6/2025, 11:04:55 PM No.106167122
>>106166723 (OP)
>Some 'if' statements may randomly return true or false.
>>106166951
>if i smash ldconfig in an endless loop with no break, at some point it will cut the output
Don't you think those are two very different "bugs" you got here?
Don't you think that you yourself should be able to narrow your issue down significantly?

This is not your personal support board where people solve your problems for free if you just act retarded enough.
sage
Replies: >>106167186
Anonymous
8/6/2025, 11:05:39 PM No.106167132
>>106166951
great catch! it is actually a very well-known bug across many different operating systems and informational systems at all - PEBKAC. you should definitely email about this problem to Torwalds, Stallman and Musk, they will give you a million dollars
Anonymous
8/6/2025, 11:05:41 PM No.106167133
>>106167113 (me)
actually it's 'pipefail -e' exiting when the pipe fails.
Anonymous
8/6/2025, 11:08:48 PM No.106167176
>>106166951
The behavior you're observing (the script returning TRUE many times before eventually exiting with FALSE) is due to a combination of factors in your script's design and how ldconfig works. Let me explain why this happens:

ldconfig -p performance: The ldconfig -p command (which prints the cache) is relatively expensive to run in a tight loop. It has to read and process the entire library cache each time.

Race condition: There's a small chance that between checking the library cache and the next check, the cache could be temporarily unavailable or in a state where libc.so.6 isn't found. This becomes more likely the more times you run the check.

set -e behavior: With set -e, if any command fails (including grep not finding a match), the script will exit. However, in your case, you're explicitly handling the grep failure with if !, so that's not the immediate issue.

Pipe behavior with set -o pipefail: The more likely explanation is that after many iterations, one of the commands in the pipeline (ldconfig -p | grep -q) fails in a way that triggers the pipefail. For example:

ldconfig might fail to access the cache due to system load

The pipe might break due to resource constraints after many iterations

System resource limits: After 80+ rapid iterations, you might be hitting some system resource limits (file descriptors, memory, etc.) which could cause one of the commands to fail.
Replies: >>106167539 >>106167594 >>106173708
Anonymous
8/6/2025, 11:09:35 PM No.106167186
>>106167122
The while loop is just an example. I was making a script that checked for a library once, and every time it was executed (once, not in a loop) it gave different results.
Replies: >>106167238 >>106167295
Anonymous
8/6/2025, 11:13:28 PM No.106167238
>>106167186
remove the set part. why did you even add that? it can't be your default for every script.
Anonymous
8/6/2025, 11:18:55 PM No.106167295
>>106167186
Oh, so
>ldconfig intermittently fails on my machine! Why is this?
That's all you had to write in your OP instead of jerking yourself off on finding le obscure bug
Anonymous
8/6/2025, 11:43:51 PM No.106167539
>>106167176
I tried putting tee into the pipe and every time it fails the output of ldconfig -p is incomplete and cut at the same spot mid-entry. pretty suspicious
Anonymous
8/6/2025, 11:51:06 PM No.106167594
>>106167176
>There's a small chance that between checking the library cache and the next check, the cache could be temporarily unavailable or in a state where libc.so.6 isn't found.
wait wat why? not op

my thread is
>>106167222
please bmup it

but literally why does linux do that? this is highly disconcerting, is it also bsd?
Anonymous
8/7/2025, 12:11:44 AM No.106167804
>>106166951
I've been running it in a loop and nothing has happened.
Replies: >>106167995
Anonymous
8/7/2025, 12:28:17 AM No.106167995
>>106167804
ran it for 300,000 iterations before ^C-ing it. Your shit is broke or retarded or something.

declare -i x=0
while ldconfig -p | grep -q 'libc.so.6'; do
echo $(( x++ ))
done
echo FALSE


simplified it a bit though. idk what to tell you. should be functionally similar sans the counter vs the TRUE print.
Anonymous
8/7/2025, 12:31:58 AM No.106168030
The absolute state of troonix
Replies: >>106168036 >>106171654
Anonymous
8/7/2025, 12:33:29 AM No.106168036
>>106168030
watch, this comment will be deleted by butthurt linux users
Replies: >>106171654
Anonymous
8/7/2025, 1:59:22 AM No.106168943
This works:
#!/bin/bash
set -euo pipefail

{
while true; do
if ! ldconfig -p | grep 'libc.so.6' >/dev/null; then
echo "FALSE"
exit 1
else
echo "TRUE"
fi
done
}
Replies: >>106168980
Anonymous
8/7/2025, 2:02:48 AM No.106168980
>>106168943
Why echo at all? just print when it fails ;3
Anonymous
8/7/2025, 2:06:36 AM No.106169020
This also works:

#!/bin/bash
set -euo pipefail
trap '' PIPE
{
while true; do
if ! ldconfig -p | grep -q 'libc.so.6'; then
echo "FALSE"
exit 1
else
echo "TRUE"
fi
done
}
Anonymous
8/7/2025, 2:09:32 AM No.106169048
#!/bin/bash
set -euo pipefail

{
while true; do
if ! (trap '' PIPE; ldconfig -p | grep -q 'libc.so.6'); then
echo "FALSE"
exit 1
else
echo "TRUE"
fi
done
}
Anonymous
8/7/2025, 2:21:54 AM No.106169172
Another one:

#!/bin/bash
set -euo pipefail

{
while true; do
if ! { ldconfig -p || true; } | grep -q 'libc.so.6'; then
echo "FALSE"
exit 1
else
echo "TRUE"
fi
done
}
Anonymous
8/7/2025, 2:26:22 AM No.106169218
One more:

#!/bin/bash
set -euo pipefail

{
while true; do
if ! grep -q 'libc.so.6' < <(ldconfig -p); then
echo "FALSE"
exit 1
else
echo "TRUE"
fi
done
}
Replies: >>106171619
Anonymous
8/7/2025, 6:37:45 AM No.106171441
>yet another nothingburger
Yawn.
Anonymous
8/7/2025, 7:00:18 AM No.106171619
>>106169218
I like this one the most.
Replies: >>106175255
Anonymous
8/7/2025, 7:04:18 AM No.106171645
>>106166951
what makes you think the "IF" itself is the problem and not the condition dumb jeet
Replies: >>106171662
Anonymous
8/7/2025, 7:06:50 AM No.106171654
>>106168030
>>106168036
Kek, mad.
Anonymous
8/7/2025, 7:08:27 AM No.106171662
>>106171645
Good morning saar. The Linux is broken.
Brahmin use Python.
Anonymous
8/7/2025, 10:11:52 AM No.106172739
1111111
1111111
md5: bdf453a0f52d8a7f01f0d183e37af902🔍
Initially I was making a script that would check for a libstdc++ 32 bit library with ldconfig instead of doing long "find /usr -name ..."
Here it fails even faster and just sometimes prints false. There's no heavy load for scheduler or anything.

#!/bin/bash
set -euo pipefail

declare -i x=0
while ldconfig -p | grep -q 'libstdc++.so.6 (libc6)'; do
echo $(( x++ ))
done
echo FALSE
Replies: >>106172992
Anonymous
8/7/2025, 10:55:29 AM No.106172992
>>106172739
What's ldconfig actually outputting when the loop breaks?
Anonymous
8/7/2025, 12:12:39 PM No.106173454
>>106166951
This is exactly one of the pitfalls of using 'set -o pipefail'. grep will early exit as soon as it finds the first instance of 'libc.so.6', however, ldconfig might not have finished writing all of its output to the pipe, causing a SIGPIPE to be raised when it tries to write the next chunk. 'pipefail' will just make the entire pipe fail with the exit code of the first command that failed, thus terminating your loop.
Anonymous
8/7/2025, 12:47:30 PM No.106173683
this is why i just use Powershell
Anonymous
8/7/2025, 12:52:06 PM No.106173708
>>106167176
Thank you ChatGPT
Anonymous
8/7/2025, 1:47:35 PM No.106174038
This fucking ldconfig is printing the most recently shared libraries that have been cached.
There's no reason you can expect any particular library to ALWAYS be in there. What are you doing?
Anonymous
8/7/2025, 4:10:45 PM No.106175255
>>106171619
Me too.