]> arthur.barton.de Git - ngircd.git/commitdiff
Fix gcc warning "ignoring return value of ..."
authorAlexander Barton <alex@barton.de>
Fri, 9 Apr 2010 18:08:47 +0000 (20:08 +0200)
committerAlexander Barton <alex@barton.de>
Fri, 9 Apr 2010 18:14:11 +0000 (20:14 +0200)
This patch fixes two warnings of gcc 4.4.3 when used with eglibc 2.11.1:

ngircd.c: In function ‘NGIRCd_Init’:
ngircd.c:801: warning: ignoring return value of ‘chdir’, declared with
 attribute warn_unused_result
conn.c: In function ‘Simple_Message’:
conn.c:2041: warning: ignoring return value of ‘write’, declared with
 attribute warn_unused_result

The first by checking the return code and an appropriate error message,
the second by "better" ignoring it (which is correct there!) ...

src/ngircd/conn.c
src/ngircd/ngircd.c

index cd350a8d619700a2ca89034b5a05b132df6cba36..ab975b31c7d97810e0fec421bee7e2259282a9c3 100644 (file)
@@ -2025,20 +2025,32 @@ cb_Read_Resolver_Result( int r_fd, UNUSED short events )
 } /* cb_Read_Resolver_Result */
 
 
+/**
+ * Write a "simple" (error) message to a socket.
+ * The message is sent without using the connection write buffers, without
+ * compression/encryption, and even without any error reporting. It is
+ * designed for error messages of e.g. New_Connection(). */
 static void
-Simple_Message( int Sock, const char *Msg )
+Simple_Message(int Sock, const char *Msg)
 {
        char buf[COMMAND_LEN];
        size_t len;
-       /* Write "simple" message to socket, without using compression
-        * or even the connection write buffers. Used e.g. for error
-        * messages by New_Connection(). */
-       assert( Sock > NONE );
-       assert( Msg != NULL );
-
-       strlcpy( buf, Msg, sizeof buf - 2);
-       len = strlcat( buf, "\r\n", sizeof buf);
-       (void)write(Sock, buf, len);
+
+       assert(Sock > NONE);
+       assert(Msg != NULL);
+
+       strlcpy(buf, Msg, sizeof buf - 2);
+       len = strlcat(buf, "\r\n", sizeof buf);
+       if (write(Sock, buf, len) < 0) {
+               /* Because this function most probably got called to log
+                * an error message, any write error is ignored here to
+                * avoid an endless loop. But casting the result of write()
+                * to "void" doesn't satisfy the GNU C code attribute
+                * "warn_unused_result" which is used by some versions of
+                * glibc (e.g. 2.11.1), therefore this silly error
+                * "handling" code here :-( */
+               return;
+       }
 } /* Simple_Error */
 
 
index 82ba67c28a945c59a0c136afc4b9cf11af2e482d..b951badb5b26ba5687ed00bb56c1b0e67694551d 100644 (file)
@@ -798,7 +798,9 @@ NGIRCd_Init( bool NGIRCd_NoDaemon )
 #else
                setpgrp(0, getpid());
 #endif
-               chdir( "/" );
+               if (chdir( "/" ) != 0)
+                       Log(LOG_ERR, "Can't change directory to '/': %s",
+                                    strerror(errno));
 
                /* Detach stdin, stdout and stderr */
                Setup_FDStreams( );