Skip to content

Commit 0235f5f

Browse files
authored
Merge 8996e96 into 11a0792
2 parents 11a0792 + 8996e96 commit 0235f5f

File tree

2 files changed

+42
-23
lines changed

2 files changed

+42
-23
lines changed

platforms/unix/vm-display-X11/sqUnixX11.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6782,31 +6782,37 @@ int openXDisplay(void)
67826782
return 0;
67836783
}
67846784

6785-
int forgetXDisplay(void)
6786-
{
6787-
/* Initialise variables related to the X connection, and
6788-
make the existing connection to the X Display invalid
6789-
for any further access from this Squeak image. Any socket
6790-
connection to the X server is closed, but the server is
6791-
not told to terminate any windows or X sessions. This
6792-
is used to support fork() for an existing Squeak image,
6793-
where the child is expected to continue as a headless
6794-
image, and the parent continues its normal execution. */
67956785

6786+
static void clearXDisplayVariables()
6787+
{
67966788
displayName= 0; /* name of display, or 0 for $DISPLAY */
67976789
stDisplay= null; /* Squeak display */
6798-
if (isConnectedToXServer)
6799-
{
6800-
if (stXfd >= 0)
6801-
aioDisable(stXfd);
6802-
close(stXfd);
6803-
}
68046790
stXfd= -1; /* X connection file descriptor */
68056791
stParent= null;
68066792
stWindow= null; /* Squeak window */
68076793
inputContext= 0;
68086794
inputFont= NULL;
68096795
isConnectedToXServer= 0;
6796+
}
6797+
6798+
6799+
/* Initialise variables related to the X connection, and make the existing
6800+
* connection to the X Display invalid for any further access from this
6801+
* Squeak image. Any socket connection to the X server is closed, but the
6802+
* server is not told to terminate any windows or X sessions. This is
6803+
* used to support fork() for an existing Squeak image, where the child
6804+
* is expected to continue as a headless image, and the parent continues
6805+
* its normal execution.
6806+
*/
6807+
int forgetXDisplay(void)
6808+
{
6809+
if (isConnectedToXServer)
6810+
{
6811+
if (stXfd >= 0)
6812+
aioDisable(stXfd);
6813+
close(stXfd);
6814+
clearXDisplayVariables();
6815+
}
68106816
return 0;
68116817
}
68126818

@@ -6828,9 +6834,11 @@ int disconnectXDisplay(void)
68286834
}
68296835
if (inputFont)
68306836
XFreeFontSet(stDisplay, inputFont);
6837+
if (stXfd >= 0)
6838+
aioDisable(stXfd);
68316839
XCloseDisplay(stDisplay);
6840+
clearXDisplayVariables();
68326841
}
6833-
forgetXDisplay();
68346842
return 0;
68356843
}
68366844

platforms/unix/vm/aio.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ long aioDebugLogging = 0;
113113
#endif
114114

115115
#if HAVE_CONFIG_H && HAVE_EPOLL
116-
static int epollFd;
116+
static int epollFd= -1;
117117
static struct epoll_event** epollEventsByFileDescriptor;
118118
static size_t epollEventsByFileDescriptorSize;
119119

@@ -230,20 +230,31 @@ growEpollEventsByFileDescriptorTo(size_t newSize) {
230230
memset(epollEventsByFileDescriptor + epollEventsByFileDescriptorSize, 0, (newSize - epollEventsByFileDescriptorSize) * sizeof(*epollEventsByFileDescriptor));
231231
epollEventsByFileDescriptorSize = newSize;
232232
}
233-
#endif
234233

235-
void
236-
aioInit(void)
234+
static void
235+
epollInit(void)
237236
{
238-
extern void forceInterruptCheck(int); /* not really, but hey */
239-
#if HAVE_CONFIG_H && HAVE_EPOLL
237+
if (epollFd >= 0)
238+
close(epollFd);
240239
epollFd = epoll_create1(EPOLL_CLOEXEC);
241240
if (epollFd == -1) {
242241
perror("epoll_create1 failed");
243242
exit(1);
244243
}
245244
epollEventsByFileDescriptorSize = 0;
246245
epollEventsByFileDescriptor = NULL;
246+
}
247+
#endif
248+
249+
250+
void
251+
aioInit(void)
252+
{
253+
extern void forceInterruptCheck(int); /* not really, but hey */
254+
#if HAVE_CONFIG_H && HAVE_EPOLL
255+
epollInit();
256+
if (pthread_atfork(NULL, NULL, epollInit))
257+
perror("pthread_atfork");
247258
#else
248259
FD_ZERO(&fdMask);
249260
FD_ZERO(&rdMask);

0 commit comments

Comments
 (0)