diff options
Diffstat (limited to 'usr/src/cmd/mdb/common/modules/mdb_ks')
-rw-r--r-- | usr/src/cmd/mdb/common/modules/mdb_ks/mdb_ks.c | 67 |
1 files changed, 64 insertions, 3 deletions
diff --git a/usr/src/cmd/mdb/common/modules/mdb_ks/mdb_ks.c b/usr/src/cmd/mdb/common/modules/mdb_ks/mdb_ks.c index 85f3839c96..68b2e9d362 100644 --- a/usr/src/cmd/mdb/common/modules/mdb_ks/mdb_ks.c +++ b/usr/src/cmd/mdb/common/modules/mdb_ks/mdb_ks.c @@ -60,6 +60,12 @@ #define MDB_PATH_NELEM 256 /* Maximum path components */ +/* + * Due to mdb_param.h shenanigans, there's no simple way to include string.h + * here... + */ +extern char *strtok(char *restrict, const char *restrict); + typedef struct mdb_path { size_t mdp_nelem; /* Number of components */ uint_t mdp_complete; /* Path completely resolved? */ @@ -1811,18 +1817,73 @@ mdb_get_lbolt(void) return ((ts/nsec) - lbi.lbi_debug_time); } +#define startswith(a, b) (strncmp((a), (b), strlen(b)) == 0) + +/* + * Dig out the branch and revision of the illumos-joyent repo, if we were + * provided with it. This is a rather fragile JSON parser, in that it requires + * JSON formatted exactly as per the boot_archive.gitstatus file that + * "buildversion" is built from. + */ void mdb_print_buildversion(void) { + boolean_t in_joyent = B_FALSE; GElf_Sym sym; - if (mdb_lookup_by_name("buildversion", &sym) != 0) - return; + if (mdb_lookup_by_name("buildversion", &sym) != 0) { + /* Older kernels used this name. */ + if (mdb_lookup_by_name("gitstatus_start", &sym) != 0) + return; + } char *str = mdb_zalloc(4096, UM_SLEEP | UM_GC); if (mdb_readstr(str, 4096, sym.st_value) < 1) return; - mdb_printf("build version: %s\n", str); + /* + * Each line is of the form + * + * "repo": "smartos-live", + */ + for (char *line = strtok(str, "\n"); line != NULL; + line = strtok(NULL, "\n")) { + /* skip whitespace and first " */ + line += strspn(line, " \t\""); + + if (startswith(line, "repo")) { + line += sizeof ("repo") - 1; + line += strspn(line, " \t\":"); + + if (startswith(line, "illumos-joyent")) + in_joyent = B_TRUE; + else if (in_joyent) + return; + continue; + } + + if (!in_joyent) + continue; + + if (startswith(line, "branch")) { + char *trail = strrchr(line, '"'); + if (trail != NULL) + *trail = '\0'; + line += sizeof ("branch") - 1; + line += strspn(line, " \t\":"); + mdb_printf("git branch: %s\n", line); + continue; + } + + if (startswith(line, "rev")) { + char *trail = strrchr(line, '"'); + if (trail != NULL) + *trail = '\0'; + line += sizeof ("rev") - 1; + line += strspn(line, " \t\":"); + mdb_printf("git rev: %s\n", line); + continue; + } + } } |