Changeset 97022e24935605949cb7664b5d9193ed7c1c499c

Show
Ignore:
Timestamp:
07/11/09 16:03:08 (3 years ago)
Author:
Nedko Arnaudov <nedko@…>
Children:
83b11b7d1bf3372b39dfaa35a7dd1624530cd85f
Parents:
b05530c4ff96e00046ae4e9555794b66265081b2
git-committer:
Nedko Arnaudov <nedko@arnaudov.name> / 2009-07-11T16:03:08Z+0300
Message:

disabled execution through clone()

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lv2_ui.c

    rb05530c r97022e2  
    2727 
    2828//#define FORK_TIME_MEASURE 
     29 
    2930#define USE_VFORK 
     31//#define USE_CLONE 
     32//#define USE_CLONE2 
    3033 
    3134#if defined(USE_VFORK) 
    3235#define FORK vfork 
    3336#define FORK_STR "vfork" 
     37#elif defined(USE_CLONE) 
     38#define FORK_STR "clone" 
     39#elif defined(USE_CLONE2) 
     40#define FORK_STR "clone2" 
    3441#else 
    3542#define FORK fork 
    3643#define FORK_STR "fork" 
    3744#endif 
    38  
    3945 
    4046#include <stdbool.h> 
     
    4854#endif 
    4955#include <unistd.h> 
     56#if defined(USE_CLONE) || defined(USE_CLONE2) 
     57# include <sched.h> 
     58#endif 
    5059#include <fcntl.h> 
    5160#include <locale.h> 
     
    228237#endif 
    229238 
     239#if defined(USE_CLONE) || defined(USE_CLONE2) 
     240 
     241static int clone_fn(void * context) 
     242{ 
     243    execvp(*(const char **)context, (char **)context); 
     244    return -1; 
     245} 
     246 
     247#endif 
     248 
    230249static 
    231250LV2UI_Handle 
     
    248267  int oldflags; 
    249268  FORK_TIME_MEASURE_VAR; 
     269  const char * argv[8]; 
     270  int ret; 
    250271 
    251272  //printf("instantiate('%s', '%s') called\n", plugin_uri, bundle_path); 
     
    306327  control_ptr->visible = false; 
    307328 
     329  argv[0] = "python"; 
     330  argv[1] = filename; 
     331  argv[2] = plugin_uri; 
     332  argv[3] = bundle_path; 
     333  argv[4] = ui_host_ptr->plugin_human_id != NULL ? ui_host_ptr->plugin_human_id : ""; 
     334  argv[5] = ui_recv_pipe;       /* reading end */ 
     335  argv[6] = ui_send_pipe;       /* writting end */ 
     336  argv[7] = NULL; 
     337 
    308338  FORK_TIME_MEASURE_BEGIN; 
    309339 
    310   switch (FORK()) 
     340#if defined(USE_CLONE) 
     341  { 
     342    int stack[8000]; 
     343 
     344    ret = clone(clone_fn, stack + 4000, CLONE_VFORK, argv); 
     345    if (ret == -1) 
     346    { 
     347      fprintf(stderr, "clone() failed: %s\n", strerror(errno)); 
     348      goto fail_free_control; 
     349    } 
     350  } 
     351#elif defined(USE_CLONE2) 
     352  fprintf(stderr, "clone2() exec not implemented yet\n"); 
     353  goto fail_free_control; 
     354#else 
     355  ret = FORK(); 
     356  switch (ret) 
    311357  { 
    312358  case 0:                       /* child process */ 
     
    318364#endif 
    319365 
    320     execlp( 
    321       "python", 
    322       "python", 
    323       filename, 
    324       plugin_uri, 
    325       bundle_path, 
    326       ui_host_ptr->plugin_human_id != NULL ? ui_host_ptr->plugin_human_id : "", 
    327       ui_recv_pipe,             /* reading end */ 
    328       ui_send_pipe,             /* writting end */ 
    329       NULL); 
     366    execvp(argv[0], (char **)argv); 
    330367    fprintf(stderr, "exec of UI failed: %s", strerror(errno)); 
    331368    exit(1); 
     
    334371    goto fail_free_control; 
    335372  } 
     373 
     374#endif 
    336375 
    337376  FORK_TIME_MEASURE_END(FORK_STR "() time");