172 {
173 std::string dest_dir = path + name;
174 BOOST_LOG_TRIVIAL(debug) <<"full lock path: "<< dest_dir;
175 struct flock fl;
176 int fdlock;
177 fl.l_type = F_WRLCK;
178 fl.l_whence = SEEK_SET;
179 fl.l_start = 0;
180 fl.l_len = 1;
181
182 if (! boost::filesystem::is_directory(path)) {
183 BOOST_LOG_TRIVIAL(debug) << "get_lock(): datadir does not exist yet, creating...";
184 if (! boost::filesystem::create_directories(path))
185 BOOST_LOG_TRIVIAL(debug) << "get_lock(): unable to create datadir !!!";
186 }
187
188 if ((fdlock = open(dest_dir.c_str(), O_WRONLY | O_CREAT, 0666)) == -1) {
189 BOOST_LOG_TRIVIAL(debug) << "Not creating lockfile.";
190 return true;
191 }
192
193 if (fcntl(fdlock, F_SETLK, &fl) == -1) {
194 BOOST_LOG_TRIVIAL(debug) << "Not creating lockfile.";
195 return true;
196 }
197
198 BOOST_LOG_TRIVIAL(debug) << "Creating lockfile.";
200 return false;
201 }