Commit graph

665 commits

Author SHA1 Message Date
Szymon Kłos
78f68fa7ef Cleanup in Unit* subclasses
- we cannot get rid of UnitBase::get() which returns the last
  set Unit class because we use it for example in WebSocketHandler
  where we don't know which kind of test we run

- free memory correctly and reset global variables for subclasses

- setup _type member variable on construction

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: Ic61b88785bff7de63b11ce2046eecc993c3ddeaf
2021-09-22 20:31:35 +02:00
Szymon Kłos
029d4195ad android fix: use correct instance for Unit classes getter
On android we had issue with not working release builds
(worked when optimization flag -O0 was used for Unit.cpp).

Global which stored instance of UnitBase subtype was returned
after cast to a choosen subtype. Unfortunately in case when
android didn't work UnitWSD was returned in UnitKit::get() !

Thich patch makes us sure we don't cast to not-correct type.

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I98e91d8fa82a8e81a8f7cee2fe3109b67c4f64f7
2021-09-22 20:31:35 +02:00
Michael Meeks
b0cd66feae Enable wait for attaching a debugger in debug builds by default.
Hopefully helps to hunt segv's more effectively in development.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Ife800f9902fe8d95711b3b14867ee21bb3c3f21b
2021-09-13 14:54:00 +01:00
Ashod Nakashian
28687c0bbf wsd: hexifying helpers and tests
Change-Id: I2f7fa4e6ade3361db612dbb9aa68e4d28b3905d9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 348ca073abe2c980f746324589bc58bf5550dc4b)
2021-09-13 09:40:09 -04:00
Tor Lillqvist
84d9a73676 Stop using .bmp files for tiles on iOS
We don't want leaking tiles to take up valuable space on the device.
Not even just while a document is open.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I761c2bb2ab121ee76b5535e96bd5702d0fce6856
2021-09-07 09:59:57 +03:00
Tor Lillqvist
c77b7e7dfd Actually do remove leftover tiles in the iOS app
Fix silly mistake in my previous commit. Had put code in #if 0 that
should be in #ifdef IOS.

Change-Id: I72f4dc3867bd070a01a4ba5625baba0eea3c2d73
Signed-off-by: Tor Lillqvist <tml@collabora.com>
2021-09-01 15:32:42 +03:00
Tor Lillqvist
6d2a6e110c Remove leftover tiles in the iOS app already when the document is closed
Normally (ideally), tiles (.bmp files) are removed as soon as the JS
has displayed them. But occasionally something goes wrong and they are
left behind. (For instance, it seems to happen if the user closes the
document immediately when it shows up.)

Do not leave them on disk until the app starts the next time.

Change-Id: I0c764280a69a16ad3b7b67c329832fd5331c2e1e
Signed-off-by: Tor Lillqvist <tml@collabora.com>
2021-09-01 13:32:23 +03:00
Pranam Lashkari
daef96dcb3 freemium: corrected typos
Signed-off-by: Pranam Lashkari <lpranam@collabora.com>
Change-Id: If21f4471b3ad4b20f049e2e9f2330e31989ead0b
2021-09-01 09:44:19 +02:00
Michael Meeks
09a2237372 Always lock the work queue.
The worker threads can be running and have not yet responded
to the last _cond.wait() by the time we start compressing again
- at least under valgrind:

loolforkit-nocaps: ./common/RenderTiles.hpp:304: void ThreadPool::run(): Assertion `_working == 0' failed.
==240379== Process terminating with default action of signal 6 (SIGABRT): dumping core
==240379==    at 0x5505322: raise (raise.c:50)
==240379==    by 0x54EE863: abort (abort.c:79)
==240379==    by 0x54EE748: __assert_fail_base.cold (assert.c:92)
==240379==    by 0x54FD9D5: __assert_fail (assert.c:101)
==240379==    by 0x5886BB: ThreadPool::run() (RenderTiles.hpp:304)
==240379==    by 0x56DC02: RenderTiles::doRender(std::shared_ptr<lok::Document>, TileCombined&, PngCache&, ThreadPool&, bool, std::function<void (unsigned char*, int, int, unsigned long, unsigned long, int, int, LibreOfficeKitTileMode)> const&, std::function<void (char const*, unsigned long)> const&) (RenderTiles.hpp:711)
==240379==    by 0x5A0104: Document::renderTiles(TileCombined&, bool) (Kit.cpp:762)
==240379==    by 0x59CF1A: Document::renderCombinedTiles(StringVector const&) (Kit.cpp:719)
==240379==    by 0x59AEC8: Document::drainQueue(std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > > const&) (Kit.cpp:1570)

That means our queue starts processing work as we do the unlocked
queue push - causing some potential badness.

Change-Id: Ib0578dac009376c0676da73a8c1d8960304dc072
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-09-01 07:14:44 +01:00
Michael Meeks
85ae2d668a Get argument count right to spawn.
Why pass a dozen empty arguments each time: someone bitten
again by the default vector constructor.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I31bc6f23f0b5d7352b85d3df4b7b5298199044a1
2021-09-01 07:14:44 +01:00
Michael Meeks
d1ae5a8fb7 Valgrind support for tracing the forkit & kits.
Change-Id: Ie9dd69598bd408ae1994d8cdd6f886224890ad23
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-09-01 07:14:44 +01:00
NickWingate
6eb93a2330 Assign _firstLine before _data is changed
_firstLine must be assigned before _data is
changed, as it is used to check _data's
first line hasn't changed

Signed-off-by: NickWingate <nicholas.wingate03@gmail.com>
Change-Id: I79dfd0a64d53fc8503709015bbe7ab6875a58204
2021-08-30 21:07:59 +01:00
NickWingate
e72b073090 Make firstLine() return reference not value
And make return const to prevent _firstLine being
mutable.

Signed-off-by: NickWingate <nicholas.wingate03@gmail.com>
Change-Id: I1a6e391cd128704b67ec5cc99a4ed4d105f64e29
2021-08-30 21:07:59 +01:00
NickWingate
cc58c79136 Remove _firstLine assignment from constructor
_firstLine is no assigned when firstLine() is called
and _firstLine is empty.

Signed-off-by: NickWingate <nicholas.wingate03@gmail.com>
Change-Id: Ie6d86abd1f9db7a4f05e95e41f6b791f5923729f
2021-08-30 21:07:59 +01:00
Tor Lillqvist
65b8001d73 Remove more leftover files taking space in the iOS app
Remove the app's copy of the document after core has saved it and we
have stored the edited version at its real location.

Remove possible leftover tile bitmaps when the app starts.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Ibc41be38c2cfb689c532640d148116bc06a248ab
2021-08-24 18:02:40 +03:00
Michael Meeks
ebc0d0aaf4 Unit: add new 'Tool' type of unit test handler.
Dummy, but useful for eg. fuzzing.

Change-Id: I9819cda898a7bf1c0fba3d1fccbb63b16955f01d
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-08-17 11:07:21 +01:00
Miklos Vajna
3186597097 log: avoid logging after shutdown on all log levels
This can happen on an assertion failure, and causes noise while looking
for real memory errors.

Also disable an unstable test, it's not clear that it passes depending
on how loaded the machine is (just increasing timeouts doesn't seem to
help).

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I049bd0a06f41e2d43702ec12a2c35944bc5200d8
2021-08-12 10:02:48 +02:00
Pranam Lashkari
dcd6795e57 use pragma instead of header guards in freemium header files
Signed-off-by: Pranam Lashkari <lpranam@collabora.com>
Change-Id: I5b55c2de4a2467503108e4172de84a27e207ba3c
2021-08-06 17:21:04 +02:00
Tor Lillqvist
17e07847cf Don't let other clients prevent textinput and removetextcontext merging
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Iff95e9624b687938b83d1666059efbffb32c2b54
2021-07-22 13:41:53 +03:00
Tor Lillqvist
07046e0a35 Merge sequential 'removetextcontext' messages when possible
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I53529bbb1fe45e74fde6fa6489b1580521f23d2d
2021-07-22 13:41:53 +03:00
Tor Lillqvist
65a42ecd2e Merge textinput messages when possible
When adding a freshly arrived textinput message to the queue, check if
there is an outstanding one queued, and if so, remove it, and prefix
its text to the text in the fresh message. Don't do this if there are
messages inbetween that affect what the textinput messages do
semantically, including textinput messages from other clients.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I712eebfb10d410bb424157c8df46b2848a236d88
2021-07-22 13:41:53 +03:00
Tor Lillqvist
8b6ee5b8bf No need for the template class MessageQueueBase
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Ie007344f9a0ffe7fdf767cb9e9069db99aa224b9
2021-07-21 09:54:28 +03:00
Szymon Kłos
9cbe11699f Don't stop loolwsd when logger already exists
there was a case detected by tinderbox when logger
somehow existed already what closed the app:

unit-wopi-versionrestore:

Test unit-wopi-versionrestore FAILED.
-25786 2021-07-19 08:37:08.429079 [ loolwsd ] TST  UnitWOPIVersionRestore (+0ms): WopiTestServer created for []| WopiTestServer.hpp:71
-25786 2021-07-19 08:37:08.429160 [ loolwsd ] TST  UnitWOPIVersionRestore (+0ms): setFileContent: [Hello, world]| WopiTestServer.hpp:57
wsd-25786-25789 2021-07-19 08:37:08.430827 [ UnitWOPIVersionRestore ] INF  Thread 25789 (7fb8e5063700) of process 25786 formerly unnamed is now called [UnitWOPIVersionRestore]| common/Util.cpp:572
wsd-25786-25789 2021-07-19 08:37:08.430954 [ UnitWOPIVersionRestore ] INF  Starting polling thread [UnitWOPIVersionRestore] with thread affinity set to 0x7fb8e5063700.| net/Socket.cpp:310
Failed to initialize LOOLWSD: Exists
wsd-25786-25786 2021-07-19 08:37:08.438294 [ loolwsd ] FTL  Failed to initialize LOOLWSD: Exists| wsd/LOOLWSD.hpp:469
Exists

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I489fab82ca604de76d13bc47674ee4f02e800f79
2021-07-21 08:49:45 +02:00
Pranam Lashkari
e02e1df76d Introduce Freemium options
Signed-off-by: Pranam Lashkari <lpranam@collabora.com>
Change-Id: Ib6b68ff74839cf84f2d8c8cfb7d380be9209f923
2021-07-20 14:41:18 +05:30
Miklos Vajna
f569c2b496 log: don't try to get the channel of a non-existing logger
Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Ic08043dac01b682184ff440b2f7d7f4f3df9522e
2021-07-15 09:01:16 +02:00
Gopi Krishna Menon
9d86193972 Log Last Uno 4 Commands During a Fatal Crash
Records the uno commands from different instances of ChildSession and
dumps the last 4 uno commands into the crashlog during a fatal crash

Signed-off-by: Gopi Krishna Menon <krishnagopi487.github@outlook.com>
Change-Id: I838f71769dc08df7076c040f3d72c15f7607e9d3
2021-07-13 19:48:21 +03:00
Tor Lillqvist
bd0c225c9f Revert "Make it possible to generate Trace Events already when loading the document"
Makes unit-rendering-options fail reliably.

This reverts commit 175c9c5b2a.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Id05c911991baaae0dbc52678a192fc01639352e0
2021-07-07 12:38:11 +03:00
Tor Lillqvist
175c9c5b2a Make it possible to generate Trace Events already when loading the document
By passing a traceevent=yes query parameter in the URL. Note that if
Trace Event generation is not enabled in loolwsd.xml this will have no
effect.

It is a bit silly to notice this query parameter only in loleaflet and
then send the information back to the server. Would be better if the
server noticed it itself before sending the URL to loleaflet.

While at it, let's not bother ever enabling Trace Event generation in
the WSD process. That is not what we are interested in.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I985bfd1e2dbd14aa5a55b386b4762fb64bcb4008
2021-07-07 09:28:02 +03:00
Tor Lillqvist
4f0f7d6123 Avoid assertion failure if toggling Trace Event generation back and forth
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Ie6b7144ecf16faa9d22e7d87801d9dbe9b97d3fc
2021-06-30 12:40:08 +03:00
Tor Lillqvist
64675d2926 Add ProfileZone to encodeSubBufferToPNG
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I7363ea929ba703ce34a5c2411687f120ac5ba59e
2021-06-22 16:43:40 +03:00
Tor Lillqvist
1a2b29d3d5 Add function to check if config has been initialized
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Ieadcb9ad6d34bb6cf789d29896889601baf88a33
2021-06-21 12:43:17 +03:00
Tor Lillqvist
4c68a97ce5 Re-factor Trace Event stuff for improved functionality and thread safety
Write to the Trace Event JSON file in just one place, protected by a
mutex.

Handle metadata events separately. We want them to propagate to the
output if Event Trace generation is just enabled, regardless whether
it has been turned on or not.

We can send the metadata for the Kit process only after we have opened
the docuemnt as sending a Trace Event to WSD uses the (singleton)
Document object in Kit.

Introduce some new functions for the above and adapt callers
appropriately.

Generate a Complete event for the handling of one image tile, from
setting the src attribute of the Image object to finishing the onload
function.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I5978e0fb2495e0d2dc479bf861eb4ac7da03fa50
2021-06-21 12:43:17 +03:00
Tor Lillqvist
b2f4776781 No need to add the thread name to the args of Trace Events now
We automatically emit metadata events that identify threads.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Icb25b5cfc29b28ba7112ca72de56dbb697c8dd5a
2021-06-21 12:43:17 +03:00
Tor Lillqvist
d6569159b7 Output a Trace Event metadata event identifying each named thread
Move the generic dummy implementation of
TraceEvent::emitOneRecording() to a source file of its own. (That is
the one which is used in test and tool executables.)

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I81cab07e5a6852b42d278a5446c13c3825cf546e
2021-06-21 12:43:17 +03:00
Ashod Nakashian
f2f713cdaf wsd: rename file after saving to support async uploading
To avoid writing (saving) while reading (uploading) or
any other undesirable racse on the document file,
we atomically rename the file after saving on disk
to pass ownership.

After saving in Core, we rename the document in the
jail to .upload (by appending it). DocumentBroker
looks for the file with that extension and atomically
renames it to .uploading (by appening the 'ing' suffix).
This way, the Kit only renames from the original to
.upload and DocBroker renames only .upload to .uploading.
This guarantees that we never rename the same file
concurrently.

Uploading decision is strictly based on the modified
timestamp of the .uploading file, compared to the
timestamp of the last file we uploaded successfully.

Change-Id: I03520cd8c87605f6dad417e7a978204f76fc0c38
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-19 17:44:59 -04:00
Ashod Nakashian
0fa12e8e76 wsd: add hexify-data utility
Using for fuzzing and integration testing.

With unit-tests.

Change-Id: I23f8c619e239310d92c74c4d5e4157afb52a5e56
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-06-13 21:57:43 -04:00
Tor Lillqvist
dcf9d9f12b Log also the average tile PNG size and the average compression ratio
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I77fb1ae0e9ef892b23212222b44dc3dc522c7ce3
2021-06-11 09:42:17 +03:00
Henry Castro
371c394d7c Revert "common: add tag string to extract backtrace logs"
It was a request an approved by @kendy despite the signal
handler limitations. After several tries, we were blind
when we introduce the commit using the heap.

This reverts commit 9720eb0f81.
2021-06-03 11:10:08 -04:00
Tor Lillqvist
0f156aefec Include the thread name in the Trace Events emitted from the C++ code, too
Make sure to avoid most of the code path through createArgsString() if
Trace Event generation is not turned on.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: Id86b2c9b4ded9d402647b7a12b9290d0122ba2aa
2021-06-02 10:18:24 +03:00
Tor Lillqvist
8cef48a0fa Introduce a generic TraceEvent class and instant events here, too
Modelled on how it is done in core. ProfileZone is derived from
NamedEvent which is derived from TraceEvent. Here we don't keep any
separate ProfileZone.hpp, though.

This was needed to introduce generation of "instant" events here, too.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I6583134e96001641c50339deb4197fca6ab7d5d5
2021-06-02 09:04:21 +03:00
Tor Lillqvist
b7ca93a41a Add the possibilty to set a thread-local logging level
Add a way to set it from the client.

For now, in the Help > About dialog, the L key toggges the logging
level between the default (whatever is set in loolwsd.xml or on the
loolwsd command line) and the maximum a client is allowed to set
(which also can be set in loolwsd.xml or on the loolwsd command line).

Also while at it, uncouple the toggling of the Trace Event generation
from the triple-click tha toggles tile debugging. It is now on the T
key.

Also swap the meaning of "min" and "max" for the logging levels. Even
if the Poco::Message::Priority values are such that the less urgent
priorities have a numerbcally higher value, conceptually it is more
clear to say the more urgent priorities (levels) are "higher".

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I5383b16ead7d2d378901525eb0d16513d88f045e
2021-05-31 10:56:19 +03:00
Tor Lillqvist
dec5d7f127 Slight renaming to make names match functionality
The "StaticNameHelper" was more than just related to a "name", so call
it StaticHelper instead. And why call the variable of that type
"Source"?

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I099b326cc731e7fb4c96ead9ec19143257090cb1
2021-05-31 10:56:19 +03:00
Tor Lillqvist
2398c792cb No Hungarian notation please
I had accidentally used core naming conventions for ProfileZone.

Change-Id: If10eceb7a5a29d26662d5b21a9289681d814a12e
Signed-off-by: Tor Lillqvist <tml@collabora.com>
2021-05-31 10:56:19 +03:00
Tor Lillqvist
929e466c91 Re-work the ProfileZone implementation here
Don't bother collecting them into a vector, like in core. Instead,
just call a static member function ProfileZone::addOneRecording() for
each Event Trace object (string) to be emitted. That function then
needs to be implemented separately in each executable. In WSD it logs
the object to the Event Trace file. In Kit it sends it to WSD for
logging. In Unit tests we use a dummy implementation.

(If Event Trace logging is not enabled at all in loolwsd.xml (the
default), nothing is done, of course.)

When receiving the "traceeventrecording start" or "traceeventrecording
stop" message from the client, turn ProfileZone recoring on or off in
the WSD and Kit process. (Probably in WSD the flag should be
per-client.)

Change-Id: Ie1127d65dd44ed77e7eeab4b0f0a90cce95dc4a2
Signed-off-by: Tor Lillqvist <tml@collabora.com>
2021-05-31 10:56:19 +03:00
Tor Lillqvist
b265586dda Add the possibility to have arbitrary "arguments" in a ProfileZone object
Note that the C++ ProfileZone class here in Online is totally separate
from the comphelper::ProfileZone in core (which is now derived from
the more generic comphelper::TraceEvent class there).

Also note that this is work in progress and I know that there isn't
any code yet to write out the collected information from this C++
ProfileZone stuff here in Online. Which is why we don't actually have
any ProfileZone variables yet sprinkled through the code. That is
upcoming.

And finally, note that the Trace Event stuff in loleaflet also is
unrelated.

Change-Id: I8765d6dbc1d5108d9d1042781644cbee2419cd9d
Signed-off-by: Tor Lillqvist <tml@collabora.com>
2021-05-24 16:49:46 +03:00
Tor Lillqvist
73943230d2 Fix build for iOS
Change-Id: I774e8802d959eefecd9863edd693f26f0fd1d863
Signed-off-by: Tor Lillqvist <tml@collabora.com>
2021-05-19 13:33:26 +03:00
Tor Lillqvist
d5ded73b11 Fix FreeBSD compilation error
Change-Id: I0201c8213c9593f225c0aab7c4e95b06bd6a22ec
Signed-off-by: Tor Lillqvist <tml@collabora.com>
2021-05-19 13:33:26 +03:00
Gökhan Karabulut
7f736a9bc4 Improve state dump
Add `dumpState` methods to `TileQueue`, `PngCache`, `ThreadPool` classes
and call them from Document::dumpState method within kit.Kit.cpp.
Because `dumpState` method of `_websocketHandler` is protected,
currently we can't dump its internals.

Also dump the other members of the `Document` class. Note that as
`_lastMemStatsTime` is never used, we don't dump it. It seems we could
simply delete it.

Signed-off-by: Gökhan Karabulut <gokhanettin@gmail.com>
Change-Id: Ia89b7fff41eaf475c7a09a644c0eb523b72cf97d
2021-05-13 09:29:35 +01:00
Ashod Nakashian
f6da8d664c wsd: create the unittest SocketPoll thread only when testing
Change-Id: I901ef4722182dd44406c35528c7642414f680814
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-06 22:14:51 -04:00
Henry Castro
ae76450398 common: revisit log messages misc files
LOG_FTL = abnormal, crash, denied service
LOG_ERR = load, save, session, connection, wrong parameters
other cases LOG_WRN, LOG_INF

Change-Id: I15bc840f5a6eaf9a74a1ee1caa57d447baa2afce
Signed-off-by: Henry Castro <hcastro@collabora.com>
2021-05-05 13:50:41 -04:00