summaryrefslogtreecommitdiff
path: root/interactive.c (follow)
Commit message (Collapse)AuthorAge
* Switch to SPDX identifiers.Andre Noll2026-03-17
| | | | | | | | Generated with sed -i 's|Copyright.*Andre Noll.*|SPDX-License-Identifier: GPL-2.0 */|g' *.c *.h followed by manually tweaking the result a bit. No license change intended.
* Improve i9e documentation.Andre Noll2025-10-08
| | | | | The new file comment for interactive.h, a few reworded comments and a bit of dedox for interactive.c.
* Merge topic branch t/completion into masterAndre Noll2025-06-14
|\ | | | | | | | | | | | | | | | | | | | | | | | | The completers for para_client and para_audioc handle some cases incorrectly or not at all. This series improves on that. * refs/heads/t/completion: Revamp bash_completion. bash completion: Fix help option parsing. audioc: Fix option completion of version and stat. i9e: Introduce i9e_get_nonopt_argnum(). i9e: Introduce i9e_cword_is_option_arg(). i9e: Constify i9e_complete_option().
| * i9e: Introduce i9e_get_nonopt_argnum().Andre Noll2025-05-18
| | | | | | | | | | Call the new function from various subcommand completers to attempt completion only on the first or the first two non-option arguments.
| * i9e: Introduce i9e_cword_is_option_arg().Andre Noll2025-05-18
| | | | | | | | | | | | | | | | | | | | | | | | Call the new function to complete --admissible, --sort and --listing-mode of the ls subcommand and teach the touch completer to prevent filename completion if a numerical argument is expected. The grab subcommand of para_audiod also benefits from the new helper: para_audioc learned to complete the three different grab modes. Since --admissible expects a mood or playlist argument, factor out the code from the select completer which returns the list of all moods and playlists so that it can be called by the ls completer as well.
| * i9e: Constify i9e_complete_option().Andre Noll2025-05-18
| | | | | | | | | | | | i9e_extract_completions() and i9e_complete_option() both take a char ** argument for the option/string list although they do not modify the pointers of the list. This commit marks these pointer variables constant.
* | i9e: Constify completer arrays.Andre Noll2025-06-10
| | | | | | | | This way the array of completers goes into the rodata section.
* | Include regex.h from para.h.Andre Noll2025-05-19
|/ | | | Every .c file includes it anyway.
* i9e: Rename i9e_completer() -> attempt_completion().Andre Noll2025-04-23
| | | | | | The old name is confusing since we also have struct i9e_completer, which is a completely different beast. Rewrite the documentation of the function while at it.
* i9e: Clear history on close.Andre Noll2024-08-31
| | | | | | | | | This frees each history entry and the history itself, reducing the amount of memory leaked by readline applications on exit. Normally, this should not be used since it leaks the memory associated with the user defined history data pointer of each entry. However, that's OK here because the i9e subsystem ignores this feature of the history library.
* Consolidate EOF error codes.Andre Noll2023-03-11
| | | | | | Currently we have ~15 error codes which indicate an EOF condition. One should suffice, so drop all codes except the generic E_EOF and use that everywhere.
* Merge topic branch t/overflow into masterAndre Noll2022-10-03
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This series implements a new memory allocation API which checks for overflows. The first part of the series just renames the main allocation functions. Later patches in the series implement allocators which take two size_t arguments (like calloc(3)) and check whether the multiplication overflows by employing the __builtin_mul_overflow() primitive supported by gcc and clang. This requires us to bump the lowest supported gcc and clang version. * refs/heads/t/overflow: build: Compile with -ftrapv. string: Introduce arr_zalloc(). string: Introduce arr_alloc(). string: Introduce arr_realloc() and check for integer overflow. string: Rename para_calloc() -> zalloc(). string: Rename para_malloc() -> alloc(). string: Overhaul para_strdup().
| * string: Introduce arr_alloc().Andre Noll2022-07-29
| | | | | | | | | | | | | | | | Change all callers of alloc() which pass a product of two integers as the allocation size to call the new function instead. This function aborts if the multiplication overflows. With arr_alloc() in place, alloc() reduces to a trivial wrapper which calls new arr_alloc() with the first argument equal to one.
| * string: Introduce arr_realloc() and check for integer overflow.Andre Noll2022-07-29
| | | | | | | | | | | | | | | | Use __builtin_mul_overflow() for the check. This builtin was introduced in gcc-5, so we need to bump the lowest supported version. Re-implement para_realloc() as a trivial wrapper for arr_realloc() to simplify and to avoid duplicating the size check.
| * string: Rename para_malloc() -> alloc().Andre Noll2022-07-29
| | | | | | | | | | | | | | Just because it's shorter and matches the naming of the new allocators we are about to introduce. The bulk of this patch was created with sed -i 's/para_malloc/alloc/g' *.c *.h yy/mp.y
* | i9e: Remove \return from documentation of i9e_attach_to_stdout().Andre Noll2022-09-27
| | | | | | | | | | | | The function returns void. Fixes: 367daa451bd837c3e267c8385bbc92898f06ecca
* | Merge branch 'refs/heads/t/ll'Andre Noll2022-09-18
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Two little cleanups related to the logging facility and two commits which add the ll command to para_server and para_audiod. The merge resulted in a conflict in afs.c due to the earlier merge of the poll topic branch which replaced all calls to select() by calls to poll(). The implementation of the ll server command introduced a new caller of select(), afs_select(), which needs to be replaced by afs_poll() to resolve the conflict. * refs/heads/t/ll: New server command: ll to change the log level at runtime. New audiod command: ll to change the log level at runtime. daemon: Kill get_loglevel_by_name(). server/audiod: Don't parse loglevel argument unnecessarily.
| * | New server command: ll to change the log level at runtime.Andre Noll2022-07-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This makes use of the infrastructure introduced in the previous patch. However, the implementation of the ll command for para_server is more involved than its audiod counterpart because in the server case we have to tell two different processes (server and afs) to change their log level while the calling process, the command handler, does not need to set the loglevel because it is about to exit anyway. For the inter-process communication we introduce a new field in the mmd shared memory area so that command handlers can read the current value or set a new value. The log level propagates from there via daemon_set_loglevel() to the server and afs processes during each iteration of the scheduler loop where para_log() will pick it up to set the log level threshold for subsequent log events. The si command handler currently refers to the argument of the --loglevel server option to include the log level in its output. With dynamic log levels this no longer works because it always prints the value from the command line or the config file rather than the run time log level. Since the new ll command also prints the loglevel when it is executed with no arguments, we simply remove this line from the si output and hope that nobody cares. The si command handler was the last user of the ENUM_STRING_VAL macro in command.c. Removing the macro also allows us to make CMD_PTR local to server.c and to remove the lopsub definitions of the server suite from command.c. However, we still include the lopsub definitions of the server *command* suite (server_cmd.lsg.h) of course. We let any authenticated user run the command with no arguments to report the current loglevel but require full privileges to change the loglevel. Thus, the check for sufficient privileges needs to be performed in the command handler.
| * | New audiod command: ll to change the log level at runtime.Andre Noll2022-07-02
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | The new public daemon_get_loglevel() is needed in the zero argument case. Otherwise, the ll command handler parses the argument and calls daemon_set_loglevel(). The lopsub stanza for the subcommand is stored in a separate file which is currently only included by the lopsub suite for para_audiod, but will be included as well by the server suite. For similar reasons we implement the completer as a generic public function, i9e_ll_completer(), although it only has one caller in audioc.c. Another caller follows when the ll server command is added.
* | Switch from select(2) to poll(2).Andre Noll2022-08-28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The select(2) API is kind of obsolete because it does not work for file descriptors greater or equal than 1024, The general advice is to switch to poll(2), which offers equivalent functionality and does not suffer from this restriction. This patch implements this switch. The fd sets of select(2) have one nice feature: One can determine in O(1) time whether the bit for a given fd is turned on in an fd set. For poll(2), the monitored file descriptors are organized in an array of struct pollfd. Without information about the given fd's index in the pollfd array, one can only perform a linear search which requires O(n) time, with n being the number of fds being watched. Since this would have to be done for each fd, the running time becomes quadratic in the number of monitored fds, which is bad. Keeping the pollfd array sorted would reduce that to n * log(n) at the cost of additional work at insert time. This patch implements a different approach. The scheduler now maintains an additional array of unsigned integers which map fds to indices into the pollfd array. This new index array is transparent to the individual tasks, which still simply pass one or more fds from their ->pre_monitor() method to the scheduler. The length of the index array equals the highest fd given. This might become prohibitive in theory, but should not be an issue for the time being. Care needs to be taken in order to deal with callers which ask for the readiness of an fd without having called sched_monitor_readfd() or sched_monitor_writefd() in the ->pre_monitor() step. Before the patch, thanks to the FD_ZERO() call at the beginning of each iteration of the scheduler's main loop, both sched_read_ok() and sched_write_ok() returned false for fds which were not asked to be watched. We need to keep it this way for a seamless transition. We achieve this by replacing the FD_ZERO() call by a memset(3) call which fills the index array with 0xff bytes. Both sched_read_ok() and sched_write_ok() call the new get_revents() helper, where we check the fd argument against the allocation sizes of the two arrays. If either function is called with an fd that was not asked to be monitored in the ->pre_monitor() step, the checks notice that the index of this fd, 0xffffffff, is larger than the highest open fd and we return "not ready for I/O". Another issue is the case where the same file descriptor is submitted twice in ->pre_monitor() to check for readiness with respect to both reading and writing. The code in client_comon.c currently does that. To keep it working, the scheduler needs to detect this case and re-use the existing slot in both arrays.
* | Rename ->{pre,post}_select methods to ->{pre,post}_monitor.Andre Noll2022-08-25
| | | | | | | | | | | | | | The word "monitor" is neutral and continues to be correct after the switch from select(2) to poll(2). Pure rename, nothing to see here.
* | Hide implementation of para_fd_set().Andre Noll2022-08-25
| | | | | | | | | | | | | | | | This preparatory patch for replacing select() renames para_fd_set() to sched_fd_set(), moves it to sched.c and makes it static. All users are modified to call either of the two new public functions sched_monitor_{read,write}fd() which take a pointer to struct sched rather than an fd set pointer.
* | interactive: Avoid select(2) in input_available().Andre Noll2022-08-25
| | | | | | | | | | | | | | | | | | | | | | In analogy to write_ok(), introduce read_ok() which uses poll(2) rather than select(2). To avoid duplications, abstract out the common code to the new xpoll() helper. We could avoid the timeout parameter of xpoll() at this point because both callers call it with a zero timeout (causing poll() to return immediately), but later patches introduce other callers which specify non-zero timeouts.
* | sched: Use integer value for select timeout.Andre Noll2022-08-25
| | | | | | | | | | | | | | | | | | | | | | | | | | This modifies the public struct sched so that users pass in the default timeout as an integer value in milliseconds rather than a struct timeval. This simplifies the code a little and eases the transition from select(2) to poll(2) because poll(2) also takes a plain integer for the timeout. Since para_select() of fd.c now calls ms2tv() to convert the timeout back to a struct timeval, all executables which link with fd.o must also link with time.o. This was not the case for para_mixer and para_audioc, so configure.ac needs to be adjusted accordingly.
* | Merge branch 'maint'Andre Noll2022-08-21
|\ \ | |/ |/| | | Two fixes for para_play.
| * i9e: Fix invalid key handling.Andre Noll2022-08-21
| | | | | | | | | | | | | | | | | | | | | | | | If an unmapped key is pressed repeatedly, we store the key sequence in a 32 byte buffer until there is no more space left in the buffer. Then we terminate the process with para_play: interactive.c:304: i9e_post_monitor: Assertion `len < sizeof(i9ep->key_sequence) - 1' failed. This is not a nice way to deal with invalid input, so be a bit more graceful and discard the buffer when it is full or when there is no further input available at the moment.
| * i9e: Fix braino in i9e_post_select().Andre Noll2022-08-21
| | | | | | | | | | | | Due to this bug we mishandled the case where the read() returns zero to indicate EOF. In this case we stuffed a random character instead of shutting down the i9e task.
* | i9e: Fix typo: s/ie9/i9e.Andre Noll2021-11-14
|/ | | | | | | It's weird that this was not noticed for so long. Fixes: e541d7bea7febed8cb9f8a65ae4bd9bdd1b5c8a0 Fixes: 3e3d8e1b48bbd8dbf46adf517c311b5e78dc820f
* Fix i9e completion.Andre Noll2019-02-10
| | | | | i9e_print_completions() does not work as intended when the cursor is positioned right after a word. This patch should fix it.
* Shorten copyright notice.Andre Noll2017-09-22
| | | | | | | | | | | | | | | | | | | | | The GPLv2 line does not add any additional information, so drop it. This leaves a single line of legalese text for most files, which is about the amount of screen real estate it deserves. This patch was created with the following script (plus some manual fixups): awk '{ if (NR <= 5) { gs = gensub(/.*Copyright.* ([0-9]+).*Andre Noll.*/, "\\1", "g") if (gs != $0) year = gs next } if (NR == 6 && year != "") printf("/* Copyright (C) %s Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */\n", year) print }'
* Merge branch 'refs/heads/t/rm_osx'Andre Noll2017-04-04
|\ | | | | | | | | | | | | | | | | Two simple patches which remove code and documentation related to Mac OS. Cooking since 2017-01-04. * refs/heads/t/rm_osx: build: Remove compatibility check for clock_gettime(). Drop support for Mac OS.
| * Drop support for Mac OS.Andre Noll2017-01-04
| | | | | | | | | | | | | | | | | | | | This software hasn't been tested on Mac OS for years, so Mac OS support is most likely already broken. This commit removes the osx writer and the autoconf tests for core audio, and adjusts the documentation to not mention Mac OS anymore. It also effectively reverts commit be1074b4 which introduced an ugly workaround in interactive.c that was only needed on Mac OS.
* | i9e: Restore file status flags on exit.Andre Noll2017-01-28
|/ | | | | | | | | | | | The i9e subsystem sets the stdin and stdout fds passed to i9e_open() to nonblocking mode but misses to restore the original flags in i9e_close(). This causes terminal applications like dialog to fail if they are started in the same terminal after e.g. para_play was executed. This commit modifies i9e_open() to fetch and save the file status flags before setting the O_NONBLOCK flag, and i9e_close() to restore the original value. STDERR is not affected.
* i9e: Replace assertion with warning.Andre Noll2016-04-02
| | | | | | | The assertion in dispatch_key() can easily be triggered with keys that map to multi-byte sequences. This patch prevents para_play from aborting when such a key is pressed. It now issues a warning message, but no longer aborts.
* i9e: Fix compilation on Ubuntu-12.04.Andre Noll2016-04-02
| | | | | | | | | | | | | Commit c0162946 (i9e: Avoid key binding macros) from half a year ago broke compilation for readline-6.2, which ships at least with Ubuntu-12.04. The problem is that c0162946 changed dispatch_key() to use rl_executing_keyseq, a readline variable that was introduced in readline-6.3. Compilation fails on systems with readline-6.2 or older because the variable does not exist. This patch modifies interactive.c to provide an equivalent of rl_executing_keyseq and changes dispatch_key() to use this version instead.
* i9e: print warning if keyseq can not be mapped.Andre Noll2016-04-02
| | | | | | | | | | In i9e_open() we currently ignore errors from rl_generic_bind(), which is OK, but we should at least let the user know that the binding won't work. While at it, call rl_bind_keyseq_in_map() instead of rl_generic_bind() as the former function provides all we need and is simpler. Also fix the typo in the comment.
* i9e: Zero out private pointer on open.Andre Noll2016-04-02
| | | | | | | | This should not matter at the moment since i9e_open() is only called once and the i9e_private structure is static, so it's already zeroed out by the first time the function is called. But since the ie9 API is supposed to work across multiple open/close cycles, it seems wise to be conservative here.
* i9e: Remove pointless call to rl_set_keymap() in i9e_open().Andre Noll2016-03-23
| | | | | The call to rl_set_keymap() can be removed since i9e_attach_to_stdout() already activates the bare key map.
* i9e: Remove stale comment for dispatch_key().Andre Noll2016-03-23
| | | | Should have been removed when we switched to key sequences.
* i9e: Remove stale comment for i9e_signal_dispatch().Andre Noll2016-03-23
| | | | The function also cares about SIGWINCH.
* i9e: Remove unused member of struct i9e_private.Andre Noll2016-03-23
|
* i9e: Avoid key binding macros.Andre Noll2015-10-25
| | | | | | | | | | | | | | | | | | | | | | | The key binding code of interactive.c is quite an ugly hack which is marked with a FIXME comment since forever. We bind each key sequence given in the ->bound_keyseqs array of struct i9e_client_info to a key code which is then mapped to a command handler provoded by the application. The bindings started at key 64 with an arbitrary limit of 32 possible mappings. Besides being ugly, the problem with this mapping scheme is that upper case keys are also in this range and are hence also mapped to the specified commands. This commit takes another approach. We now bind key sequences to a function instead of a macro, passing ISFUNC as the first parameter to libreadline's rl_generic_bind(). All key sequences are bound to the same function, dispatch_key(), which calls the application-defined key handler. This is still not optimal because we need to look up the key sequence again in dispatch_key(). But since this is not a fast path anyway, it should be OK.
* interactive.c does not depend on curses.h.Andre Noll2015-02-19
| | | | | | | | | On systems where libreadline is installed but curses headers are not, the build fails because interactive.c, which includes curses.h, is attempted to be compiled. Fortunately, it is unnecessary to include this header, so this commit removes the include directive. However, we must include para.h before the readline headers because the latter depend on stdio.h.
* Update year in copyright headers.Andre Noll2015-01-12
| | | | | | | | | | | | | | | | Done with files=$(git grep -l 'Copyright (C) [0-9]\{4\}\(-2014\)* Andre Noll') sed --in-place= -e 's/Copyright (C) \([0-9]\{4\}\)-2014 Andre Noll/Copyright (C) \1 Andre Noll/1' $files In previous years we ran a similar script to set the second year in the range to the current year. This is kind of silly, so let's get rid of this useless information. This commit replaces "Copyright (C) A-B" by "Copyright (C) A" in all file headers, i.e. only the first year (A) is left in. Accurate information including time stamps for each change can be obtained from the git history.
* Remove unnecessary system header includes.Andre Noll2015-01-12
| | | | All these headers get included from para.h.
* doc: Change email address to maan@tuebingen.mpg.deAndre Noll2014-08-18
| | | | | | | | | | | | | | The mail server on systemlinux.org was down for more than a week lately, so let's use an alternative official address. This commit changes all maan@systemlinux.org addresses to maan@tuebingen.mpg.de. Most .c and .h files contain the email address in the copyright header, so they must all be patched. Three other files contain the address for a different reason: * README lists email and git, gitweb and home page URLs * configure.ac needs it for configure -h * version.c contains it for the -V option of all commands
* sched: Directly pass context pointer to pre/post_select().Andre Noll2014-05-25
| | | | | | | | | | | | | | | The patch is large, but it's fairly straight forward: Instead of a task pointer all ->pre_select() and ->post_select() methods now receive the context pointer that was passed to the scheduler when the task was registered. This allows to kill the public task_context(). Two pre_select/post_select functions are not directly called by the scheduler: session_post_select(), generic_recv_pre_select(). These are changed to receive a proper struct rather than a void pointer. Note that generic_filter_pre_select() is not changed in this manner because some filters do not provide a pre_select wrapper but set task->pre_select to generic_filter_pre_select().
* sched: Introduce task_status().Andre Noll2014-05-25
| | | | | | | | | | | Before struct task can be made private to sched.c we must eliminate code which directly accesses the fields of this structure. The last offender is ->error: in many places we check this field to detect whether some task is in an error condition. This patch provides a public accessor function, task_status(), for this purpose. All users of ->error are modified to call this function instead.
* sched: Remove register_task().Andre Noll2014-05-25
| | | | | Now that all users of this function have been converted to task_register(), the old function can go away.
* task_register() conversion: i9e taskAndre Noll2014-05-25
|