Packaging/Binaries: Difference between revisions
imported>Milahu add section: Wrong file paths |
imported>Milahu Wrong file paths: more on strace |
||
Line 280: | Line 280: | ||
== Wrong file paths == | == Wrong file paths == | ||
Some programs will try to access hard-coded FHS file paths like <code>/usr/lib</code>, but mostly, this will | Some programs will try to access hard-coded FHS file paths like <code>/usr/lib</code> or <code>/opt</code>, but mostly, this will produce silent <code>No such file</code> errors, which can break the program | ||
To make these errors visible, we can use <code>strace</code> | |||
<pre> | |||
strace --trace=file,process --follow-forks --string-limit=200 \ | |||
./result/bin/some-program 2>strace.log | |||
cat strace.log | grep -e 'No such file' -e 'execve("' \ | |||
| grep -v -E -e '(open|stat|access)(at)?\(.*"/nix/store/' \ | |||
-e resumed -e '/etc/ld-nix.so.preload' | |||
</pre> | |||
example: | |||
<pre> | |||
[pid 357679] openat(AT_FDCWD, "/opt/brother/Printers/hll3210cw/inf/lut/0600-k_cache17.bin", O_RDONLY) = -1 ENOENT (No such file or directory) | |||
[pid 357679] openat(AT_FDCWD, "0600-k_cache17.bin", O_RDONLY) = -1 ENOENT (No such file or directory) | |||
</pre> | |||
this means: process 357679 is trying to open file <code>0600-k_cache17.bin</code> either from the hard-coded path in <code>/opt/brother/Printers/hll3210cw/inf/lut</code> or from the current workdir. so, as a quick fix, we could change the working directory of the wrapped binary with [https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/setup-hooks/make-wrapper.sh makeWrapper] | |||
<pre> | |||
makeWrapper <executable> <out_path> --run 'cd /nix/store/path/to/workdir' | |||
</pre> | |||
what process is throwing the <code>No such file</code> error? lets search for the process ID and the <code>exec</code> syscall | |||
<pre> | <pre> | ||
cat strace.log | grep 357679 | grep exec | |||
[pid 357679] execve("/nix/store/ybl1pacslmhci9zy5qv95hshdgz6ihjl-brother-hll3210cw-1.0.2-0/opt/brother/Printers/hll3210cw/lpd/brhll3210cwfilter", ["/nix/store/ybl1pacslmhci9zy5qv95"..., "-pi", "/nix/store/ybl1pacslmhci9zy5qv95"..., "-rc", "/nix/store/ybl1pacslmhci9zy5qv95"...], 0x8ba010 /* 132 vars */ <unfinished ...> | |||
</pre> | </pre> | ||