From a24682f3d48930ef722491ea5f22b098e66a30c4 Mon Sep 17 00:00:00 2001 From: Kuba Winnicki Date: Sun, 28 Aug 2016 10:38:18 +0200 Subject: [PATCH] librocket: make demo on export --- lib/device.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/lib/device.c b/lib/device.c index be22cea..fe3d766 100644 --- a/lib/device.c +++ b/lib/device.c @@ -5,6 +5,7 @@ #include #include #include +#include static int find_track(struct sync_device *d, const char *name) { @@ -266,13 +267,6 @@ static int save_track(const struct sync_track *t, const char *path) { int i; - int cwd = open(".", O_RDONLY); - if (!cwd) - return -1; - - if (!chdir("build/sync")) - return -1; - FILE *fp = fopen(path, "wb"); if (!fp) return -1; @@ -287,18 +281,55 @@ static int save_track(const struct sync_track *t, const char *path) fclose(fp); - if (!fchdir(cwd)) - return -1; return 0; } void sync_save_tracks(const struct sync_device *d) { int i; + + int cwd = open(".", O_RDONLY); + if (cwd == -1) { + dprintf(2, "can't open current directory\n"); + return; + } + + if (chdir("build/sync")) { + dprintf(2, "can't enter build/sync directory\n"); + return; + } + for (i = 0; i < (int)d->num_tracks; ++i) { const struct sync_track *t = d->tracks[i]; save_track(t, sync_track_path(d->base, t->name)); } + + if (fchdir(cwd)) { + dprintf(2, "%s\n", strerror(errno)); + } + + close(cwd); + + printf("forking\n"); + pid_t pid = fork(); + if (pid == 0) + { + char path[1024]; + getcwd(path, 1024); + dprintf(2, "making in %s...\n", path); + execv("/usr/bin/make", (char *[]){ "make", "-f", "Makefile.demo", "run_kick", NULL }); + } + else if (i > 0) + { + int status; + printf("waiting...\n"); + waitpid(pid, &status, 0); + } + else + { + printf("failing...\n"); + perror("fork failed"); + } } static int get_track_data(struct sync_device *d, struct sync_track *t)