2021-01-03 21:55:15 +08:00
|
|
|
#include "process.h"
|
|
|
|
|
2021-10-23 00:51:20 +08:00
|
|
|
#include <libgen.h>
|
2021-01-03 21:55:15 +08:00
|
|
|
#include "log.h"
|
|
|
|
|
2021-11-12 00:49:47 +08:00
|
|
|
enum process_result
|
|
|
|
process_execute(const char *const argv[], process_t *pid) {
|
|
|
|
return process_execute_redirect(argv, pid, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2021-01-03 21:55:15 +08:00
|
|
|
bool
|
2021-01-23 02:20:30 +08:00
|
|
|
process_check_success(process_t proc, const char *name, bool close) {
|
2021-01-03 21:55:15 +08:00
|
|
|
if (proc == PROCESS_NONE) {
|
|
|
|
LOGE("Could not execute \"%s\"", name);
|
|
|
|
return false;
|
|
|
|
}
|
2021-01-23 02:20:30 +08:00
|
|
|
exit_code_t exit_code = process_wait(proc, close);
|
2021-01-23 01:29:21 +08:00
|
|
|
if (exit_code) {
|
2021-01-03 21:55:15 +08:00
|
|
|
if (exit_code != NO_EXIT_CODE) {
|
|
|
|
LOGE("\"%s\" returned with value %" PRIexitcode, name, exit_code);
|
|
|
|
} else {
|
|
|
|
LOGE("\"%s\" exited unexpectedly", name);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2021-10-23 00:51:20 +08:00
|
|
|
|
2021-10-17 22:20:46 +08:00
|
|
|
ssize_t
|
|
|
|
read_pipe_all(pipe_t pipe, char *data, size_t len) {
|
|
|
|
size_t copied = 0;
|
|
|
|
while (len > 0) {
|
|
|
|
ssize_t r = read_pipe(pipe, data, len);
|
|
|
|
if (r <= 0) {
|
|
|
|
return copied ? (ssize_t) copied : r;
|
|
|
|
}
|
|
|
|
len -= r;
|
|
|
|
data += r;
|
|
|
|
copied += r;
|
|
|
|
}
|
|
|
|
return copied;
|
|
|
|
}
|