hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Restart.cpp
Go to the documentation of this file.
1 #include <Restart.h>
2 bool restartApplication(char **argv)
3 {
4  char dirName[] = "/proc/self/fd/";
5  char buf[256], fullName[256];
6  DIR *dir = opendir(dirName);
7  if(dir)
8  {
9  int dfd = dirfd(dir);
10  struct dirent *entry = NULL;
11  while((entry = readdir(dir)) != NULL)
12  {
13  if(entry->d_name[0] <= '9' && entry->d_name[0] >= '0')
14  {
15  int fd = atoi(entry->d_name);
16  if(fd > 2 && fd != dfd)
17  {
18  sprintf(fullName, "%s%s", dirName, entry->d_name);
19  int l = readlink(fullName, buf, sizeof(buf) - 1);
20  buf[l] = '\0';
21  printf("close %s\n",buf);
22  close(fd);
23  }
24  }
25  }
26  closedir(dir);
27  }
28  else
29  {
30  printf("Can't open /proc/self/fd/\n");
31  }
32  int l = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
33  buf[l] = '\0';
34  if(execv(buf, argv) < 0)
35  {
36  perror("exec:");
37  return false;
38  }
39  return true;
40 }