Commit de894f08 authored by Max Lv's avatar Max Lv

update libev implementation

parent 532ab108
...@@ -2,4 +2,5 @@ ...@@ -2,4 +2,5 @@
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, "shadowsocks", __VA_ARGS__)) #define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, "shadowsocks", __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "shadowsocks", __VA_ARGS__)) #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "shadowsocks", __VA_ARGS__))
#define perror(a) (LOGE("%s: %s", a, strerror(errno)))
...@@ -49,14 +49,10 @@ void get_table(const char* key) { ...@@ -49,14 +49,10 @@ void get_table(const char* key) {
_a = *(unsigned long long *)tmp_hash; _a = *(unsigned long long *)tmp_hash;
unsigned int i; unsigned int i;
LOGD("key hash: %lld", _a);
for(i = 0; i < 256; ++i) { for(i = 0; i < 256; ++i) {
table[i] = i; table[i] = i;
} }
for(i = 1; i < 1024; ++i) { for(i = 1; i < 1024; ++i) {
// use bubble sort in order to keep the array stable as in Python
unsigned char t;
_i = i; _i = i;
qsort(table, 256, sizeof(unsigned char), random_compare); qsort(table, 256, sizeof(unsigned char), random_compare);
} }
......
...@@ -539,10 +539,11 @@ int main (int argc, char **argv) ...@@ -539,10 +539,11 @@ int main (int argc, char **argv)
char *port = NULL; char *port = NULL;
char *key = NULL; char *key = NULL;
int c; int c;
int f_flags = 0;
opterr = 0; opterr = 0;
while ((c = getopt (argc, argv, "s:p:l:k:")) != -1) { while ((c = getopt (argc, argv, "fs:p:l:k:")) != -1) {
switch (c) { switch (c) {
case 's': case 's':
server = optarg; server = optarg;
...@@ -556,6 +557,9 @@ int main (int argc, char **argv) ...@@ -556,6 +557,9 @@ int main (int argc, char **argv)
case 'k': case 'k':
key = optarg; key = optarg;
break; break;
case 'f':
f_flags = 1;
break;
} }
} }
...@@ -564,46 +568,49 @@ int main (int argc, char **argv) ...@@ -564,46 +568,49 @@ int main (int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* Our process ID and Session ID */ if (f_flags) {
pid_t pid, sid;
/* Fork off the parent process */ /* Our process ID and Session ID */
pid = fork(); pid_t pid, sid;
if (pid < 0) {
exit(EXIT_FAILURE);
}
/* If we got a good PID, then
we can exit the parent process. */
if (pid > 0) {
FILE *file = fopen("/data/data/com.github.shadowsocks/shadowsocks.pid", "w");
fprintf(file, "%d", pid);
fclose(file);
exit(EXIT_SUCCESS);
}
/* Change the file mode mask */ /* Fork off the parent process */
umask(0); pid = fork();
if (pid < 0) {
exit(EXIT_FAILURE);
}
/* If we got a good PID, then
we can exit the parent process. */
if (pid > 0) {
FILE *file = fopen("/data/data/com.github.shadowsocks/shadowsocks.pid", "w");
fprintf(file, "%d", pid);
fclose(file);
exit(EXIT_SUCCESS);
}
/* Open any logs here */ /* Change the file mode mask */
umask(0);
/* Create a new SID for the child process */ /* Open any logs here */
sid = setsid();
if (sid < 0) {
/* Log the failure */
exit(EXIT_FAILURE);
}
/* Create a new SID for the child process */
sid = setsid();
if (sid < 0) {
/* Log the failure */
exit(EXIT_FAILURE);
}
/* Change the current working directory */
if ((chdir("/")) < 0) {
/* Log the failure */
exit(EXIT_FAILURE);
}
/* Close out the standard file descriptors */ /* Change the current working directory */
close(STDIN_FILENO); if ((chdir("/")) < 0) {
close(STDOUT_FILENO); /* Log the failure */
close(STDERR_FILENO); exit(EXIT_FAILURE);
}
/* Close out the standard file descriptors */
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
}
_server = strdup(server); _server = strdup(server);
_remote_port = strdup(remote_port); _remote_port = strdup(remote_port);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment