/** * @brief read process stderr * @param c the child to read stderr from * @returns 0 on success, -1 on error. */ int read_stderr(child_node *c) { buffer bigbuff; char buff[255]; char *line; int count, ret; ret = 0; memset(&(bigbuff), 0, sizeof(buffer)); while((count=read(c->stderr_fd, buff, 255)) > 0) { if(append_to_buffer(&(bigbuff), buff, count)) { ret = -1; goto exit; } while((line = get_line_from_buffer(&(bigbuff)))) { ret = on_cmd_stderr(c, line); free(line); if(ret) goto exit; } } exit: if(count<0) { print( ERROR, "read: %s", strerror(errno)); ret = -1; } release_buffer(&(bigbuff)); return ret; }
/** * @brief handle a command message * @param m the received message * @returns 0 on success, -1 on error. */ int on_command(JNIEnv *env, message *m) { switch(m->data[0]) { case CMD_STARTED: return on_cmd_started(m); case CMD_FAIL: return on_cmd_fail(m); case CMD_END: return on_cmd_end(env, m); case CMD_DIED: return on_cmd_died(env, m); case CMD_STDERR: return on_cmd_stderr(env, m); default: LOGW("%s: unkown command code: %02hhX", __func__, m->data[0]); return -1; } }