summaryrefslogtreecommitdiff
path: root/stdout.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.
* Fix some doxygen comments related to stdin and stdout.Andre Noll2026-02-25
|
* Fix two stdin/stdout related memory leaks.Andre Noll2025-11-17
| | | | | | | | | | | | The moderately recent commit which revamped the stdin/stdout API missed to patch the client code to call the cleanup functions {stdin,stdout}_free() introduced by that commit. Also, both {stdin,stdout}.c missed to remove the buffer tree node in certain cases. The additional btr_remove_node() calls fix this, and they don't hurt since this function is idempotent. Fixes: c30b3cf7b9eb76f6b0a6259a4f630017de804608
* Revamp the stdin/stdout API.Andre Noll2025-08-27
| | | | | | | | | | | | | | | | | | With the current API it is impossible to free the memory that was allocated by stdin_task_register() after schedule() returns. This commit replaces the APIs defined in stdin.h and stdout.h to remove the memory leaks which are inevitable with the old API. We also make struct stdin_task and stdout_task opaque because the API users (client.c, filter.c, recv.c and write.c) should not be able to manipulate the fields of these structures directly. The new stdout API differs from the new stdin API only in that stdout_new() needs an additional argument to let the caller pass in a pointer to the parent buffer tree node. Other than that, the APIs are symmetric. Use the opportunity to do the non-blocking dance in std{in,out}_new() and std{in,out}_free() rather than in the post-monitor functions. This way we may get rid of the silly ->must_set_nonblock_flag boolean of struct std{in,out}_task.
* 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.
* stdin/stdout: Streamline documentation of {pre,post}_select().Andre Noll2022-08-25
| | | | Don't state the obvious and avoid talking about fd sets.
* 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.
* sched: Introduce sched_{read,write}_ok().Andre Noll2022-08-25
| | | | | Two trivial wrappers for FD_ISSET() which hide the fact that we're still using the select(2) API.
* 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 'maint'Andre Noll2017-08-06
|\ | | | | | | | | * maint: stdin/stdout: Only set nonblock flags for non-tty fds.
| * stdin/stdout: Only set nonblock flags for non-tty fds.Andre Noll2017-08-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Although the ->post_select methods of all paraslash executables perform I/O only when select(2) reports that the file descriptor is ready, we set the O_NONBLOCK flag for all monitored fds. This is considered good practice because, in general, it might happen that a subsequent read(2) call blocks even if select(2) indicates that the fd is ready for reading. For example, an fd corresponding to a TCP socket might be flagged as ready for reading if a network packet with incorrect checksum has arrived, but a subsequent read(2) blocks until the packet has been retransmitted. However, stdin and stdout often correspond to a terminal device where the above scenario won't happen. Moreover, for terminals it's essential to reset the O_NONBLOCK flag to the old value on exit because the shell refers to the same file description and thus shares the file status flags, including O_NONBLOCK. Many terminal applications, for example dialog(1), expect stdout to be set to blocking mode and fail in arcane ways if O_NONBLOCK is set. When the stdin and stdout tasks are about to exit, they reset the file status flags back to the original values. However if "para_client stat" is killed with SIGINT, SIGTERM or SIGKILL, or put to sleep with SIGSTOP, the O_NONBLOCK flag remains set because para_client does not handle signals at all. para_recv, para_filter and para_write suffer from the same issue. Adding signal handling to these programs would not help in the SIGSTOP case because this signal can not be caught. This patch modifies stdin.c and stdout.c to no longer set O_NONBLOCK for fd 0 and fd 1 if these fds are associated with a terminal device. This is much easier and should do the job as well.
* | doxygen: Add \ref to references.Andre Noll2017-06-25
|/ | | | | This way doxygen issues a warning if the file/function/structure no longer exists and a stale reference remains.
* 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 alternative task API.Andre Noll2014-05-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the current implementation struct task is public so users of this structure can mess with internal scheduler details as they please. This has led to many bugs and questionable code in the past. This commit is the first step to overcome this design mistake. At the end of this patch series struct task can be made private to sched.c. This commit introduces the following new public functions: * task_register, * task_context, * sched_shutdown. It also adds the new public task_info structure which carries the information passed to the scheduler when a new task is registered. This structure will stay public while struct task will become private once all users have been converted. task_register() is supposed to eventually replace register_task(). The main difference of the two is that the new function returns a _pointer_ to a task structure which is allocated dynamically. Users are not supposed to look at the fields of this pointer directly. task_context() is a temporary helper which can be removed again at the end of the series. Its sole purpose is to return the context pointer which was passed at task register time as part of struct task_info. The final new function, sched_shutdown(), deallocates the task structures allocated during task_register() to cleanly shut down the scheduler after all tasks have terminated. All users need to be converted to the new API. This patch only converts the stdout task though. The other tasks will be converted in subsequent patches. The scheduler can tell if a task was registered using the new API by means of the new ->owned_by_sched bit of struct task. This boolean variable can also be removed after all tasks have been converted. Some users will need to query the exit status of a terminated task. Hence we keep all tasks on the task list after ->post_select() returned negative but call neither ->pre_select() nor ->post_select() any more for such tasks. This leads to the concept of zombie tasks.
* Change copyright year to 2014.Andre Noll2014-02-22
| | | | | | | | | 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
* Merge branch 't/stdin_stdout_fixes'Andre Noll2013-06-11
|\ | | | | | | | | | | | | | | | | | | Was cooking for almost a month. b99b4a stdin/stdout: Restore fd flags on shutdown. Conflicts: stdin.c stdout.c
| * stdin/stdout: Restore fd flags on shutdown.Andre Noll2013-05-05
| | | | | | | | | | | | | | | | | | The stdin/stdout code should restore the flags to the old value to avoid surprises, for example in shell scripts. This changes stdin.c and stdout.c to save the old value. It is restored in ->post_select when the buffer tree node is removed and no more I/O takes place.
* | sched: Rename new_post_select back to post_select.Andre Noll2013-04-30
| |
* | sched: Kill old ->post_select variant.Andre Noll2013-04-30
| | | | | | | | It has no more users.
* | stdout: Switch to the alternative post select method.Andre Noll2013-04-30
|/
* Change copyright year to 2013.Andre Noll2013-03-25
| | | | Better late than never.
* btr: Remove btr_free_node().Andre Noll2012-07-08
| | | | | | | | | This has turned out to be source for bugs. Deallocate everything in btr_remove_node() hence making removing the node and freeing its resources an atomic operation. To avoid dangling pointers to freed btrn nodes, the argument of btr_remove_node() is changed to to struct btr_node **btrnp.
* Rename write_nonblock() to xwrite().Andre Noll2012-01-20
| | | | | | This function is not only useful for non-blocking file descriptors, so the name was misleading. Rename it to xwrite() for the lack of a better name.
* Change year in copyright message to 2012.Andre Noll2012-01-07
|
* Always include stdbool.h.Andre Noll2011-12-18
| | | | | | | | | This adds the #include statement for stdbool.h to para.h. This allows to get rid of the individual includes in *.c. More importantly, since all *.c files include para.h, booleans will now be available everywhere so that we won't need to touch dozens of files anymore whenever a boolean is added to a public structure.
* Remove some unnecessary includes.Andre Noll2011-03-27
| | | | | | | | This gets rid of quite some inclusions of <dirent.h> which are not needed as most .c files do not deal with directories at all. afs.c doe not mmap anything and needs nothing from sys/time.h so remove these includes as well.
* Replace 2010 in copyright message by 2011.Andre Noll2011-01-17
|
* cleanup: remove redundant 'max length' argumentGerrit Renker2010-06-07
| | | | | | | | This removes the redundant 'max_size_bytes' argument of * write_nonblocking(), * send_queued_chunks(), and * send_chunk(), since it was set to 0 in all cases.
* Change year in COPYRIGHT to 2010.Andre Noll2010-04-05
| | | | Hey, this is earlier than last year :)
* stdin/stdout cleanup.Andre Noll2010-01-15
| | | | | para_client was the last user of the non-btr code in stdin.[ch] and stdout.[ch]. Remove this unused code and update the documentation.
* stdout: Try to write as much as possible in one go.Andre Noll2010-01-10
|
* [btr] Add the node type parameter to btr_node_status().Andre Noll2010-01-05
| | | | | | This allows to have a single function which can be called from both the pre_select and the post_select methods of all receivers/ filters/writers and from the stdin and stdout tasks.
* [btr] Split btr_del_node() into two functions.Andre Noll2010-01-05
| | | | | Also, close filter/receiver nodes in filter.c/recv.c instead of in each post_select().
* stdout: Misc cleanups.Andre Noll2009-12-31
|
* btr: Make it kind of work for http recv + stdout.Andre Noll2009-12-29
|
* stdout.c: Add a flag to activate buffer tree API.Andre Noll2009-12-28
| | | | Not used yet.
* Introduce para_regcomp.Andre Noll2009-07-08
| | | | | | | | | | | | | A wrapper for regcomp() that logs an error message if the regcomp() failed and uses a return value according to the paraslash rules. Currently there is only one user of regular expressions, is_v4_dot_quad(), which is converted to para_regex(), but new callers will be added soon. Unfortunately, this change made it necessary to include regex.h in all .c files that use string.h. Clean up the order in which headers are included a bit while we're at it. Maybe I should rethink the rule "Only .c files shall include header files"...
* Use only a single buffer pointer for filters/receivers.Andre Noll2009-05-02
| | | | This allows filters to change the output buffer size on the fly.
* Change year of copyright from 2008 to 2009.Andre Noll2009-01-10
|
* Fix another bug in stdout.c.Andre Noll2008-04-01
| | | | This one caused the first chunk of data to be swallowed.
* Fix a bug in stdout.c.Andre Noll2008-04-01
|
* Update documentation for stdin.c and stdout.c.Andre Noll2008-04-01
| | | | It contained some outdated comments.
* Simplify the scheduling code.Andre Noll2008-03-30
| | | | | | | | | | | | | | | | | | | | | | - Get rid of sched->select_ret. Tasks shouldn't care about the return value of the select call. - Kill task->private_data. Use container_of() instead. - Remove task->event_handler. It is never necessary and only makes the code more convoluted. The scheduler unregisters tasks as soon as either the pre_select or the post_select functions return an error. - Rename task->ret to task->error and get rid of a couple of error fields in other structs that usually only contained a copy of the task's error value. This conversion likely introduces many bugs that have to be shaken out in subsequent patches. Hopefully it will result in less error-prone code in the long run.
* More trivial cleanups.Andre Noll2008-02-09
|
* Always check the return value of mark_fd_nonblocking().Andre Noll2008-01-19
|
* Turn PARA_STRERROR into an inline function.Andre Noll2007-12-28
| | | | Add documentation and an assertion for (num > 0).
* Replace eof by error in receivers/filters/writers.Andre Noll2007-12-15
| | | | | | | | | | This way it's possible to tell at a later time why the receiver/filter/writer terminated. This allows to increase the delay for reconnecting in case the receiver failed to connect to para_server: Let the receivers set the error value to -E_RECV_EOF in case a normal end of file event occurred and check this value when calculating the restart barrier.