Revert "swrap_warn_stale reproduce deadlock third_party/socket_wrapper/socket_wrapper.c"
authorStefan Metzmacher <metze@samba.org>
Wed, 17 Feb 2021 15:26:35 +0000 (16:26 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 23 Apr 2024 16:16:46 +0000 (18:16 +0200)
This reverts commit 3a73b1a7982d62fb54c5152613ef8c1550bcc0c3.

third_party/socket_wrapper/socket_wrapper.c

index 52b02bb1f3801b7b100848ca819fd20149aeb645..c5d939f28ee16e60aca4d1c441c9b51bbdfff34c 100644 (file)
@@ -2748,27 +2748,6 @@ static bool check_addr_port_in_use(const struct sockaddr *sa, socklen_t len)
 }
 #endif
 
-static void swrap_warn_stale(int fd)
-{
-       struct socket_info *si;
-       int si_index;
-
-       swrap_mutex_lock(&socket_reset_mutex);
-
-       si_index = find_socket_info_index(fd);
-       if (si_index == -1) {
-               swrap_mutex_unlock(&socket_reset_mutex);
-               return;
-       }
-
-       si = swrap_get_socket_info(si_index);
-                       SWRAP_LOG(SWRAP_LOG_ERROR, "PID(%d):TID(%lld):PPID(%d): Stale fd=%d si_index=%d from sun_path[%s]",
-                                 getpid(), (unsigned long long)gettid(), getppid(),
-                                 fd, si_index, si->un_addr.sun_path);
-
-       swrap_mutex_unlock(&socket_reset_mutex);
-}
-
 static void swrap_remove_stale(int fd);
 
 static int sockaddr_convert_to_un(struct socket_info *si,
@@ -3330,8 +3309,7 @@ static int swrap_pcap_get_fd(const char *fname)
                file_hdr.frame_max_len  = SWRAP_FRAME_LENGTH_MAX;
                file_hdr.link_type      = 0x0065; /* 101 RAW IP */
 
-               swrap_warn_stale(fd);
-               if (write(fd, &file_hdr, sizeof(file_hdr)) != sizeof(file_hdr)) {
+               if (libc_write(fd, &file_hdr, sizeof(file_hdr)) != sizeof(file_hdr)) {
                        libc_close(fd);
                        fd = -1;
                }
@@ -3339,9 +3317,6 @@ static int swrap_pcap_get_fd(const char *fname)
        }
 
        fd = libc_open(fname, O_WRONLY|O_APPEND, 0644);
-       if (fd != -1) {
-               swrap_warn_stale(fd);
-       }
 
        return fd;
 }
@@ -3669,7 +3644,7 @@ static void swrap_pcap_dump_packet(struct socket_info *si,
 
        fd = swrap_pcap_get_fd(file_name);
        if (fd != -1) {
-               if (write(fd, packet, packet_len) != (ssize_t)packet_len) {
+               if (libc_write(fd, packet, packet_len) != (ssize_t)packet_len) {
                        free(packet);
                        goto done;
                }
@@ -4172,7 +4147,7 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family)
 
        if (autobind_start_init != 1) {
                autobind_start_init = 1;
-               autobind_start = 12345;//getpid();
+               autobind_start = getpid();
                autobind_start %= 50000;
                autobind_start += 10000;
        }
@@ -4275,12 +4250,6 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family)
                        goto done;
                }
 
-               if (type == SOCKET_TYPE_CHAR_UDP) {
-                       SWRAP_LOG(SWRAP_LOG_ERROR, "PID(%d):TID(%lld):PPID(%d): Bound fd=%d port=%u to sun_path[%s]",
-                                 getpid(), (unsigned long long)gettid(), getppid(),
-                                 fd, (unsigned)port, un_addr.sa.un.sun_path);
-
-               }
                si->un_addr = un_addr.sa.un;
 
                si->bound = 1;
@@ -5931,7 +5900,7 @@ static int swrap_sendmsg_unix_scm_rights(struct cmsghdr *cmsg,
                return -1;
        }
 
-       sret = write(pipefd[1], &info, sizeof(info));
+       sret = libc_write(pipefd[1], &info, sizeof(info));
        if (sret != sizeof(info)) {
                int saved_errno = errno;
                if (sret != -1) {
@@ -8295,9 +8264,6 @@ static int swrap_remove_wrapper(const char *__func_name,
        swrap_mutex_lock(&first_free_mutex);
        SWRAP_LOCK_SI(si);
 
-                       swrap_log(SWRAP_LOG_ERROR, __func_name, "PID(%d):TID(%lld):PPID(%d): Close fd=%d si_index=%d from sun_path[%s]",
-                                 getpid(), (unsigned long long)gettid(), getppid(),
-                                 fd, si_index, si->un_addr.sun_path);
        ret = __close_fd_fn(fd);
        if (ret == -1) {
                ret_errno = errno;