#! /bin/sh /usr/share/dpatch/dpatch-run ## 01_lsb_version.dpatch by Matvey Kozhev ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: add LSB version support @DPATCH@ diff -u -r psi-0.11~/src/systeminfo.cpp psi-0.11/src/systeminfo.cpp --- psi-0.11~/src/systeminfo.cpp 2007-10-27 20:17:41.000000000 +0700 +++ psi-0.11/src/systeminfo.cpp 2007-11-08 22:38:54.000000000 +0600 @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #endif @@ -17,6 +19,8 @@ #include "systeminfo.h" +static char buff[4096]; + SystemInfo::SystemInfo() : QObject(QCoreApplication::instance()) { // Initialize @@ -30,6 +34,7 @@ time(&x); char str[256]; char fmt[32]; + struct stat st; strcpy(fmt, "%z"); strftime(str, 256, fmt, localtime(&x)); if(strcmp(fmt, str)) { @@ -45,6 +50,11 @@ timezone_str_ = str; #endif #if defined(Q_WS_X11) + if(stat(LSB_RELEASE, &st) != -1) { + os_str_ = lsbRelease("--id --short"); + os_str_ += " "; + os_str_ += lsbRelease("--release --short"); + } else { struct utsname u; uname(&u); os_str_.sprintf("%s", u.sysname); @@ -130,6 +140,7 @@ break; } } + } #elif defined(Q_WS_MAC) QSysInfo::MacVersion v = QSysInfo::MacintoshVersion; if(v == QSysInfo::MV_10_3) @@ -192,3 +203,41 @@ } SystemInfo* SystemInfo::instance_ = NULL; + +char *SystemInfo::lsbRelease(const char arg[]) +{ + FILE *moo; + char cmd[1024]; + char *tmp; + int opt; + + sprintf(cmd, "%s %s", LSB_RELEASE, arg); + + moo = popen(cmd, "r"); + + if(moo == NULL) { + //perror("[-] popen"); + return NULL; + } + + memset(buff, 0, sizeof(buff)); + + fgets(buff, sizeof(buff), moo); + + if(pclose(moo) < 0) { + //perror("[-] pclose"); + return NULL; + } + + tmp = buff; + opt = strlen(tmp) - 1; + + while(isspace(tmp[opt])) + opt--; + tmp[++opt] = 0; + + while(isspace(*tmp)) + tmp++; + + return &tmp[0]; +} diff -u -r psi-0.11~/src/systeminfo.h psi-0.11/src/systeminfo.h --- psi-0.11~/src/systeminfo.h 2007-10-27 20:17:41.000000000 +0700 +++ psi-0.11/src/systeminfo.h 2007-11-08 22:38:08.000000000 +0600 @@ -4,6 +4,8 @@ #include #include +#define LSB_RELEASE "/usr/bin/lsb_release" + class SystemInfo : public QObject { public: @@ -14,6 +16,7 @@ private: SystemInfo(); + static char *lsbRelease(const char arg[]); static SystemInfo* instance_; int timezone_offset_;