MCPcopy Create free account
hub / github.com/apache/trafficserver / bind

Method bind

src/mgmt/rpc/server/IPCSocketServer.cc:286–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

284}
285
286void
287IPCSocketServer::bind(std::error_code &ec)
288{
289 _lock_fd = open(_conf.lockPathName.c_str(), O_RDONLY | O_CREAT, 0600);
290 if (_lock_fd == -1) {
291 ec = std::make_error_code(static_cast<std::errc>(errno));
292 return;
293 }
294
295 int ret = flock(_lock_fd, LOCK_EX | LOCK_NB);
296
297 if (ret != 0) {
298 ec = std::make_error_code(static_cast<std::errc>(errno));
299 return;
300 }
301 // TODO: we may be able to use SO_REUSEADDR
302
303 // remove socket file
304 unlink(_conf.sockPathName.c_str());
305
306 ret = ::bind(_socket, (struct sockaddr *)&_serverAddr, sizeof(struct sockaddr_un));
307 if (ret < 0) {
308 ec = std::make_error_code(static_cast<std::errc>(errno));
309 return;
310 }
311
312 // If the socket is not administratively restricted, check whether we have platform
313 // support. Otherwise, default to making it restricted.
314 bool restricted{true};
315 if (!_conf.restrictedAccessApi) {
316 restricted = !has_peereid();
317 }
318
319 mode_t mode = restricted ? 00700 : 00777;
320 if (chmod(_conf.sockPathName.c_str(), mode) < 0) {
321 ec = std::make_error_code(static_cast<std::errc>(errno));
322 return;
323 }
324}
325
326void
327IPCSocketServer::listen(std::error_code &ec)

Callers 1

initMethod · 0.95

Calls 4

has_peereidFunction · 0.85
make_error_codeFunction · 0.70
flockClass · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected