197 addr.sun_family = AF_UNIX; |
197 addr.sun_family = AF_UNIX; |
198 strcpy(addr.sun_path, initial_path); |
198 strcpy(addr.sun_path, initial_path); |
199 ::unlink(initial_path); |
199 ::unlink(initial_path); |
200 int res = ::bind(listener, (struct sockaddr*)&addr, sizeof(addr)); |
200 int res = ::bind(listener, (struct sockaddr*)&addr, sizeof(addr)); |
201 if (res == -1) { |
201 if (res == -1) { |
202 RESTARTABLE(::close(listener), res); |
202 ::close(listener); |
203 return -1; |
203 return -1; |
204 } |
204 } |
205 |
205 |
206 // put in listen mode, set permissions, and rename into place |
206 // put in listen mode, set permissions, and rename into place |
207 res = ::listen(listener, 5); |
207 res = ::listen(listener, 5); |
338 // get the credentials of the peer and check the effective uid/guid |
338 // get the credentials of the peer and check the effective uid/guid |
339 // - check with jeff on this. |
339 // - check with jeff on this. |
340 struct ucred cred_info; |
340 struct ucred cred_info; |
341 socklen_t optlen = sizeof(cred_info); |
341 socklen_t optlen = sizeof(cred_info); |
342 if (::getsockopt(s, SOL_SOCKET, SO_PEERCRED, (void*)&cred_info, &optlen) == -1) { |
342 if (::getsockopt(s, SOL_SOCKET, SO_PEERCRED, (void*)&cred_info, &optlen) == -1) { |
343 int res; |
343 ::close(s); |
344 RESTARTABLE(::close(s), res); |
|
345 continue; |
344 continue; |
346 } |
345 } |
347 uid_t euid = geteuid(); |
346 uid_t euid = geteuid(); |
348 gid_t egid = getegid(); |
347 gid_t egid = getegid(); |
349 |
348 |
350 if (cred_info.uid != euid || cred_info.gid != egid) { |
349 if (cred_info.uid != euid || cred_info.gid != egid) { |
351 int res; |
350 ::close(s); |
352 RESTARTABLE(::close(s), res); |
|
353 continue; |
351 continue; |
354 } |
352 } |
355 |
353 |
356 // peer credential look okay so we read the request |
354 // peer credential look okay so we read the request |
357 LinuxAttachOperation* op = read_request(s); |
355 LinuxAttachOperation* op = read_request(s); |
358 if (op == NULL) { |
356 if (op == NULL) { |
359 int res; |
357 ::close(s); |
360 RESTARTABLE(::close(s), res); |
|
361 continue; |
358 continue; |
362 } else { |
359 } else { |
363 return op; |
360 return op; |
364 } |
361 } |
365 } |
362 } |
406 LinuxAttachListener::write_fully(this->socket(), (char*) st->base(), st->size()); |
403 LinuxAttachListener::write_fully(this->socket(), (char*) st->base(), st->size()); |
407 ::shutdown(this->socket(), 2); |
404 ::shutdown(this->socket(), 2); |
408 } |
405 } |
409 |
406 |
410 // done |
407 // done |
411 RESTARTABLE(::close(this->socket()), rc); |
408 ::close(this->socket()); |
412 |
409 |
413 // were we externally suspended while we were waiting? |
410 // were we externally suspended while we were waiting? |
414 thread->check_and_wait_while_suspended(); |
411 thread->check_and_wait_while_suspended(); |
415 |
412 |
416 delete this; |
413 delete this; |