1. Variables & packages

 

Once it hits the fan, the only rational choice is to sweep it up, package it, and sell it as fertilizer.

 anonymous

This document tries to cover multiple platforms through conditional compilation. There is a configure.pl that determines the host type and sets up a config.sh containing environment variable definitions. There also are equivalent config.csh, config.h, config.mak, config.sed, and config.xml. The Makefile then uses individual sub-directories for each platform. The name of these directories (and some other platform specific values) is retrieved through environment variables. The directory structure is not without meaning.

The files in src/ are obfuscated with obscene amounts of variable references like ${TEVWH_ELF_BASE} or even ${TEVWH_PATH_LS}. I admit that using variables instead of plain program names makes shell scripts harder to read. But this is necessary to maintain a minimum level of reproducibility on SunOS. Anyway, directory pre/ makes that 10000 and /usr/xpg4/bin/ls, so you will probably never encounter this syntax nightmare. An almost complete list of used variables is given below.

Table 1. Variables prefixed with TEVWH_

Variable nameValue on this platformVariable nameValue on this platform
ARCHsparcASM_COMMENT!
ASM_FLAVORASM_RETURN\(restore\|unimp\)
ASM_STYLEattBYTE_ORDERM
CFLAGS-O1 -I out/sparc-sunos5.7 -D NDEBUGELF_ADDR_SIZE32
ELF_ALIGN0x10000ELF_BASE0x10000
ELF_EHDRElf32_EhdrELF_MAGIC0x10001
ELF_PHDRElf32_PhdrELF_SHDRElf32_Shdr
HOSTTYPESunOS/sparcOS_CODEsparc-sunos5.7
OS_NAMESunOS 5.7OS_PKG_SYSSunOS
OS_VERSION5.7OUTout/sparc-sunos5.7
OUT_XMLout/sparc-sunos5.7/xmlPAGESIZE0x1000
PREpre/sparc-sunos5.7PROC_EXE/proc/self/object/a.out
TMPtmp/sparc-sunos5.7UNAMESunOS

Note that hexadecimal shell variables actually miss the leading 0x to simplify calculations with bc. These values are also available to C code through corresponding #define statements after #include <config.h>. Values are not quoted, but hexadecimal values are correctly prefixed by 0x.

Table 2. Variables prefixed with TEVWH_PATH_

Variable nameValue on this platformVariable nameValue on this platform
BC/usr/bin/bcCC/usr/local/bin/gcc
CHMOD/usr/bin/chmodCOL/usr/bin/col
CSH/usr/bin/cshCUT/usr/bin/cut
DD/usr/bin/ddDU/usr/xpg4/bin/du
DUMP/usr/ccs/bin/dumpECHO/usr/bin/echo
ELFDUMP/usr/ccs/bin/elfdumpEXPAND/usr/bin/expand
FILE/usr/bin/fileFIND/usr/bin/find
GDB/usr/local/bin/gdbGREP/usr/xpg4/bin/grep
HEAD/usr/bin/headKILL/usr/bin/kill
LD/usr/local/bin/ldLDD/usr/bin/ldd
LS/usr/xpg4/bin/lsMAKE/usr/xpg4/bin/make
MAN/usr/bin/manMT/usr/bin/mt
NICE/usr/xpg4/bin/niceNM/usr/xpg4/bin/nm
OBJDUMP/usr/local/bin/objdumpOD/usr/xpg4/bin/od
PERL/usr/bin/perlPKGCHK/usr/sbin/pkgchk
PKGINFO/usr/bin/pkginfoREADELF/usr/local/bin/readelf
SED/usr/xpg4/bin/sedSH/usr/xpg4/bin/sh
SORT/usr/xpg4/bin/sortSTRACE/usr/bin/strace
STRINGS/usr/bin/stringsSTRIP/usr/local/bin/strip
TAIL/usr/xpg4/bin/tailTEE/usr/bin/tee
TR/usr/xpg4/bin/trTRUSS/usr/bin/truss
UNIQ/usr/bin/uniqWHICH/usr/bin/which
XARGS/usr/bin/xargs  

1.1. The owner of files

One of the lesser known features of package management is self-reflection. How do we determine the package owning a file if we have the canonical path name?

The package format used by SunOS 5.7 is called "pkg Datastream (SVR4)" by a recent file(1). Relevant information is stored as a set of text files in directory /var/sadm. For each installed package there is a sub directory in /var/sadm/pkg that includes a description.

The first half of a query does a linear search trough text file /var/sadm/install/contents. The tricky part is to find the canonical name of a file. A lot of tools are provided in two different variations. The POSIX confirming ones are located in directory /usr/xpg4/bin/, as described by xpg4(5). The classic tools are installed in /usr/bin. But since /bin is a symbolic link to /usr/bin, a naive which(1) can give unexpected results.

The second part of the query works on a single file, /var/sadm/pkg/*/pkginfo:

1.2. The source of man-pages

Option -a of man returns all matching entries, not just the lowest section. This behavior is identical between platforms.

Requesting a specific section requires option -s section on SunOS, while Linux prefers a plain section.

1.3. Verifying installed packages

This chapter is not about checking the integrity of package files. See Intrusion detection systems for a general introduction.

SunOS uses checksums based on sum(1). pkgchk(1) lets you verify everything, complete packages or a list of files specified with option -i listfile. Diagnostics are written to stderr and no news is good news.

Command: pre/sparc-sunos5.7/packages/SunOS/verify.sh
#!/usr/xpg4/bin/sh
pkg=$( /usr/sbin/pkgchk -l -p /etc/profile \
| /usr/xpg4/bin/grep -v '^[A-Z]' )
/usr/bin/echo pkg=[${pkg}]
/usr/sbin/pkgchk ${pkg} 2>&1 | /usr/bin/head
/usr/bin/echo status=$?

Output: out/sparc-sunos5.7/packages/verify
pkg=[ SUNWcsr ]
ERROR: /etc/default/init
    file size <219> expected <605> actual
    file cksum <18231> expected <48341> actual
ERROR: /etc/device.tab
    file size <1207> expected <1998> actual
    file cksum <37074> expected <37523> actual
ERROR: /etc/devlink.tab
    group name <sys> expected <other> actual
    file size <4043> expected <4117> actual
    file cksum <28952> expected <35993> actual
status=0

Option -n is advertised as "Do not check volatile or editable files". With option -d package_file you can verify against the checksums included in a package file, e.g. on the installation CD.