Browse Source

fix a bug on OS X 10.6.x

pull/4/merge
Max Lv 11 years ago
parent
commit
70ddd012e3
6 changed files with 26 additions and 9 deletions
  1. 12
      libasyncns/asyncns.c
  2. 2
      src/jconf.c
  3. 4
      src/local.c
  4. 4
      src/redir.c
  5. 12
      src/utils.c
  6. 1
      src/utils.h

12
libasyncns/asyncns.c

@ -645,7 +645,9 @@ static int process_worker(int in_fd, int out_fd) {
if (!have_death_sig) {
fd_set fds;
struct timeval tv = { 0, 5000000 };
struct timeval tv;
tv.tv_usec = 500000;
tv.tv_sec = 0;
FD_ZERO(&fds);
FD_SET(in_fd, &fds);
@ -699,13 +701,17 @@ static void* thread_worker(void *p) {
if (!asyncns->dead) {
fd_set fds;
struct timeval tv = { 0, 5000000 };
struct timeval tv;
tv.tv_usec = 500000;
tv.tv_sec = 0;
FD_ZERO(&fds);
FD_SET(in_fd, &fds);
if (select(in_fd+1, &fds, NULL, NULL, &tv) < 0)
if (select(in_fd+1, &fds, NULL, NULL, &tv) < 0) {
perror("test");
break;
}
}
if (length < 0 &&

2
src/jconf.c

@ -11,7 +11,7 @@
static char *to_string(const json_value *value) {
if (value->type == json_string) {
return strndup(value->u.string.ptr, value->u.string.length);
return ss_strndup(value->u.string.ptr, value->u.string.length);
} else if (value->type == json_integer) {
return strdup(itoa(value->u.integer));
} else if (value->type == json_null) {

4
src/local.c

@ -699,9 +699,9 @@ int main (int argc, char **argv) {
listen_ctx.remote_host = malloc(sizeof(char *) * remote_num);
while (remote_num > 0) {
int index = --remote_num;
listen_ctx.remote_host[index] = strdup(remote_host[index]);
listen_ctx.remote_host[index] = remote_host[index];
}
listen_ctx.remote_port = strdup(remote_port);
listen_ctx.remote_port = remote_port;
listen_ctx.timeout = atoi(timeout);
listen_ctx.fd = listenfd;
listen_ctx.iface = iface;

4
src/redir.c

@ -624,9 +624,9 @@ int main (int argc, char **argv) {
listen_ctx.remote_host = malloc(sizeof(char *) * remote_num);
while (remote_num > 0) {
int index = --remote_num;
listen_ctx.remote_host[index] = strdup(remote_host[index]);
listen_ctx.remote_host[index] = remote_host[index];
}
listen_ctx.remote_port = strdup(remote_port);
listen_ctx.remote_port = remote_port;
listen_ctx.timeout = atoi(timeout);
listen_ctx.fd = listenfd;

12
src/utils.c

@ -43,6 +43,17 @@ char *itoa(int i) {
return p;
}
char *ss_strndup(const char *s, size_t n) {
size_t len = strlen(s);
char *ret;
if (len <= n) return strdup(s);
ret = malloc(n + 1);
strncpy(ret, s, n);
ret[n] = '\0';
return ret;
}
void FATAL(const char *msg) {
LOGE("%s", msg);
@ -109,6 +120,5 @@ void demonize(const char* path) {
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
}

1
src/utils.h

@ -35,5 +35,6 @@ void ERROR(const char *s);
void usage(void);
void demonize(const char* path);
char *itoa(int i);
char *ss_strndup(const char *s, size_t n);
#endif // _UTILS_H
Loading…
Cancel
Save