#5 pass filename to command via env

open
nobody
Plugins (3)
5
2008-09-27
2008-09-27
Anonymous
No

Writing external commands for output_file.so would be made easier if the filename were available. Adding setenv() before calling system() does this pretty easily

in output_file.c I added

/* if parameters are needed, use a BASH-script as argument */
if ( command != NULL ) {
setenv("MJPG_FILE", buffer2, 1);
system(command);
}

That way the command doesn't have to guess which file is the one to operate on.

Discussion

  • It might be cleaner to pass the filename as an argument to the command

     
  • Jón Fairbairn
    Jón Fairbairn
    2009-05-26

    Couldn't see how to attach patch. Something like this might do:

    diff -rN -Naur old-mjpg-streamer-r63/plugins/output_file/output_file.c new-mjpg-streamer-r63/plugins/output_file/output_file.c
    --- old-mjpg-streamer-r63/plugins/output_file/output_file.c 2009-05-26 18:56:28.000000000 +0100
    +++ new-mjpg-streamer-r63/plugins/output_file/output_file.c 2009-05-26 18:56:28.000000000 +0100
    @@ -95,7 +95,7 @@
    ******************************************************************************/
    void *worker_thread( void *arg ) {
    int ok = 1, frame_size=0, previous_frame_size=0;
    - char buffer1[1024] = {0}, buffer2[1024] = {0};
    + char buffer1[1024] = {0}, buffer2[1024] = {0}, command_with_args[1024] = {0};
    unsigned long long counter=0;
    time_t t;
    struct tm *tmp;
    @@ -170,7 +170,13 @@

    /* if parameters are needed, use a BASH-script as argument */
    if ( command != NULL ) {
    - system(command);
    + memset (command_with_args, 0, sizeof(command_with_args));
    + if (snprintf (command_with_args, sizeof(command_with_args), "%s %s", command, buffer2)) {
    + system(command_with_args);
    + }
    + else {
    + perror ("couldn't make commandline");
    + }
    }

    if (delay > 0) {