Changeset 383

Show
Ignore:
Timestamp:
06/12/07 18:34:32 (2 years ago)
Author:
blackhedd
Message:

continued work on the popen implementation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • version_0/ext/cmain.cpp

    r381 r383  
    299299**********/ 
    300300 
    301 extern "C" const char *evma_popen (const char *cmd
    302 { 
    303         if (!EventMachine) 
    304                 throw std::runtime_error ("not initialized"); 
    305         return EventMachine->Socketpair (cmd); 
     301extern "C" const char *evma_popen (char * const*cmd_strings
     302{ 
     303        if (!EventMachine) 
     304                throw std::runtime_error ("not initialized"); 
     305        return EventMachine->Socketpair (cmd_strings); 
    306306} 
    307307 
  • version_0/ext/em.cpp

    r382 r383  
    13381338**************************/ 
    13391339 
    1340 const char *EventMachine_t::Socketpair (const char *cmd
     1340const char *EventMachine_t::Socketpair (char * const*cmd_strings
    13411341{ 
    13421342        #ifdef OS_WIN32 
     
    13471347        // Eventually we need this functionality (or a full-duplex equivalent) on Windows. 
    13481348        #ifdef OS_UNIX 
     1349        // Make sure the incoming array of command strings is sane. 
     1350        if (!cmd_strings) 
     1351                return NULL; 
     1352        int j; 
     1353        for (j=0; j < 100 && cmd_strings[j]; j++) 
     1354                ; 
     1355        if ((j==0) || (j==100)) 
     1356                return NULL; 
     1357 
    13491358        const char *output_binding = NULL; 
    13501359 
     
    13751384                close (sv[1]); 
    13761385                dup2 (STDIN_FILENO, STDOUT_FILENO); 
    1377                 execlp ("ls", "ls", "-l", (char*)NULL); 
     1386                execvp (cmd_strings[0], cmd_strings+1); 
    13781387                exit (-1); // end the child process if the exec doesn't work. 
    13791388        } 
  • version_0/ext/em.h

    r381 r383  
    7272                const char *_OpenFileForWriting (const char*); 
    7373                const char *Popen (const char*, const char*); 
    74                 const char *Socketpair (const char*); 
     74                const char *Socketpair (char* const*); 
    7575 
    7676                void Add (EventableDescriptor*); 
  • version_0/ext/eventmachine.h

    r381 r383  
    5858 
    5959        const char *evma__write_file (const char *filename); 
    60         const char *evma_popen (const char *cmd); 
     60        const char *evma_popen (char * const*cmd_strings); 
    6161 
    6262        int evma_set_rlimit_nofile (int n_files); 
  • version_0/ext/rubymain.cpp

    r381 r383  
    315315static VALUE t_invoke_popen (VALUE self, VALUE cmd) 
    316316{ 
    317         const char *f = evma_popen (StringValuePtr(cmd)); 
     317        int len = RARRAY (cmd)->len; 
     318        if (len > 98) 
     319                rb_raise (rb_eRuntimeError, "too many arguments to popen"); 
     320        char *strings [100]; 
     321        for (int i=0; i < len; i++) { 
     322                VALUE ix = INT2FIX (i); 
     323                VALUE s = rb_ary_aref (1, &ix, cmd); 
     324                strings[i] = StringValuePtr (s); 
     325        } 
     326        strings[len] = NULL; 
     327 
     328        const char *f = evma_popen (strings); 
    318329        if (!f || !*f) { 
    319330                char *err = strerror (errno); 
  • version_0/lib/eventmachine.rb

    r381 r383  
    5959require 'em/eventable' 
    6060require 'em/messages' 
     61 
     62require 'shellwords' 
     63 
    6164#-- Additional requires are at the BOTTOM of this file, because they 
    6265#-- depend on stuff defined in here. Refactor that someday. 
     
    894897 
    895898 
    896         # TODO, must document popen. At this moment, it's only available on Unix, and it's half-duplex
    897         # Both of these limitations are expected to go away. 
     899        # TODO, must document popen. At this moment, it's only available on Unix
     900        # This limitation is expected to go away. 
    898901        #-- 
     902        # Perhaps misnamed since the underlying function uses socketpair and is full-duplex. 
    899903        # 
    900904        def self::popen cmd, handler=nil 
     
    905909                end 
    906910 
    907                 s = invoke_popen cmd 
     911                w = Shellwords::shellwords( cmd ) 
     912                w.unshift( w.first ) if w.first 
     913                s = invoke_popen( w ) 
    908914                c = klass.new s 
    909915                @conns[s] = c