Andre Noll [Mon, 6 Jan 2014 20:12:38 +0000 (20:12 +0000)]
gui: Speed up window refresh.
We had way too many calls to wrefresh() which copies the named
window to the physical terminal screen. This slows down the display
considerably, especially on slow machines.
It is more efficient to perform the copy only once per scheduler
iteration. So this commit adds a flag "needs_update" to struct
gui_window, and all callers to wrefresh() are changed to call
refresh_window() instead. This new function is much cheaper since it
only turns on the needs_update flag but does nothing else.
In input_post_select() we check which windows have the flag set and
repaint those windows using wnoutrefresh() and then doupdate(). This
two-step approach is described in the curs_refresh(3X) man page as
more efficient then calling wrefresh() for each window separately
since it avoids alternating calls to wnoutrefresh() and doupdate().
Andre Noll [Sat, 4 Jan 2014 22:16:22 +0000 (22:16 +0000)]
gui: Rename cmd_task to exec_task.
The term "command" currently means either a gui command handler or
the process which is executing as a result of a defined key map. Avoid
this confusion by using the word only for command handlers.
This commit also simplifies exec_cmd() and exec_para() slightly by
moving the "hit any key to abort" message into the common function
exec_and_display().
Andre Noll [Sat, 4 Jan 2014 06:48:36 +0000 (06:48 +0000)]
gui: Move static variables of cmd_post_select() into struct cmd_task.
For the same reason stated in the commit message of the previous patch,
these variables belong to the context structure of the command task,
so move them there.
The COMMAND_BUF_SIZE define had to be moved above the definition of
struct cmd_task since COMMAND_BUF_SIZE uses it.
Andre Noll [Sat, 4 Jan 2014 06:32:04 +0000 (06:32 +0000)]
gui: Move some variables into struct status_task.
pre_select and post_select methods should never define static variables
but store their state in the context structure which also contains
the task structure.
This commit moves the static variables of status_post_select() and the
global variables next_exec and stat_pipe into the context structure
of the status task.
Andre Noll [Sat, 4 Jan 2014 06:04:26 +0000 (06:04 +0000)]
gui: Switch to the standard paraslash scheduler.
Due to the preparations performed in previous patches, this is a
rather simple change. Note we don't need to define a struct signal_task
since this structure is already defined in signal.h.
Andre Noll [Fri, 10 Jan 2014 00:22:07 +0000 (00:22 +0000)]
gui: Use cpp magic to define command handlers.
This shortens the code a bit and avoids duplications. The command
handler for cancel_scroll had to be renamed from com_cancel_scrolling()
to com_cancel_scroll() since the old name did not match command name.
Andre Noll [Sat, 4 Jan 2014 05:38:23 +0000 (05:38 +0000)]
gui: Execute stat command in status_post_select().
pre_select methods should only deal with fd sets and select timeouts,
so the part of status_pre_select() which restarts the status command
belongs to status_post_select().
Unfortunately, after this change both status_pre_select() and
status_post_select() need to know when to restart the stat command.
Therefore we had to add a new global variable next_exec.
The patch also moves status_pre_select() up so that the two functions
are close to each other.
Andre Noll [Sat, 29 Mar 2014 17:31:41 +0000 (18:31 +0100)]
gui: Rename COMMAND/EXTERNAL/GETCH mode.
This value tells if there is a command executing, and if so, whether
it is an external command or a display command. Hence "cmd_status"
is to be more to the point.
Andre Noll [Sat, 29 Mar 2014 12:48:03 +0000 (13:48 +0100)]
gui: Get rid of do_select()'s mode parameter and call it only once.
The current code calls do_select() from three different locations. The
mode parameter indicates whether a command is currently running
and if it is a display command or an external command (where curses
is disabled). This is unnecessarily complex as we can tell from the
values of the command_fd[] array and the cmd_pid variable which mode
we are in.
This commit introduces get_select_mode() which looks at these variables
and returns the current mode. This allows to get rid of the mode
parameter of do_select() and to call do_select() only once at startup
from main(). It now runs in an endless loop, checking the current mode
in each iteration. The other two call sites, exec_and_display_cmd()
and external_cmd(), don't need to call do_select() any more.
This change removes more lines than it adds and makes the logic
of para_gui much simpler to follow. It is also the last big step
to replace the do_select() loop in favor of the standard paraslash
scheduler.
Andre Noll [Sat, 29 Mar 2014 10:34:02 +0000 (11:34 +0100)]
gui: Reorder functions.
As a preparation for the removal of do_select() we need various
functions of gui.c to be in a different order. Specifically,
input_post_select() will soon call handle_command(), so the latter
function will need to be declared before the former.
Patches which move functions around are generally hard to
read, so this commit performs pure code movement only. However,
as exec_and_display_cmd() still calls do_select() we introduce a
temporary forward declaration for do_select(). It will be removed
in the next patch.
Andre Noll [Fri, 3 Jan 2014 19:03:22 +0000 (19:03 +0000)]
gui: Move signal handling code out of do_select().
As a further preparation for employing the standard paraslash scheduler
within para_gui, this simple patch introduces signal_pre_select()
and renames handle_signal() to signal_post_select().
The signal related part of do_select() is moved to these two functions
so that do_select() is reduced to the bare minimum: one call to each
of the two new functions.
Andre Noll [Fri, 3 Jan 2014 18:16:51 +0000 (18:16 +0000)]
gui: Move external command handling out of do_select().
This commit moves the part of do_select() that deals with
external commands to separate functions, command_pre_select() and
command_post_select().
This change shortens do_select() considerably and is another step
towards the goal of using the paraslash scheduling system also for
para_gui.
One thing to note is that the new command_post_select() returns -1 if
both both fds are closed, i.e. when the currently running command has
terminated. This value gets translated back to zero in do_select(),
preserving the current semantics.
Andre Noll [Sun, 26 Jan 2014 17:14:34 +0000 (18:14 +0100)]
gui: Introduce status_post_select().
This moves stat pipe error handling into read_stat_pipe() and renames
the function to status_post_select(), which is more to the point. It
shortens do_select() a bit.
Since status_post_select() now calls print_all_items() and
clear_all_items() it had to be moved down to avoid a forward
declaration.
Andre Noll [Thu, 13 Mar 2014 08:41:44 +0000 (09:41 +0100)]
gui: Improve config reload.
There are two ways to make para_gui reload its config file: Sending
SIGUSR1 and running the internal reread_conf command. When SIGUSR1
is received, signal_post_select() calls com_reread_conf(). This is
a layer violation since command handlers should only be called from
the input task.
This patch provides the generic function reread_conf() which is called
from both the command handler and from signal_post_select().
Andre Noll [Tue, 7 Jan 2014 22:04:21 +0000 (22:04 +0000)]
gui: Unify config file parsing.
The gui config file is parsed on startup, when the reload command
is executed or when SIGUSR1 is received. In all cases we set up a
gengetopt params structure and pass its address to the gengetopt
command line parser.
This commit moves the common code to the new parse_config_file_or_die()
which does the right thing for both the startup and the reload
case. The new function also contains the logic of configfile_exists(),
so this latter function can be removed.
Andre Noll [Thu, 9 Jan 2014 23:34:11 +0000 (23:34 +0000)]
gui: Remove ->cols and ->lines of struct gui_window.
The curses library provides the getmaxyx() macro to obtain the window
geometry. It's better to use these instead of storing the number of
lines and columns in the gui_window structure because with getmaxyx()
there is no risk to have stale values gui_window structure.
While the ncurses implementation provides getmaxx() and getmaxy()
to get only the number of lines or columns, respectively, only
getmaxyx() is described in the XSI Curses standard. Hence we provide
our own version of the former two functions. These call getmaxyx()
and return one of the two numbers.
With the ->cols and ->lines fields of struct gui_window gone, all
callers had to be adjusted to use either getmaxyx() or one of the
new functions.
Andre Noll [Tue, 7 Jan 2014 17:35:08 +0000 (17:35 +0000)]
gui: Combine exit functions.
Currently we have kill_pg_and_die(), finish(), msg_n_exit(), which
is kind of excessive. This patch replaces these three functions by
the single die() which does the right thing in all cases.
Andre Noll [Tue, 7 Jan 2014 15:59:27 +0000 (15:59 +0000)]
gui: Parse command line options only once.
There is no point in calling gui_cmdline_parser_ext() when rereading
the configuration since this parser only looks at the command line
options which never change.
Removing the call in com_reread_conf() also allows to get rid of the
global _argc and _argv variables.
Andre Noll [Sun, 5 Jan 2014 20:48:29 +0000 (20:48 +0000)]
gui: Replace global variable curses_active by a function.
There is no need to store this information as we can easily compute it.
shutdown_curses() needed to be changed to cope with early failures:
On fatal errors that happen after initscr() was called but before
the top window exists, we must shut down the curses subsystem albeit
curses_active() returns false in this case.
Andre Noll [Tue, 7 Jan 2014 00:25:38 +0000 (00:25 +0000)]
Remove chop().
In curses_log() we currently we call chop(), which calls strlen()
to find the last character of the given string. This is unnecessary
since xvasprintf() returns this information anyway, we just have to
remember it.
With this change the last user of chop() is gone, so this patch
removes chop() from string.c.
Andre Noll [Mon, 6 Jan 2014 02:45:28 +0000 (02:45 +0000)]
gui: Use whline() for drawing the separator.
This should be slightly more efficient.
This patch also changes the type of struct gui_theme->sep_str from
const char * to plain char and renames the field to sep_char. It must
be a single-character string anyway.
For the colorful blackness theme we now use the default character
from curses.h rather than '-'. This looks nicer. Tested with ncurses
on Linux and the curses implementation that ships with NetBSD.
Andre Noll [Tue, 7 Jan 2014 19:20:13 +0000 (19:20 +0000)]
gui: Remove welcome message.
The only information shown by print_welcome() that is not already
contained in the status bar is the name of the current theme. This
is not very interesting, so remove the function and the corresponding
color pair.
Andre Noll [Sun, 26 Jan 2014 17:39:56 +0000 (18:39 +0100)]
gui: Simplify print_status_bar().
Curses is always active at this point, so remove the check. Moreover,
refreshing of all other windows is performed in init_wins(), so move
the call to wrefresh() there to be consistent. Finally, the comment
of this function is rather pointless, so remove that as well.
Andre Noll [Sun, 26 Jan 2014 16:00:20 +0000 (17:00 +0100)]
gui: Add trailing newline to all log messages.
Currently we have a funny mixture of the two styles. This is no problem
since curses_log() will chop the trailing newline. But let's better
be consistent.
Andre Noll [Sat, 29 Mar 2014 12:48:40 +0000 (13:48 +0100)]
gui: Initialize command_fds to -1.
We check at various locations whether the two members of the
command_fds array are negative to tell if an external command or a
display command is currently running. At startup, there is no such
command, hence the two integers of the array should be initialized
to a negative value.
Andre Noll [Fri, 3 Jan 2014 23:42:38 +0000 (23:42 +0000)]
gui: Reset command buf offset on errors.
On read errors or EOF we close the pipe that corresponds to
stdout/stderr of the current display command. However, we miss to
reset the offset value of the command buffer in this case. If this
offset was positive at the time the read error occurred, we skip the
first part of the output of the next command.
Fix this by always resetting the offset after closing the pipe.
Andre Noll [Tue, 7 Jan 2014 16:14:12 +0000 (16:14 +0000)]
gui: Shut down curses before rereading the config file.
If the config file contains errors, gui_cmdline_parser_config_file()
calls exit() while curses is still active, leading to messed up
terminal settings. Fix this by calling shutdown_curses() before
parsing the config file, and init_curses() thereafter.
Andre Noll [Sat, 3 May 2014 17:56:01 +0000 (19:56 +0200)]
Merge branch 't/alsa_improvements'
Was cooking for almost two months.
* t/alsa_improvements:
alsa: Remove pointless initialization.
alsa_mix: Allow non-positive mixer values.
alsa: New writer option: --buffer-time.
alsa: Work around poll fd problems.
alsa: Set period time.
alsa: Also dump hardware params.
alsa: Improve help text of --device.
alsa: Improve documentation of struct private_alsa_write_data.
alsa: Don't set t->error in ->pre_select().
Andre Noll [Tue, 31 Dec 2013 15:44:24 +0000 (15:44 +0000)]
Remove client_disconnect().
Everything this function does can be done as well when the task
terminates by returning negative in ->post_select().
This also avoids to leak the stream cipher structure of the previous
connection when running in interactive mode.
1,032 bytes in 1 blocks are definitely lost in loss record 61 of 85
at 0x402994A: malloc (vg_replace_malloc.c:263)
by 0x804C689: para_malloc (string.c:71)
by 0x804FF87: sc_new (crypt.c:268)
by 0x804E204: client_post_select (client_common.c:370)
by 0x804D203: schedule (sched.c:59)
by 0x804A2E7: main (client.c:500)
1,032 bytes in 1 blocks are definitely lost in loss record 62 of 85
at 0x402994A: malloc (vg_replace_malloc.c:263)
by 0x804C689: para_malloc (string.c:71)
by 0x804FF87: sc_new (crypt.c:268)
by 0x804E217: client_post_select (client_common.c:371)
by 0x804D203: schedule (sched.c:59)
by 0x804A2E7: main (client.c:500)
Andre Noll [Tue, 31 Dec 2013 13:29:16 +0000 (13:29 +0000)]
Fix memory leak in btr_splice_out_node().
Commit 072391fc (Improve btr_splice_out_node(), 2013-03) modified this
function to take a pointer to a buffer tree node pointer so that the
node pointer can be invalidated after it is spliced out. However, this
also means the caller can no longer free its resources. Hence we must
free the btrn in btr_splice_out_node() in order to avoid memory leaks.
Andre Noll [Fri, 4 Apr 2014 12:23:44 +0000 (14:23 +0200)]
audiod: Avoid segfault on exit.
When para_audiod terminates, it calls clean_exit() which closes
all slots unconditionally, regardless of whether they are in use.
This may lead to a segfault due to an invalid read:
==25253== Invalid read of size 4
==25253== at 0x40EBEA: close_slot (audiod.c:443)
==25253== by 0x40FCE8: clean_exit (audiod.c:1163)
==25253== by 0x40FD7D: signal_post_select (audiod.c:1014)
==25253== by 0x41490A: schedule (sched.c:65)
==25253== by 0x406BC3: main (audiod.c:1436)
==25253== Address 0x5c19d8 is not stack'd, malloc'd or (recently) free'd
This bug was introduced 9 month ago in commit eec23a69 (audiod:
Fix memory leak on exit: close slots). Fix it by calling
close_unused_slots(). This also simplifies clean_exit() a bit.
Andre Noll [Sun, 30 Mar 2014 16:31:57 +0000 (18:31 +0200)]
Merge branch 't/misc'
Various fixes, improvements, cleanups. Cooking since 2014-02-22.
* t/misc: (29 commits)
build: Don't link with -lreadline if readline was not found.
audiod: Skip NULL pointer check in compute_time_diff().
audiod: Make compute_time_diff() return void.
com_stat(): Remove pointless uptime variable.
gcrypt: Fix gcc warning on Ubuntu Lucid.
flac: Try to link also without -logg.
version.c: Fix comment of version_single_line().
doxygen: Expand all macros, in particular config.h.
recv_common.c: Improve documentation of check_receiver_arg().
audiod: get_time_string() comment fix.
configure: Really print opus audio file handler if opus lib was found.
Overhaul doxygen main page.
afs.h: Don't try to list all supported audio formats.
Change copyright year to 2014.
Add link to sideband.h in doxygen main page.
Doxify error2.c and add GPL header.
Add -Wdeclaration-after-statement.
Add some missing includes.
Makefile.real: Add clean2 to the list of phony targets.
mood.c: Fix a trivial whitespace issue.
...
Andre Noll [Sun, 23 Mar 2014 18:21:37 +0000 (19:21 +0100)]
Merge branch 't/fade_improvements'
Cooking since 2014-02-08.
* t/fade_improvements:
fade: Improve error diagnostics.
fade: Switch to the fade-in mood *before* sleeping.
fade: Allow to set more than one channel in sleep mode.
fade: Implement new mode "set".
fade: Log to stderr.
Andre Noll [Mon, 9 Sep 2013 03:53:32 +0000 (03:53 +0000)]
alsa: New writer option: --buffer-time.
This removes the old way of setting of private_alsa_write_data->buffer_time
Currently we set the buffer time to the minimum of the maximum
buffer time and 500ms. This results in different values for different
hardware. In view of the introduction of the sync filter it seems to
be desirable to have more control over this value.
This patch adds the --buffer-time config option to the alsa
writer which allows to specify a suitable value, the default being
170ms. The unit of private_alsa_write_data->buffer_time is changed
from microseconds to milliseconds as this avoids to divide by 1000
in ->pre_select().
Andre Noll [Thu, 13 Jun 2013 08:53:55 +0000 (10:53 +0200)]
alsa: Work around poll fd problems.
In its ->pre_select method the alsa writer adds the alsa poll file
descriptor to the set of fds to be monitored during the next select
call. When this fd is ready for I/O, select() returns and ->post_select
is called. Currently ->post_select checks if the alsa poll fd is set
and returns early if it is not.
The problem is that on some hardware/kernel/alsa-lib combinations,
the poll fd is never marked as ready for I/O. This happens at least
on the raspberry pi with linux-3.10.10 and alsa-lib-1.0.27. The result
is no audio at all.
We address this problem in two ways:
* In alsa_init() we remember the buffer duration for later use in
->pre_select where we ask the scheduler to impose half of the duration
as an upper bound on the select timeout.
* In ->post_select, if there is input data available, we don't
check any more whether the poll fd is ready but try to write
unconditionally. On EAGAIN, we read from the poll fd to discard any
pending events.
Andre Noll [Thu, 27 Feb 2014 18:10:55 +0000 (19:10 +0100)]
Merge branch 't/cmd_improvements'
Cooking since 2014-01-16.
* t/cmd_improvements:
afs.cmd: Strip redundant "sort" from ls help output.
audiod.cmd: Improve grab client help text.
afs.cmd: Improve second level indenting.
afd.cmd: Fix a trivial whitespace issue.
Andre Noll [Wed, 26 Feb 2014 18:16:03 +0000 (19:16 +0100)]
build: Check whether rl_free_keymap is declared.
Readline versions up to and including 6.2 miss to declare the public
symbol rl_free_keymap(). We currently work around this issue by
manually declaring the function in interactive.c.
The recently released readline-6.3, however, does declare that symbol.
Since we compile with -Wredundant-decls this leads to the following
warning:
interactive.c:239:6: warning: redundant redeclaration of 'rl_free_keymap' [-Wredundant-decls]
void rl_free_keymap(Keymap keymap);
This patch gets rid of the warning by adding a check to configure.ac
which detects whether the symbol is declared in the readline header
file. Only if it is uncdelared we declare it manually as before.
Andre Noll [Sat, 22 Feb 2014 16:29:10 +0000 (17:29 +0100)]
Merge branch 't/sync'
Cooking since 2014-01-14.
* t/sync:
The sync filter.
net: Let maksock() callers perform flowopt cleanup.
net: makesock_addrinfo(): Make socketfd local to the loop.
net: Let makesock() continue on setsockopt() failure.
net: Reduce indentation level in makesock_addrinfo().
net: Further simplify makesock_addrinfo().
net: Replace the double loop of lookup_address() by a single loop.
net: makesock(): Combine code for passive sockets.
net: Change makesock_addrinfo() to set given flowopts before SO_REUSEADDR.
net: Clarify code flow of makesock_addrinfo().
net: Remove unnecessary condition in makesock_addrinfo().
net: Remove pointless initialization in makesock_addrinfo().
net: Kill dead code in makesock_addrinfo().
net: Remove networking headers from para.h.
net: Improve error handling of makesock_addrinfo().
net: Split makesock(), part 2: Introduce makesock_addrinfo().
net: Split makesock(), part 1: Introduce lookup_address().
net: Simplify makesock().
net: Fix parse_url().
net: Correct \return text of parse_url().
Andre Noll [Mon, 27 Jan 2014 12:54:49 +0000 (13:54 +0100)]
flac: Try to link also without -logg.
If libflac was compiled without ogg support, the build system should
include flac even if libogg is not installed. Currently this does
not work because the autoconf test tries to link with -logg, so it
always fails if libogg is not available.
Andre Noll [Fri, 3 Jan 2014 05:59:22 +0000 (05:59 +0000)]
Overhaul doxygen main page.
It got way too large, and contained quite a few links to .c files
whose doxygen page is not very interesting. For example, the doxygen
page of the .c files of filters, receivers and writers contain only
the init function since all other functions are static.
This commit limits the number of links on the main page considerably.
The new page tries to focus on important data structures and APIs
and does not strive for completeness.
Andre Noll [Wed, 1 Jan 2014 00:00:34 +0000 (00:00 +0000)]
Change copyright year to 2014.
This year, we're really on time. The changes in this patch were
created by the following silly script:
files=$(git grep -l 'Copyright (C) [0-9]\{4\}\(-2013\)* Andre Noll')
sed --in-place= -e 's/Copyright (C) \([0-9]\{4\}\)-2013 Andre Noll/Copyright (C) \1-2014 Andre Noll/1' $files
sed --in-place= -e 's/Copyright (C) 2013 Andre Noll/Copyright (C) 2013-2014 Andre Noll/1' $files