Browse Source

Fix #585

pull/587/head
Max Lv 8 years ago
parent
commit
ac5f26c6fa
6 changed files with 7 additions and 39 deletions
  1. 13
      src/local.c
  2. 2
      src/manager.c
  3. 6
      src/redir.c
  4. 11
      src/server.c
  5. 6
      src/tunnel.c
  6. 8
      src/utils.c

13
src/local.c

@ -214,6 +214,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
server_t *server = server_recv_ctx->server;
remote_t *remote = server->remote;
buffer_t *buf;
ssize_t r;
if (remote == NULL) {
buf = server->buf;
@ -221,9 +222,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
buf = remote->buf;
}
ssize_t r;
errno = 0;
r = recv(server->fd, buf->array, BUF_SIZE, 0);
r = recv(server->fd, buf->array, BUF_SIZE, 0);
if (r == 0) {
// connection closed
@ -312,7 +311,6 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
s = send(remote->fd, remote->buf->array, remote->buf->len, 0);
}
#else
errno = 0;
int s = sendto(remote->fd, remote->buf->array, remote->buf->len, MSG_FASTOPEN,
(struct sockaddr *)&(remote->addr), remote->addr_len);
#endif
@ -350,7 +348,6 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
#endif
}
} else {
errno = 0;
int s = send(remote->fd, remote->buf->array, remote->buf->len, 0);
if (s == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
@ -583,7 +580,6 @@ static void server_send_cb(EV_P_ ev_io *w, int revents)
return;
} else {
// has data to send
errno = 0;
ssize_t s = send(server->fd, server->buf->array + server->buf->idx,
server->buf->len, 0);
if (s < 0) {
@ -647,7 +643,7 @@ static void remote_recv_cb(EV_P_ ev_io *w, int revents)
#ifdef ANDROID
stat_update_cb(loop);
#endif
errno = 0;
ssize_t r = recv(remote->fd, server->buf->array, BUF_SIZE, 0);
if (r == 0) {
@ -682,7 +678,7 @@ static void remote_recv_cb(EV_P_ ev_io *w, int revents)
return;
}
}
errno = 0;
int s = send(server->fd, server->buf->array, server->buf->len, 0);
if (s == -1) {
@ -745,7 +741,6 @@ static void remote_send_cb(EV_P_ ev_io *w, int revents)
return;
} else {
// has data to send
errno = 0;
ssize_t s = send(remote->fd, remote->buf->array + remote->buf->idx,
remote->buf->len, 0);
if (s < 0) {

2
src/manager.c

@ -758,7 +758,6 @@ int main(int argc, char **argv)
const char *homedir = pw->pw_dir;
snprintf(working_dir, PATH_MAX, "%s/.shadowsocks", homedir);
errno = 0;
int err = mkdir(working_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
if (err != 0 && errno != EEXIST) {
ERROR("mkdir");
@ -789,7 +788,6 @@ int main(int argc, char **argv)
setnonblocking(sfd);
errno = 0;
if (remove(manager_address) == -1 && errno != ENOENT) {
ERROR("bind");
exit(EXIT_FAILURE);

6
src/redir.c

@ -171,7 +171,6 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
server_t *server = server_recv_ctx->server;
remote_t *remote = server->remote;
errno = 0;
ssize_t r = recv(server->fd, remote->buf->array, BUF_SIZE, 0);
if (r == 0) {
@ -213,7 +212,6 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
return;
}
errno = 0;
int s = send(remote->fd, remote->buf->array, remote->buf->len, 0);
if (s == -1) {
@ -250,7 +248,6 @@ static void server_send_cb(EV_P_ ev_io *w, int revents)
return;
} else {
// has data to send
errno = 0;
ssize_t s = send(server->fd, server->buf->array + server->buf->idx,
server->buf->len, 0);
if (s < 0) {
@ -294,7 +291,6 @@ static void remote_recv_cb(EV_P_ ev_io *w, int revents)
remote_t *remote = remote_recv_ctx->remote;
server_t *server = remote->server;
errno = 0;
ssize_t r = recv(remote->fd, server->buf->array, BUF_SIZE, 0);
if (r == 0) {
@ -324,7 +320,6 @@ static void remote_recv_cb(EV_P_ ev_io *w, int revents)
close_and_free_server(EV_A_ server);
return;
}
errno = 0;
int s = send(server->fd, server->buf->array, server->buf->len, 0);
if (s == -1) {
@ -429,7 +424,6 @@ static void remote_send_cb(EV_P_ ev_io *w, int revents)
return;
} else {
// has data to send
errno = 0;
ssize_t s = send(remote->fd, remote->buf->array + remote->buf->idx,
remote->buf->len, 0);
if (s < 0) {

11
src/server.c

@ -273,8 +273,8 @@ int setfastopen(int fd)
#else
int opt = 5;
#endif
errno = 0;
s = setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN, &opt, sizeof(opt));
s = setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN, &opt, sizeof(opt));
if (s == -1) {
if (errno == EPROTONOSUPPORT || errno == ENOPROTOOPT) {
LOGE("fast open is not supported on this platform");
@ -453,7 +453,6 @@ static remote_t *connect_to_remote(struct addrinfo *res,
s = len;
}
#else
errno = 0;
ssize_t s = sendto(sockfd, server->buf->array + server->buf->idx,
server->buf->len, MSG_FASTOPEN, res->ai_addr,
res->ai_addrlen);
@ -503,7 +502,6 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
len = 0;
}
errno = 0;
ssize_t r = recv(server->fd, buf->array + len, BUF_SIZE - len, 0);
if (r == 0) {
@ -566,7 +564,6 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
close_and_free_remote(EV_A_ remote);
return;
}
errno = 0;
int s = send(remote->fd, remote->buf->array, remote->buf->len, 0);
if (s == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
@ -837,7 +834,6 @@ static void server_send_cb(EV_P_ ev_io *w, int revents)
return;
} else {
// has data to send
errno = 0;
ssize_t s = send(server->fd, server->buf->array + server->buf->idx,
server->buf->len, 0);
if (s < 0) {
@ -953,7 +949,6 @@ static void remote_recv_cb(EV_P_ ev_io *w, int revents)
ev_timer_again(EV_A_ & server->recv_ctx->watcher);
errno = 0;
ssize_t r = recv(remote->fd, server->buf->array, BUF_SIZE, 0);
if (r == 0) {
@ -989,7 +984,6 @@ static void remote_recv_cb(EV_P_ ev_io *w, int revents)
return;
}
errno = 0;
int s = send(server->fd, server->buf->array, server->buf->len, 0);
if (s == -1) {
@ -1062,7 +1056,6 @@ static void remote_send_cb(EV_P_ ev_io *w, int revents)
return;
} else {
// has data to send
errno = 0;
ssize_t s = send(remote->fd, remote->buf->array + remote->buf->idx,
remote->buf->len, 0);
if (s == -1) {

6
src/tunnel.c

@ -186,7 +186,6 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
return;
}
errno = 0;
ssize_t r = recv(server->fd, remote->buf->array, BUF_SIZE, 0);
if (r == 0) {
@ -222,7 +221,6 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
return;
}
errno = 0;
int s = send(remote->fd, remote->buf->array, remote->buf->len, 0);
if (s == -1) {
@ -259,7 +257,6 @@ static void server_send_cb(EV_P_ ev_io *w, int revents)
return;
} else {
// has data to send
errno = 0;
ssize_t s = send(server->fd, server->buf->array + server->buf->idx,
server->buf->len, 0);
if (s < 0) {
@ -313,7 +310,6 @@ static void remote_recv_cb(EV_P_ ev_io *w, int revents)
remote_t *remote = remote_recv_ctx->remote;
server_t *server = remote->server;
errno = 0;
ssize_t r = recv(remote->fd, server->buf->array, BUF_SIZE, 0);
if (r == 0) {
@ -345,7 +341,6 @@ static void remote_recv_cb(EV_P_ ev_io *w, int revents)
return;
}
errno = 0;
int s = send(server->fd, server->buf->array, server->buf->len, 0);
if (s == -1) {
@ -476,7 +471,6 @@ static void remote_send_cb(EV_P_ ev_io *w, int revents)
return;
} else {
// has data to send
errno = 0;
ssize_t s = send(remote->fd, remote->buf->array + remote->buf->idx,
remote->buf->len, 0);
if (s < 0) {

8
src/utils.c

@ -102,19 +102,16 @@ int run_as(const char *user)
/* Note that we use getpwnam_r() instead of getpwnam(),
* which returns its result in a statically allocated buffer and
* cannot be considered thread safe. */
errno = 0;
err = getpwnam_r(user, &pwdbuf, buf, buflen, &pwd);
err = getpwnam_r(user, &pwdbuf, buf, buflen, &pwd);
if (err == 0 && pwd) {
/* setgid first, because we may not be allowed to do it anymore after setuid */
errno = 0;
if (setgid(pwd->pw_gid) != 0) {
LOGE(
"Could not change group id to that of run_as user '%s': %s",
user, strerror(errno));
return 0;
}
errno = 0;
if (setuid(pwd->pw_uid) != 0) {
LOGE(
@ -150,13 +147,11 @@ int run_as(const char *user)
return 0;
}
/* setgid first, because we may not allowed to do it anymore after setuid */
errno = 0;
if (setgid(pwd->pw_gid) != 0) {
LOGE("Could not change group id to that of run_as user '%s': %s",
user, strerror(errno));
return 0;
}
errno = 0;
if (setuid(pwd->pw_uid) != 0) {
LOGE("Could not change user id to that of run_as user '%s': %s",
user, strerror(errno));
@ -356,7 +351,6 @@ int set_nofile(int nofile)
if (nofile <= 0) {
FATAL("nofile must be greater than 0\n");
}
errno = 0;
if (setrlimit(RLIMIT_NOFILE, &limit) < 0) {
if (errno == EPERM) {

Loading…
Cancel
Save