char *args[] = {"rpm", "-qf", filename, "--qf", "%{NAME};%{VERSION};%{RELEASE};%{ARCH}", NULL};
int readed;
- if ((readed = run_command_write_fd_timeout("rpm", args, NULL, 0, rpm_info, RPM_INFO_MAXLEN, 60)) == -1) {
+ if ((readed = run_command_write_fd_timeout("rpm", args, NULL, 0, rpm_info, RPM_INFO_MAXLEN, 60)) < 0) {
_E("Failed to get information about rpm installed packages");
return -1;
} else {
return -1;
}
-static void wait_for_child(pid_t pid, int timeout)
+static int wait_for_child(pid_t pid, int *exit_code, int timeout)
{
for (int i = 0; i < 10*timeout; i++) {
int status;
if (p == pid) {
if (WIFSIGNALED(status)) {
_I("Killed by signal %d\n", WTERMSIG(status));
- break;
+ return -1;
} else if (WIFEXITED(status)) {
- if (WEXITSTATUS(status) > 0)
- _I("Exit code %d\n", WEXITSTATUS(status));
- break;
+ *exit_code = WEXITSTATUS(status);
+ return 0;
}
} else if (p == -1) {
_E("waitpid error: %m");
- break;
+ return -1;
}
usleep(100000);
}
+ return -1;
}
static int read_into_buff(int fd, char *buff, int size, int timeout_us, int *eof)
}
// let's wait a second for a child
- wait_for_child(pid, 1);
+ int exit_code = -1;
+ if (wait_for_child(pid, &exit_code, 1) == 0 && exit_code != 0)
+ _I("\"%s\" exit code: %d\n", path, exit_code);
- return eof == 1 ? count : -1;
+ return (eof == 1 && exit_code == 0) ? count : -abs(exit_code);
} else {
_E("fork() error: %m");
return -1;