Back to index

avfs  1.0.1
Functions
runprog.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int av_start_program (const char **prog, struct program **resp)
int av_program_getline (struct program *pr, char **linep, long timeoutms)
int av_program_log_output (struct program *pr)
int av_run_program (const char **prog)

Function Documentation

int av_program_getline ( struct program pr,
char **  linep,
long  timeoutms 
)

Definition at line 142 of file runprog.c.

{
    int res;
    char *line;

    *linep = NULL;
    while(1) {
        res = flush_error(pr);
        if(res < 0)
            return res;
        
        res = av_filebuf_readline(pr->fbs[0], &line);
        if(res < 0)
            return res;
        if(res == 1)
            break;

        if(av_filebuf_eof(pr->fbs[0]) && av_filebuf_eof(pr->fbs[1])) {
            res = av_wait_prog(&pr->pri, 0, 0);
            if(res < 0)
                return res;

            return 1;
        }

        res = av_filebuf_check(pr->fbs, 2, timeoutms);
        if(res <= 0)
            return res;
    }

    *linep = line;
    return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int av_program_log_output ( struct program pr)

Definition at line 176 of file runprog.c.

{
    int res;

    res = av_wait_prog(&pr->pri, 0, 1);
    if(res < 0)
        return res;
    
    if(res == 1)
        return 0;

    return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int av_run_program ( const char **  prog)

Definition at line 216 of file runprog.c.

{
    int res;
    struct program *pr;

    res = av_start_program(prog, &pr);
    if(res < 0)
        return res;


    res = av_process_program(pr);
    av_unref_obj(pr);

    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int av_start_program ( const char **  prog,
struct program **  resp 
)

Definition at line 55 of file runprog.c.

{
    int res;
    int pipeout[2];
    int pipeerr[2];
    struct program *pr;

    pipeout[0] = -1;
    pipeout[1] = -1;
    if(pipe(pipeout) == -1 || pipe(pipeerr) == -1) {
        res = -errno;
        av_log(AVLOG_ERROR, "RUNPROG: unable to create pipe: %s",
               strerror(errno));
        close(pipeout[0]);
        close(pipeout[1]);
        return res;
    }
    av_registerfd(pipeout[0]);
    av_registerfd(pipeerr[0]);

    AV_NEW_OBJ(pr, program_delete);
    av_init_proginfo(&pr->pri);
    pr->fbs[0] = NULL;
    pr->fbs[1] = NULL;
    pr->prog = copy_prog(prog);

    pr->pri.prog = (const char **) pr->prog;
    pr->pri.ifd = open("/dev/null", O_RDONLY);
    if(pr->pri.ifd == -1) {
        res = -errno;
        av_log(AVLOG_ERROR, "RUNPROG: unable to open '/dev/null': %s",
               strerror(errno));
        close(pipeout[0]);
        close(pipeout[1]);
        close(pipeerr[0]);
        close(pipeerr[1]);
        av_unref_obj(pr);
        return res;
    }
    pr->pri.ofd = pipeout[1];
    pr->pri.efd = pipeerr[1];

    res = av_start_prog(&pr->pri);
    close(pr->pri.ifd);
    close(pr->pri.ofd);
    close(pr->pri.efd);

    if(res < 0) {
        close(pipeout[0]);
        close(pipeerr[0]);
        av_unref_obj(pr);
        return res;
    }
    
    pr->fbs[0] = av_filebuf_new(pipeout[0], FILEBUF_NONBLOCK);
    pr->fbs[1] = av_filebuf_new(pipeerr[0], FILEBUF_NONBLOCK);

    *resp = pr;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: