GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/publish/cmd_util.cc
Date: 2024-04-21 02:33:16
Exec Total Coverage
Lines: 0 23 0.0%
Branches: 0 48 0.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #include "cvmfs_config.h"
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 {
22 if (!FileExists(path_hooks))
23 return 0;
24
25 int pipe_stdin[2];
26 MakePipe(pipe_stdin);
27 std::set<int> preserve_fildes;
28 preserve_fildes.insert(0);
29 preserve_fildes.insert(1);
30 preserve_fildes.insert(2);
31 std::map<int, int> map_fildes;
32 map_fildes[pipe_stdin[0]] = 0; // Reading end of pipe_stdin
33 std::vector<std::string> cmd_line;
34 cmd_line.push_back("/bin/sh");
35 pid_t child_pid;
36 bool rvb = ManagedExec(cmd_line,
37 preserve_fildes,
38 map_fildes,
39 false /* drop_credentials */,
40 false /* clear_env */,
41 false /* double_fork */,
42 &child_pid);
43 if (!rvb) {
44 ClosePipe(pipe_stdin);
45 return -127;
46 }
47 close(pipe_stdin[0]);
48
49 const std::string callout =
50 func + "() { :; }\n" +
51 ". " + path_hooks + "\n" +
52 func + " " + fqrn + "\n";
53 WritePipe(pipe_stdin[1], callout.data(), callout.length());
54 close(pipe_stdin[1]);
55
56 return WaitForChild(child_pid);
57 }
58