From d7d38aa4436606743712c09ac095dc0347e50aa2 Mon Sep 17 00:00:00 2001 From: David Maciejak Date: Wed, 15 Feb 2023 05:42:39 +0800 Subject: [PATCH] Info Panel: display more OS details Rely on old utsname and os-release (http://0pointer.de/blog/projects/os-release) when available to display more underlying OS details in the Info panel. The idea is when someone creates a bug entry we can request them to copy/paste that screen to give more info about the context that could help us debug the issue. For example, on my current system it's displaying: "Running on: Ubuntu 22.10 (x86_64)" --- src/dialog.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 9 deletions(-) diff --git a/src/dialog.c b/src/dialog.c index b8d3c6db..36991952 100755 --- a/src/dialog.c +++ b/src/dialog.c @@ -37,6 +37,7 @@ #include #include #include +#include #ifdef HAVE_MALLOC_H #include @@ -1172,6 +1173,58 @@ static void destroyInfoPanel(WCoreWindow *foo, void *data, XEvent *event) infoPanel = NULL; } +char *getPrettyOSName(void) +{ + char line[200]; + char *token; + char *posn = NULL; + const char s[2] = "="; + FILE *fp; + + fp = fopen("/etc/os-release", "r"); + if (!fp) { + fp = fopen("/usr/lib/os-release", "r"); + if (!fp) { + wwarning(_("no os-release file on the system")); + return NULL; + } + } + + while (fgets(line, sizeof(line), fp) != NULL) { + if (strncmp(line, "PRETTY_NAME", strlen("PRETTY_NAME")) == 0) { + line[strcspn(line, "\r\n")] = 0; + token = strtok(line, s); + if (token) { + //get straight to the second part of the line + token = strtok(NULL, s); + if (token) { + //removing potential quotes + char *dst = token; + char *src = token; + char c; + + while ((c = *src++) != '\0') { + if (c == '\\') { + *dst++ = c; + if ((c = *src++) == '\0') + break; + *dst++ = c; + } + else if (c != '"' && c != '\'') + *dst++ = c; + } + *dst = '\0'; + posn = malloc(strlen(token)); + strncpy(posn, token, strlen(token)); + } + } + break; + } + } + fclose(fp); + return posn; +} + void wShowInfoPanel(WScreen *scr) { InfoPanel *panel; @@ -1198,6 +1251,7 @@ void wShowInfoPanel(WScreen *scr) int current_year = 2020; time_t s; struct tm *current_time; + struct utsname uts; s = time(NULL); if (s) { @@ -1225,7 +1279,7 @@ void wShowInfoPanel(WScreen *scr) #else pwidth = WMScaleX(382); #endif - pheight = WMScaleY(250); + pheight = WMScaleY(270); WMResizeWidget(panel->win, pwidth, pheight); logo = WMCreateApplicationIconBlendedPixmap(scr->wmscreen, (RColor *) NULL); @@ -1289,7 +1343,7 @@ void wShowInfoPanel(WScreen *scr) panel->copyrL = WMCreateLabel(panel->win); WMResizeWidget(panel->copyrL, WMScaleX(360), WMScaleY(60)); - WMMoveWidget(panel->copyrL, WMScaleX(15), WMScaleY(190)); + WMMoveWidget(panel->copyrL, WMScaleX(15), WMScaleY(210)); WMSetLabelTextAlignment(panel->copyrL, WALeft); snprintf(buffer, sizeof(buffer), COPYRIGHT_TEXT, current_year); @@ -1302,9 +1356,19 @@ void wShowInfoPanel(WScreen *scr) } strbuf = NULL; + if (uname(&uts) != -1) { + char *posn = getPrettyOSName(); + if (posn) { + snprintf(buffer, sizeof(buffer), _("Running on: %s (%s)\n"), posn, uts.machine); + free(posn); + } + else + snprintf(buffer, sizeof(buffer), _("Running on: %s (%s)\n"), uts.sysname, uts.machine); + strbuf = wstrappend(strbuf, buffer); + } + snprintf(buffer, sizeof(buffer), _("Using visual 0x%x: %s %ibpp "), (unsigned)scr->w_visual->visualid, visuals[scr->w_visual->class], scr->w_depth); - strbuf = wstrappend(strbuf, buffer); switch (scr->w_depth) { @@ -1329,9 +1393,9 @@ void wShowInfoPanel(WScreen *scr) struct mallinfo2 ma = mallinfo2(); snprintf(buffer, sizeof(buffer), #ifdef DEBUG - _("Total memory allocated: %lu kB (in use: %lu kB, %lu free chunks).\n"), + _("Total memory allocated: %lu kB (in use: %lu kB, %lu free chunks)\n"), #else - _("Total memory allocated: %lu kB (in use: %lu kB).\n"), + _("Total memory allocated: %lu kB (in use: %lu kB)\n"), #endif (ma.arena + ma.hblkhd) / 1024, (ma.uordblks + ma.hblkhd) / 1024 @@ -1382,7 +1446,7 @@ void wShowInfoPanel(WScreen *scr) strbuf = wstrappend(strbuf, _("Xinerama: ")); { char tmp[128]; - snprintf(tmp, sizeof(tmp) - 1, _("%d head(s) found."), scr->xine_info.count); + snprintf(tmp, sizeof(tmp) - 1, _("%d head(s) found"), scr->xine_info.count); strbuf = wstrappend(strbuf, tmp); } #endif @@ -1394,14 +1458,13 @@ void wShowInfoPanel(WScreen *scr) strbuf = wstrappend(strbuf, _("supported")); else strbuf = wstrappend(strbuf, _("unsupported")); - strbuf = wstrappend(strbuf, "."); #endif panel->infoL = WMCreateLabel(panel->win); #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO2) && defined(DEBUG) - WMResizeWidget(panel->infoL, WMScaleX(380), WMScaleY(80)); + WMResizeWidget(panel->infoL, WMScaleX(380), WMScaleY(100)); #else - WMResizeWidget(panel->infoL, WMScaleX(350), WMScaleY(80)); + WMResizeWidget(panel->infoL, WMScaleX(350), WMScaleY(100)); #endif WMMoveWidget(panel->infoL, WMScaleX(15), WMScaleY(115)); WMSetLabelText(panel->infoL, strbuf);