fake-uname: fix gcc argument order and improve preloaded shared library
authorMichael Prokop <mika@grml.org>
Thu, 29 Apr 2021 22:25:44 +0000 (00:25 +0200)
committerMichael Prokop <mika@grml.org>
Fri, 30 Apr 2021 11:22:57 +0000 (13:22 +0200)
commit4d625ea05ba167d60766f86f2ff2edad2cfd561a
treeb85b929d39e26c31ab74715bc5dfdd0423dd01ad
parent72ce6b646deca99877f9f8db774b2c09215c7bc1
fake-uname: fix gcc argument order and improve preloaded shared library

This includes recent changes as integrated at
https://github.com/sipwise/deployment-iso

Makefile:

- Fix gcc argument order: newer gcc versions have become more picky on
  their argument order, due to the --as-needed default, and require the
  libraries to be linked to, to be passed after the code/objects that
  use them, otherwise they will get dropped as unused. This change is
  required for compiling with gcc v10.2.1-6 as present on
  Debian/bullseye (otherwise fails to execute with `undefined symbol:
  dlsym`)
- Add `make check` target to run some basic tests
- Also get rid of *.o *.so files in clean target, adjust targets
  accordingly to always clean and then build fake-uname.so afterwards
- Mark as serial-only via .NOTPARALLEL

fake-uname.c:

- Use hidden visibility by default, and export the symbol explicitly.
- Resolve real_uname() only once.
- Return early if the real_uname() fails, to avoid acting on bogus data.
- Call dlerror() before dlsym() to clear any previous errors.
- Compute the release member size from the utsname struct instead of
  hard-coding it.
- Always NUL-terminate the relese buffer, so protect against very long
  environment strings.
- Make various variables into const.

Acked-by: Guillem Jover <gjover@sipwise.com>
Thanks: Guillem Jover
packer/Makefile
packer/fake-uname.c