Refine nofile option

This commit is contained in:
Max Lv
2015-12-14 19:31:12 +08:00
parent 72ea070b1d
commit 47f984e61c
5 changed files with 62 additions and 8 deletions
+6 -3
View File
@@ -992,10 +992,10 @@ int main(int argc, char **argv)
USE_TTY();
#ifdef ANDROID
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:a:uvVA",
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:a:n:uvVA",
long_options, &option_index)) != -1) {
#else
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:a:uvA",
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:a:n:uvA",
long_options, &option_index)) != -1) {
#endif
switch (c) {
@@ -1044,6 +1044,9 @@ int main(int argc, char **argv)
case 'a':
user = optarg;
break;
case 'n':
nofile = atoi(optarg);
break;
case 'u':
mode = TCP_AND_UDP;
break;
@@ -1110,7 +1113,7 @@ int main(int argc, char **argv)
* no need to check the return value here since we will show
* the user an error message if setrlimit(2) fails
*/
if (nofile) {
if (nofile > 1024) {
if (verbose) {
LOGI("setting NOFILE to %d", nofile);
}
+22 -1
View File
@@ -84,6 +84,9 @@ int verbose = 0;
static int mode = TCP_ONLY;
static int auth = 0;
#ifdef HAVE_SETRLIMIT
static int nofile = 0;
#endif
int getdestaddr(int fd, struct sockaddr_storage *destaddr)
{
@@ -636,7 +639,7 @@ int main(int argc, char **argv)
opterr = 0;
while ((c = getopt(argc, argv, "f:s:p:l:k:t:m:c:b:a:uUvA")) != -1)
while ((c = getopt(argc, argv, "f:s:p:l:k:t:m:c:b:a:n:uUvA")) != -1)
switch (c) {
case 's':
if (remote_num < MAX_REMOTE_NUM) {
@@ -672,6 +675,9 @@ int main(int argc, char **argv)
case 'a':
user = optarg;
break;
case 'n':
nofile = atoi(optarg);
break;
case 'u':
mode = TCP_AND_UDP;
break;
@@ -725,6 +731,21 @@ int main(int argc, char **argv)
if (auth == 0) {
auth = conf->auth;
}
#ifdef HAVE_SETRLIMIT
if (nofile == 0) {
nofile = conf->nofile;
}
/*
* no need to check the return value here since we will show
* the user an error message if setrlimit(2) fails
*/
if (nofile > 1024) {
if (verbose) {
LOGI("setting NOFILE to %d", nofile);
}
set_nofile(nofile);
}
#endif
}
if (remote_num == 0 || remote_port == NULL ||
+5 -2
View File
@@ -1297,7 +1297,7 @@ int main(int argc, char **argv)
USE_TTY();
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:c:i:d:a:uUvAw",
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:c:i:d:a:n:uUvAw",
long_options, &option_index)) != -1)
switch (c) {
case 0:
@@ -1346,6 +1346,9 @@ int main(int argc, char **argv)
case 'a':
user = optarg;
break;
case 'n':
nofile = atoi(optarg);
break;
case 'u':
mode = TCP_AND_UDP;
break;
@@ -1411,7 +1414,7 @@ int main(int argc, char **argv)
* no need to check the return value here since we will show
* the user an error message if setrlimit(2) fails
*/
if (nofile) {
if (nofile > 1024) {
if (verbose) {
LOGI("setting NOFILE to %d", nofile);
}
+23 -2
View File
@@ -92,6 +92,9 @@ int verbose = 0;
static int mode = TCP_ONLY;
static int auth = 0;
#ifdef HAVE_SETRLIMIT
static int nofile = 0;
#endif
#ifndef __MINGW32__
static int setnonblocking(int fd)
@@ -693,9 +696,9 @@ int main(int argc, char **argv)
USE_TTY();
#ifdef ANDROID
while ((c = getopt(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:uUvVA")) != -1) {
while ((c = getopt(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:n:uUvVA")) != -1) {
#else
while ((c = getopt(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:uUvA")) != -1) {
while ((c = getopt(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:n:uUvA")) != -1) {
#endif
switch (c) {
case 's':
@@ -744,6 +747,9 @@ int main(int argc, char **argv)
case 'a':
user = optarg;
break;
case 'n':
nofile = atoi(optarg);
break;
case 'v':
verbose = 1;
break;
@@ -797,6 +803,21 @@ int main(int argc, char **argv)
if (auth == 0) {
auth = conf->auth;
}
#ifdef HAVE_SETRLIMIT
if (nofile == 0) {
nofile = conf->nofile;
}
/*
* no need to check the return value here since we will show
* the user an error message if setrlimit(2) fails
*/
if (nofile > 1024) {
if (verbose) {
LOGI("setting NOFILE to %d", nofile);
}
set_nofile(nofile);
}
#endif
}
if (remote_num == 0 || remote_port == NULL || tunnel_addr_str == NULL ||
+6
View File
@@ -223,12 +223,18 @@ void usage()
printf(
" rc2-cfb, seed-cfb, salsa20 and chacha20.\n");
printf("\n");
printf(
" [-a <user>] Run as another user.\n");
printf(
" [-f <pid_file>] The file path to store pid.\n");
printf(
" [-t <timeout>] Socket timeout in seconds.\n");
printf(
" [-c <config_file>] The path to config file.\n");
#ifdef HAVE_SETRLIMIT
printf(
" [-n <number>] Max number of open files, only available on Linux.\n");
#endif
#ifndef MODULE_REDIR
printf(
" [-i <interface>] Network interface to bind.\n");