Compare commits
3 Commits
4a9056bba8
...
f3921b8bc0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3921b8bc0 | ||
|
|
5578fb9fdf | ||
|
|
a24682f3d4 |
57
lib/device.c
57
lib/device.c
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user