plclient->exited = TRUE;
plclient->pid = -1;
/* Evaluate child exit status */
- pclient->exit_code = -1;
+ pclient->exit_code = PROGRAM_CLIENT_EXIT_INTERNAL_FAILURE;
if (WIFEXITED(plclient->status)) {
/* Exited */
if (exit_code != 0) {
i_info("program `%s' terminated with non-zero exit code %d",
pclient->path, exit_code);
- pclient->exit_code = 0;
+ pclient->exit_code = PROGRAM_CLIENT_EXIT_FAILURE;
} else {
- pclient->exit_code = 1;
+ pclient->exit_code = PROGRAM_CLIENT_EXIT_SUCCESS;
}
} else if (WIFSIGNALED(plclient->status)) {
/* Killed with a signal */
if (pid < 0) {
/* program never started */
- pclient->exit_code = 0;
+ pclient->exit_code = PROGRAM_CLIENT_EXIT_FAILURE;
program_client_local_exited(plclient);
return;
}
PROGRAM_CLIENT_ERROR_OTHER
};
+enum program_client_exit_code {
+ PROGRAM_CLIENT_EXIT_INTERNAL_FAILURE = -1,
+ PROGRAM_CLIENT_EXIT_FAILURE = 0,
+ PROGRAM_CLIENT_EXIT_SUCCESS = 1,
+};
+
struct program_client_extra_fd {
struct program_client *pclient;
bool other_error;
enum program_client_error error;
- int exit_code;
+ enum program_client_exit_code exit_code;
int (*connect) (struct program_client * pclient);
int (*close_output) (struct program_client * pclient);
i_stream_unref(&scstream->istream.parent);
}
+static void
+program_client_istream_parse_result(struct program_client_istream *scstream,
+ size_t pos)
+{
+ struct istream_private *stream = &scstream->istream;
+
+ if (stream->buffer == NULL || pos < 2 ||
+ stream->buffer[pos - 1] != '\n') {
+ scstream->client->exit_code =
+ PROGRAM_CLIENT_EXIT_INTERNAL_FAILURE;
+ return;
+ }
+
+ switch (stream->buffer[pos - 2]) {
+ case '+':
+ scstream->client->exit_code = PROGRAM_CLIENT_EXIT_SUCCESS;
+ break;
+ case '-':
+ scstream->client->exit_code = PROGRAM_CLIENT_EXIT_FAILURE;
+ break;
+ default:
+ scstream->client->exit_code =
+ PROGRAM_CLIENT_EXIT_INTERNAL_FAILURE;
+ }
+}
+
static ssize_t
program_client_istream_read(struct istream_private *stream)
{
if (stream->parent->eof) {
/* Check return code at EOF */
- if (stream->buffer != NULL && pos >= 2 &&
- stream->buffer[pos - 1] == '\n') {
- switch (stream->buffer[pos - 2]) {
- case '+':
- scstream->client->exit_code = 1;
- break;
- case '-':
- scstream->client->exit_code = 0;
- break;
- default:
- scstream->client->exit_code =
- -1;
- }
- } else {
- scstream->client->exit_code = -1;
- }
+ program_client_istream_parse_result(scstream, pos);
}
if (stream->buffer != NULL && pos >= 1) {
generally unlikely to occur. */
if (pclient->program_input->stream_errno != 0 ||
i_stream_have_bytes_left(pclient->program_input))
- pclient->exit_code = -1;
+ pclient->exit_code = PROGRAM_CLIENT_EXIT_INTERNAL_FAILURE;
} else {
- pclient->exit_code = 1;
+ pclient->exit_code = PROGRAM_CLIENT_EXIT_SUCCESS;
}
program_client_disconnected(pclient);
program_client_callback(pclient,
pclient->error != PROGRAM_CLIENT_ERROR_NONE ?
-1 :
- pclient->exit_code,
+ (int)pclient->exit_code,
pclient->context);
}
if (pclient->error != PROGRAM_CLIENT_ERROR_NONE)
return -1;
- return pclient->exit_code;
+ return (int)pclient->exit_code;
}
#undef program_client_run_async
i_assert(callback != NULL);
pclient->disconnected = FALSE;
- pclient->exit_code = 1;
+ pclient->exit_code = PROGRAM_CLIENT_EXIT_SUCCESS;
pclient->error = PROGRAM_CLIENT_ERROR_NONE;
pclient->callback = callback;