1This patch makes stap(1) know about the kernel store path on NixOS.
2
3--- systemtap-1.2/main.cxx 2010-03-22 22:51:49.000000000 +0100
4+++ systemtap-1.2/main.cxx 2010-05-04 14:56:19.000000000 +0200
5@@ -528,6 +528,32 @@ getmemusage ()
6 return oss.str();
7 }
8
9+/* Read `/proc/cmdline' and extract the store path. The assumption is that
10+ `/proc/cmdline' looks like this:
11+
12+ BOOT_IMAGE=/nix/store/sxjd69wfcr6w8jlbcc5bc20nwjliq872-linux-2.6.32.8/bzImage systemConfig=/nix/store/kiicqkjwgfvkwrg4fp3dnhwldh7dq7is-system init=/nix/store/czgncihjwx3n58xij6i1rlnz8wv6ym4j-stage-2-init.sh splash=verbose vga=0x317
13+
14+ This is the case on NixOS GNU/Linux. */
15+static string
16+kernel_store_path (void)
17+{
18+ ifstream proc_cmdline ("/proc/cmdline");
19+ string variable_name, store_path;
20+
21+ getline (proc_cmdline, variable_name, '=');
22+ if (variable_name == "BOOT_IMAGE")
23+ {
24+ string boot_image_path;
25+ size_t slash_pos;
26+
27+ getline (proc_cmdline, boot_image_path, ' ');
28+ slash_pos = boot_image_path.find_last_of ('/');
29+ store_path = boot_image_path.substr (0, slash_pos);
30+ }
31+
32+ return store_path;
33+}
34+
35 int
36 main (int argc, char * const argv [])
37 {
38@@ -541,7 +567,8 @@ main (int argc, char * const argv [])
39 struct utsname buf;
40 (void) uname (& buf);
41 s.kernel_release = string (buf.release);
42- s.kernel_build_tree = "/lib/modules/" + s.kernel_release + "/build";
43+ s.kernel_build_tree =
44+ kernel_store_path () + "/lib/modules/" + s.kernel_release + "/build";
45
46 // PR4186: Copy logic from coreutils uname (uname -i) to squash
47 // i?86->i386. Actually, copy logic from linux top-level Makefile