--- openmosixview-1.5.orig/openmosixprocs/openmosixprocs.cpp +++ openmosixview-1.5/openmosixprocs/openmosixprocs.cpp @@ -19,6 +19,9 @@ #include #endif +#include +#include + #include #include "openmosixprocs.h" @@ -126,22 +129,29 @@ string which; char zeile[201]; string nodename; - which = which + clustercommand + " whois "; - which = which + node + " > /tmp/nodes.tmp"; - system(which.c_str()); - if (file_exist("/tmp/nodes.tmp")) { - std::ifstream readnodename("/tmp/nodes.tmp"); - if (readnodename) { - readnodename.getline(zeile, 200); - nodename.erase(); - nodename= nodename+zeile; - readnodename.close(); - } else { - cout << "could not read from /tmp/nodes.tmp" << endl; - return 0; - } + + which += " whois "; + which += node; + + FILE *fp = popen(which.c_str(), "r"); + if (!fp) + { + cout << "could not run " << clustercommand << endl; } - unlink("/tmp/nodes.tmp"); + + int n; + while ((n = fread(zeile, 1, 200, fp)) > 0) + { + int count; // only copy the first line, and skip the \n + for (count = 0; count < n; count++) + if (zeile[count] == '\n') + break; + nodename.append(zeile,count); + if (count != n) + break; + } + fclose(fp); + return nodename; } --- openmosixview-1.5.orig/openmosixview/openmosixview.cpp +++ openmosixview-1.5/openmosixview/openmosixview.cpp @@ -16,6 +16,8 @@ ***************************************************************************/ #include +#include +#include #include "openmosixview.h" #include "filesave.xpm" #include "fileopen.xpm" @@ -454,24 +456,32 @@ // converts a cluster id to an hostname string OpenMosixViewApp::getnodename(string node) { // gather nodes hostname - string which; + string which(clustercommand); char zeile[201]; string nodename; - which = which + clustercommand + " whois "; - which = which + node + " > /tmp/nodes.tmp"; - system(which.c_str()); - if (file_exist("/tmp/nodes.tmp")) { - std::ifstream readnodename("/tmp/nodes.tmp"); - if (readnodename) { - readnodename.getline(zeile, 200); - nodename.erase(); - nodename= nodename+zeile; - readnodename.close(); - } else { - cout << "could not read from /tmp/nodes.tmp" << endl; - return 0; - } + + which += " whois "; + which += node; + + FILE *fp = popen(which.c_str(), "r"); + if (!fp) + { + cout << "could not run " << clustercommand << endl; } + + int n; + while ((n = fread(zeile, 1, 200, fp)) > 0) + { + int count; + for (count = 0; count < n; count++) + if (zeile[count] == '\n') + break; + nodename.append(zeile,count); + if (count != n) + break; + } + fclose(fp); + return nodename; }