Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
src
EventFilter
Processor
src
FileDescriptorHandler.cc
Go to the documentation of this file.
1
#include "
FileDescriptorHandler.h
"
2
3
#include <iostream>
4
#include <sstream>
5
6
#include <sys/types.h>
7
#include <sys/stat.h>
8
#include <dirent.h>
9
10
#include <stdlib.h>
11
#include <unistd.h>
12
13
#include <vector>
14
15
namespace
evf{
16
17
FileDescriptorHandler::FileDescriptorHandler
(){
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
}
51
52
}
i
int i
Definition:
DBlmapReader.cc:9
FileDescriptorHandler.h
evf::FileDescriptorHandler::FileDescriptorHandler
FileDescriptorHandler()
Definition:
FileDescriptorHandler.cc:17
evf::utils::pid
num pid
Definition:
procUtils.cc:73
mergeVDriftHistosByStation.name
string name
Definition:
mergeVDriftHistosByStation.py:77
path
int path() const
Definition:
HLTadd.h:3
gather_cfg.cout
tuple cout
Definition:
gather_cfg.py:41
dir
dbl *** dir
Definition:
mlp_gen.cc:35
Generated for CMSSW Reference Manual by
1.8.5