Compare commits

...

3 Commits

Author SHA1 Message Date
Kuba Winnicki
f3921b8bc0 Rocket start from everywhere 2017-02-21 14:11:22 +01:00
Kuba Winnicki
5578fb9fdf Use unified makefile for building 2017-02-16 15:02:10 +01:00
Kuba Winnicki
a24682f3d4 librocket: make demo on export 2016-08-28 10:38:18 +02:00

View File

@ -5,6 +5,7 @@
#include <math.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
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,58 @@ 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)
void sync_save_tracks(const struct sync_device *d, int row)
{
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];
char def_track_start[64];
snprintf(def_track_start, 64, "TRACK_START_ROW=%d", row);
getcwd(path, 1024);
dprintf(2, "making in %s...\n", path);
execv("/usr/bin/make", (char *[]){ "make", "run", def_track_start, 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)
@ -400,7 +434,6 @@ int sync_update(struct sync_device *d, int row, struct sync_cb *cb,
/* look for new commands */
while (socket_poll(d->sock)) {
unsigned char cmd = 0, flag;
uint32_t row;
if (xrecv(d->sock, (char *)&cmd, 1, 0))
goto sockerr;
@ -426,7 +459,7 @@ int sync_update(struct sync_device *d, int row, struct sync_cb *cb,
cb->pause(cb_param, flag);
break;
case SAVE_TRACKS:
sync_save_tracks(d);
sync_save_tracks(d, row);
break;
default:
fprintf(stderr, "unknown cmd: %02x\n", cmd);