From de894f081465d0fe7736b3fdcde36a7faa263975 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Thu, 27 Dec 2012 11:36:22 +0800 Subject: [PATCH] update libev implementation --- jni/shadowsocks/android.h | 1 + jni/shadowsocks/encrypt.c | 4 -- jni/shadowsocks/local.c | 85 +++++++++++++++++++++------------------ 3 files changed, 47 insertions(+), 43 deletions(-) diff --git a/jni/shadowsocks/android.h b/jni/shadowsocks/android.h index 89939d49..e025ebfe 100644 --- a/jni/shadowsocks/android.h +++ b/jni/shadowsocks/android.h @@ -2,4 +2,5 @@ #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 perror(a) (LOGE("%s: %s", a, strerror(errno))) diff --git a/jni/shadowsocks/encrypt.c b/jni/shadowsocks/encrypt.c index 2d6f4205..e6dba755 100755 --- a/jni/shadowsocks/encrypt.c +++ b/jni/shadowsocks/encrypt.c @@ -49,14 +49,10 @@ void get_table(const char* key) { _a = *(unsigned long long *)tmp_hash; unsigned int i; - LOGD("key hash: %lld", _a); - for(i = 0; i < 256; ++i) { table[i] = 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; qsort(table, 256, sizeof(unsigned char), random_compare); } diff --git a/jni/shadowsocks/local.c b/jni/shadowsocks/local.c index 0fc91a28..c7926f7e 100644 --- a/jni/shadowsocks/local.c +++ b/jni/shadowsocks/local.c @@ -539,10 +539,11 @@ int main (int argc, char **argv) char *port = NULL; char *key = NULL; int c; + int f_flags = 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) { case 's': server = optarg; @@ -556,6 +557,9 @@ int main (int argc, char **argv) case 'k': key = optarg; break; + case 'f': + f_flags = 1; + break; } } @@ -564,46 +568,49 @@ int main (int argc, char **argv) exit(EXIT_FAILURE); } - /* Our process ID and Session ID */ - pid_t pid, sid; + if (f_flags) { - /* Fork off the parent process */ - pid = fork(); - if (pid < 0) { - exit(EXIT_FAILURE); + /* Our process ID and Session ID */ + pid_t pid, sid; + + /* Fork off the parent process */ + 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); + } + + /* Change the file mode mask */ + umask(0); + + /* Open any logs here */ + + /* 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 */ + close(STDIN_FILENO); + close(STDOUT_FILENO); + close(STDERR_FILENO); } - /* 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 */ - umask(0); - - /* Open any logs here */ - - /* 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 */ - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); _server = strdup(server); _remote_port = strdup(remote_port);