mirror of
https://github.com/palera1n/palera1n.git
synced 2026-10-25 10:39:48 +01:00
Execute checkra1n
This commit is contained in:
1 parent
752d32600c
commit
3ea3ea0ce9
8 files changed
+79
-13
No files matched your search
@@ -0,0 +1,56 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <spawn.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
extern char **environ;
|
||||
|
||||
#include "common.h"
|
||||
#include "checkra1n.h"
|
||||
|
||||
void exec_checkra1n() {
|
||||
LOG(LOG_INFO, "About to execute checkra1n");
|
||||
int fd, ret;
|
||||
char checkra1n_path[] = "/tmp/checkra1n.XXXXXX";
|
||||
fd = mkstemp(checkra1n_path);
|
||||
if (fd == -1) {
|
||||
LOG(LOG_FATAL, "Cannot open temporary file: %d (%s)", errno, strerror(errno));
|
||||
return;
|
||||
}
|
||||
ssize_t didWrite = write(fd, checkra1n, checkra1n_len);
|
||||
if (didWrite != checkra1n_len) {
|
||||
LOG(LOG_FATAL, "Size written does not match expected: %lld != %d: %d (%s)", didWrite, checkra1n_len, errno, strerror(errno));
|
||||
close(fd);
|
||||
unlink(checkra1n_path);
|
||||
return;
|
||||
}
|
||||
close(fd);
|
||||
ret = chmod(checkra1n_path, 0700);
|
||||
if (ret) {
|
||||
LOG(LOG_FATAL, "Cannot chmod %s: %d (%s)", checkra1n_path, errno, strerror(errno));
|
||||
unlink(checkra1n_path);
|
||||
}
|
||||
char* checkra1n_qrgv[] = {
|
||||
checkra1n_path,
|
||||
"-pVE",
|
||||
NULL
|
||||
};
|
||||
pid_t pid;
|
||||
ret = posix_spawn(&pid, checkra1n_path, NULL, NULL, checkra1n_qrgv, environ);
|
||||
if (ret) {
|
||||
LOG(LOG_FATAL, "Cannot posix spawn %s: %d (%s)", checkra1n_path, errno, strerror(errno));
|
||||
unlink(checkra1n_path);
|
||||
}
|
||||
unlink(checkra1n_path);
|
||||
waitpid(pid, NULL, 0);
|
||||
return;
|
||||
}
|
||||
Reference in new issue
Block a user