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)
79 }
else if (new_fd == -1) {
80 throw EPublish(
"Error while attempting to acquire lock " +
path_);
91 unlink(
path_.c_str());
100 int fd = open(
path_.c_str(), O_CREAT | O_RDWR, 0600);
117 std::vector<std::string> cmd_line;
118 cmd_line.push_back(
"/usr/bin/cvmfs_suid_helper");
119 cmd_line.push_back(verb);
120 cmd_line.push_back(fqrn);
121 std::set<int> preserved_fds;
122 preserved_fds.insert(1);
123 preserved_fds.insert(2);
125 bool retval =
ManagedExec(cmd_line, preserved_fds, std::map<int, int>(),
129 throw EPublish(
"cannot spawn suid helper");
137 const std::string &value) {
140 throw EPublish(
"cannot modify configuration file " + path);
142 std::string new_content;
144 bool key_exists =
false;
146 std::string trimmed =
Trim(line);
147 if (
HasPrefix(trimmed, key +
"=",
false )) {
150 new_content += key +
"=" + value +
"\n";
152 new_content += line +
"\n";
155 if (!key_exists && !value.empty())
156 new_content += key +
"=" + value +
"\n";
158 off_t off_zero = lseek(fd, 0, SEEK_SET);
161 throw EPublish(
"cannot rewind configuration file " + path);
163 int rvi = ftruncate(fd, 0);
166 throw EPublish(
"cannot truncate configuration file " + path);
168 bool rvb =
SafeWrite(fd, new_content.data(), new_content.length());
171 throw EPublish(
"cannot rewrite configuration file " + path);
179 throw EPublish(
"Socket " + socket +
" not found");
180 throw EPublish(
"Socket " + socket +
" inaccessible");
188 while ((retval = read(fd, &buf, 1)) == 1) {
189 result.push_back(buf);
193 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)