X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:message-id:date:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=vRA XqGr9PdkeSluTWNpjh/i2IeXntPgFb7zVFirhZTYFLA6ZA9WEdq4Sqv5Ar7F12nV Tjm42VlAK0qtUie4WLQBo8M7AUmJou+Tob28HXUcWWtIOojOPOyC43IazQHCg1Fc cdCw0jNY5Uaqh/f7lw8PIJkboB9HphsXYDxZaTco= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:message-id:date:mime-version :content-type:content-transfer-encoding; s=default; bh=e5OmY/gOG M2d27IUj1QKRu+Vks8=; b=YOlWgL5RoSgvQMDgbdLv6/yM8Jfc5dSoCItGadPyg Nv5HTwmXOXP3C0OcgwRtCZaXHjHiB6Fr2WqE+6QTHL6NEs2ZfkJlKd1SQ4En+2is FnNpggTyW82Xz1wONeK/XG2BRqjiBH1yICQKcE4N05L09PYwKJ4ruWEtpLpBQy+o yU= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,FROM_EXCESS_BASE64,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.1 spammy=listening, HX-Languages-Length:1834 X-HELO: mail-wr1-f54.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:disposition-notification-to:date :user-agent:mime-version:content-language:content-transfer-encoding; bh=ZouwUI0Z46VaAPKE+a/23MiDabqcS8l0JAntbvD2ftk=; b=OZBZR868pmbOJKvemqhmWTqpL2HmUV6rtBCWen5CyB+YqGOlOOKFd9eGJ/a9O5Xzuo fkDOexgpZfighREeZoCitiYbEyg+bIBnn9rsDq1cv/iGeVEaWCuwGCtUJvCHDHo6iedt LmSO6FZBDHJ1K24pVwSZY1L++GBM9SUnxmnq1aE+ypgpf3+ej24kg1B8oqqmbFdb1dKv 9T730ldqMNcgHEwMXXgDTr7l5rXbbeC0uB7Q46XYgMdsQWT/RT0VYCqGvU4UTurScy2+ O88lYhoDrSkzwIpD0q+1U+o9rhLnYmjK0ja/VRSlXaCSwXJgdjrpGGZD7GbEHPqPoZ7c 0DSw== To: cygwin AT cygwin DOT com From: =?UTF-8?B?UGV0ciBTa2/EjcOtaw==?= Subject: bind() behavior inconsistency with Linux and MacOS Message-ID: <846c1e23-0d60-2375-2968-e1aa7d5896c9@gmail.com> Date: Wed, 5 Jun 2019 15:06:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Hi. I don't know if this is technically a bug, but I've noticed that unlike on Linux or MacOS, I a cannot bind a unix domain socket in a child process and then listen on it in the parent. The bind succeeds but `listen()` in the parent then fails with EINVAL. (The reason I'd like to `bind` in a different process is so I could `chdir` to a different directory before `bind`ing and then conceptually back without having the `chdir` break file operations in different threads.) Just wanted to let you guys know in case there was an easy fix. Best regards, Petr Skocik ____________________ Example code: #include #include #include #include #include #include #include #include #include #include int main(int C, char **V) { int sfd; if(0>(sfd=socket(AF_UNIX, SOCK_STREAM, 0),1)) return perror("socket"),1; struct sockaddr_un uaddr; uaddr.sun_family = AF_UNIX; char const *nm = "FOO.sock"; size_t nmlen = nm[0]?strlen(nm):(1+strlen(&nm[1])); size_t actlen = nmlen <= sizeof(uaddr.sun_path)-1 ? nmlen : sizeof(uaddr.sun_path)-1; memcpy(&uaddr.sun_path[0],nm,actlen); uaddr.sun_path[actlen]='\0'; size_t socklen = 0 ? sizeof(struct sockaddr_un) : offsetof(struct sockaddr_un, sun_path) + actlen + 1; fflush(stdout); pid_t pid=0; int fork_eh = atoi(V[1]?V[1]:"1"); if(fork_eh) if(0>(pid=fork())) return perror("fork"),1; if(0==pid){ printf("pid=%d binding\n", (int)getpid()); if(0>bind(sfd, (struct sockaddr*)&uaddr, (socklen_t)+socklen)) perror("bind"),_exit(1); printf("pid=%d bound\n", (int)getpid()); fflush(stdout); if(fork_eh) _exit(0); } wait(0); if(0>listen(sfd,INT_MAX)) return perror("listen"),1; printf("pid=%d listening\n", (int)getpid()); } -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple