5 #include "cvmfs_config.h"
29 FILE *f = fopen(path.c_str(),
"r");
37 line =
Trim(line,
true );
38 std::vector<std::string> tokens =
SplitString(line,
' ');
40 if (tokens.size() == 4)
41 previous_branch = tokens[3];
42 if (tokens.size() < 3 || tokens.size() > 4)
78 }
else if (new_fd == -1) {
79 throw EPublish(
"Error while attempting to acquire lock " +
path_);
90 unlink(
path_.c_str());
99 int fd = open(
path_.c_str(), O_CREAT | O_RDWR, 0600);
107 unlink(
path_.c_str());
120 std::vector<std::string> cmd_line;
121 cmd_line.push_back(
"/usr/bin/cvmfs_suid_helper");
122 cmd_line.push_back(verb);
123 cmd_line.push_back(fqrn);
124 std::set<int> preserved_fds;
125 preserved_fds.insert(1);
126 preserved_fds.insert(2);
128 bool retval =
ManagedExec(cmd_line, preserved_fds, std::map<int, int>(),
134 throw EPublish(
"cannot spawn suid helper");
142 const std::string &key,
const std::string &value)
146 throw EPublish(
"cannot modify configuration file " + path);
148 std::string new_content;
150 bool key_exists =
false;
152 std::string trimmed =
Trim(line);
153 if (
HasPrefix(trimmed, key +
"=",
false )) {
156 new_content += key +
"=" + value +
"\n";
158 new_content += line +
"\n";
161 if (!key_exists && !value.empty())
162 new_content += key +
"=" + value +
"\n";
164 off_t off_zero = lseek(fd, 0, SEEK_SET);
167 throw EPublish(
"cannot rewind configuration file " + path);
169 int rvi = ftruncate(fd, 0);
172 throw EPublish(
"cannot truncate configuration file " + path);
174 bool rvb =
SafeWrite(fd, new_content.data(), new_content.length());
177 throw EPublish(
"cannot rewrite configuration file " + path);
185 throw EPublish(
"Socket " + socket +
" not found");
186 throw EPublish(
"Socket " + socket +
" inaccessible");
194 while ((retval = read(fd, &buf, 1)) == 1) {
195 result.push_back(buf);
199 throw EPublish(
"Broken socket: " + socket);
const int kDefaultFileMode
string Trim(const string &raw, bool trim_newline)
std::string ToString(const bool with_suffix=false) const
bool ManagedExec(const std::vector< std::string > &command_line, const std::set< int > &preserve_fildes, const std::map< int, int > &map_fildes, const bool drop_credentials, const bool clear_env, const bool double_fork, pid_t *child_pid)
bool SafeWrite(int fd, const void *buf, size_t nbyte)
assert((mem||(size==0))&&"Out Of Memory")
bool SafeWriteToFile(const std::string &content, const std::string &path, int mode)
int WaitForChild(pid_t pid, const std::vector< int > &sig_ok)
bool FileExists(const std::string &path)
bool GetLineFile(FILE *f, std::string *line)
vector< string > SplitString(const string &str, char delim)
std::string previous_branch() const
CheckoutMarker(const std::string &t, const std::string &b, const shash::Any &h, const std::string &p)
const char kSuffixCatalog
void SetInConfig(const std::string &path, const std::string &key, const std::string &value)
int TryLockFile(const std::string &path)
string StringifyInt(const int64_t value)
bool HasPrefix(const string &str, const string &prefix, const bool ignore_case)
void SaveAs(const std::string &path) const
std::string SendTalkCommand(const std::string &socket, const std::string &cmd)
std::string previous_branch_
bool GetLineFd(const int fd, std::string *line)
void RunSuidHelper(const std::string &verb, const std::string &fqrn)
int ConnectSocket(const std::string &path)
Any MkFromHexPtr(const HexPtr hex, const char suffix)
void WritePipe(int fd, const void *buf, size_t nbyte)
static CheckoutMarker * CreateFrom(const std::string &path)