checkUnity.cpp
Go to the documentation of this file.
1 #include <string>
2 #include <unistd.h>
3 #include <dirent.h>
4 #include <sys/types.h>
5 #include "UnityProxy.h"
6 
7 
9 {
10  bool haveUnity = false;
11  bool haveSound = false;
12 
13  std::string PROCESS_INDICATOR_SOUND = "indicator-sound-service";
14  std::string PROCESS_UNITY = "unity-panel-service";
15  std::string clPath, clStr, dName, procName;
16  char tmp[1024];
17  struct dirent* de;
18  DIR* pdir;
19  FILE* clFile;
20 
21  // read /proc
22  pdir = opendir("/proc");
23  if (pdir == NULL) exit(EXIT_FAILURE);
24 
25  for (de = readdir(pdir); de != NULL && (!haveUnity || !haveSound); de = readdir(pdir)) {
26  // only read process directories
27  if (de->d_type == DT_DIR) {
28  dName = de->d_name;
29  if (dName.find_first_not_of("0123456789") == std::string::npos) {
30  clPath.assign("/proc/");
31  clPath.append(de->d_name);
32  clPath.append("/cmdline");
33 
34  // open /proc/*/cmdline and read it's contents
35  clFile = fopen(clPath.c_str(), "r");
36  if (clFile != NULL) {
37  fscanf(clFile, "%s", tmp);
38  fclose(clFile);
39  clStr = tmp;
40  // get base of process name
41  procName = clStr.substr(clStr.find_last_of("/") + 1);
42  if (!haveSound)
43  haveSound = (procName == PROCESS_INDICATOR_SOUND) ? true : false;
44  if (!haveUnity)
45  haveUnity = (procName == PROCESS_UNITY) ? true : false;
46  }
47  }
48  }
49  }
50  closedir(pdir);
51 
52  // make sure we have both of them
53  return (haveUnity && haveSound);
54 }
NS_DECL_ISUPPORTS NS_DECL_IUNITYPROXY bool isUnityRunning()
Definition: checkUnity.cpp:8