Move platform-specific code to common/system_*
authorMathieu Parent <math.parent@gmail.com>
Sat, 5 Nov 2011 18:04:40 +0000 (19:04 +0100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 6 Dec 2011 00:57:11 +0000 (11:57 +1100)
This removes #ifdef AIX and ease the addition of new platforms.

common/system_aix.c
common/system_linux.c
include/ctdb_private.h
server/ctdb_daemon.c

index 1404a8290138ef3736a4e7d90c5e32024cd3352a..c17598a3af8cddc623e9d6210ca72c94ff76dbf4 100644 (file)
@@ -362,3 +362,14 @@ bool ctdb_sys_check_iface_exists(const char *iface)
        return true;
 }
 
+int ctdb_get_peer_pid(const int fd, pid_t *peer_pid)
+{
+       struct peercred_struct cr;
+       socklen_t crl = sizeof(struct peercred_struct);
+       int ret;
+       if ((ret = getsockopt(fd, SOL_SOCKET, SO_PEERID, &cr, &crl) == 0)) {
+               peer_pid = cr.pid;
+       }
+       return ret;
+}
+
index ca2d47580baac59cdc6329e43efe06684a2ddcbf..cb26dcd654bf676693e585455f624c8c6e6d480f 100644 (file)
@@ -563,3 +563,15 @@ bool ctdb_sys_check_iface_exists(const char *iface)
        
        return true;
 }
+
+int ctdb_get_peer_pid(const int fd, pid_t *peer_pid)
+{
+       struct ucred cr;
+       socklen_t crl = sizeof(struct ucred);
+       int ret;
+       if ((ret = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &crl) == 0)) {
+               peer_pid = cr.pid;
+       }
+       return ret;
+}
+
index f545eaa4b414bf6a31e0ef919f7c237f4b428595..5ce32a10f030e6c82669d92b4035567182ff4748 100644 (file)
@@ -1132,6 +1132,7 @@ uint32_t uint16_checksum(uint16_t *data, size_t n);
 int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface);
 bool ctdb_sys_have_ip(ctdb_sock_addr *addr);
 bool ctdb_sys_check_iface_exists(const char *iface);
+int ctdb_get_peer_pid(const int fd, pid_t *peer_pid);
 int ctdb_sys_send_tcp(const ctdb_sock_addr *dest, 
                      const ctdb_sock_addr *src,
                      uint32_t seq, uint32_t ack, int rst);
index c650eb3de2ddd268bf7e0ba7afaaf4c887d77e27..69488dfac4258cb7bc4e20c8d4a64ab65a753c39 100644 (file)
@@ -894,13 +894,7 @@ static void ctdb_accept_client(struct event_context *ev, struct fd_event *fde,
        struct ctdb_context *ctdb = talloc_get_type(private_data, struct ctdb_context);
        struct ctdb_client *client;
        struct ctdb_client_pid_list *client_pid;
-#ifdef _AIX
-       struct peercred_struct cr;
-       socklen_t crl = sizeof(struct peercred_struct);
-#else
-       struct ucred cr;
-       socklen_t crl = sizeof(struct ucred);
-#endif
+       pid_t peer_pid = 0;
 
        memset(&addr, 0, sizeof(addr));
        len = sizeof(addr);
@@ -915,18 +909,14 @@ static void ctdb_accept_client(struct event_context *ev, struct fd_event *fde,
        DEBUG(DEBUG_DEBUG,(__location__ " Created SOCKET FD:%d to connected child\n", fd));
 
        client = talloc_zero(ctdb, struct ctdb_client);
-#ifdef _AIX
-       if (getsockopt(fd, SOL_SOCKET, SO_PEERID, &cr, &crl) == 0) {
-#else
-       if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &crl) == 0) {
-#endif
-               DEBUG(DEBUG_INFO,("Connected client with pid:%u\n", (unsigned)cr.pid));
+       if (ctdb_get_peer_pid(fd, &peer_pid) == 0) {
+               DEBUG(DEBUG_INFO,("Connected client with pid:%u\n", (unsigned)peer_pid));
        }
 
        client->ctdb = ctdb;
        client->fd = fd;
        client->client_id = ctdb_reqid_new(ctdb, client);
-       client->pid = cr.pid;
+       client->pid = peer_pid;
 
        client_pid = talloc(client, struct ctdb_client_pid_list);
        if (client_pid == NULL) {
@@ -936,7 +926,7 @@ static void ctdb_accept_client(struct event_context *ev, struct fd_event *fde,
                return;
        }               
        client_pid->ctdb   = ctdb;
-       client_pid->pid    = cr.pid;
+       client_pid->pid    = peer_pid;
        client_pid->client = client;
 
        DLIST_ADD(ctdb->client_pids, client_pid);