Commit graph

14 commits

Author SHA1 Message Date
Tom Cherry
a0e4af67eb logwrapper: update benchmark and remove old functions
All of the previous callers have been updated, so we can remove these
old functions.

Test: build
Change-Id: I31597a69635795bacf9bb8054ccf5ffa8089e481
2019-09-28 07:27:26 -07:00
Tom Cherry
ff7d067ffa logwrap: convert to C++, rename function logwrap_fork_execvp().
Call the function now logwrap_fork_execvp() and fix const correctness
issues, so no longer do callers need to const_cast<> their args.

Test: logwrapper still works
Change-Id: Iea34f5cae90a06a37d395bf9a91e01fb38c35fa6
2019-09-26 10:29:57 -07:00
Tom Cherry
013289364e logwrapper: open child_ptty in child process and remove ignore_int_quit
Opening child_ptty before fork() means that the parent process will
use child_ptty as the controlling terminal if it doesn't already have
one.  This is a problem, because when the parent_ptty closes, SIGHUP
will be sent to the parent process, since its controlling terminal has
closed.

It's better to have the child process start its own session and then
open child_ptty as its controlling terminal.  In this case, the child
process will get SIGHUP if the parent process exits, but the parent
process avoids the original issue.

There is a concern that the child_ptty will never be opened and
POLLHUP will never be generated, but there is a work-around in place
with a timeout to handle that extremely rare situation.

Secondly, remove the ignore_int_quit logic.  It is described to
totally ignore these signals, similar to `nohup` which should be
preferred.  However, it regressed shortly after being introduced in
2013 and serves essentially no purpose currently.

Thirdly, add a forward_signals option that does what we should have
done the whole time with signals: it forwards SIGHUP, SIGQUIT, and
SIGINT to the child process and let that process handle them.  This
only needs to be enabled in the `logwrapper` case itself.  Other
processes should not need to change any signals.  This fixes case 3)
below.

Lastly, add O_CLOEXEC where appropriate.

Test: launch process as `adb shell logwrapper yes`
      1) The both processes exit when given SIGINT
      2) The process prints when abbreviated is not enabled
      3) The process does print when abbreviated is enabled;
         this was previously broken
Test: launch process as `adb shell` then `logwrapper yes`
      4) The both processes exit when given SIGINT
      5) The process prints if abbreviated is enabled or not.
      6) Ctrl-c then Ctrl-c again rapidly and observe that the
         logwrapper process is terminated by the second Ctrl-c.
Test: simulate a failure in child() before opening child_tty and
      observe logwrapper and the child exiting appropriately.

Change-Id: Ia76cd17e16535500170d8f5e2183b3bbbf843df7
2019-09-25 12:59:52 -07:00
Narayan Kamath
abd4613f05 Logwrapper: Remove unused support for input / output processing.
Should make it easier to switch callers over to posix_spawn once
that's available.

NOTE: The (now) unused arguments will be removed in a followup (multi-project)c
hange once we empirically confirm that there aren't any prebuilt blobs
using this function. I did readelf all currently checked in prebuilts to look
for a reference to this method, but one can never be too paranoid.

Test: make checkbuild
Change-Id: I454d80c52f269c31846133cc54375decd702fe71
2017-03-22 11:00:43 +00:00
Yusuke Sato
7980426a6f Add FORK_EXECVP_OPTION_CAPTURE_OUTPUT to logwrap.h
This allows raw popen calls in e.g. system/netd/ to be replaced
with android_fork_execvp_ext().

Change-Id: I159ece7369fa38ff8782024bef0d7cfafe74ecee
2015-08-21 17:14:59 -07:00
Yusuke Sato
d81c3c6c45 Add |opts| argument to android_fork_execvp_ext
to allow the caller to send data to the child's stdin.

Bug: 21725996
Change-Id: I818f5cf61045286c8d64a91b6d50f05740329be1
2015-08-19 11:00:37 -07:00
Ken Sumrall
4eaf905858 Create a separate copy of the fsck logs
The log_target parameter of android_fork_execvp_ext() is now a
bit field, and multiple targets can be set to log to multiple
places at the same time.

The new target LOG_FILE will log to a file specified by the new
parameter file_path.

Set LOG_FILE and log to a file in /dev (the only writable filesystem
avilable when e2fsck runs) when invoking e2fsck in fs_mgr.

Bug: 10021342

Change-Id: I63baf644cc8c3afccc8345df27a74203b44d0400
2013-09-20 17:44:33 -07:00
Ken Sumrall
96e11b5bc4 logwrapper: Add ability to log to kernel log
Also add ability to do abbreviated logging where only the first
4K bytes and last 4K bytes of output are added to the desginated log.

Also update standalog logwrapper command to support the new options.

Change-Id: Ia49cbe58479b9f9ed077498d6852e20b21287bad
2013-04-14 17:10:55 -07:00
Rom Lemarchand
2f34c5033e logwrap: Change semantics of NULL status in android_fork_execvp
When passing a NULL status to android_fork_execvp the return
status will now be the return value of the child if it exited
properly, otherwise a non-0 value will be returned.

Change-Id: I13309c61b37b6b3f9d5507f7d6484e7b6baaf8d0
2013-02-08 09:37:52 -08:00
Rom Lemarchand
2a46bfa6b9 logwrapper: rename logwrap() to android_fork_execvp()
Also change the quiet flag to a logwrap flag (inverses the meaning of
the boolean).

Change-Id: I76047a7b460f4c28d52f26bfe3f65889d96047f8
2013-01-30 12:26:05 -08:00
Rom Lemarchand
f5200c0750 logwrap: add quiet flag to logwrap()
Add a quiet flag to the logwrap function that prevents messages from
getting logged.

Change-Id: Ic56c011fb608babae32b03900b955833a6bdd070
2013-01-28 16:14:20 -08:00
Rom Lemarchand
75c289aab9 logwrap: wait for child process when receiving SIGINT or SIGQUIT
- Wait for the child to exit before propagating SIGINT and SIGQUIT
to the parent
- Add ignore_int_quit argument to logwrap() that gives the caller the
option to ignore SIGINT and SIGQUIT while logwrap is running

Change-Id: If5c96cf23094917211310f00aa6aed515f110f5b
2013-01-29 00:04:50 +00:00
Rom Lemarchand
b58a822955 logwrapper: prevent logwrap from hanging when child dies
Sometimes the read on the PTY can wait indefinitely if the child
dies. By using a poll statement that monitors both the output
of the child and its state we prevent this from happening.

Change-Id: I51d5556c66f039bca673145ca72db262977e1689
2013-01-14 11:11:58 -08:00
Rom Lemarchand
113bd47d61 logwrapper: split into liblogwrap and the executable itself
Abstracting the functionality of logwrapper into a library and making
use of it for the logwrapper executable.

Change-Id: I2bcf722413f3a8454c6f52137dec86c4477fb8b5
2013-01-11 13:58:29 -08:00