The branch, master has been updated
       via  fa99f40 ctdb-tests: Coverity fixes
       via  12fa8ed ctdb-tcp: Coverity fixes
       via  b8f4887 ctdb-tools/ctdb: Coverity fixes
       via  7562701 ctdb-common: Coverity fixes
       via  c72e745 ctdb-client: Coverity fixes
       via  6d1b74f ctdb-server: Coverity fixes
      from  c0bdd80 docs: remove duplicate "used" from smb.conf manpage.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit fa99f4071b5e18017a70142e08334ddd7f457d9e
Author: Amitay Isaacs <[email protected]>
Date:   Mon Nov 11 12:41:17 2013 +1100

    ctdb-tests: Coverity fixes
    
    Signed-off-by: Amitay Isaacs <[email protected]>
    Reviewed-by: Michael Adam <[email protected]>
    
    Autobuild-User(master): Michael Adam <[email protected]>
    Autobuild-Date(master): Tue Nov 19 19:06:51 CET 2013 on sn-devel-104

commit 12fa8ed0cd9b7bbe10632af50bba13c30fa50285
Author: Amitay Isaacs <[email protected]>
Date:   Mon Nov 11 12:41:00 2013 +1100

    ctdb-tcp: Coverity fixes
    
    Signed-off-by: Amitay Isaacs <[email protected]>
    Reviewed-by: Michael Adam <[email protected]>

commit b8f4887ab5a4fef0d4e038a69b4e7a4b0129e1d8
Author: Amitay Isaacs <[email protected]>
Date:   Mon Nov 11 12:40:44 2013 +1100

    ctdb-tools/ctdb: Coverity fixes
    
    Signed-off-by: Amitay Isaacs <[email protected]>
    Reviewed-by: Michael Adam <[email protected]>

commit 7562701153c97c22ceeeb3bfe995b8a74965a543
Author: Amitay Isaacs <[email protected]>
Date:   Mon Nov 11 12:40:28 2013 +1100

    ctdb-common: Coverity fixes
    
    Signed-off-by: Amitay Isaacs <[email protected]>
    Reviewed-by: Michael Adam <[email protected]>

commit c72e745511d7187388a0f12566086140d8164845
Author: Amitay Isaacs <[email protected]>
Date:   Mon Nov 11 12:39:48 2013 +1100

    ctdb-client: Coverity fixes
    
    Signed-off-by: Amitay Isaacs <[email protected]>
    Reviewed-by: Michael Adam <[email protected]>

commit 6d1b74f052a8aebaeb78ee962c1ea4137e199ae3
Author: Amitay Isaacs <[email protected]>
Date:   Mon Nov 11 12:39:27 2013 +1100

    ctdb-server: Coverity fixes
    
    Signed-off-by: Amitay Isaacs <[email protected]>
    Reviewed-by: Michael Adam <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 ctdb/client/ctdb_client.c           |    5 +++-
 ctdb/common/ctdb_ltdb.c             |    5 +++-
 ctdb/common/ctdb_util.c             |   28 ++++++++++++++++++++++----
 ctdb/common/system_linux.c          |   20 +++++++++---------
 ctdb/server/ctdb_banning.c          |    2 +-
 ctdb/server/ctdb_control.c          |    6 +++++
 ctdb/server/ctdb_daemon.c           |    2 +-
 ctdb/server/ctdb_lock.c             |   11 ++++++---
 ctdb/server/ctdb_logging.c          |    8 +++++-
 ctdb/server/ctdb_recover.c          |    6 ++++-
 ctdb/server/ctdb_recoverd.c         |   36 +++++++++++++++++++++-------------
 ctdb/server/ctdb_takeover.c         |    2 +-
 ctdb/tcp/tcp_connect.c              |   32 ++++++++++++++++++++++++------
 ctdb/tests/src/ctdb_porting_tests.c |   22 +++++++++++++-------
 ctdb/tools/ctdb.c                   |   16 ++++++++++----
 15 files changed, 140 insertions(+), 61 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ctdb/client/ctdb_client.c b/ctdb/client/ctdb_client.c
index fddbd02..e2eccb7 100644
--- a/ctdb/client/ctdb_client.c
+++ b/ctdb/client/ctdb_client.c
@@ -253,7 +253,7 @@ int ctdb_socket_connect(struct ctdb_context *ctdb)
 
        memset(&addr, 0, sizeof(addr));
        addr.sun_family = AF_UNIX;
-       strncpy(addr.sun_path, ctdb->daemon.name, sizeof(addr.sun_path));
+       strncpy(addr.sun_path, ctdb->daemon.name, sizeof(addr.sun_path)-1);
 
        ctdb->daemon.sd = socket(AF_UNIX, SOCK_STREAM, 0);
        if (ctdb->daemon.sd == -1) {
@@ -3444,6 +3444,9 @@ static void async_callback(struct 
ctdb_client_control_state *state)
        int32_t res = -1;
        uint32_t destnode = state->c->hdr.destnode;
 
+       outdata.dsize = 0;
+       outdata.dptr = NULL;
+
        /* one more node has responded with recmode data */
        data->count--;
 
diff --git a/ctdb/common/ctdb_ltdb.c b/ctdb/common/ctdb_ltdb.c
index 4681f30..500f721 100644
--- a/ctdb/common/ctdb_ltdb.c
+++ b/ctdb/common/ctdb_ltdb.c
@@ -98,7 +98,10 @@ int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db,
                        *data = d2;
                }
                if (ctdb_db->persistent || header->dmaster == 
ctdb_db->ctdb->pnn) {
-                       ctdb_ltdb_store(ctdb_db, key, header, d2);
+                       if (ctdb_ltdb_store(ctdb_db, key, header, d2) != 0) {
+                               DEBUG(DEBUG_NOTICE,
+                                     (__location__ "failed to store initial 
header\n"));
+                       }
                }
                return 0;
        }
diff --git a/ctdb/common/ctdb_util.c b/ctdb/common/ctdb_util.c
index 7a70fea..44eb0db 100644
--- a/ctdb/common/ctdb_util.c
+++ b/ctdb/common/ctdb_util.c
@@ -415,16 +415,34 @@ void ctdb_restore_scheduler(struct ctdb_context *ctdb)
 
 void set_nonblocking(int fd)
 {
-       unsigned v;
+       int v;
+
        v = fcntl(fd, F_GETFL, 0);
-        fcntl(fd, F_SETFL, v | O_NONBLOCK);
+       if (v == -1) {
+               DEBUG(DEBUG_WARNING, ("Failed to get file status flags - %s\n",
+                                     strerror(errno)));
+               return;
+       }
+        if (fcntl(fd, F_SETFL, v | O_NONBLOCK) == -1) {
+               DEBUG(DEBUG_WARNING, ("Failed to set non_blocking on fd - %s\n",
+                                     strerror(errno)));
+       }
 }
 
 void set_close_on_exec(int fd)
 {
-       unsigned v;
+       int v;
+
        v = fcntl(fd, F_GETFD, 0);
-       fcntl(fd, F_SETFD, v | FD_CLOEXEC);
+       if (v == -1) {
+               DEBUG(DEBUG_WARNING, ("Failed to get file descriptor flags - 
%s\n",
+                                     strerror(errno)));
+               return;
+       }
+       if (fcntl(fd, F_SETFD, v | FD_CLOEXEC) != 0) {
+               DEBUG(DEBUG_WARNING, ("Failed to set close_on_exec on fd - 
%s\n",
+                                     strerror(errno)));
+       }
 }
 
 
@@ -821,7 +839,7 @@ void ctdb_mkdir_p_or_die(struct ctdb_context *ctdb, const 
char *dir, int mode)
                DEBUG(DEBUG_ALERT,
                      ("ctdb exiting with error: "
                       "failed to create directory \"%s\" (%s)\n",
-                      dir, strerror(ret)));
+                      dir, strerror(errno)));
                exit(1);
        }
 }
diff --git a/ctdb/common/system_linux.c b/ctdb/common/system_linux.c
index 84daba4..9aaa1fd 100644
--- a/ctdb/common/system_linux.c
+++ b/ctdb/common/system_linux.c
@@ -83,6 +83,8 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char 
*iface)
        struct ifreq ifr;
 
        ZERO_STRUCT(sall);
+       ZERO_STRUCT(ifr);
+       ZERO_STRUCT(if_hwaddr);
 
        switch (addr->ip.sin_family) {
        case AF_INET:
@@ -93,7 +95,7 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char 
*iface)
                }
 
                DEBUG(DEBUG_DEBUG, (__location__ " Created SOCKET FD:%d for 
sending arp\n", s));
-               strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
+               strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)-1);
                if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
                        DEBUG(DEBUG_CRIT,(__location__ " interface '%s' not 
found\n", iface));
                        close(s);
@@ -101,7 +103,7 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const 
char *iface)
                }
 
                /* get the mac address */
-               strcpy(if_hwaddr.ifr_name, iface);
+               strncpy(if_hwaddr.ifr_name, iface, 
sizeof(if_hwaddr.ifr_name)-1);
                ret = ioctl(s, SIOCGIFHWADDR, &if_hwaddr);
                if ( ret < 0 ) {
                        close(s);
@@ -195,7 +197,7 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const 
char *iface)
                }
 
                /* get the mac address */
-               strcpy(if_hwaddr.ifr_name, iface);
+               strncpy(if_hwaddr.ifr_name, iface, 
sizeof(if_hwaddr.ifr_name)-1);
                ret = ioctl(s, SIOCGIFHWADDR, &if_hwaddr);
                if ( ret < 0 ) {
                        close(s);
@@ -554,7 +556,7 @@ bool ctdb_sys_check_iface_exists(const char *iface)
                return true;
        }
 
-       strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
+       strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)-1);
        if (ioctl(s, SIOCGIFINDEX, &ifr) < 0 && errno == ENODEV) {
                DEBUG(DEBUG_CRIT,(__location__ " interface '%s' not found\n", 
iface));
                close(s);
@@ -587,7 +589,7 @@ char *ctdb_get_process_name(pid_t pid)
        int n;
 
        snprintf(path, sizeof(path), "/proc/%d/exe", pid);
-       n = readlink(path, buf, sizeof(buf));
+       n = readlink(path, buf, sizeof(buf)-1);
        if (n < 0) {
                return NULL;
        }
@@ -595,7 +597,7 @@ char *ctdb_get_process_name(pid_t pid)
        /* Remove any extra fields */
        buf[n] = '\0';
        ptr = strtok(buf, " ");
-       return strdup(ptr);
+       return (ptr == NULL ? ptr : strdup(ptr));
 }
 
 /*
@@ -701,14 +703,13 @@ bool ctdb_get_lock_info(pid_t req_pid, struct 
ctdb_lock_info *lock_info)
        struct ctdb_lock_info curlock;
        pid_t pid;
        char buf[1024];
-       char *ptr;
        bool status = false;
 
        if ((fp = fopen("/proc/locks", "r")) == NULL) {
                DEBUG(DEBUG_ERR, ("Failed to read locks information"));
                return false;
        }
-       while ((ptr = fgets(buf, sizeof(buf), fp)) != NULL) {
+       while (fgets(buf, sizeof(buf), fp) != NULL) {
                if (! parse_proc_locks_line(buf, &pid, &curlock)) {
                        continue;
                }
@@ -733,14 +734,13 @@ bool ctdb_get_blocker_pid(struct ctdb_lock_info *reqlock, 
pid_t *blocker_pid)
        struct ctdb_lock_info curlock;
        pid_t pid;
        char buf[1024];
-       char *ptr;
        bool status = false;
 
        if ((fp = fopen("/proc/locks", "r")) == NULL) {
                DEBUG(DEBUG_ERR, ("Failed to read locks information"));
                return false;
        }
-       while ((ptr = fgets(buf, sizeof(buf), fp)) != NULL) {
+       while (fgets(buf, sizeof(buf), fp) != NULL) {
                if (! parse_proc_locks_line(buf, &pid, &curlock)) {
                        continue;
                }
diff --git a/ctdb/server/ctdb_banning.c b/ctdb/server/ctdb_banning.c
index e6df4b9..13d97c8 100644
--- a/ctdb/server/ctdb_banning.c
+++ b/ctdb/server/ctdb_banning.c
@@ -84,7 +84,7 @@ int32_t ctdb_control_set_ban_state(struct ctdb_context *ctdb, 
TDB_DATA indata)
        DEBUG(DEBUG_INFO,("SET BAN STATE\n"));
 
        if (bantime->pnn != ctdb->pnn) {
-               if (bantime->pnn < 0 || bantime->pnn >= ctdb->num_nodes) {
+               if (bantime->pnn >= ctdb->num_nodes) {
                        DEBUG(DEBUG_ERR,(__location__ " ERROR: Invalid ban 
request. PNN:%d is invalid. Max nodes %d\n", bantime->pnn, ctdb->num_nodes));
                        return -1;
                }
diff --git a/ctdb/server/ctdb_control.c b/ctdb/server/ctdb_control.c
index 99319ac..581c478 100644
--- a/ctdb/server/ctdb_control.c
+++ b/ctdb/server/ctdb_control.c
@@ -50,6 +50,12 @@ int32_t ctdb_dump_memory(struct ctdb_context *ctdb, TDB_DATA 
*outdata)
        }
        talloc_report_full(NULL, f);
        fsize = ftell(f);
+       if (fsize == -1) {
+               DEBUG(DEBUG_ERR, (__location__ " Unable to get file size - 
%s\n",
+                                 strerror(errno)));
+               fclose(f);
+               return -1;
+       }
        rewind(f);
        outdata->dptr = talloc_size(outdata, fsize);
        if (outdata->dptr == NULL) {
diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c
index cbe6b23..50b2de3 100644
--- a/ctdb/server/ctdb_daemon.c
+++ b/ctdb/server/ctdb_daemon.c
@@ -978,7 +978,7 @@ static int ux_socket_bind(struct ctdb_context *ctdb)
 
        memset(&addr, 0, sizeof(addr));
        addr.sun_family = AF_UNIX;
-       strncpy(addr.sun_path, ctdb->daemon.name, sizeof(addr.sun_path));
+       strncpy(addr.sun_path, ctdb->daemon.name, sizeof(addr.sun_path)-1);
 
        /* First check if an old ctdbd might be running */
        if (connect(ctdb->daemon.sd,
diff --git a/ctdb/server/ctdb_lock.c b/ctdb/server/ctdb_lock.c
index fc437b0..bb66f94 100644
--- a/ctdb/server/ctdb_lock.c
+++ b/ctdb/server/ctdb_lock.c
@@ -259,7 +259,7 @@ static int ctdb_lockall_unmark(struct ctdb_context *ctdb)
 {
        uint32_t priority;
 
-       for (priority=NUM_DB_PRIORITIES; priority>=0; priority--) {
+       for (priority=NUM_DB_PRIORITIES; priority>0; priority--) {
                if (ctdb_db_iterator(ctdb, priority, db_lock_unmark_handler, 
NULL) != 0) {
                        return -1;
                }
@@ -448,8 +448,11 @@ static void ctdb_lock_handler(struct tevent_context *ev,
        }
 
        /* Read the status from the child process */
-       read(lock_ctx->fd[0], &c, 1);
-       locked = (c == 0 ? true : false);
+       if (read(lock_ctx->fd[0], &c, 1) != 1) {
+               locked = false;
+       } else {
+               locked = (c == 0 ? true : false);
+       }
 
        /* Update statistics */
        CTDB_DECREMENT_STAT(lock_ctx->ctdb, locks.num_pending);
@@ -998,7 +1001,7 @@ struct lock_request *ctdb_lock_alldb_prio(struct 
ctdb_context *ctdb,
                                          void (*callback)(void *, bool),
                                          void *private_data)
 {
-       if (priority < 0 || priority > NUM_DB_PRIORITIES) {
+       if (priority < 1 || priority > NUM_DB_PRIORITIES) {
                DEBUG(DEBUG_ERR, ("Invalid db priority: %u\n", priority));
                return NULL;
        }
diff --git a/ctdb/server/ctdb_logging.c b/ctdb/server/ctdb_logging.c
index 218186e..17c5c35 100644
--- a/ctdb/server/ctdb_logging.c
+++ b/ctdb/server/ctdb_logging.c
@@ -38,7 +38,6 @@ struct ctdb_syslog_state {
 
 static int syslogd_is_started = 0;
 
-
 /* called when child is finished
  * this is for the syslog daemon, we can not use DEBUG here
  */
@@ -60,6 +59,10 @@ static void ctdb_syslog_handler(struct event_context *ev, 
struct fd_event *fde,
                return;
        }
        msg = (struct syslog_message *)str;
+       if (msg->len >= (sizeof(str) - offsetof(struct syslog_message, 
message))) {
+               msg->len = (sizeof(str)-1) - offsetof(struct syslog_message, 
message);
+       }
+       msg->message[msg->len] = '\0';
 
        syslog(msg->level, "%s", msg->message);
 }
@@ -401,8 +404,9 @@ static void write_to_log(struct ctdb_log_state *log,
                        do_debug("%*.*s\n", len, len, buf);
                }
                /* log it in the eventsystem as well */
-               if (log->logfn)
+               if (log && log->logfn) {
                        log->logfn(log->buf, len, log->logfn_private);
+               }
        }
 }
 
diff --git a/ctdb/server/ctdb_recover.c b/ctdb/server/ctdb_recover.c
index 1cbcc59..414f5b1 100644
--- a/ctdb/server/ctdb_recover.c
+++ b/ctdb/server/ctdb_recover.c
@@ -1147,7 +1147,11 @@ static int store_tdb_record(struct ctdb_context *ctdb,
 
        data2 = tdb_fetch(ctdb_db->ltdb->tdb, key);
        if (data2.dptr == NULL || data2.dsize < sizeof(struct 
ctdb_ltdb_header)) {
-               tdb_store(ctdb_db->ltdb->tdb, key, data, 0);
+               if (tdb_store(ctdb_db->ltdb->tdb, key, data, 0) == -1) {
+                       DEBUG(DEBUG_ERR, (__location__ "Failed to store 
record\n"));
+                       ret = -1;
+                       goto done;
+               }
                DEBUG(DEBUG_INFO, (__location__ " Stored record\n"));
                ret = 0;
                goto done;
diff --git a/ctdb/server/ctdb_recoverd.c b/ctdb/server/ctdb_recoverd.c
index 5caf7c0..8b4b6d0 100644
--- a/ctdb/server/ctdb_recoverd.c
+++ b/ctdb/server/ctdb_recoverd.c
@@ -535,15 +535,17 @@ static int create_missing_remote_databases(struct 
ctdb_context *ctdb, struct ctd
                                continue;
                        }
                        /* ok so we need to create this database */
-                       ctdb_ctrl_getdbname(ctdb, CONTROL_TIMEOUT(), pnn, 
dbmap->dbs[db].dbid, 
-                                           mem_ctx, &name);
+                       ret = ctdb_ctrl_getdbname(ctdb, CONTROL_TIMEOUT(), pnn,
+                                                 dbmap->dbs[db].dbid, mem_ctx,
+                                                 &name);
                        if (ret != 0) {
                                DEBUG(DEBUG_ERR, (__location__ " Unable to get 
dbname from node %u\n", pnn));
                                return -1;
                        }
-                       ctdb_ctrl_createdb(ctdb, CONTROL_TIMEOUT(), 
nodemap->nodes[j].pnn, 
-                                          mem_ctx, name,
-                                          dbmap->dbs[db].flags & 
CTDB_DB_FLAGS_PERSISTENT);
+                       ret = ctdb_ctrl_createdb(ctdb, CONTROL_TIMEOUT(),
+                                                nodemap->nodes[j].pnn,
+                                                mem_ctx, name,
+                                                dbmap->dbs[db].flags & 
CTDB_DB_FLAGS_PERSISTENT);
                        if (ret != 0) {
                                DEBUG(DEBUG_ERR, (__location__ " Unable to 
create remote db:%s\n", name));
                                return -1;
@@ -2035,7 +2037,12 @@ static int do_recovery(struct ctdb_recoverd *rec,
 
        /* send a message to all clients telling them that the cluster 
           has been reconfigured */
-       ctdb_client_send_message(ctdb, CTDB_BROADCAST_CONNECTED, 
CTDB_SRVID_RECONFIGURE, tdb_null);
+       ret = ctdb_client_send_message(ctdb, CTDB_BROADCAST_CONNECTED,
+                                      CTDB_SRVID_RECONFIGURE, tdb_null);
+       if (ret != 0) {
+               DEBUG(DEBUG_ERR, (__location__ " Failed to send reconfigure 
message\n"));
+               return -1;
+       }
 
        DEBUG(DEBUG_NOTICE, (__location__ " Recovery complete\n"));
 
@@ -2206,9 +2213,7 @@ static int send_election_request(struct ctdb_recoverd 
*rec, uint32_t pnn)
 
        /* send an election message to all active nodes */
        DEBUG(DEBUG_INFO,(__location__ " Send election request to all active 
nodes\n"));
-       ctdb_client_send_message(ctdb, CTDB_BROADCAST_ALL, srvid, 
election_data);
-
-       return 0;
+       return ctdb_client_send_message(ctdb, CTDB_BROADCAST_ALL, srvid, 
election_data);
 }
 
 /*
@@ -2229,7 +2234,12 @@ static void unban_all_nodes(struct ctdb_context *ctdb)
        for (i=0;i<nodemap->num;i++) {
                if ( (!(nodemap->nodes[i].flags & NODE_FLAGS_DISCONNECTED))
                  && (nodemap->nodes[i].flags & NODE_FLAGS_BANNED) ) {
-                       ctdb_ctrl_modflags(ctdb, CONTROL_TIMEOUT(), 
nodemap->nodes[i].pnn, 0, NODE_FLAGS_BANNED);
+                       ret = ctdb_ctrl_modflags(ctdb, CONTROL_TIMEOUT(),
+                                                nodemap->nodes[i].pnn, 0,
+                                                NODE_FLAGS_BANNED);
+                       if (ret != 0) {
+                               DEBUG(DEBUG_ERR, (__location__ " failed to 
reset ban state\n"));
+                       }
                }
        }
 
@@ -2487,13 +2497,11 @@ static void disable_takeover_runs_handler(struct 
ctdb_context *ctdb,
                DEBUG(DEBUG_ERR,(__location__ " Wrong size for data :%lu "
                                 "expecting %lu\n", (long unsigned)data.dsize,
                                 (long unsigned)sizeof(struct srvid_request)));
-               ret = -EINVAL;
-               goto done;
+               return;
        }
        if (data.dptr == NULL) {
                DEBUG(DEBUG_ERR,(__location__ " No data received\n"));
-               ret = -EINVAL;
-               goto done;
+               return;
        }
 
        r = (struct srvid_request *)data.dptr;
diff --git a/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c
index 91f3030..04cdd66 100644
--- a/ctdb/server/ctdb_takeover.c
+++ b/ctdb/server/ctdb_takeover.c
@@ -3386,7 +3386,7 @@ int32_t ctdb_control_get_public_ip_info(struct 
ctdb_context *ctdb,
                if (vnn->iface == cur) {
                        info->active_idx = i;
                }
-               strcpy(info->ifaces[i].name, cur->name);
+               strncpy(info->ifaces[i].name, cur->name, 
sizeof(info->ifaces[i].name)-1);
                info->ifaces[i].link_state = cur->link_up;
                info->ifaces[i].references = cur->references;
        }
diff --git a/ctdb/tcp/tcp_connect.c b/ctdb/tcp/tcp_connect.c
index 9df3300..8032662 100644
--- a/ctdb/tcp/tcp_connect.c
+++ b/ctdb/tcp/tcp_connect.c
@@ -95,8 +95,14 @@ static void ctdb_node_connect_write(struct event_context 
*ev, struct fd_event *f
        talloc_free(tnode->connect_fde);
        tnode->connect_fde = NULL;
 
-        setsockopt(tnode->fd,IPPROTO_TCP,TCP_NODELAY,(char *)&one,sizeof(one));
-        setsockopt(tnode->fd,SOL_SOCKET,SO_KEEPALIVE,(char *)&one,sizeof(one));
+        if (setsockopt(tnode->fd,IPPROTO_TCP,TCP_NODELAY,(char 
*)&one,sizeof(one)) == -1) {
+               DEBUG(DEBUG_WARNING, ("Failed to set TCP_NODELAY on fd - %s\n",
+                                     strerror(errno)));
+       }
+        if (setsockopt(tnode->fd,SOL_SOCKET,SO_KEEPALIVE,(char 
*)&one,sizeof(one)) == -1) {
+               DEBUG(DEBUG_WARNING, ("Failed to set KEEPALIVE on fd - %s\n",
+                                     strerror(errno)));
+       }
 
        ctdb_queue_set_fd(tnode->out_queue, tnode->fd);
 
@@ -268,7 +274,10 @@ static void ctdb_listen_event(struct event_context *ev, 
struct fd_event *fde,
 
        DEBUG(DEBUG_DEBUG, (__location__ " Created SOCKET FD:%d to incoming 
ctdb connection\n", fd));
 
-        setsockopt(in->fd,SOL_SOCKET,SO_KEEPALIVE,(char *)&one,sizeof(one));
+        if (setsockopt(in->fd,SOL_SOCKET,SO_KEEPALIVE,(char 
*)&one,sizeof(one)) == -1) {
+               DEBUG(DEBUG_WARNING, ("Failed to set KEEPALIVE on fd - %s\n",
+                                     strerror(errno)));
+       }
 
        in->queue = ctdb_queue_setup(ctdb, in, in->fd, CTDB_TCP_ALIGNMENT, 
                                     ctdb_tcp_read_cb, in, "ctdbd-%s", 
incoming_node);
@@ -358,7 +367,11 @@ static int ctdb_tcp_listen_automatic(struct ctdb_context 
*ctdb)
 
                set_close_on_exec(ctcp->listen_fd);
 
-               setsockopt(ctcp->listen_fd,SOL_SOCKET,SO_REUSEADDR,(char 
*)&one,sizeof(one));
+               if (setsockopt(ctcp->listen_fd,SOL_SOCKET,SO_REUSEADDR,
+                              (char *)&one,sizeof(one)) == -1) {
+                       DEBUG(DEBUG_WARNING, ("Failed to set REUSEADDR on fd - 
%s\n",
+                                             strerror(errno)));
+               }
 
                if (bind(ctcp->listen_fd, (struct sockaddr * )&sock, sock_size) 
== 0) {
                        break;
@@ -402,8 +415,10 @@ static int ctdb_tcp_listen_automatic(struct ctdb_context 
*ctdb)
        
 failed:
        close(lock_fd);
-       close(ctcp->listen_fd);
-       ctcp->listen_fd = -1;
+       if (ctcp->listen_fd != -1) {
+               close(ctcp->listen_fd);
+               ctcp->listen_fd = -1;
+       }
        return -1;
 }
 
@@ -458,7 +473,10 @@ int ctdb_tcp_listen(struct ctdb_context *ctdb)
 
        set_close_on_exec(ctcp->listen_fd);
 
-        setsockopt(ctcp->listen_fd,SOL_SOCKET,SO_REUSEADDR,(char 
*)&one,sizeof(one));
+        if (setsockopt(ctcp->listen_fd,SOL_SOCKET,SO_REUSEADDR,(char 
*)&one,sizeof(one)) == -1) {
+               DEBUG(DEBUG_WARNING, ("Failed to set REUSEADDR on fd - %s\n",
+                                     strerror(errno)));
+       }
 
        if (bind(ctcp->listen_fd, (struct sockaddr * )&sock, sock_size) != 0) {
                DEBUG(DEBUG_ERR,(__location__ " Failed to bind() to socket. 
%s(%d)\n", strerror(errno), errno));
diff --git a/ctdb/tests/src/ctdb_porting_tests.c 
b/ctdb/tests/src/ctdb_porting_tests.c
index 0c43451..063c6da 100644
--- a/ctdb/tests/src/ctdb_porting_tests.c
+++ b/ctdb/tests/src/ctdb_porting_tests.c
@@ -58,7 +58,7 @@ static int socket_server_create(void)
 
        memset(&addr, 0, sizeof(addr));
        addr.sun_family = AF_UNIX;
-       strncpy(addr.sun_path, globals.socketname, sizeof(addr.sun_path));
+       strncpy(addr.sun_path, globals.socketname, sizeof(addr.sun_path)-1);
 
        if (bind(globals.socket, (struct sockaddr *)&addr, sizeof(addr)) == -1) 
{
                DEBUG(DEBUG_CRIT,("Unable to bind on socket '%s': %s\n", 
globals.socketname, strerror(errno)));
@@ -129,7 +129,7 @@ static int socket_client_connect(void)


-- 
Samba Shared Repository

Reply via email to