Skip to content

Commit d6d1509

Browse files
committed
Always wait for children inside the event loop
Unfortunatelly, we don't have any way to control asynchronous SIGCHLD signals which can arrive at the same time, causing ltx to eventually miss results inside some slots. For this reason, we need to run waitpid() for all children each time we receive an event that could be effect of a SIGCHLD.
1 parent 1333471 commit d6d1509

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

ltx.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,6 @@ static volatile int stop_loop = 0;
184184
/* it's 1 when stdin/stdout pipes are broken. zero otherwise */
185185
static volatile int broken_pipe = 0;
186186

187-
/* it's 1 when children completed. zero otherwise */
188-
static volatile int child_done = 0;
189-
190187
static void ltx_message_reserve_next(struct ltx_session *session)
191188
{
192189
++(session->ltx_message.curr);
@@ -819,7 +816,7 @@ static int ltx_check_stdout(struct ltx_session *session, const int slot_id)
819816

820817
ssize_t ret = read(slot->event.fd, slot->buffer, READ_BUFFER_SIZE);
821818
if (ret == -1) {
822-
if (errno != EAGAIN && errno != EWOULDBLOCK)
819+
if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
823820
LTX_HANDLE_ERROR(session, "read() log", 1);
824821

825822
return 0;
@@ -841,7 +838,7 @@ static int ltx_check_stdout(struct ltx_session *session, const int slot_id)
841838
return 1;
842839
}
843840

844-
static void ltx_send_result(struct ltx_session *session)
841+
static void ltx_slots_waitpid(struct ltx_session *session)
845842
{
846843
struct ltx_slot *slot;
847844
uint64_t slot_id;
@@ -1096,9 +1093,6 @@ static void ltx_signal_handler(int signo)
10961093
case SIGPIPE:
10971094
broken_pipe = 1;
10981095
break;
1099-
case SIGCHLD:
1100-
child_done = 1;
1101-
break;
11021096
}
11031097
}
11041098

@@ -1148,7 +1142,6 @@ struct ltx_session *ltx_session_init(const int stdin_fd, const int stdout_fd)
11481142

11491143
sigaction(SIGINT, &action, NULL);
11501144
sigaction(SIGPIPE, &action, NULL);
1151-
sigaction(SIGCHLD, &action, NULL);
11521145

11531146
return session;
11541147
}
@@ -1233,12 +1226,6 @@ static void ltx_event_loop(struct ltx_session *session)
12331226
goto exit;
12341227
}
12351228

1236-
if (child_done) {
1237-
ltx_send_result(session);
1238-
child_done = 0;
1239-
continue;
1240-
}
1241-
12421229
for (i = 0; i < num; i++) {
12431230
epoll_evt = events + i;
12441231
ltx_evt = (struct ltx_event *) epoll_evt->data.ptr;
@@ -1269,6 +1256,8 @@ static void ltx_event_loop(struct ltx_session *session)
12691256
break;
12701257
}
12711258
}
1259+
1260+
ltx_slots_waitpid(session);
12721261
}
12731262

12741263
exit:

0 commit comments

Comments
 (0)