Signal 13 when ldd piped to grep -q without STDERR redirection

While writing a script to check that sendmail was compiled with SASL I ran into this:

# ldd /usr/libexec/sendmail/sendmail | grep -q libsasl2.so
/usr/libexec/sendmail/sendmail: signal 13


Workaround was to redirect STDERR:

# ldd /usr/libexec/sendmail/sendmail 2>&1 | grep -q libsasl2.so

Command completes successfully if the -q option to grep is not used.

Same behaviour on 14.5-RELEASE and 15.1-RELEASE (both GENERIC amd64)
 
I don't get this behavior on 15.1-RELEASE and 15.0-RELEASE. The command does what it supposed to do and answer as exit code 0 or 1, whether the string is present in the ldd output or not.

Do you have something in GREP_OPTIONS?
 
Redirecting stderr doesn't prevent the SIGPIPE error, it just makes grep -q eat up the message.

I don't get SIGPIPE either, but for me sendmail is not linked against libsasl2.so, so grep rightfully doesn't exit prematurely.

SIGPIPE is correct behavior here when the grep -q term appears in the output on the non-last line.

The big question here is why is your sendmail linked against libsasl2.so and mine is not?
 
Never seen the sigpipe error like this before, but I can replicate. It's timing issue, it's not always working:
Code:
[11:13:44] fbsd15:(~)# ldd /bin/ls  | grep
usage: grep [-abcDEFGHhIiLlmnOopqRSsUVvwxz] [-A num] [-B num] [-C num]
    [-e pattern] [-f file] [--binary-files=value] [--color=when]
    [--context=num] [--directories=action] [--label] [--line-buffered]
    [--null] [pattern] [file ...]
[11:13:48] fbsd15:(~)#

[11:13:48] fbsd15:(~)# ldd /bin/ls  | grep
usage: grep [-abcDEFGHhIiLlmnOopqRSsUVvwxz] [-A num] [-B num] [-C num]
    [-e pattern] [-f file] [--binary-files=value] [--color=when]
    [--context=num] [--directories=action] [--label] [--line-buffered]
    [--null] [pattern] [file ...]
/bin/ls: signal 13
[11:13:49] fbsd15:(~)#
My first guess without investigating deeper is that grep finishes sooner than ldd, ldd still wants to push some data (or do a check on a pipe) and ends up with sigpipe.
 
Redirecting stderr doesn't prevent the SIGPIPE error, it just makes grep -q eat up the message.
That's not what I see?
Code:
# ldd /usr/libexec/sendmail/sendmail 2>&1 | grep -q sasl ; echo $?
0
# ldd /usr/libexec/sendmail/sendmail 2>&1 | grep -q signal ; echo $?
1

SIGPIPE is correct behavior here when the grep -q term appears in the output on the non-last line.
Are you saying it's correct specifically for ldd?
Code:
# uname -mv
FreeBSD 15.1-RELEASE releng/15.1-n283562-96841ea08dcf GENERIC amd64
# head -n 3 .profile
#
HOME=/root
export HOME
root@webserver:~ # head .profile | grep -q root ; echo $?
0
root@webserver:~ # ldd /usr/libexec/sendmail/sendmail | grep -q libc.so
/usr/libexec/sendmail/sendmail: signal 13
You're correct that it doesn't happen if grep doesn't terminate before the last line:
Code:
# ldd /usr/libexec/sendmail/sendmail | tail -n 1
        [vdso] (0x3e2877ece000)
# ldd /usr/libexec/sendmail/sendmail | grep -q vdso ; echo $?
0
#
The big question here is why is your sendmail linked against libsasl2.so and mine is not?
Running sendmail with SMTP Authentication requires it: https://docs.freebsd.org/en/books/handbook/mail/#SMTP-Auth
The system running 14.5 has the modified sendmail, the system running 15.1 has the stock sendmail.
 
It's most likely the -q behavior that kills the grep upon match. It's too soon for ldd resulting in sigpipe.
Code:
# always ends up in sigpipe
[18:40:47] martin@fbsd15:(~)$ ldd /usr/libexec/sendmail/sendmail |grep  -q \/
/usr/libexec/sendmail/sendmail: signal 13
[18:40:47] martin@fbsd15:(~)$

# vdso is in the end, never triggers sigpipe
[18:41:24] martin@fbsd15:(~)$ ldd /usr/libexec/sendmail/sendmail |grep  -q vd
[18:41:25] martin@fbsd15:(~)$
 
Back
Top