[hackers] [quark] Rename fd to listenfd for readability || sin

From: <git_AT_suckless.org>
Date: Fri, 22 Aug 2014 11:53:42 +0200

commit 29c8cfa2017b1d8401ca01850aa8cb6c0530834f
Author: sin <sin_AT_2f30.org>
Date: Thu Aug 21 23:11:23 2014 +0100

    Rename fd to listenfd for readability
    
    Avoid confusion in functions that use 'fd' and shadow the
    global fd.

diff --git a/quark.c b/quark.c
index 3e18509..d211abb 100644
--- a/quark.c
+++ b/quark.c
_AT_@ -97,7 +97,7 @@ static char reqbuf[MAXBUFLEN];
 static char resbuf[MAXBUFLEN];
 static char reqhost[256];
 static char reqmod[256];
-static int fd = -1;
+static int listenfd = -1;
 static Request req;
 
 char *
_AT_@ -555,7 +555,7 @@ sighandler(int sig) {
                 while(0 < waitpid(-1, NULL, WNOHANG));
         } else {
                 logerrmsg("info signal %s, closing down
", strsignal(sig));
- close(fd);
+ close(listenfd);
                 running = 0;
         }
 }
_AT_@ -637,15 +637,15 @@ main(int argc, char *argv[]) {
                 logerrmsg("error getaddrinfo: %s
", gai_strerror(i));
                 goto err;
         }
- if ((fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) == -1) {
+ if ((listenfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) == -1) {
                 logerrmsg("error socket: %s
", strerror(errno));
                 goto err;
         }
- if (bind(fd, ai->ai_addr, ai->ai_addrlen) == -1) {
+ if (bind(listenfd, ai->ai_addr, ai->ai_addrlen) == -1) {
                 logerrmsg("error bind: %s
", strerror(errno));
                 goto err;
         }
- if (listen(fd, SOMAXCONN) == -1) {
+ if (listen(listenfd, SOMAXCONN) == -1) {
                 logerrmsg("error listen: %s
", strerror(errno));
                 goto err;
         }
_AT_@ -695,13 +695,13 @@ main(int argc, char *argv[]) {
 
         logmsg("ready %s:%s %s
", servername, serverport, docroot);
 
- serve(fd); /* main loop */
- close(fd);
+ serve(listenfd); /* main loop */
+ close(listenfd);
         freeaddrinfo(ai);
         return EXIT_SUCCESS;
 err:
- if (fd != -1)
- close(fd);
+ if (listenfd != -1)
+ close(listenfd);
         if (ai)
                 freeaddrinfo(ai);
         return EXIT_FAILURE;
Received on Fri Aug 22 2014 - 11:53:42 CEST

This archive was generated by hypermail 2.3.0 : Fri Aug 22 2014 - 12:00:11 CEST