| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/** |
| 2 |
|
|
* This file is part of the CernVM File System. |
| 3 |
|
|
*/ |
| 4 |
|
|
|
| 5 |
|
|
|
| 6 |
|
|
#include "cmd_util.h" |
| 7 |
|
|
|
| 8 |
|
|
#include <unistd.h> |
| 9 |
|
|
|
| 10 |
|
|
#include <map> |
| 11 |
|
|
#include <set> |
| 12 |
|
|
#include <string> |
| 13 |
|
|
#include <vector> |
| 14 |
|
|
|
| 15 |
|
|
#include "publish/except.h" |
| 16 |
|
|
#include "util/posix.h" |
| 17 |
|
|
|
| 18 |
|
✗ |
int publish::CallServerHook(const std::string &func, |
| 19 |
|
|
const std::string &fqrn, |
| 20 |
|
|
const std::string &path_hooks) { |
| 21 |
|
✗ |
if (!FileExists(path_hooks)) |
| 22 |
|
✗ |
return 0; |
| 23 |
|
|
|
| 24 |
|
|
int pipe_stdin[2]; |
| 25 |
|
✗ |
MakePipe(pipe_stdin); |
| 26 |
|
✗ |
std::set<int> preserve_fildes; |
| 27 |
|
✗ |
preserve_fildes.insert(0); |
| 28 |
|
✗ |
preserve_fildes.insert(1); |
| 29 |
|
✗ |
preserve_fildes.insert(2); |
| 30 |
|
✗ |
std::map<int, int> map_fildes; |
| 31 |
|
✗ |
map_fildes[pipe_stdin[0]] = 0; // Reading end of pipe_stdin |
| 32 |
|
✗ |
std::vector<std::string> cmd_line; |
| 33 |
|
✗ |
cmd_line.push_back("/bin/sh"); |
| 34 |
|
|
pid_t child_pid; |
| 35 |
|
✗ |
const bool rvb = ManagedExec( |
| 36 |
|
|
cmd_line, preserve_fildes, map_fildes, false /* drop_credentials */, |
| 37 |
|
|
false /* clear_env */, false /* double_fork */, &child_pid); |
| 38 |
|
✗ |
if (!rvb) { |
| 39 |
|
✗ |
ClosePipe(pipe_stdin); |
| 40 |
|
✗ |
return -127; |
| 41 |
|
|
} |
| 42 |
|
✗ |
close(pipe_stdin[0]); |
| 43 |
|
|
|
| 44 |
|
✗ |
const std::string callout = func + "() { :; }\n" + ". " + path_hooks + "\n" |
| 45 |
|
✗ |
+ func + " " + fqrn + "\n"; |
| 46 |
|
✗ |
WritePipe(pipe_stdin[1], callout.data(), callout.length()); |
| 47 |
|
✗ |
close(pipe_stdin[1]); |
| 48 |
|
|
|
| 49 |
|
✗ |
return WaitForChild(child_pid); |
| 50 |
|
|
} |
| 51 |
|
|
|