Mercurial > hg > truffle
comparison src/os/linux/vm/attachListener_linux.cpp @ 12912:d840f02d03b4
Merge
author | chegar |
---|---|
date | Mon, 15 Jul 2013 11:07:03 +0100 |
parents | e95fc50106cf |
children | 2e8f19c2feef |
comparison
equal
deleted
inserted
replaced
12911:5c599c419c1d | 12912:d840f02d03b4 |
---|---|
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); |
210 if (res == 0) { | 210 if (res == 0) { |
211 res = ::rename(initial_path, path); | 211 res = ::rename(initial_path, path); |
212 } | 212 } |
213 } | 213 } |
214 if (res == -1) { | 214 if (res == -1) { |
215 RESTARTABLE(::close(listener), res); | 215 ::close(listener); |
216 ::unlink(initial_path); | 216 ::unlink(initial_path); |
217 return -1; | 217 return -1; |
218 } | 218 } |
219 set_path(path); | 219 set_path(path); |
220 set_listener(listener); | 220 set_listener(listener); |
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; |