+ /* Copy struct sockaddr, we need it later in listen(). */
+ entry->orig_addr = xmalloc(addrlen);
+ memcpy(entry->orig_addr, addr, addrlen);
+ entry->orig_addrlen = addrlen;
+
+ return real_bind(sockfd, addr, addrlen);
+}
+
+int listen(int sockfd, int backlog) {
+ static int (*real_listen)(int, int);
+ LOAD_FUNCTION(real_listen, "listen");
+
+ if (!global_options) {
+ global_options = get_options();
+ }
+
+ if (global_options & OPTION_CLIENT_ONLY) {
+ DBG("listen(%d, %d): server hooking disabled", sockfd, backlog);
+ return real_listen(sockfd, backlog);
+ }
+
+ struct list *entry = find_sockfd(sockfd);
+ if (!entry) {
+ DBG("listen(%d, %d): sockfd not found", sockfd, backlog);
+ return real_listen(sockfd, backlog);
+ }
+ assert(sockfd == entry->orig_sockfd);
+ DBG("listen(%d, %d): %s %s",
+ sockfd, backlog,
+ af_to_name(entry->orig_domain), sock_to_name(entry->orig_type));
+
+ int unix_sockfd = socket(AF_UNIX, entry->orig_type, 0);
+ if (unix_sockfd < 0) {
+ DIE("listen(): failed to create UNIX socket");
+ }
+