Commit Graph

550 Commits (144b701453de72c7c5a741cc148a42b25c309ad4)

Author SHA1 Message Date
Michael Meeks 144b701453 cool#8703 - Drop random node creation and rely on inherited fd.
Re-using an inherited file descriptor to /dev/urandom frees us
from problems with mount options including 'nodev' and removes a
capability from the set we need.

Change-Id: I70337e923f802d7efbd3159c11a4e39f6529b6e6
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-04-07 12:11:48 +02:00
Michael Meeks e27a095775 bgsave: initial implementation (gated on COOL_BGSAVE=1)
Initial background save implementation from the Kit perspective.

To do a background save we:

   1. join known threads - we can't fork with >1 thread.
   2. check all is well: one thread, nothing unusual...
   3. create a socketpair to communicate with the child
   4. fork
   5. child: cleanup duplicated sockets
   6. child: setup LOK to not damage our shared file-system
   7. child: save
   8. child: report status back to parent & _Exit

There is still a substantial TODO, but this can be built on.

Change-Id: Ibf2c492372e2b5133932773e230ad05e18521794
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-04-05 17:34:43 +01:00
Patrick Luby 52a039e832 If there are no open documents, wait until one is added
Remove any stale elements from KitSocketPoll::KSPolls and
block until an element is added to KitSocketPoll::KSPolls

Signed-off-by: Patrick Luby <guibomacdev@gmail.com>
Change-Id: I25726171ef28d9107772f7665dd3cbb467e364e5
2024-04-05 09:02:13 -04:00
Jaume Pujantell 8921e19d84 reduce uses of MOBILEAPP on some files
Reduce the uses of MOBILEAPP conditionals by using the isMobileApp
function.

Signed-off-by: Jaume Pujantell <jaume.pujantell@collabora.com>
Change-Id: If541307fbc457b342674cc560b6c53454f3904cf
2024-03-20 09:13:00 +01:00
Ashod Nakashian c7b67ec100 wsd: corrections to TraceEvent
We continue to process all entries of
the array.

The command name is now correct.
Otherwise, an error was logged instead.

Change-Id: Ie5085e062dc36a4e955347246d5087ec7749d270
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2024-03-18 18:41:49 +00:00
Ashod Nakashian 0dfd863fd3 wsd: streamline TraceEvent strings
Change-Id: I56e5cf05d45914e71d96a0b0a583d413fd6bd79a
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2024-03-18 18:41:49 +00:00
Gökay Şatır 27670275ab Send isAllowChangeComments flag to ChildSession.
We also set the variable on the core side in order to allow saving edited documents.

Signed-off-by: Gökay Şatır <gokaysatir@gmail.com>
Change-Id: I9ba97daca7013bf26b25fff785f175e3fb213dfb
2024-03-16 07:28:30 +03:00
Michael Meeks e9ef062eee Set thread name early & cleanup thread_locals.
On fork a thread_local variable simply inherits the parents'
value - so clearing the cached thread_id helps to make
logging more accurate.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Ib03d2605489291589854caa10940fd7c11caea36
2024-03-15 11:41:23 +00:00
Michael Meeks a8d97dc16d Calm down warnings.
Seems browsers start to ping servers on their websockets, so don't
warn about that.

We trim memory left and right in clients, that doesn't deserve a
warning either.

Change-Id: I7bdcc99d167a8df3c847a1893dee8cd9123250f2
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-03-12 08:33:17 +00:00
Ashod Nakashian d57baeb906 wsd: reduce directives for unused variable supression
We use [[maybe_unused]] to reduce explicit supression
especially under compile-time directives.

Change-Id: Ic5f3f3227a80efe52097cb35520d05b9cdaacb42
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2024-03-09 12:37:19 -05:00
Michael Meeks f00486ac52 Setup thread-counter to monitor live threads in a Kit process.
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I77ea935ed2c731ecf5361413492ed5768f58c57a
2024-03-07 09:36:00 +00:00
Michael Meeks 3c19d92833 Delta -> unique_ptr to break include problems on Mac.
Also rename _pngPool to _deltaPool.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I35fb7db4c5c62e2f05a69ac6d6bd742f9ae78ca8
2024-03-06 20:56:55 -05:00
Michael Meeks 0b91bacdc8 killpoco: reduce scope and number of various includes.
Change-Id: Ic3eb409fbb11cc665f0f3a55bb7a4e59cbd28f8b
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-03-06 20:56:55 -05:00
Michael Meeks c117d87bb4 nearly pure re-factor: split out code into its own modules.
StateRecorder.hpp split from ChildSession.cpp
KitWebSocketHandler.[ch]pp split from Kit.cpp.
ThreadPool.hpp split from RenderTiles.hpp

Expose headers for KitSocketPoll and Document
at the same time.

Not clear we need the DocumentManagerInterface anymore.

Conditionally compile out Document::createSession for unittest
dependency breaking, and avoid Rlimit::handleSetrlimitCommand
likewise.

Make makePropertyValue a private method of Kit.cpp.

clang-format new files.

Change-Id: I47a1d6afe20165f156b477a931b94c916cff4b9d
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-03-06 20:56:55 -05:00
Gökay Şatır bf7ce2b086 Allow events through core side on readonlymode.
Signed-off-by: Gökay Şatır <gokaysatir@gmail.com>
Change-Id: I4ff02b96f0019aa794834c824de0d1a323a00c7c
Signed-off-by: Gökay Şatır <gokaysatir@gmail.com>
2024-03-06 14:03:02 +01:00
Michael Meeks ca2c174a7d Notify crash-dumping of an inconsistent jail.
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Ib3c81ad15a1386664c63818ec658f703d5359eae
2024-02-29 15:26:34 +00:00
Caolán McNamara ed5924c494 set the initial rendering state before the first invalidateCanonicalId
now that we will typically init the document theme, etc. from the
users last used settings, the current rendering state is likely the one
that the user wants to use.

The browser-side throws away all tiles, etc on getting a
canonidalidchange, so get the current document renderering state to
describe this initial state so later LOK_CALLBACK_VIEW_RENDER_STATE
events can be compared to this initial state and only emit
canonidalidchange if there is a need.

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I2902ff4e143f432755c335e1225149207fafdfc3
2024-02-26 10:02:32 +00:00
Aron Budea 3b8f3d07f6 Replace Util::startsWith/endsWith w/ C++20 equivalent
Replace a few cases of Util::toString(...), too.

Signed-off-by: Aron Budea <aron.budea@collabora.com>
Change-Id: I53c5dbbdf2f60710e94add9dd137aa9becb7bd3e
2024-02-22 08:08:32 +01:00
Michael Meeks c090b4fd21 notasync warning improvement.
Kit's GlobalCallback has an alarming habit of enabling
inputprocessing during a jsdialog popup occuring during
load, so use a stronger heuristic to avoid sending errors.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I4a57685dcf63b4a3607c894e80a13e27bffaece5
2024-02-21 12:57:11 +00:00
Caolán McNamara 7154ac5d07 init document theme during load
like we do for the spelling setting, so we have the document in the
desired state early before any rendering, dropping the early full
document invalidations during initial setup

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I6b762c95fd4c00c7da04cf89f7bbeef4bc57375d
2024-02-21 10:23:15 +00:00
Michael Meeks e7e909bf3d Don't complain about non-async dialogs on load & save.
Change-Id: I2e846ea99e8d062088c80be166c4fc73bb3f004d
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-02-16 20:31:53 +00:00
Caolán McNamara 64a4dab516 we never have an empty std::unique_ptr for .second
and don't check for it in the other cases, so drop it in these ones

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Ie343178869cadc127ee898968fef8f798b6068d5
2024-02-08 08:51:46 +01:00
Michael Meeks 7387d9cc04 Reduce noise of somewhat excessive trace debug.
Given the surrounding debug we should be able infer the same
state from its absence.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Id20de40f67ed52dc5535585aec9b5888131d6324
2024-02-07 21:17:48 +00:00
Michael Meeks 29fa4a40a1 signal activity dumping: enrich with session details and state.
Cue up some basic state for being signal safe dumped on crash/abort.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Ibc6713aef2a0e7b878b178b05f0e13c8d40b47fc
2024-02-06 19:29:28 +00:00
Ashod Nakashian c1ced10f17 wsd: no need to create existing mount-point
The mount-point must exist already, since
we always mount read-only. There is no
directory to create, but the subsequent
chmod always fails, since the mounted
directory is read-only. Since we started
warning when chmod fails recently,
6208b37a32,
these previously-silent failures became
noisy.

Change-Id: I9efaa89182c016e9a7a5d36cc3da5bfa7ee599c2
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2024-02-05 16:47:08 +00:00
Michael Meeks 27a7199fbd Warn on non-async dialog usage when in debug mode.
Change-Id: Ic623ba04b9e2735735bfd3ecc8738e12942ddee0
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-01-26 20:03:45 +00:00
Caolán McNamara 8c3bf40bbe the viewrenderedstate=string string is only used in debugging
so we can pass through the full state that the view reports
which makes it easy to see if a browser side is given a view
whose render settings are unexpected.

e.g. clicking "formatting marks" and not getting a viewrenderedstate
with 'P' or view#1 clicks their "formatting marks" and view#2
receives a 'P'ilcrow state.

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I31d3a8397f02dedf2505bed5dd83576f3138b504
2024-01-26 15:17:48 +00:00
Aron Budea ed53c00fde kit: Only log smaps_rollup open failure when it actually failed
...not when it wasn't even attempted.

Signed-off-by: Aron Budea <aron.budea@collabora.com>
Change-Id: Ide56c46b1a2d99c3639aace430cec099c6afcbf4
2024-01-11 14:26:54 +00:00
Caolán McNamara 0f922c2322 Rewinding and rereading proc/smaps_rollup doubles the values on some kernels
So this only affects the case where we reuse the fd from opening smaps_rollup

Bug seen in 4.15.0 and not in 6.5.10, suspected to be fixed by:
258f669e7e
included in >= v4.19

Test for this in coolwsd and set a flag if it is broken

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I0a4aca77b9d9201e4f70172340296e5eb5460229
2024-01-10 17:30:46 +00:00
Michael Meeks b10b9276b8 Use /proc/self/smaps_rollup for improved perf #7927
Using the aggregated file saves a hundred+ system-calls per
pid we're getting data for, and presumably also lots of time.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I41c40982ebbec44aba72a1d15dabf24a8986f59e
2024-01-03 20:20:02 +00:00
Jaume Pujantell 35d6e2925f use isKitInProcess() instead of KIT_IN_PROCESS
Removed all uses of KIT_IN_PROCESS, used Utils::isKitInProcess()
when necessary. Also removed the now unused parameter 'limit' from
forkLibreOfficeKit.

Signed-off-by: Jaume Pujantell <jaume.pujantell@collabora.com>
Change-Id: I068d3f55ab49076590f111847c87b3188f4d25d0
2023-12-18 10:34:10 +00:00
Caolán McNamara 7f2b8c0aef duplicate jsdialog messages seen in UnitBadDocLoad
debugging some intermittent failures in UnitBadDocLoad I see that there
are some duplicate jsdialog messages appearing which is easily
reproducible by just opening test/data/corrupted.odt in online.

probably has been like this since:

commit 7f70197723
Date:   Mon Dec 28 11:37:27 2020 -0400

    kit: enable input process when early dialog show

and possibly not the problem I was originally trying to chase

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I7aa342e86ad9ae73082cb71f1b2c9b2bf0f212b9
2023-12-05 11:38:24 +00:00
Szymon Kłos 30ccc1ef2e Avoid duplicated / in paths
Also use some allowed path for HOME and XDG_CONFIG_HOME so we start correctly.
Setup Work path for pdf/epub export.
Enable osl allowed paths for nocap only.

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I4fa058fe5fabc5eafdff7630dfcc72dedfe22e4a
2023-12-01 12:31:33 +01:00
Michael Meeks f11cad502b Use the OSL sandbox as well: belt + braces.
Also move the nocaps TMPDIR into the jail folder, to sandbox better.

Change-Id: I161695b4585a2c6003779caa88152b744d36266b
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2023-12-01 12:31:33 +01:00
Michael Meeks 7183a3d3de spdx: improve machine and human readability of headers.
Change-Id: Ice934380029bf27054e830fffc07a5d037d1430f
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2023-11-14 19:36:31 +00:00
Caolán McNamara 80566a9bfe cid#318836 silence Resource leak
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I57255fe9fd13558a4edf2edd06681c7f08b25e51
2023-10-24 09:23:47 +02:00
Cosmin Humeniuc 7dae294a71 Avoid logging messages when anonymization is on
Signed-off-by: Cosmin Humeniuc <cosmin.humeniuc@1and1.ro>
Change-Id: I5bcf615521d13758b2b70a0c9466a3bbc1a0a918
2023-10-18 16:22:31 +01:00
Caolán McNamara 8d42849156 ProcSMapsFile might not be a valid file descriptor
in which case don't send it, which then implies we might have
an empty shareFDs which we can treat the same as a nonexisting
shareFDs

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I80a78a01c69dbee5ee28a64442a5069a6c2b4dbe
2023-10-14 12:56:15 +01:00
Caolán McNamara 672f3cee2c rework URP to use a dedicated channel
Instead of fighting the SolarMutex to get the messages
processed by the main loop. Simple and no additional
threading, mutexes etc.

messages from the external uno client are just
written to URPtoLoFD and the core reads from that

messages to the external uno client are written
to URPfromLoFD by core, that fd is in poll, and
activity there triggers a read by the DocBroker
to send it to the external uno client.

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Ib1f0a0d5fb5ab22eee476d5d740b290c51de59dc
2023-10-03 10:15:55 +01:00
Skyler Grey e6d9c1f87c Add support for URP messages in COOLWSD
- Allow COOLWSD client sessions to forward messages with the prefix
  'urp' to the child, and return messages with 'urp:' to the client,
  communicating with binary
- Make COOLWSD child sessions use the FunctionBasedURPConnection from
  https://gerrit.libreoffice.org/c/core/+/155100
  (core change ID I2bda3d0b988bef7883f9b6829eeb5b7ae8075f27) to start a
  new URP session
- Make COOLWSD child sessions submit messages to this URP session,
  stripping and adding the 'urp' and 'urp:' prefixes so the Java client
  from https://gerrit.libreoffice.org/c/core/+/154680
  (core change ID I91ee52922a24688a6b94512cb7e7bc760bf25ec9) can
  use the connection (and to avoid interference with any other websocket
  messages)
- Add a COOLWSD option for enabling/disabling URP given the security
  implications around allowing anyone to write URP (e.g. URP lets you
  run shell commands so a mallicious actor can take over the child
  session)

Signed-off-by: Skyler Grey <skyler.grey@collabora.com>
Change-Id: Idadfe288a78cfd72b01253dfdade150d506e3f05
2023-10-03 10:15:55 +01:00
Ashod Nakashian 150663cc28 wsd: stop the rendering thread pool before exiting
Change-Id: I8a084ee1fd583f6c37ba4ca8c1ebf8abe74288a2
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-10-02 20:14:53 +01:00
Rash419 9d6b1d148b don't request new tiles unnecessarily on canonicalidchange
- it applies for 2 cases:
1. when document is loaded for the first time document already has
tiles of respective theme
2. when Kit loads the document it sends canonicalidchange  unconditionally
(5520965b15/kit/Kit.cpp (L1708))
we don't need to request new tiles for that also

Signed-off-by: Rash419 <rashesh.padia@collabora.com>
Change-Id: I42cdc5a03e70c3d3d653f3124d3d5ed9382e22c0
2023-10-02 13:29:25 +05:30
Caolán McNamara 14dce568f0 cid#318836 Resource leak
in error branches dlclose unusable dso, leave it open on success

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I3a2eafceb573cc59ada922d98ae6a9b421d6accc
2023-10-02 08:30:42 +02:00
Ashod Nakashian 3d93e69e49 wsd: use a smaller value when trimming after inactivity
This is to differentiate between a complete
trimming when idle compared to trimming
when inactive.

Change-Id: I61b309968e0a5199fe4f0fb445437a953c0e468a
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-09-25 19:29:12 -04:00
Paris Oplopoios e5b7464bbf Invalidate canonical id unconditionally
Signed-off-by: Paris Oplopoios <paris.oplopoios@collabora.com>
Change-Id: I061e34af1a1676e5bba5d476ea9e7ff5758744a1
2023-09-12 00:49:18 +02:00
Patrick Luby 0898e05e3a Invalidate canonical ID for Draw and PDF files so that the slides
in the slide pane will render

Signed-off-by: Patrick Luby <plubius@neooffice.org>
Change-Id: I43f93c0c02d801391eaea9916ab1bd8e827249a9
2023-09-12 00:49:18 +02:00
Paris Oplopoios 0621aa4825 Fix canonical id related unit tests
Signed-off-by: Paris Oplopoios <paris.oplopoios@collabora.com>
Change-Id: Ie4b965c3bac8cddd48a47343d2d1c5f387d8bd41
2023-09-06 10:28:26 +02:00
Paris Oplopoios cfd1d2e01f Revert "Give new sockets a canonical view id in tests"
This reverts commit a003126a65.

Signed-off-by: Paris Oplopoios <paris.oplopoios@collabora.com>
2023-09-06 10:28:26 +02:00
Michael Meeks f34efeecd3 Add trimming to activity log in case of crash.
Also rename trimIfExcessive to trimAfterInactivity.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I62166a3ed5d70d1e6fd9804e91e07452978523fd
2023-08-29 20:18:23 +01:00
Caolán McNamara 492f678996 add and use 'N_ELEMENTS' in lieu of std::size
which isn't available in the current android toolchain

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I5834adb7c6211c7aad38f5977a7e425d9ca257fd
2023-08-23 12:06:31 +02:00