]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - write.c
para_write: Fix --bufsize.
[paraslash.git] / write.c
diff --git a/write.c b/write.c
index c692dc92fe1a77433aad26078879555a93bb39c6..998a6d2cccde01cf45bcb6e5dea9d5e11c3f7da0 100644 (file)
--- a/write.c
+++ b/write.c
@@ -34,6 +34,7 @@ struct check_wav_task {
        unsigned channels;
        /** Sample rate specified in wav header given by \a buf. */
        unsigned samplerate;
+       /** The task structure used by the scheduler. */
        struct task task;
 };
 
@@ -105,14 +106,19 @@ static void initial_delay_pre_select(struct sched *s, struct task *t)
 
        if (!idt->start_time.tv_sec && !idt->start_time.tv_usec) {
                t->error = -E_NO_DELAY;
-               return;
+               goto register_check_wav;
        }
        if (tv_diff(now, &idt->start_time, &diff) > 0) {
                t->error = -E_DELAY_TIMEOUT;
-               return;
+               goto register_check_wav;
        }
        if (tv_diff(&s->timeout , &diff, NULL) > 0)
                s->timeout = diff;
+       return;
+register_check_wav:
+       register_task(&the_check_wav_task.task);
+       s->timeout.tv_sec = 0;
+       s->timeout.tv_usec = 1;
 }
 
 INIT_STDERR_LOGGING(conf.loglevel_arg)
@@ -182,7 +188,7 @@ out:
 int main(int argc, char *argv[])
 {
        int ret = -E_WRITE_SYNTAX;
-       struct sched s;
+       static struct sched s;
        struct check_wav_task *cwt = &the_check_wav_task;
        struct initial_delay_task *idt = &the_initial_delay_task;
 
@@ -194,8 +200,12 @@ int main(int argc, char *argv[])
        if (!wng)
                goto out;
        stdin_set_defaults(&sit);
-       if (conf.bufsize_given)
-               sit.bufsize = conf.bufsize_arg;
+       ret = -ERRNO_TO_PARA_ERROR(EINVAL);
+       if (conf.bufsize_arg < 0)
+               goto out;
+       if (conf.bufsize_arg >= INT_MAX / 1024)
+               goto out;
+       sit.bufsize = conf.bufsize_arg * 1024;
        sit.buf = para_malloc(sit.bufsize);
 
        wng->buf = sit.buf;
@@ -209,7 +219,6 @@ int main(int argc, char *argv[])
        cwt->input_error = &sit.task.error;
        sprintf(cwt->task.status, "check wav");
        cwt->task.pre_select = check_wav_pre_select;
-       register_task(&cwt->task);
 
        idt->task.pre_select = initial_delay_pre_select;
        sprintf(idt->task.status, "initial_delay");