Changeset 383
- Timestamp:
- 06/12/07 18:34:32 (2 years ago)
- Files:
-
- version_0/ext/cmain.cpp (modified) (1 diff)
- version_0/ext/em.cpp (modified) (3 diffs)
- version_0/ext/em.h (modified) (1 diff)
- version_0/ext/eventmachine.h (modified) (1 diff)
- version_0/ext/rubymain.cpp (modified) (1 diff)
- version_0/lib/eventmachine.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
version_0/ext/cmain.cpp
r381 r383 299 299 **********/ 300 300 301 extern "C" const char *evma_popen (c onst char *cmd)302 { 303 if (!EventMachine) 304 throw std::runtime_error ("not initialized"); 305 return EventMachine->Socketpair (cmd );301 extern "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); 306 306 } 307 307 version_0/ext/em.cpp
r382 r383 1338 1338 **************************/ 1339 1339 1340 const char *EventMachine_t::Socketpair (c onst char *cmd)1340 const char *EventMachine_t::Socketpair (char * const*cmd_strings) 1341 1341 { 1342 1342 #ifdef OS_WIN32 … … 1347 1347 // Eventually we need this functionality (or a full-duplex equivalent) on Windows. 1348 1348 #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 1349 1358 const char *output_binding = NULL; 1350 1359 … … 1375 1384 close (sv[1]); 1376 1385 dup2 (STDIN_FILENO, STDOUT_FILENO); 1377 exec lp ("ls", "ls", "-l", (char*)NULL);1386 execvp (cmd_strings[0], cmd_strings+1); 1378 1387 exit (-1); // end the child process if the exec doesn't work. 1379 1388 } version_0/ext/em.h
r381 r383 72 72 const char *_OpenFileForWriting (const char*); 73 73 const char *Popen (const char*, const char*); 74 const char *Socketpair (c onst char*);74 const char *Socketpair (char* const*); 75 75 76 76 void Add (EventableDescriptor*); version_0/ext/eventmachine.h
r381 r383 58 58 59 59 const char *evma__write_file (const char *filename); 60 const char *evma_popen (c onst char *cmd);60 const char *evma_popen (char * const*cmd_strings); 61 61 62 62 int evma_set_rlimit_nofile (int n_files); version_0/ext/rubymain.cpp
r381 r383 315 315 static VALUE t_invoke_popen (VALUE self, VALUE cmd) 316 316 { 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); 318 329 if (!f || !*f) { 319 330 char *err = strerror (errno); version_0/lib/eventmachine.rb
r381 r383 59 59 require 'em/eventable' 60 60 require 'em/messages' 61 62 require 'shellwords' 63 61 64 #-- Additional requires are at the BOTTOM of this file, because they 62 65 #-- depend on stuff defined in here. Refactor that someday. … … 894 897 895 898 896 # TODO, must document popen. At this moment, it's only available on Unix , and it's half-duplex.897 # Both of these limitations areexpected 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. 898 901 #-- 902 # Perhaps misnamed since the underlying function uses socketpair and is full-duplex. 899 903 # 900 904 def self::popen cmd, handler=nil … … 905 909 end 906 910 907 s = invoke_popen cmd 911 w = Shellwords::shellwords( cmd ) 912 w.unshift( w.first ) if w.first 913 s = invoke_popen( w ) 908 914 c = klass.new s 909 915 @conns[s] = c