Skip to content

Commit 391ab95

Browse files
committed
Merge branch 'mr/jicquel/gnatcoll-core#138' into 'master'
Prevent infinite loop in wait_for_processes__unix Closes #138 See merge request eng/toolchain/gnatcoll-core!209
2 parents f09c5db + b2d406e commit 391ab95

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

core/src/os/unix/process-wrappers.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ int __gnatcoll_remove_monitoring_fd (int fd)
8787
int __gnatcoll_wait_for_sigchld (int fd, sint_64 timeout)
8888
{
8989
fd_set fd_list;
90-
struct timeval tv;
91-
struct timeval *effective_timeout;
90+
struct timeval tv = {0, 0};
91+
struct timeval *effective_timeout = NULL;
9292
int retval = 0;
9393
char buf[1];
9494

@@ -103,7 +103,7 @@ int __gnatcoll_wait_for_sigchld (int fd, sint_64 timeout)
103103
effective_timeout = &tv;
104104
}
105105

106-
while (tv.tv_sec > 0 || tv.tv_usec > 0) {
106+
while (tv.tv_sec > 0 || tv.tv_usec > 0 || effective_timeout == NULL) {
107107
retval = select(fd + 1, &fd_list, NULL, NULL, effective_timeout);
108108
if (retval > 0)
109109
{

testsuite/core/tests/os/process/wait_for_processes/test.adb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ begin
3333

3434
Result2 := Wait_For_Processes (Processes => (H1, H2), Timeout => 5.0);
3535
A.Assert (Result2 /= Invalid_Handle, "a process should be available");
36-
A.Assert (Result1 /= Result2, "Resutl1 should be different from Result2");
36+
A.Assert (Result1 /= Result2, "Result1 should be different from Result2");
3737
if Result2 /= Invalid_Handle then
3838
Status := Wait (Result2);
3939
A.Assert (Status, 42, "exit status should be 42");
@@ -72,5 +72,23 @@ begin
7272
A.Assert (Status, 42, "exit status should be 42");
7373
end if;
7474

75+
H1 := Start (Args);
76+
H2 := Start (Args);
77+
78+
Result1 := Wait_For_Processes (Processes => (H1, H2));
79+
A.Assert (Result1 /= Invalid_Handle, "a process should be available");
80+
if Result1 /= Invalid_Handle then
81+
Status := Wait (Result1);
82+
A.Assert (Status, 42, "exit status should be 42");
83+
end if;
84+
85+
Result2 := Wait_For_Processes (Processes => (H1, H2));
86+
A.Assert (Result2 /= Invalid_Handle, "a process should be available");
87+
A.Assert (Result1 /= Result2, "Result1 should be different from Result2");
88+
if Result2 /= Invalid_Handle then
89+
Status := Wait (Result2);
90+
A.Assert (Status, 42, "exit status should be 42");
91+
end if;
92+
7593
return A.Report;
7694
end Test;

0 commit comments

Comments
 (0)