ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Arthur Reutenauer <arthur.reutenauer@normalesup.org>
To: "Thomas A. Schmitz" <thomas.schmitz@uni-bonn.de>
Cc: mailing list for ConTeXt users <ntg-context@ntg.nl>,
	Mojca Miklavec <mojca.miklavec.lists@gmail.com>
Subject: Re: linux binaries split?
Date: Sun, 25 Mar 2018 18:24:43 +0200	[thread overview]
Message-ID: <20180325162443.GA1741376@phare.normalesup.org> (raw)
In-Reply-To: <3b013748-a736-c5a4-8736-91387257e9b9@uni-bonn.de>

On Sat, Mar 24, 2018 at 06:05:08PM +0100, Thomas A. Schmitz wrote:
> Arthur's
> 
> if command -v ldd >/dev/null && ldd --version 2>&1 | fgrep -q '^musl'
> 
> works for me, but again, there may be other corner cases that we don't see
> now. I would suggest reversing the logic of this test: default to linux
> unless you clearly find the string "musl" in the output; don't rely on a
> zero result, which may be prevented by a number f reasons...

  Yes, well.  About that ...

  If you think about what “default” means, you’ll realise that the bit
of code you quote does actually make glibc the default: indeed,

	if [some complex condition]; then
		libc=musl
	else
		libc=glic
	fi

or, equivalently, Henri’s suggested alternative

	libc=glibc
	if [some complex condition]; then
		libc=musl
	fi

means exactly “set libc to glibc, unless [some complex condition] is
met”.  The trick is that in your case, the test unexpectedly *succeeds*
(which confused me yesterday).  How can that be?

  The exact test is

	command -v ldd >/dev/null && ldd --version 2>&1 | grep -q ^musl

which in your case boils down to

	grep -q ^musl [output of ldd --version]

meaning that grep will search for the regexp ^musl in the output of ldd --version.
Or will it?  As I explained, the string ^musl can in zsh (if EXTENDED_GLOB
is set) be interpreted as “all file names in the current directory but musl”,
which means that it is actually expanded as

	grep -q [filename 1] [filename 2] [filename 3] ... [output of ldd --version]

and grep will thus look for the first file name in that list (whose
exact order is hard to predict and depends in particular on your
locale).  Every file in the current directory (and the output of ldd
--version) will be searched for that name, so if it’s simple enough
there’s a high chance that it will be found.  Amusingly, in my case, the
first file name is the rather unlikely 20170802093441240.pdf, but it is
found anyway, because I sent it as an email attachment one day, so the
line

	Content-Disposition: attachment; filename="20170802093441240.pdf"

is found in my sent messages (which is a plain text file in my home
directory).

  That is not all!  As you experienced, grep does actually report an
error for each directory name, and should thus return a non-zero value;
which indeed it does in a number of experiments I conducted.  But!  In
the original test, grep is called with the -q switch, that has the
following specification in POSIX:

	Quiet.  Nothing shall be written to the standard output,
	regardless of matching lines.  Exit with zero status if an input
	line is selected.

  And here we are.  For a number of unlikely reasons, the condition,
that should only hold true in a very specific situation, ends up being
satisfied.

	Best,

		Arthur
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  parent reply	other threads:[~2018-03-25 16:24 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-24 10:59 Thomas A. Schmitz
2018-03-24 11:14 ` luigi scarso
2018-03-24 12:30   ` Thomas A. Schmitz
2018-03-24 12:40     ` Hans Hagen
2018-03-24 12:40     ` Mojca Miklavec
2018-03-24 12:43       ` Hans Hagen
2018-03-24 11:15 ` Hans Hagen
2018-03-24 11:26 ` Hans Hagen
2018-03-24 12:32 ` Mojca Miklavec
2018-03-24 12:42   ` Hans Hagen
2018-03-24 12:57   ` Thomas A. Schmitz
2018-03-24 13:06     ` Arthur Reutenauer
2018-03-24 13:16       ` Thomas A. Schmitz
2018-03-24 16:44         ` Arthur Reutenauer
2018-03-24 16:51           ` Mojca Miklavec
2018-03-24 17:05             ` Thomas A. Schmitz
2018-03-24 18:10               ` Arthur Reutenauer
2018-03-24 23:55                 ` Arthur Reutenauer
2018-03-25 16:24               ` Arthur Reutenauer [this message]
2018-03-24 17:36             ` luigi scarso
2018-03-24 17:43               ` Mojca Miklavec
2018-03-24 17:47                 ` luigi scarso
2018-03-24 21:53                   ` Henri Menke
2018-03-24 23:30                     ` Arthur Reutenauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180325162443.GA1741376@phare.normalesup.org \
    --to=arthur.reutenauer@normalesup.org \
    --cc=mojca.miklavec.lists@gmail.com \
    --cc=ntg-context@ntg.nl \
    --cc=thomas.schmitz@uni-bonn.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).