Mercurial > dwindows
comparison dwcompat.h @ 1962:50c71474709b
Added PID to the unix domain socket name, to avoid conflicts from multiple
instances of the same application. Also unlink (delete) any left over
filesystem nodes from previous runs of the application.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 26 Jul 2019 21:54:14 +0000 |
parents | 824fdbc2f761 |
children | b2cb0ef3ec3d |
comparison
equal
deleted
inserted
replaced
1961:824fdbc2f761 | 1962:50c71474709b |
---|---|
193 | 193 |
194 #ifndef PIPEROOT | 194 #ifndef PIPEROOT |
195 #define PIPEROOT "/tmp/" | 195 #define PIPEROOT "/tmp/" |
196 #endif | 196 #endif |
197 | 197 |
198 #define PIPENAME "%s" __TARGET__ "%d" | 198 #define PIPENAME "%s" __TARGET__ "%d-%d" |
199 | 199 |
200 #if defined(_P_NOWAIT) && !defined(P_NOWAIT) | 200 #if defined(_P_NOWAIT) && !defined(P_NOWAIT) |
201 #define P_NOWAIT _P_NOWAIT | 201 #define P_NOWAIT _P_NOWAIT |
202 #endif | 202 #endif |
203 | 203 |
340 struct sockaddr_un un; \ | 340 struct sockaddr_un un; \ |
341 int tmpsock = socket(AF_UNIX, SOCK_STREAM, 0); \ | 341 int tmpsock = socket(AF_UNIX, SOCK_STREAM, 0); \ |
342 pipes[1] = socket(AF_UNIX, SOCK_STREAM, 0); \ | 342 pipes[1] = socket(AF_UNIX, SOCK_STREAM, 0); \ |
343 memset(&un, 0, sizeof(un)); \ | 343 memset(&un, 0, sizeof(un)); \ |
344 un.sun_family=AF_UNIX; \ | 344 un.sun_family=AF_UNIX; \ |
345 sprintf(un.sun_path, PIPENAME, PIPEROOT, pipes[1]); \ | 345 sprintf(un.sun_path, PIPENAME, PIPEROOT, (int)getpid(), pipes[1]); \ |
346 unlink(un.sun_path); \ | |
346 bind(tmpsock, (struct sockaddr *)&un, sizeof(un)); \ | 347 bind(tmpsock, (struct sockaddr *)&un, sizeof(un)); \ |
347 listen(tmpsock, 0); \ | 348 listen(tmpsock, 0); \ |
348 connect(pipes[1], (struct sockaddr *)&un, sizeof(un)); \ | 349 connect(pipes[1], (struct sockaddr *)&un, sizeof(un)); \ |
349 pipes[0] = accept(tmpsock, 0, 0); \ | 350 pipes[0] = accept(tmpsock, 0, 0); \ |
350 sockclose(tmpsock); \ | 351 sockclose(tmpsock); \ |