feat: throw logs into a log file
Fuck. I had to add another dependency...
This commit is contained in:
parent
d8b8b7b729
commit
2ebbc86799
2
Makefile
2
Makefile
@ -16,7 +16,7 @@ CFLAGS += -D_POSIX_C_SOURCE=2
|
|||||||
CFLAGS += -D_GNU_SOURCE
|
CFLAGS += -D_GNU_SOURCE
|
||||||
CFLAGS += -Wall -Werror -std=c23 -g
|
CFLAGS += -Wall -Werror -std=c23 -g
|
||||||
CFLAGS += -Iinclude
|
CFLAGS += -Iinclude
|
||||||
CFLAGS += -lpthread
|
CFLAGS += -lpthread -luuid
|
||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
|
|
||||||
|
25
src/main.c
25
src/main.c
@ -4,9 +4,11 @@
|
|||||||
#include "pipeline.h"
|
#include "pipeline.h"
|
||||||
#include "threadpool.h"
|
#include "threadpool.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <spawn.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <spawn.h>
|
#include <uuid/uuid.h>
|
||||||
#include <wait.h>
|
#include <wait.h>
|
||||||
|
|
||||||
threadpool* pool = NULL;
|
threadpool* pool = NULL;
|
||||||
@ -24,14 +26,31 @@ void executor(void* data) {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
char* argv[] = { "/bin/sh", "-c", e->command, NULL };
|
char* argv[] = { "/bin/sh", "-c", e->command, NULL };
|
||||||
if(posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, envp) != 0) {
|
uuid_t uuid;
|
||||||
|
uuid_generate(uuid);
|
||||||
|
char* pipeline_id = malloc(32);
|
||||||
|
uuid_unparse_lower(uuid, pipeline_id);
|
||||||
|
posix_spawn_file_actions_t actions;
|
||||||
|
posix_spawn_file_actions_init(&actions);
|
||||||
|
char* output_file = join(pipeline_id, ".log");
|
||||||
|
int fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||||
|
if (fd == -1) {
|
||||||
|
perror("open");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
posix_spawn_file_actions_adddup2(&actions, fd, STDOUT_FILENO);
|
||||||
|
posix_spawn_file_actions_adddup2(&actions, fd, STDERR_FILENO);
|
||||||
|
if(posix_spawn(&pid, "/bin/sh", &actions, NULL, argv, envp) != 0) {
|
||||||
perror("posix_spawn");
|
perror("posix_spawn");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
log_trace("{%s} spawned (%s)", pipeline_id, e->name);
|
||||||
int status;
|
int status;
|
||||||
waitpid(pid, &status, 0);
|
waitpid(pid, &status, 0);
|
||||||
if(WIFEXITED(status))
|
if(WIFEXITED(status))
|
||||||
log_trace("pipeline exited with status %d", WEXITSTATUS(status));
|
log_trace("{%s} exited with status %d", pipeline_id, WEXITSTATUS(status));
|
||||||
|
free(pipeline_id);
|
||||||
|
free(output_file);
|
||||||
free(name);
|
free(name);
|
||||||
free(url);
|
free(url);
|
||||||
free(trigger);
|
free(trigger);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user