1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-27 22:50:26 +03:00

Move platform-specific code to common/system_*

This removes #ifdef AIX and ease the addition of new platforms.

(This used to be ctdb commit 2fd1067a075fe0e4b2a36d4ea18af139d03f17bf)
This commit is contained in:
Mathieu Parent 2011-11-05 19:04:40 +01:00 committed by Ronnie Sahlberg
parent 4ce585cd0e
commit bb3d6698e9
4 changed files with 29 additions and 15 deletions

View 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;
}

View 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;
}

View 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);

View 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);