static gboolean wait_process( pid_t pid, int fd_err, char *name) { gboolean rval = TRUE; amwait_t wait_status; char *line; while ((line = areads(fd_err)) != NULL) { g_debug("%s stderr: %s", name, line); rval = FALSE; free(line); } close(fd_err); waitpid(pid, &wait_status, 0); if (WIFSIGNALED(wait_status)) { g_debug("%s terminated with signal %d", name, WTERMSIG(wait_status)); rval = FALSE; } else if (WIFEXITED(wait_status)) { if (WEXITSTATUS(wait_status) != 0) { g_debug("%s exited with status %d", name, WEXITSTATUS(wait_status)); rval = FALSE; } } else { g_debug("%s got bad exit", name); rval = FALSE; } return rval; }
void parse_backup_messages( dle_t *dle, int mesgin) { int goterror; char *line; amfree(errorstr); for(; (line = areads(mesgin)) != NULL; free(line)) { process_dumpline(line); } if(errno) { error(_("error [read mesg pipe: %s]"), strerror(errno)); /*NOTREACHED*/ } goterror = check_result(mesgfd); if(errorstr) { error(_("error [%s]"), errorstr); /*NOTREACHED*/ } else if(dump_size == -1) { error(_("error [no backup size line]")); /*NOTREACHED*/ } program->end_backup(dle, goterror); fdprintf(mesgfd, _("%s: size %ld\n"), get_pname(), dump_size); fdprintf(mesgfd, _("%s: end\n"), get_pname()); }
int get_line(void) { char *line = NULL; char *part = NULL; size_t len; while(1) { if((part = areads(server_socket)) == NULL) { int save_errno = errno; if(server_line) { fputs(server_line, stderr); /* show the last line read */ fputc('\n', stderr); } if(save_errno != 0) { g_fprintf(stderr, _("%s: Error reading line from server: %s\n"), get_pname(), strerror(save_errno)); } else { g_fprintf(stderr, _("%s: Unexpected end of file, check amindexd*debug on server %s\n"), get_pname(), server_name); } errno = save_errno; break; /* exit while loop */ } if(line) { strappend(line, part); amfree(part); } else { line = part; part = NULL; } if((len = strlen(line)) > 0 && line[len-1] == '\r') { line[len-1] = '\0'; g_free(server_line); server_line = g_strdup(line); amfree(line); return 0; } /* * Hmmm. We got a "line" from areads(), which means it saw * a '\n' (or EOF, etc), but there was not a '\r' before it. * Put a '\n' back in the buffer and loop for more. */ strappend(line, "\n"); } amfree(line); amfree(server_line); return -1; }
cmd_t getresult( int fd, int show, int *result_argc, char ***result_argv) { cmd_t t; char *line; if((line = areads(fd)) == NULL) { if(errno) { error(_("reading result from %s: %s"), childstr(fd), strerror(errno)); /*NOTREACHED*/ } *result_argv = NULL; *result_argc = 0; /* EOF */ } else { *result_argv = split_quoted_strings(line); *result_argc = g_strv_length(*result_argv); } if(show) { g_printf(_("driver: result time %s from %s:"), walltime_str(curclock()), childstr(fd)); if(line) { g_printf(" %s", line); putchar('\n'); } else { g_printf(" (eof)\n"); } fflush(stdout); } amfree(line); if(*result_argc < 1) return BOGUS; for(t = (cmd_t)(BOGUS+1); t < LAST_TOK; t++) if(strcmp((*result_argv)[0], cmdstr[t]) == 0) return t; return BOGUS; }
struct cmdargs * getcmd(void) { char *line; cmd_t cmd_i; struct cmdargs *cmdargs = g_new0(struct cmdargs, 1); if (isatty(0)) { g_printf("%s> ", get_pname()); fflush(stdout); line = agets(stdin); } else { line = areads(0); } if (line == NULL) { line = g_strdup("QUIT"); } dbprintf(_("getcmd: %s\n"), line); cmdargs->argv = split_quoted_strings(line); cmdargs->argc = g_strv_length(cmdargs->argv); cmdargs->cmd = BOGUS; amfree(line); if (cmdargs->argc < 1) { return cmdargs; } for(cmd_i=BOGUS; cmdstr[cmd_i] != NULL; cmd_i++) if(g_str_equal(cmdargs->argv[0], cmdstr[cmd_i])) { cmdargs->cmd = cmd_i; return cmdargs; } return cmdargs; }
static int changer_command( char *cmd, char *arg) { int exitcode = 0; char *cmdstr = NULL; amfree(changer_resultstr); if (!start_chg_glue()) { exitcode = 2; goto failed; } cmdstr = vstralloc(cmd, arg ? " " : "", arg ? arg : "", "\n", NULL); g_debug("changer: >> %s %s", cmd, arg? arg : ""); /* write the command to chg_glue */ if (full_write(tpchanger_stdin, cmdstr, strlen(cmdstr)) != strlen(cmdstr)) { changer_resultstr = g_strdup("<error> chg-glue exited unexpectedly"); exitcode = 2; goto failed; } /* read the first line of the response */ changer_resultstr = areads(tpchanger_stdout); if (!changer_resultstr || !*changer_resultstr) { changer_resultstr = g_strdup("<error> unexpected EOF"); exitcode = 2; goto failed; } g_debug("changer: << %s", changer_resultstr); if (strncmp_const(changer_resultstr, "EXITSTATUS ") != 0) { report_bad_resultstr(cmd); exitcode = 2; goto failed; } exitcode = atoi(changer_resultstr + strlen("EXITSTATUS ")); /* and the second */ changer_resultstr = areads(tpchanger_stdout); if (!changer_resultstr) { changer_resultstr = g_strdup("<error> unexpected EOF"); exitcode = 2; goto failed; } g_debug("changer: << %s", changer_resultstr); failed: if (exitcode != 0) { g_debug("changer: ERROR %s", changer_resultstr); } amfree(cmdstr); return exitcode; }