CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions
evf::FileDescriptorHandler Class Reference

#include <FileDescriptorHandler.h>

Public Member Functions

 FileDescriptorHandler ()
 

Detailed Description

Definition at line 5 of file FileDescriptorHandler.h.

Constructor & Destructor Documentation

evf::FileDescriptorHandler::FileDescriptorHandler ( )

Definition at line 17 of file FileDescriptorHandler.cc.

References gather_cfg::cout, dir, linker::DIR, i, mergeVDriftHistosByStation::name, getHLTPrescaleColumns::path, evf::utils::pid, and AlCaHLTBitMon_QueryRunRegistry::string.

17  {
18 
19  //find all socket file descriptors inherited from parent process and close them
20 
21  pid_t pid = ::getpid();
22  std::ostringstream ost;
23  ost << "/proc/" << pid << "/fd/";
24  DIR *dir = opendir(ost.str().c_str());
25  dirent *de;
26  struct stat buf;
27  std::vector<int> oldfds;
28  std::vector<int> newfds;
29 
30  while((de = readdir(dir))!=0){
31  char *name = de->d_name;
32  std::string path = ost.str()+name;
33  stat(path.c_str(),&buf);
34  if(S_ISSOCK(buf.st_mode)){
35  int fd = atoi(name);
36  oldfds.push_back(fd);
37  int newfd = dup(fd);
38  if(newfd>0) newfds.push_back(newfd);
39  else std::cout <<"couldn't duplicate old fd " << fd << std::endl;
40  }
41  }
42  closedir(dir);
43  for(unsigned int i = 0; i < oldfds.size(); i++){
44  close(oldfds[i]);
45  int newfd = dup2(newfds[i],oldfds[i]);
46  if(newfd!=oldfds[i]) std::cout <<"couldn't duplicate new fd to old "
47  << oldfds[i] << std::endl;
48  close(newfds[i]);
49  }
50 }
int i
Definition: DBlmapReader.cc:9
list DIR
Definition: linker.py:124
tuple cout
Definition: gather_cfg.py:121
dbl *** dir
Definition: mlp_gen.cc:35