X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/9674674739f8ab3c2b81879f36fdb7fcf294cb5e..f6fa3c2112ee8b0aa26ab0765674601a9800db77:/Console.cpp?ds=sidebyside diff --git a/Console.cpp b/Console.cpp index f93e090..0840ca5 100644 --- a/Console.cpp +++ b/Console.cpp @@ -808,29 +808,49 @@ int Main(int argc, char const * const argv[], char const * const envp[]) { if (pid == _not(pid_t)) client_ = -1; else { - int server(_syscall(socket(PF_UNIX, SOCK_STREAM, 0))); try { - struct sockaddr_un address; - memset(&address, 0, sizeof(address)); - address.sun_family = AF_UNIX; - - sprintf(address.sun_path, "/tmp/.s.cy.%u", getpid()); - - _syscall(bind(server, reinterpret_cast(&address), SUN_LEN(&address))); - _syscall(chmod(address.sun_path, 0777)); - - try { - _syscall(listen(server, 1)); - InjectLibrary(pid); - client_ = _syscall(accept(server, NULL, NULL)); - } catch (...) { - // XXX: exception? - unlink(address.sun_path); - throw; + struct Socket { + int fd_; + + Socket(int fd) : + fd_(fd) + { } - } catch (...) { - _syscall(close(server)); - throw; - } + + ~Socket() { + close(fd_); + } + + operator int() { + return fd_; + } + } server(_syscall(socket(PF_UNIX, SOCK_STREAM, 0))); + + struct sockaddr_un address; + memset(&address, 0, sizeof(address)); + address.sun_family = AF_UNIX; + + sprintf(address.sun_path, "/tmp/.s.cy.%u", getpid()); + unlink(address.sun_path); + + struct File { + const char *path_; + + File(const char *path) : + path_(path) + { + } + + ~File() { + unlink(path_); + } + } file(address.sun_path); + + _syscall(bind(server, reinterpret_cast(&address), SUN_LEN(&address))); + _syscall(chmod(address.sun_path, 0777)); + + _syscall(listen(server, 1)); + InjectLibrary(pid); + client_ = _syscall(accept(server, NULL, NULL)); } #else client_ = -1;