From: Mathieu Parent Date: Sat, 5 Nov 2011 18:04:40 +0000 (+0100) Subject: Move platform-specific code to common/system_* X-Git-Tag: ctdb-1.13~71 X-Git-Url: http://git.samba.org/?p=ctdb.git;a=commitdiff_plain;h=2fd1067a075fe0e4b2a36d4ea18af139d03f17bf Move platform-specific code to common/system_* This removes #ifdef AIX and ease the addition of new platforms. --- diff --git a/common/system_aix.c b/common/system_aix.c index 1404a829..c17598a3 100644 --- a/common/system_aix.c +++ b/common/system_aix.c @@ -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; +} + diff --git a/common/system_linux.c b/common/system_linux.c index ca2d4758..cb26dcd6 100644 --- a/common/system_linux.c +++ b/common/system_linux.c @@ -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; +} + diff --git a/include/ctdb_private.h b/include/ctdb_private.h index f545eaa4..5ce32a10 100644 --- a/include/ctdb_private.h +++ b/include/ctdb_private.h @@ -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); diff --git a/server/ctdb_daemon.c b/server/ctdb_daemon.c index c650eb3d..69488dfa 100644 --- a/server/ctdb_daemon.c +++ b/server/ctdb_daemon.c @@ -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);