summaryrefslogtreecommitdiff
path: root/c-sources/pcap-monitor.c
AgeCommit message (Collapse)AuthorFilesLines
2020-06-05reader: Encapsulate libpcapWill Thompson1-5/+4
2020-06-05monitor: Use tee to save pcap streamWill Thompson1-43/+34
Previously, Bustle read directly from dbus-monitor, parsed the pcap stream, then reserialized it back to a file. dbus-monitor → bustle → UI ↓ file Instead, use tee between dbus-monitor and Bustle to write the raw pcap stream to disk: dbus-monitor → tee → bustle ↓ file This makes the code in Bustle quite a bit simpler.
2020-06-05Factor out BustlePcapReaderWill Thompson1-46/+29
2020-06-05monitor: include GDBusMessage in ::message-loggedWill Thompson1-3/+13
Not used on the Haskell side yet.
2018-12-07monitor: use a PTY to send SIGINT to privileged childWill Thompson1-18/+117
Previously, we sent SIGKILL directly to the child process. If we're monitoring the system bus, the child process is owned by root, so the parent process can't send it signals. In this case, we relied on the child process dying with "Broken pipe" when it next tries to write to stdout (which we close). If you run `pkexec dbus-monitor --system` in a terminal, you are able to press Ctrl-C to send SIGINT to that privileged child process. This is because the signal is not sent directly. Instead, the terminal emulator writes ^C to the child's controlling terminal; the kernel turns this into SIGINT and send that to the child. We can do the same thing here. Here are the steps: * Create a pseudo-terminal (PTY) master/slave (not my terminology) pair * Make this PTY the controlling terminal for the child process: * Make the slave FD the stdin for the child * In a GSubprocessLauncher child_setup function, which runs between fork() and exec(): * Move the process to a new session with setsid(), removing any existing controlling terminal * Call ioctl(STDIN_FILENO, TIOCSCTTY, 0) to set the stdin FD as the controlling terminal * When it comes time to kill the child, write ^C into the master side of the PTY We continue to send SIGINT (rather than SIGKILL; it seems kinder) the old-fashioned way (in case something goes wrong setting the controlling terminal) and closing the pipe so that the child eventually dies with EPIPE (in case the old-fashioned way fails too). A potential fly in the works is that, in the Flatpak case, the immediate child is a flatpak-spawn process; `pkexec dbus-monitor --system` is actually launched from the session helper. Happily, the session helper already calls setsid() + TIOCSCTTY if any of stdin/stdout/stderr on the spawned process are TTYs <https://github.com/flatpak/flatpak/blob/1.0.1/session-helper/flatpak-session-helper.c#L182-L202> so we just skip the child_setup function in that case. See https://blog.nelhage.com/2011/02/changing-ctty/ for some useful background reading on controlling terminals.
2018-12-07pcap-monitor: factor out building argv and spawning subprocessWill Thompson1-15/+34
2018-08-21monitor: assume DLT_DBUS is definedWill Thompson1-4/+0
This has been defined since libpcap 1.2.1 in 2010.
2018-06-28monitor: claim name before dumping other namesWill Thompson1-0/+32
This will allow the viewer to hide this connection even once it stops unconditionally hiding all messages to and from the bus daemon.
2018-06-26PcapMonitor: get rid of priv structureWill Thompson1-130/+108
We can just hide the object struct definition.
2018-06-26monitor: don't try to autostart the bus daemonWill Thompson1-1/+2
2018-06-15Use dbus-monitor --pcap to capture trafficWill Thompson1-282/+597
Modern versions of D-Bus have a BecomeMonitor method which allows a sufficiently-privileged user (ie root) to capture all messages on the system bus. Modern versions of dbus-monitor use this method, and support pcap output natively. This allows us to use pkexec to escalate just the dbus-monitor process, and so add a way to monitor the system bus from within the UI. We can also use Flatpak's HostCommand method (via `flatpak-spawn --host`) to do the same from within the Flatpak sandbox. It's not much extra effort to support monitoring an arbitrary bus by address, so that's wired up too. Bustle itself still connects to the bus you're monitoring to dump all current names, so will still require full session and system bus access. If this fails, it's not considered fatal. We assume that dbus-monitor is present on the host, and recent enough to support --pcap. We'll see if this assumption is true in practice!
2018-01-31::message-logged: update "why not gint64" commentWill Thompson1-1/+1
2017-10-26Bump minimum GLib version to 2.44Will Thompson1-1/+1
2017-07-24Revert "Limit captured message size to 65535 bytes"Will Thompson1-37/+1
This reverts commit aa52f3c269046cc01d8340789caa1ffec4e202e7. libpcap upstream has addressed the issue this was working around, so now we can record and read back the full contents of D-Bus messages. https://github.com/the-tcpdump-group/libpcap/commit/2be9c29 https://github.com/the-tcpdump-group/libpcap/commit/1a6b088 https://bugs.freedesktop.org/show_bug.cgi?id=100220
2017-07-18Limit captured message size to 65535 bytesWill Thompson1-1/+37
https://bugs.freedesktop.org/show_bug.cgi?id=100220
2016-01-27Use DLT_DBUS in pcap dumpsWill Thompson1-2/+6
Back in 2011 I don't think the magic number had been specified. Thanks to Jaap Keuter for the prompt.
2013-12-05Give a nice error if DBUS_SESSION_BUS_ADDRESS is blankWill Thompson1-0/+14
2013-12-05Don't close the shared GDBusConnectionWill Thompson1-7/+16
I have literally no idea how recording more than once in a Bustle session ever worked before. This would crash (another bug) because setting up the monitor failed because ending the first recording closed the shared connection returned by g_bus_get_sync(). By making a private connection we can be sure of not trampling on anything else that might happen to be using the shared bus in the Bustle process.
2012-11-14Revert "Use g_thread_try_new rather than g_thread_create"Will Thompson1-1/+1
This reverts commit b5bdd77ff2c8532365806bdfae490b59295fd795.
2012-11-14Set max GLib version to 2.30Will Thompson1-0/+1
This squashes deprecation warnings about the old thread API.
2012-09-03Use g_thread_try_new rather than g_thread_createWill Thompson1-1/+1
The latter is deprecated. This seems like an extremely worthwhile change to have to make.
2012-01-17Disable exit-on-close to work around a GLib bug.Will Thompson1-0/+6
2012-01-16Include timestamps in live logsWill Thompson1-2/+22
2012-01-13monitor: signal all messages up to the applicationWill Thompson1-20/+11
This is kind of a regression because we get all the internal guff too, so the counter in the UI is wrong. But the loader needs all the messages, even the internal ones, to track name changes. We'll later update the recorder not to count messages that don't show any output, and not to feed them to the renderer.
2012-01-13pcap-monitor: include details in message-logged signal.Will Thompson1-38/+40
This lets us move verbose output for the command line tool into the command line tool, and also lays the foundation for actual live logging.
2012-01-13pcap-monitor: use GByteArray internallyWill Thompson1-11/+19
This is a refcounted boxed type.
2012-01-13pcap-monitor: specify eavesdrop=trueWill Thompson1-6/+18
2012-01-13Rename BustlePcap to BustlePcapMonitorWill Thompson1-0/+534
This is a clearer name, matches the Haskell binding better, and means we don't include two different headers called pcap.h.