9fans / plan9port

Plan 9 from User Space
https://9fans.github.io/plan9port/
Other
1.62k stars 320 forks source link

Don't hardcode /usr/local/plan9 in C source code #532

Closed nmeum closed 2 years ago

nmeum commented 2 years ago

I maintain a plan9port package for Alpine Linux. For this package, plan9port is installed to /usr/lib/plan9 not /usr/local/plan9 in order to comply with our packaging policy. Doing so is supported by plan9port via the PLAN9_TARGET environment variable and the ./INSTALL -r flag. The installation script replaces hardcoded references to /usr/local/plan9 with PLAN9_TARGET in various files via the ./lib/moveplan9.sh script.

A few days ago I was made aware that moveplan9.sh does not replace hardcoded references to /usr/local/plan9 in C source code files since it is invoked after the code has been compiled. The following files have been identified to contain such hardcoded paths:

  1. src/lib9/get9root.c
  2. src/cmd/sam/sam.c
  3. src/cmd/upas/nfs/imap.c

As such, the affected code in these files does not work correctly if plan9port is installed to /usr/lib/plan9. For example, get9root does not work if $PLAN9 is not set (e.g. in a rc(1) login shell). This pull request fixes get9root by falling back to the configured PLAN9_TARGET via a CPP define instead of hardcoding /usr/local/plan9 in get9root.c. The remaining two files have been fixed by either using get9root (sam.c) or using the PLAN9_TARGET CPP define as well (imap.c).

Would be nice to get this merged in order to ease packaging plan9port for Linux distributions.