ctdb-common: Move ctdb_get_peer_pid() to system.[ch]
authorMartin Schwenke <martin@meltin.net>
Thu, 28 Jun 2018 10:35:56 +0000 (20:35 +1000)
committerMartin Schwenke <martins@samba.org>
Mon, 2 Jul 2018 06:51:21 +0000 (08:51 +0200)
The system_<os>.c files contain a lot of duplication, making
maintenance difficult.  These functions are being merged into
system_socket.c and system.c.

This function doesn't need ctdb_sock_addr so put it with general
system utilities.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/common/system.c
ctdb/common/system.h
ctdb/common/system_aix.c
ctdb/common/system_freebsd.c
ctdb/common/system_gnu.c
ctdb/common/system_kfreebsd.c
ctdb/common/system_linux.c

index 50054f0abc65879ea0e27673fbad436a8799f6bd..a95f314e66fc3606ffe6b71a0b07de31634df9e2 100644 (file)
@@ -198,3 +198,52 @@ bool ctdb_sys_check_iface_exists(const char *iface)
 }
 
 #endif /* HAVE_AF_PACKET */
+
+#ifdef HAVE_PEERCRED
+
+int ctdb_get_peer_pid(const int fd, pid_t *peer_pid)
+{
+       struct ucred cr;
+       socklen_t crl = sizeof(struct ucred);
+       int ret;
+
+       ret = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &crl);
+       if (ret == 0) {
+               *peer_pid = cr.pid;
+       } else {
+               *peer_pid = -1;
+       }
+       return ret;
+}
+
+#else /* HAVE_PEERCRED */
+
+#ifdef _AIX_
+
+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;
+
+       ret = getsockopt(fd, SOL_SOCKET, SO_PEERID, &cr, &crl);
+       if (ret == 0) {
+               *peer_pid = cr.pid;
+       } else {
+               *peer_pid = -1;
+       }
+       return ret;
+}
+
+#else /* _AIX_ */
+
+int ctdb_get_peer_pid(const int fd, pid_t *peer_pid)
+{
+       /* Not implemented */
+       *peer_pid = -1;
+       return ENOSYS;
+}
+
+#endif /* _AIX_ */
+
+#endif /* HAVE_PEERCRED */
index 908d29d27946c8f69ec2483274bdf3fef141d31b..d63fb91db6b69cc863bbc710c8914dea4baaf701 100644 (file)
@@ -34,7 +34,6 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,
                             ctdb_sock_addr *src, ctdb_sock_addr *dst,
                             uint32_t *ack_seq, uint32_t *seq,
                             int *rst, uint16_t *window);
-int ctdb_get_peer_pid(const int fd, pid_t *peer_pid);
 
 /* From system_util.c */
 
@@ -48,5 +47,6 @@ void mkdir_p_or_die(const char *dir, int mode);
 void ctdb_wait_for_process_to_exit(pid_t pid);
 
 bool ctdb_sys_check_iface_exists(const char *iface);
+int ctdb_get_peer_pid(const int fd, pid_t *peer_pid);
 
 #endif /* __CTDB_SYSTEM_H__ */
index f17125cbd394d1146af8ed2669bcdcecfcced70c..b19e7569929b30cda16336e2fb785d80995dc319 100644 (file)
@@ -379,14 +379,3 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,
 
        return -1;
 }
-
-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 de7bf2b33963e1a9a8f3464f83027c1a8e87f913..9632fb209fadc84dc0785413e8244f134ed3968d 100644 (file)
@@ -383,9 +383,3 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,
 
        return -1;
 }
-
-int ctdb_get_peer_pid(const int fd, pid_t *peer_pid)
-{
-       /* FIXME FreeBSD: get_peer_pid not implemented */
-       return 1;
-}
index 7f2654e61d757333c91e01cb6de8d1678a1964ea..c45c6e930d46b1e0da2896745e083d1d33cf1ee4 100644 (file)
@@ -378,9 +378,3 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,
 
        return -1;
 }
-
-int ctdb_get_peer_pid(const int fd, pid_t *peer_pid)
-{
-       /* FIXME GNU/Hurd: get_peer_pid not implemented */
-       return 1;
-}
index ccad294615d78922900115e3d7e3bc67433e576c..694ae58a37cd9c9d6e2bfdc49284f801a7fecff1 100644 (file)
@@ -378,9 +378,3 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,
 
        return -1;
 }
-
-int ctdb_get_peer_pid(const int fd, pid_t *peer_pid)
-{
-       /* FIXME kFreeBSD: get_peer_pid not implemented */
-       return 1;
-}
index 3cff3b20c94a8e3f2dc7095d3e3a12f7dc030dc5..a95076dc5f3b71f3eba4f8b1b715e0f9ff006d66 100644 (file)
@@ -603,14 +603,3 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,
 
        return -1;
 }
-
-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;
-}