Compare commits
No commits in common. "f3921b8bc0b6152c014c739f29b745d2c3ea4475" and "4a9056bba89363a9092566945a879d62386dfabb" have entirely different histories.
f3921b8bc0
...
4a9056bba8
57
lib/device.c
57
lib/device.c
@ -5,7 +5,6 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
static int find_track(struct sync_device *d, const char *name)
|
static int find_track(struct sync_device *d, const char *name)
|
||||||
{
|
{
|
||||||
@ -267,6 +266,13 @@ static int save_track(const struct sync_track *t, const char *path)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
int cwd = open(".", O_RDONLY);
|
||||||
|
if (!cwd)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (!chdir("build/sync"))
|
||||||
|
return -1;
|
||||||
|
|
||||||
FILE *fp = fopen(path, "wb");
|
FILE *fp = fopen(path, "wb");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return -1;
|
return -1;
|
||||||
@ -281,58 +287,18 @@ static int save_track(const struct sync_track *t, const char *path)
|
|||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
|
if (!fchdir(cwd))
|
||||||
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sync_save_tracks(const struct sync_device *d, int row)
|
void sync_save_tracks(const struct sync_device *d)
|
||||||
{
|
{
|
||||||
int i;
|
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) {
|
for (i = 0; i < (int)d->num_tracks; ++i) {
|
||||||
const struct sync_track *t = d->tracks[i];
|
const struct sync_track *t = d->tracks[i];
|
||||||
save_track(t, sync_track_path(d->base, t->name));
|
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)
|
static int get_track_data(struct sync_device *d, struct sync_track *t)
|
||||||
@ -434,6 +400,7 @@ int sync_update(struct sync_device *d, int row, struct sync_cb *cb,
|
|||||||
/* look for new commands */
|
/* look for new commands */
|
||||||
while (socket_poll(d->sock)) {
|
while (socket_poll(d->sock)) {
|
||||||
unsigned char cmd = 0, flag;
|
unsigned char cmd = 0, flag;
|
||||||
|
uint32_t row;
|
||||||
if (xrecv(d->sock, (char *)&cmd, 1, 0))
|
if (xrecv(d->sock, (char *)&cmd, 1, 0))
|
||||||
goto sockerr;
|
goto sockerr;
|
||||||
|
|
||||||
@ -459,7 +426,7 @@ int sync_update(struct sync_device *d, int row, struct sync_cb *cb,
|
|||||||
cb->pause(cb_param, flag);
|
cb->pause(cb_param, flag);
|
||||||
break;
|
break;
|
||||||
case SAVE_TRACKS:
|
case SAVE_TRACKS:
|
||||||
sync_save_tracks(d, row);
|
sync_save_tracks(d);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "unknown cmd: %02x\n", cmd);
|
fprintf(stderr, "unknown cmd: %02x\n", cmd);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user