aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Savoye <rob.savoye@linaro.org>2014-07-10 10:25:49 -0600
committerRob Savoye <rob.savoye@linaro.org>2014-07-10 10:25:49 -0600
commit2482a9bc60ac4be110f1a02035adec72552eae32 (patch)
tree35ae95f1d453370416fb7031caa92e1df7c6940a
parentcfcefce97f0432a93e668aeb73db62124ac274b7 (diff)
extract the cpu variant and add it to the initialization host message
-rw-r--r--loadavg.cc44
1 files changed, 42 insertions, 2 deletions
diff --git a/loadavg.cc b/loadavg.cc
index 8da64c0..2b6c94b 100644
--- a/loadavg.cc
+++ b/loadavg.cc
@@ -36,11 +36,12 @@
#include <sys/time.h>
#include <errno.h>
#include <sys/utsname.h>
+#include <stdlib.h>
extern char **environ;
void usage(const char *prog);
void sleep();
-
+char *cpuinfo(char **arch);
bool debugMode = false;
@@ -133,15 +134,18 @@ main(int argc, char *argv[])
}
// Send initialization msg
+ char *arch = 0;
+ cpuinfo(&arch);
if (*utsname.machine == 0) {
uname(&utsname);
std::string clientReqStr = "host " + std::string(inet_ntoa(in)) +
- " " + utsname.machine;
+ " " + utsname.machine + "-" + arch;
DMUCS_DEBUG((stderr, "Writing -->%s<-- to the server\n",
clientReqStr.c_str()));
Sputs((char *) clientReqStr.c_str(), client_sock);
}
+ free(arch);
DMUCS_DEBUG((stderr, "got socket: %s\n", Sprtskt(client_sock)));
@@ -209,3 +213,39 @@ usage(const char *prog)
fprintf(stderr, "Usage: %s [-s|--server <server>] [-p|--port <port>] "
"[-t|--type <str>] [-D|--debug]\n\n", prog);
}
+
+char *
+cpuinfo(char **arch)
+{
+ char buf[503];
+ memset(buf, 0, sizeof(buf));
+
+ if (*arch == 0) {
+ *arch = (char *)::calloc(1, 10);
+ }
+
+ FILE *cpuinfo = ::fopen("/proc/cpuinfo", "r");
+ const char *armpat = "CPU part";
+ const char *ipat = "microcode";
+ bool hit = false;
+ while (fgets(buf, sizeof(buf), cpuinfo) != NULL) {
+ if (strncmp(ipat, buf, sizeof(ipat)) == 0) {
+ hit = true;
+ }
+ if (strncmp(armpat, buf, sizeof(armpat)) == 0) {
+ hit = true;
+ }
+
+ if (hit) {
+ char *start = ::strchr(buf, ' ');
+ char *end = ::strchr(buf, '\n');
+ ::strncpy(*arch, start+1, end-start-1);
+ fclose(cpuinfo);
+ return *arch;
+ }
+ memset(buf, 0, sizeof(buf));
+ }
+
+ fclose(cpuinfo);
+ return 0;
+}