Bug 219352 - emulators/tpm-emulator: fail to run in arm64 due to improper getopt(3) use
Summary: emulators/tpm-emulator: fail to run in arm64 due to improper getopt(3) use
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: arm64 Any
: --- Affects Many People
Assignee: Larry Rosenman
URL:
Keywords:
Depends on:
Blocks: 201763
  Show dependency treegraph
 
Reported: 2017-05-17 13:02 UTC by Phillip R. Jaenke
Modified: 2017-06-03 21:57 UTC (History)
4 users (show)

See Also:
bugzilla: maintainer-feedback? (hrs)


Attachments
Patch suitable for ${WRKSRC} and upstream submission (308 bytes, patch)
2017-05-17 13:05 UTC, Phillip R. Jaenke
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Phillip R. Jaenke 2017-05-17 13:02:57 UTC
Confirmed on multiple systems and also by kevans91 on IRC, who confirmed the issue is getopt(3) returning 1. This results in tpmd refusing to start under any conditions and only returning the usage error. Failure has 100% reproduction under -CURRENT.

Root cause is use of signed char for getopt(3) return instead of int which is more correct for all platforms, so patch will need submitted upstream. Testing under 11.0-RELEASE showed no behavior change as expected.

Code demonstrating the issue from kevans91 is available here:
https://gist.github.com/anonymous/2cf21321e011cdf1555a8b174cc23bc4

On arm64:
 root@skyhorn ~ # uname -a
FreeBSD skyhorn.SANITIZED 12.0-CURRENT FreeBSD 12.0-CURRENT #0 r313109M: Thu Feb  2 16:16:39 MST 2017     raspberry@hive.raspbsd.org:/usr/home/brd/rpi3/crochet/work/obj/arm64.aarch64/usr/src/sys/GENERIC  arm64

 root@skyhorn ~ # cc test.c -o char_c
test.c:8:54: warning: comparison of constant -1 with expression of type 'char'
      is always true [-Wtautological-constant-out-of-range-compare]
    while ((c = getopt(argc, argv, "dfs:u:o:g:c:h")) != -1) {
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
1 warning generated.
 root@skyhorn ~ # ./char_c
1
Handling option 255
Comment 1 Phillip R. Jaenke 2017-05-17 13:05:04 UTC
Created attachment 182663 [details]
Patch suitable for ${WRKSRC} and upstream submission
Comment 2 Phillip R. Jaenke 2017-05-17 17:36:53 UTC
I have confirmed this patch resolves the issue. Port was built with patch added to files via qemu on poudriere system. tpm-emulator was reinstalled on test system and simple test performed.

[root@ironhorn ~]# uname -a
FreeBSD ironhorn.rootwyrm.pvt 12.0-CURRENT FreeBSD 12.0-CURRENT #0 r313109M: Thu Feb  2 16:16:39 MST 2017     raspberry@hive.raspbsd.org:/usr/home/brd/rpi3/crochet/work/obj/arm64.aarch64/usr/src/sys/GENERIC  arm64
[root@ironhorn ~]# service tpmd start
Starting tpmd.
tpmd.c:390: Info: starting TPM Emulator daemon (1.2.0.7-475)
tpmd.c:93: Info: parsing options
tpmd.c:164: Info: no startup mode was specified; asuming 'clear'
tpmd.c:175: Info: switching effective group ID to 601
tpmd.c:182: Info: switching effective user ID to 601
tpmd.c:198: Info: installing signal handlers
tpmd.c:220: Info: daemonizing process
[root@ironhorn ~]# ps axuw | grep tpm
_tss 3056   0.0  0.1  6800  1064  -  Ss   13:33      0:00.42 /usr/local/bin/tpmd -o _tss -g _tss
<trimmed 'pkg install trousers'>
[root@ironhorn ~]# service tcsd start
Starting tcsd.
[root@ironhorn ~]# service tcsd status
tcsd is running as pid 3084.
Comment 3 Phillip R. Jaenke 2017-05-27 23:18:15 UTC
Further research reveals that the tpm-emulator project has moved to github. The version on github is significantly newer and has already addressed this issue fully.

https://github.com/PeterHuewe/tpm-emulator
Comment 4 commit-hook freebsd_committer 2017-06-03 21:56:41 UTC
A commit references this bug:

Author: ler
Date: Sat Jun  3 21:56:26 UTC 2017
New revision: 442522
URL: https://svnweb.freebsd.org/changeset/ports/442522

Log:
  emulators/tpm-emulator: fail to run in arm64 due to improper getopt(3) use

  Add patch to fix it.

  PR:		219352
  Submitted by:	Phillip R. Jaenke <prj@rootwyrm.com>
  Approved by:	maintainer timeout.

Changes:
  head/emulators/tpm-emulator/Makefile
  head/emulators/tpm-emulator/files/patch-tpmd_unix_tpmd.c
Comment 5 Larry Rosenman freebsd_committer 2017-06-03 21:57:09 UTC
Committed, thanks!