156 {
157 std::string dest_dir = path + name;
158 BOOST_LOG_TRIVIAL(debug) <<"full lock path: "<< dest_dir;
159 struct flock fl;
160 int fdlock;
161 fl.l_type = F_WRLCK;
163 fl.l_start = 0;
164 fl.l_len = 1;
165
166 if (! boost::filesystem::is_directory(path)) {
167 BOOST_LOG_TRIVIAL(debug) << "get_lock(): datadir does not exist yet, creating...";
168 if (! boost::filesystem::create_directories(path))
169 BOOST_LOG_TRIVIAL(debug) << "get_lock(): unable to create datadir !!!";
170 }
171
172 if ((fdlock = open(dest_dir.c_str(), O_WRONLY | O_CREAT, 0666)) == -1) {
173 BOOST_LOG_TRIVIAL(debug) << "Not creating lockfile.";
174 return true;
175 }
176
177 if (fcntl(fdlock, F_SETLK, &fl) == -1) {
178 BOOST_LOG_TRIVIAL(debug) << "Not creating lockfile.";
179 return true;
180 }
181
182 BOOST_LOG_TRIVIAL(debug) << "Creating lockfile.";
184 return false;
185 }
static bool s_created_lockfile
Definition InstanceCheck.cpp:55