]>
git.saurik.com Git - cycript.git/blob - Connector.cpp
7 #include <sys/socket.h>
8 #include <netinet/in.h>
11 #include <apr-1/apr_thread_proc.h>
16 #import <CoreFoundation/CFLogUtilities.h>
24 apr_status_t
CYPoolDLClose_(void *data
) {
25 // XXX: this is an interesting idea
26 /* void *handle(reinterpret_cast<void *>(data));
31 static void * APR_THREAD_FUNC
Cyrver(apr_thread_t
*thread
, void *data
) {
32 CYServer
*server(reinterpret_cast<CYServer
*>(data
));
35 int socket(_syscall(accept(server
->socket_
, NULL
, NULL
)));
37 if (void *handle
= dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY
| RTLD_LOCAL
)) {
39 _aprcall(apr_pool_create(&pool
, NULL
));
41 apr_pool_cleanup_register(pool
, handle
, &CYPoolDLClose_
, &apr_pool_cleanup_null
);
43 if (void (*CYHandleClient_
)(apr_pool_t
*, int) = reinterpret_cast<void (*)(apr_pool_t
*, int)>(dlsym(handle
, "CYHandleClient")))
44 (*CYHandleClient_
)(pool
, socket
);
46 apr_pool_destroy(pool
);
48 CFLog(kCFLogLevelError
, CFSTR("CY:Error: cannot load: %s"), dlerror());
55 static void Unlink() {
58 sprintf(path
, "/tmp/.s.cy.%u", pid
);
63 _aprcall(apr_initialize());
65 CYServer
*server(new CYServer());
66 server
->socket_
= _syscall(socket(PF_UNIX
, SOCK_STREAM
, 0));
68 struct sockaddr_un address
;
69 memset(&address
, 0, sizeof(address
));
70 address
.sun_family
= AF_UNIX
;
73 sprintf(address
.sun_path
, "/tmp/.s.cy.%u", pid
);
76 _syscall(bind(server
->socket_
, reinterpret_cast<sockaddr
*>(&address
), SUN_LEN(&address
)));
78 _syscall(listen(server
->socket_
, 0));
80 apr_threadattr_t
*attr
;
81 _aprcall(apr_threadattr_create(&attr
, server
->pool_
));
84 _aprcall(apr_thread_create(&thread
, attr
, &Cyrver
, server
, server
->pool_
));
86 CFLog(kCFLogLevelError
, CFSTR("CY:Error: cannot bind unix domain socket"));