Skip to content

Commit

Permalink
feat: allow passing G_SPAWN stdio flags to awesome.spawn
Browse files Browse the repository at this point in the history
Fixes: awesomeWM#3865
Currently works by allowing the exact strings "DEV_NULL" or "INHERIT" to
be passed to return_std*.

Documentation / error messages need to be fixed.

Signed-off-by: aarondill <[email protected]>
  • Loading branch information
aarondill committed Jun 30, 2024
1 parent ad0290b commit 989e018
Showing 1 changed file with 54 additions and 9 deletions.
63 changes: 54 additions & 9 deletions spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ spawn_child_exited(pid_t pid, int status)
*
* @tparam string|table cmd The command to launch.
* @tparam[opt=true] boolean use_sn Use startup-notification?
* @tparam[opt=false] boolean stdin Return a fd for stdin?
* @tparam[opt=false] boolean stdout Return a fd for stdout?
* @tparam[opt=false] boolean stderr Return a fd for stderr?
* @tparam[opt=false] boolean|string stdin Return a fd for stdin?
* @tparam[opt=false] boolean|string stdout Return a fd for stdout?
* @tparam[opt=false] boolean|string stderr Return a fd for stderr?
* @tparam[opt=nil] function exit_callback Function to call on process exit. The
* function arguments will be type of exit ("exit" or "signal") and the exit
* code / the signal number causing process termination.
Expand All @@ -441,12 +441,57 @@ luaA_spawn(lua_State *L)

if(lua_gettop(L) >= 2)
use_sn = luaA_checkboolean(L, 2);
if(lua_gettop(L) >= 3)
return_stdin = luaA_checkboolean(L, 3);
if(lua_gettop(L) >= 4)
return_stdout = luaA_checkboolean(L, 4);
if(lua_gettop(L) >= 5)
return_stderr = luaA_checkboolean(L, 5);
/* Valid values for return_std* are:
* true -> return a fd
* false -> keep glib's default behaviour
* "DEV_NULL" -> use direct output to /dev/null
* "INHERIT" -> use the same fd as the parent
*/
if(lua_gettop(L) >= 3) {
if (lua_isstring(L, 3)) {
const char *str = lua_tostring(L, 3);
if (strcmp(str, "DEV_NULL") == 0)
flags |= G_SPAWN_STDIN_FROM_DEV_NULL;
else if (strcmp(str, "INHERIT") == 0)
flags |= G_SPAWN_CHILD_INHERITS_STDIN;
else
luaA_typerror(L, 3, "DEV_NULL or INHERIT"); // TODO: create a better error message
} else if(lua_isboolean(L, 3)) {
return_stdin = lua_toboolean(L, 3);
} else {
luaA_typerror(L, 3, "boolean or string");
}
}
if(lua_gettop(L) >= 4) {
if (lua_isstring(L, 4)) {
const char *str = lua_tostring(L, 4);
if (strcmp(str, "DEV_NULL") == 0)
flags |= G_SPAWN_STDOUT_TO_DEV_NULL;
else if (strcmp(str, "INHERIT") == 0)
flags |= G_SPAWN_CHILD_INHERITS_STDOUT;
else
luaA_typerror(L, 4, "DEV_NULL or INHERIT"); // TODO: create a better error message
} else if(lua_isboolean(L, 4)) {
return_stdout = lua_toboolean(L, 4);
} else {
luaA_typerror(L, 4, "boolean or string");
}
}
if(lua_gettop(L) >= 5) {
if (lua_isstring(L, 5)) {
const char *str = lua_tostring(L, 5);
if (strcmp(str, "DEV_NULL") == 0)
flags |= G_SPAWN_STDERR_TO_DEV_NULL;
else if (strcmp(str, "INHERIT") == 0)
flags |= G_SPAWN_CHILD_INHERITS_STDERR;
else
luaA_typerror(L, 5, "DEV_NULL or INHERIT"); // TODO: create a better error message
} else if(lua_isboolean(L, 5)) {
return_stderr = lua_toboolean(L, 5);
} else {
luaA_typerror(L, 5, "boolean or string");
}
}
if (!lua_isnoneornil(L, 6))
{
luaA_checkfunction(L, 6);
Expand Down

0 comments on commit 989e018

Please sign in to comment.