Commit Graph

72 Commits

Author SHA1 Message Date
Daniel Hahler 36d7535cd5
Minor: typos, Makefile aesthetics (#2690)
* lib/awful/mouse/resize.lua: s/extendable/extensible

* Fix code comment typo: s/find/found

* Makefile: remove -n with echo

Missed in e9b5e28d1.
2019-02-22 08:42:43 +01:00
Daniel Hahler c21e8b980a
minor: spawn_child_exited: use "signal" for signals in warning (#2417) 2018-10-04 19:09:01 +02:00
Uli Schlachter 6c559e188c Handle SIGCHLD ourselves instead of through GLib
GLib is very careful not to "fetch" any children that it was not asked
to fetch. Thus, if awesome inherits some children, it does not reap them
and starts collecting zombies.

Thus, this commit makes awesome handle SIGCHLD directly: On SIGCHLD, a
byte is written to a pipe. The main loop reads from this pipe and
collects children via waitpid(-1). Unknown children cause a warning to
be printed. We might want to remove this warning if it turns out to be
annoying.

This commit adds 79 lines and removes 89 lines. Thus, this is a net
reduction in lines of codes. This is because previously, we gave the
list of still-running children that we know about to the next awesome
instance we a --reap command line argument. This was added so that
awesome does not get zombie children. However, this commit fixes this
problem and makes all the code for this 'feature' unnecessary.

Fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=886393
Signed-off-by: Uli Schlachter <psychon@znc.in>
2018-08-21 15:30:07 +02:00
Uli Schlachter 3f93bf4cd5 Use signal_array_getbyname() where appropriate
Signed-off-by: Uli Schlachter <psychon@znc.in>
2018-01-24 09:13:35 +01:00
Uli Schlachter a222e5c0af spawn: Fix some comments and messages
Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-08-16 13:23:19 +02:00
Uli Schlachter 9f8ff76079 awesome.spawn: Add a new argument for env
This adds a new argument to awesome.spawn that can be used to specify
the environment of the spawned process.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-08-16 13:23:19 +02:00
Uli Schlachter aac519b946 Refactor spawn.c
This moves some code of parse_command() out into a new helper function.
No functional changes intended.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-08-16 13:23:19 +02:00
Uli Schlachter cc0871498c Make awesome.spawn() live up to its documentation
This function is documented to return "an error string if an error
occurred". However, the function actually threw a Lua error instead.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-08-16 13:23:19 +02:00
Uli Schlachter 2b6350009e Fix a typo in spawn.c
Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-08-16 13:23:19 +02:00
Uli Schlachter af8288335b Use command line instead of env for passing children
Commit e54361a374 added code so that we pass the list of
currently running children across restart via an environment variable.
As Colin Walters correctly points out, setenv() is not safe in a
multi-threaded processes.

Thus, instead of using the environment, use the command line to pass
this information along.

https://github.com/awesomeWM/awesome/issues/1812
Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-06-04 16:04:44 +02:00
Uli Schlachter 84080c64c5 spawn: Use CLOEXEC for pipes (#1811)
Fixes: https://github.com/awesomeWM/awesome/issues/1193#issuecomment-305705724
Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-06-02 10:13:26 +02:00
Uli Schlachter e54361a374 Reap children even across a restart
In Unix, so that a process can learn about the exit status of the child
processes that it started, children become zombie processes until the
parents collects their exit information. We use glib both for starting
and for collecting processes. However, when awesome is restarted, the
new instance inherits children, but does not know about them and does
not inherit them.

Fix this by explicitly tracking a list of running child processes and by
serialising them across a restart via an environment variable. The new
awesome instance can then watch for these child processes, but besides
that it ignores them and does not use their exit status in any way.

Thanks to Colin Walters for the hint with serialising the list of processes.

Fixes: https://github.com/awesomeWM/awesome/issues/1193
Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-06-01 15:47:24 +02:00
Uli Schlachter 01e61079c3 Add & use a non-fatal kind of assert() (#1779)
Aborting the process is sometimes a bit harsh for a failed assertion.
This adds a non-fatal assert() macro called "check()" and uses it in
some places where we might be able to survive the error.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-05-13 23:22:15 +02:00
Renato Botelho 18cb05d232 Fix build on FreeBSD (#1381)
Including <sys/wait.h> is required on FreeBSD for WIFEXITED and another couple
of macros.

This includes sys/types.h and sys/wait.h always as described in waitpid(2).
2017-01-13 22:23:49 +01:00
Uli Schlachter 461da9ea4b Fix error handling in awesome.spawn()
Commit 5e6a893 broke error handling in awesome.spawn(): Instead of
returning an error message, it would just return its last argument.

This commit fixes that, removes some not-so-helpful warnings, and adds
lots of tests for this code.

Fixes: https://github.com/awesomeWM/awesome/issues/1281
Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-12-25 14:50:39 +01:00
Uli Schlachter 259c4f716f Remove @release @AWESOME_VERSION@ everywhere (#1157)
It does not provide much value. The version number is already known to
ldoc globally in the "description" variable.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-10-09 22:36:20 +02:00
Emmanuel Lepage Vallee b8eeb76608 spawn: Fix crash when called with an empty table.
The spawn code didn't properly handle the case where there
is an empty command stream. In that case, no error is
reported as there is simply nothing to do. The error message
was probed and this caused an invalid read and crash.

Fix #1033
2016-08-09 18:32:31 -04:00
Uli Schlachter 231436d9e3 C: Remove unneeded calls to signal_add()
Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-06-04 17:57:08 +02:00
Uli Schlachter a964396771 Deprecate signal_add() on C-API objects
This commit makes the code automatically add signals when they are first used.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-06-04 17:51:45 +02:00
Uli Schlachter e5f9ec4723 C code: Move docs for signals away from signal_add()
Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-06-04 17:39:14 +02:00
Uli Schlachter 051d0de85f Replace many pushnumber calls with pushinteger
The only remaining calls are for a window's opacity and in the DBus type
handling. Everything else wants integers, not something with a comma.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-02-06 13:46:46 +01:00
Uli Schlachter fd8d35cb12 Merge branch 'async-spawn-optional-callbacks' of https://github.com/actionless/awesome 2016-01-17 16:00:39 +01:00
actionless 7546c236db feat(spawn, lib: awful: spawn: with_line_callback): make callbacks optional 2016-01-03 15:38:06 +01:00
Uli Schlachter 5e6a893207 Replace various calls to warn() with luaA_warn()
luaA_warn() prints a Lua backtrace and thus generates more useful output. warn()
should only be used in awesome-internal places (e.g. receiving an error from the
X11 server).

Closes https://github.com/awesomeWM/awesome/pull/608.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-12-31 15:35:13 +01:00
Uli Schlachter a8ac146bd0 awesome.spawn: Add exit status support
This adds a new argument to awesome.spawn. This argument is a function that will
be called with the exit status once the spawned process terminates. For normal
exit, the function is called with "exit" and the exit code. If the process is
terminated by a signal, the function will be called with "signal" and the signal
number of the signal that caused termination.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-11-29 11:53:12 +01:00
Uli Schlachter 9afb2578f8 Spawn: Improve handling of startup notification
The ID for startup notification is transmitted to the spawned process via the
DESKTOP_STARTUP_ID environment variable. Before this commit, we set this
variable in the main process. This meant that if we started something "without"
a startup id, then it might get the ID that was used by the last spawn and which
was still saved in our env. Fix this by setting the environment variable only
after fork().

Small anecdote: The above wasn't enough to make Daniel's test case succeed and
at first I couldn't figure out why.

Turns out that rxvt-unicode doesn't unset the DESKTOP_STARTUP_ID environment
variable (I think it should, according to some spec), even though it supports
startup notification. So awesome was already started with DESKTOP_STARTUP_ID set
and thus all spawned processes used this ID.

Fix this by explicitly unsetting DESKTOP_STARTUP_ID if we don't set any new
value (even though this breaks encapsulation; we shouldn't have to care about
this "implementation detail" of libstartup-notification).

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-11-05 23:02:20 +01:00
Uli Schlachter 2d8bf89ff9 awesome.spawn(): Add possibility to return pipes
This adds three new arguments to awesome.spawn() that tell it to return pipes
for stdin, stdout and stderr of the spawned process.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2015-08-13 09:05:52 +02:00
Daniel Hahler f12f9b3b97 spawn: improve doc, and add `sn` for `awful.util.spawn_with_shell`
Closes https://github.com/awesomeWM/awesome/pull/347.
2015-07-25 15:16:23 +02:00
Daniel Hahler 9dad4f59a4 doc: remove references to Zaphod mode
This has been removed a long time ago (in 32d9a5b).
2015-07-24 15:22:03 +02:00
Daniel Hahler ccb6843144 Call `warn` in case of errors in luaA_spawn
This is useful to have, as it might indicate a missing program etc.
2015-06-22 14:01:16 +02:00
Julian Wollrath 26f15a13f3 Document C API directly in the C source code
v2: Add available signals to the docs.

Signed-off-by: Julian Wollrath <jwollrath@web.de>
2015-06-19 23:13:31 +02:00
Daniel Hahler a899a46664 Set &error in parse_command, return it from luaA_spawn
In case of parse errors from `g_shell_parse_argv`, this now gets
returned by `luaA_spawn`.
2015-03-31 01:17:45 +02:00
Uli Schlachter e5120e1bec Hide globalconf.L
Everything that needs the lua_State should create a local variable like this:

  lua_State *L = globalconf_get_lua_State();

This ensures that the compiler warns if there are two variables with name "L" in
scope. The idea here is that it should become harder to accidentally use the
global lua state instead of the state of the current state.

While writing this commit, I found another place that gets its wrong: Reading
client.focus from a coroutine was broken, since it was returning the result on
the main thread instead of the current one.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-12-06 11:56:58 +01:00
Uli Schlachter d2b1e92f9e Clean up header includes
Every .c file has to include the corresponding .h file first to make sure the
headers are self-contained. Additionally, this moves some unneeded includes
around.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-03-30 20:07:48 +02:00
Uli Schlachter d8b73de739 screen.[ch]: Move into objects/
Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-03-30 15:12:47 +02:00
Emmanuel Lepage Vallee d6e06450d3 Add end to end support for spawning tracking using startup notifications
This allow to spawn something, then apply some properties or rules when
the client show up ("manage").

This commit add:
 * "startup_id" property for all clients object (immutable, can be nil)
 * Second return value to awful.util.spawn() with the startup_id
 * Update the documentation

Example:

  local wait_for_it = {}

  local pid,snid = awful.util.spawn("urxvtc")
  wait_for_it[snid] = {ontop=true,sticky=false,
     tag = awful.tag.gettags(mouse.screen)[1] }

  client.connect_signal("manage", function (c, startup)
     if c.startup_id and wait_for_it[c.startup_id] then
        for k,v in pairs(wait_for_it[c.startup_id]) do
           c[k] = v
        end
        if wait_for_it[c.startup_id].tag then
           c:tags({wait_for_it[c.startup_id].tag})
        end
     end
  end)

Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-03-15 23:14:02 +01:00
Uli Schlachter f9a1093e45 spawn: Remove useless argv[0] calculation
Since commit 3c40d6b, the passed in argument is decomposed into an array of
strings before the sn-related code runs. This means we already know argv[0] and
thus we don't need the code here that tries to figure it out again.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-03-12 11:15:40 +01:00
Uli Schlachter 5432e0a332 awesome.spawn(): Check table arguments better
Previously, any not-string-convertible entry in the array argument would result
in lua_tostring() returning NULL which g_strdup() would pass through. Thus, we
would end up with a NULL entry in an array whose end is marked with a NULL
entry. This mainly means that we had a memory leak.

Fix this by actually verifying that we only have strings in the table that we
are looking at.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-03-12 11:12:23 +01:00
Uli Schlachter 800a9a41f6 spawn: Don't try to spawn with empty argv (FS#1225)
When e.g. calling awesome.spawn({}), our argv array would be empty, so just a
pointer to a NULL pointer that marks the end of the array.

Since startup notification was enabled, this would then try to figure out the
name of the started binary. This would immediately dereference a NULL pointer
and crash.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-03-12 11:10:48 +01:00
Uli Schlachter 3c40d6b470 awesome.spawn: Accept tables as arguments
With this change, awesome.spawn() can be called with a table as its command line
argument. This gets rid of lots of problems with escaping the arguments. For
example, the following call is now possible:

  awesome.spawn({ "bash", "-c", "echo \"foo\"" })

Thanks to Ignas Anikevičius for inspiring me to this.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2013-03-10 14:54:58 +01:00
Uli Schlachter ea30119410 Use glib instead of libev
This commit ports awesome from libev to the glib main loop. This means that
awesome has fewer dependencies, because we were already depending on glib before
and now no longer need glib.

However, the main reason for this change is that, thanks to lgi, we have glib
bindings for lua. This means that lua code can add all kinds of event sources to
the main loop (timeouts, fd watchers, SIGCHLD watchers, ....). Yay

Signed-off-by: Uli Schlachter <psychon@znc.in>
2012-11-21 21:01:12 +01:00
Majic 0e8fc995bb Minor readability fixes, STREQ()-like macros added
Signed-off-by: Julien Danjou <julien@danjou.info>
2011-11-18 17:56:21 +01:00
Gregor Best c2ea920ca0 remove encoding=utf-8 from modelines
This option is no longer valid in modelines, so it has been removed from
all modelines using the following shellscript:

    #!/bin/ksh

    git ls-tree -r HEAD | cut -f2 | while read f; do
        egrep -e '^(//|--) vim: .*encoding=' $f >/dev/null || continue
        sed -E -e '/^(\/\/|--) vim:/s/:encoding=utf-8//' $f > /tmp/foo
        mv /tmp/foo $f
    done

Signed-off-by: Gregor Best <gbe@ring0.de>
Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-09-11 17:34:09 +02:00
Uli Schlachter f05dabd76e spawn: Create sessions for processes (FS#851)
Each process spawned from awesome now gets its own session and process group.
This makes sure they aren't connected to awesome in any way any more. This
especially fixes some problems with signals.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2010-12-04 13:22:47 +01:00
Uli Schlachter 9deafe68c8 Font: Remove, oopango took over the job
Signed-off-by: Uli Schlachter <psychon@znc.in>
2010-10-06 20:09:17 +02:00
Uli Schlachter e0774377ca Sort all signal lists alphabetically
Signed-off-by: Uli Schlachter <psychon@znc.in>
2010-08-26 17:46:17 +02:00
Uli Schlachter ab4c151ed8 Add signals before using them
This commit makes it an error if an unknown signal is connected, disconnected or
emitted. All signals have to be added before they can be used.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2010-08-25 23:00:36 +02:00
Uli Schlachter 6b2e4352bb Remove globalconf.xinerama_is_active
Signed-off-by: Uli Schlachter <psychon@znc.in>
2010-08-16 14:20:45 +02:00
Uli Schlachter e76310ef77 Move the startup notification monitor context to globalconf
Signed-off-by: Uli Schlachter <psychon@znc.in>
2010-08-16 13:57:31 +02:00
Uli Schlachter 32d9a5b2ab Remove support for zaphod mode
This makes awesome support only a single X11 protocol screen. If you are still
using zaphod mode, you can run multiple instances of awesome on the single
screens, e.g.:

DISPLAY=:1.0 awesome & DISPLAY=:1.1 awesome &

Signed-off-by: Uli Schlachter <psychon@znc.in>
2010-08-16 13:47:40 +02:00