diff options
author | Stefan Bolte <sbolte@lavabit.com> | 2013-06-02 17:11:36 +0200 |
---|---|---|
committer | Stefan Bolte <sbolte@lavabit.com> | 2013-06-02 17:11:36 +0200 |
commit | 2a476be510264eba00db69298d730f1fe479fc6b (patch) | |
tree | ca6e5dc16db6251b8d979696abdb56b04f873b9f | |
parent | 830cc13d85e4057d620195b6053ee38814275723 (diff) | |
download | dwb-2a476be510264eba00db69298d730f1fe479fc6b.zip |
Open io-channels in non-blocking mode, wrap system.spawn again
-rw-r--r-- | scripts/lib/system.js | 27 | ||||
-rw-r--r-- | src/scripts.c | 8 |
2 files changed, 32 insertions, 3 deletions
diff --git a/scripts/lib/system.js b/scripts/lib/system.js new file mode 100644 index 00000000..1a276f8b --- /dev/null +++ b/scripts/lib/system.js @@ -0,0 +1,27 @@ +(function() { + Object.defineProperties(system, { + "spawn" : + { + value : (function() { + return function(command, onStdout, onStderr, stdin, environ) { + var stdout, stderr; + return system._spawn(command, + !onStdout ? null : function(response) { + var ret; + stdout = onStdout.call(onStdout, response) || response; + }, + !onStderr ? null : function(response) { + var ret; + stderr = onStderr.call(onStderr, response) || response; + return ret; + }, + stdin, environ).then( + function() { return stdout; }, + function() { return stdin; } + ); + }; + })() + } + }); + Object.freeze(system); +})(); diff --git a/src/scripts.c b/src/scripts.c index f2e3eab8..8d0ad1e1 100644 --- a/src/scripts.c +++ b/src/scripts.c @@ -3202,8 +3202,8 @@ system_spawn(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, siz if (!g_shell_parse_argv(cmdline, &srgc, &srgv, NULL) || !g_spawn_async_with_pipes(NULL, srgv, envp, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, - NULL, - //pipe_stdin != NULL ? &infd : NULL, + //NULL, + pipe_stdin != NULL ? &infd : NULL, oc != NULL ? &outfd : NULL, ec != NULL ? &errfd : NULL, NULL)) { @@ -3215,6 +3215,7 @@ system_spawn(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, siz { out_channel = g_io_channel_unix_new(outfd); JSValueProtect(ctx, oc); + g_io_channel_set_flags(out_channel, G_IO_FLAG_NONBLOCK, NULL); g_io_add_watch(out_channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, (GIOFunc)spawn_output, oc); g_io_channel_set_close_on_unref(out_channel, true); } @@ -3222,6 +3223,7 @@ system_spawn(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, siz { err_channel = g_io_channel_unix_new(errfd); JSValueProtect(ctx, ec); + g_io_channel_set_flags(err_channel, G_IO_FLAG_NONBLOCK, NULL); g_io_add_watch(err_channel, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, (GIOFunc)spawn_output, ec); g_io_channel_set_close_on_unref(err_channel, true); } @@ -5018,7 +5020,7 @@ create_global_object() * @static * */ JSStaticFunction system_functions[] = { - { "spawn", system_spawn, kJSDefaultAttributes }, + { "_spawn", system_spawn, kJSDefaultAttributes }, { "spawnSync", system_spawn_sync, kJSDefaultAttributes }, { "getEnv", system_get_env, kJSDefaultAttributes }, { "fileTest", system_file_test, kJSDefaultAttributes }, |