Skip to content
This repository
Browse code

luv_process: upgrade to libuv 0.8

libuv started using an array of uv_stdio_container_t objects instead of
the explicit stderr/stdin/stdout object. Update to this new API to get
the stdout moving again in test-process.lua.

TODO: test-process.lua is still hanging, something is still holding a
ref.
  • Loading branch information...
commit 870fbbc3dcaa2a340c8dcaeccd428198fce1cdf4 1 parent aa4cc47
Brandon Philips authored August 06, 2012 philips committed August 07, 2012
38  src/luv_process.c
@@ -48,9 +48,9 @@ int luv_getpid(lua_State* L){
48 48
 
49 49
 /* Initializes uv_process_t and starts the process. */
50 50
 int luv_spawn(lua_State* L) {
51  
-  uv_pipe_t* stdin_stream = (uv_pipe_t*)luv_checkudata(L, 1, "pipe");
52  
-  uv_pipe_t* stdout_stream = (uv_pipe_t*)luv_checkudata(L, 2, "pipe");
53  
-  uv_pipe_t* stderr_stream = (uv_pipe_t*)luv_checkudata(L, 3, "pipe");
  51
+  uv_stream_t* stdin_stream = (uv_stream_t*)luv_checkudata(L, 1, "pipe");
  52
+  uv_stream_t* stdout_stream = (uv_stream_t*)luv_checkudata(L, 2, "pipe");
  53
+  uv_stream_t* stderr_stream = (uv_stream_t*)luv_checkudata(L, 3, "pipe");
54 54
   const char* command = luaL_checkstring(L, 4);
55 55
   size_t argc;
56 56
   char** args;
@@ -58,6 +58,7 @@ int luv_spawn(lua_State* L) {
58 58
   char* cwd;
59 59
   char** env;
60 60
   uv_process_options_t options;
  61
+  uv_stdio_container_t stdio[3];
61 62
   uv_process_t* handle;
62 63
   int r;
63 64
 
@@ -65,6 +66,32 @@ int luv_spawn(lua_State* L) {
65 66
   luaL_checktype(L, 6, LUA_TTABLE); /* options */
66 67
 
67 68
   memset(&options, 0, sizeof(uv_process_options_t));
  69
+  memset(stdio, 0, sizeof(stdio));
  70
+
  71
+  options.stdio = stdio;
  72
+  options.stdio_count = 3;
  73
+
  74
+  /*
  75
+  TODO: Handle ignoring stdio
  76
+  options.stdio[0].flags = UV_IGNORE;
  77
+  options.stdio[1].flags = UV_IGNORE;
  78
+  options.stdio[2].flags = UV_IGNORE;
  79
+  */
  80
+
  81
+  /*
  82
+  TODO: Handle creating pipes
  83
+  options.stdio[0].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
  84
+  options.stdio[1].flags = UV_CREATE_PIPE | UV_READABLE_PIPE;
  85
+  options.stdio[2].flags = UV_CREATE_PIPE | UV_READABLE_PIPE;s
  86
+  */
  87
+
  88
+  options.stdio[0].flags = UV_INHERIT_STREAM;
  89
+  options.stdio[1].flags = UV_INHERIT_STREAM;
  90
+  options.stdio[2].flags = UV_INHERIT_STREAM;
  91
+
  92
+  options.stdio[0].data.stream = stdin_stream;
  93
+  options.stdio[1].data.stream = stdout_stream;
  94
+  options.stdio[2].data.stream = stderr_stream;
68 95
 
69 96
   /* Parse the args array */
70 97
   argc = lua_objlen(L, 5) + 1;
@@ -103,11 +130,6 @@ int luv_spawn(lua_State* L) {
103 130
 
104 131
   options.env = env ? env : luv_os_environ();
105 132
   options.cwd = cwd;
106  
-#if 0
107  
-  options.stdin_stream = stdin_stream;
108  
-  options.stdout_stream = stdout_stream;
109  
-  options.stderr_stream = stderr_stream;
110  
-#endif
111 133
 
112 134
   /* Create the userdata */
113 135
   handle = luv_create_process(L);
1  tests/test-process.lua
@@ -15,6 +15,7 @@ function test()
15 15
     child = spawn('bash', {'-c', 'set'}, options)
16 16
   end
17 17
   child.stdout:on('data', function(chunk)
  18
+    print(chunk)
18 19
     if chunk:find('TEST1=1') then
19 20
       environmentTestResult = true
20 21
     end

0 notes on commit 870fbbc

Please sign in to comment.
Something went wrong with that request. Please try again.