This repository has been archived by the owner on May 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
add close_on_exec and agent_work_dir #1
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,19 @@ | |
#ifndef COMMON_UTIL_H_ | ||
#define COMMON_UTIL_H_ | ||
|
||
#include <unistd.h> | ||
#include <fcntl.h> | ||
#include <stdlib.h> | ||
#include <sys/types.h> | ||
#include <dirent.h> | ||
|
||
#include <map> | ||
#include <sstream> | ||
#include <string> | ||
|
||
// use only in linux | ||
extern char** environ; | ||
|
||
namespace common { | ||
namespace util { | ||
|
||
|
@@ -20,6 +33,57 @@ std::string GetLocalHostName() { | |
return hostname; | ||
} | ||
|
||
void CloseOnExec(int fd) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个函数在哪调用了? |
||
int flags = fcntl(fd, F_GETFD); | ||
flags |= FD_CLOEXEC; | ||
fcntl(fd, F_SETFD, flags); | ||
} | ||
|
||
void GetEnviron(std::map<std::string, std::string>& env) { | ||
char** cur_environ = environ; | ||
|
||
env.clear(); | ||
for (int index = 0; cur_environ[index] != NULL; index++) { | ||
// split = | ||
std::string env_item(cur_environ[index]); | ||
size_t pos = env_item.find_first_of('='); | ||
if (pos == std::string::npos) { | ||
// invalid format | ||
continue; | ||
} | ||
env[env_item.substr(0, pos)] = env_item.substr(pos + 1); | ||
} | ||
return; | ||
} | ||
|
||
void GetProcessFdList(int pid, std::vector<int>& fds) { | ||
std::ostringstream stream; | ||
stream << pid; | ||
std::string proc_path = "/proc/"; | ||
proc_path.append(stream.str()); | ||
proc_path.append("/fd/"); | ||
|
||
DIR* dir = opendir(proc_path.c_str()); | ||
if (dir == NULL) { | ||
return; | ||
} | ||
|
||
fds.push_back(0); | ||
|
||
struct dirent* entry; | ||
while ((entry = readdir(dir)) != NULL) { | ||
if (strncmp(entry->d_name, ".", 1) == 0) { | ||
continue; | ||
} | ||
int fd = atoi(entry->d_name); | ||
if (fd == 0) { | ||
continue; | ||
} | ||
fds.push_back(fd); | ||
} | ||
closedir(dir); | ||
} | ||
|
||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没看懂这个怎么解决的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mesos得做法是用的libprocess,libprocess本身再处理socket得时候就考虑了这点 所以直接设置了cloexec,暂时得解决办法只能扫/proc下得fd,clone的方法暂未发现能够解决