X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=src%2Fsocket2unix.c;h=693892d5c44c8190c2f5b39b38e0e89ef1cdf4d4;hb=41de691e385f39679db82c3cfeadf875f5aeca51;hp=27f8d6833e43cff6afe21a3c4c2f1c531c3b7412;hpb=dc1a0912c69d0f8eafdacc841b20750a2b270bb5;p=socket2unix%2Fsocket2unix.git diff --git a/src/socket2unix.c b/src/socket2unix.c index 27f8d68..693892d 100644 --- a/src/socket2unix.c +++ b/src/socket2unix.c @@ -230,22 +230,24 @@ static int get_log_level(void) { return number; } static int get_options(void) { - const char *pos = getenv("SOCKET2UNIX_OPTIONS"); - if (!pos) { + const char *start = getenv("SOCKET2UNIX_OPTIONS"); + if (!start) { return OPTION_PARSED; } int options = OPTION_PARSED; - while (*pos != '\0') { + const char *end = start + strlen(start); + const char *pos, *curend; + + for (pos = start; pos < end; pos = curend + 1) { size_t length; - const char *end = strchr(pos, ','); - if (end == NULL) { - length = strlen(pos); - } else { - length = (size_t)(end - pos); + curend = strchr(pos, ','); + if (curend == NULL) { + curend = end; } + length = (size_t)(curend - pos); if (!strncmp("client_only", pos, length)) { options |= OPTION_CLIENT_ONLY; @@ -258,11 +260,6 @@ static int get_options(void) { ERROR("unknown option '%s' in SOCKET2UNIX_OPTIONS\n", option); } - - if (end == NULL) { - break; - } - pos = end + 1; } if ((options & OPTION_CLIENT_ONLY) && (options & OPTION_SERVER_ONLY)) { @@ -448,14 +445,14 @@ int close(int fd) { static int (*real_close)(int); LOAD_FUNCTION(real_close, "close"); - DBG("close(%d)\n", fd); - struct list *entry = remove_sockfd(fd); if (entry == NULL) { DBG("close(%d): sockfd not found\n", fd); return real_close(fd); } assert(fd == entry->orig_sockfd); + + DBG("close(%d)\n", fd); free(entry->orig_addr); free(entry); @@ -466,8 +463,6 @@ int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { static int (*real_bind)(int, const struct sockaddr *, socklen_t); LOAD_FUNCTION(real_bind, "bind"); - DBG("bind(%d, ..)\n", sockfd); - if (addr == NULL || addrlen < sizeof(addr->sa_family) || addr->sa_family == AF_UNIX || addr->sa_family == AF_LOCAL) { @@ -593,8 +588,6 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { return real_accept(sockfd, addr, addrlen); } - DBG("accept(%d, ..)\n", sockfd); - struct list *entry = find_sockfd(sockfd); if (!entry) { DBG("accept(%d, ..): sockfd not found\n", sockfd); @@ -647,8 +640,6 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { return real_connect(sockfd, addr, addrlen); } - DBG("connect(%d, ..)\n", sockfd); - if (addr == NULL || addrlen < sizeof(addr->sa_family) || addr->sa_family == AF_UNIX || addr->sa_family == AF_LOCAL) {