Commit graph

303 commits

Author SHA1 Message Date
Mihai Varga
0ea00afb99 loolwsd: allow the specification of the mime type 2015-10-16 19:45:57 +03:00
Miklos Vajna
fed0cbc77c loolwsd: -Werror=unused-parameter 2015-10-16 17:45:03 +02:00
Miklos Vajna
9212c1c321 loolwsd: convert-to handler skeleton 2015-10-16 17:38:24 +02:00
Miklos Vajna
63bf9a1329 loolwsd: invert this condition, so it's possible to add other cases 2015-10-16 15:47:39 +02:00
Miklos Vajna
700b7d08b7 loolwsd: allow frame size of 200K
I got:

WebSocketException: Insufficient buffer for payload size 113579

So double the allocated size: that seems to help.
2015-10-16 15:24:19 +02:00
Tor Lillqvist
7e78f3f0c6 bugs.ccu#1248: If locale is C, set it to en_US.utf8 2015-10-13 20:05:42 +03:00
Mihai Varga
c4825f5492 loolwsd: allow cross origin requests 2015-10-12 20:33:29 +03:00
Mihai Varga
676c6d60d1 tdf#94607 downloadAs command that generates an URL for the doc
When requested, the document is exported under
/jail_path/CHILD_ID/user/thedocument/RANDOMDIR/filename
and CHILD_ID, RANDOMDIR and the filename are communicated to the client.

When the client requests
http://server:port/CHILD_ID/RANDOMDIR/filename, the exported document
is served and then RANDOMDIR is removed
2015-10-09 16:11:38 +03:00
Henry Castro
8a10a16855 loolwsd: restore interactive testing 2015-09-11 16:31:43 -04:00
Mihai Varga
564572e561 loolwsd: also add /etc/host.conf in chroot 2015-09-08 13:03:14 +03:00
Mihai Varga
e17598e866 loolwsd: also copy /etc/nsswitch.conf 2015-09-08 11:31:49 +03:00
Mihai Varga
5396a83c26 loolwsd: copy /etc/hosts when running the server 2015-09-07 15:56:47 +03:00
Mihai Varga
515e6f7fea loolwsd: copy /etc/resolv.conf in the jail
Because sometimes the hostname is not resolved
2015-09-04 18:43:47 +03:00
Henry Castro
7aeca2f92b loolwsd: destroy LOKit when child finished 2015-08-08 08:20:16 -04:00
Henry Castro
54b1e1b612 loolwsd: set thread name to debug socket 2015-08-08 07:55:54 -04:00
Henry Castro
ee928f9af1 loolwsd: create lokit process id logs
Also, when used with --test option, create lokit PID log
so it is attached to the debugger.

gdb loolwsd $(cat /tmp/lokit.pid)
2015-08-05 20:20:05 -04:00
Henry Castro
1c0153d5e0 loolwsd: ensure one child when debugging
when used with --test option:
./loolwsd --test --systemplate=${SYSTEMPLATE} --lotemplate=${MASTER}/instdir
--childroot=${ROOTFORJAILS}

ensure that one child is created and attach to it easily to debug lokit
messages
2015-08-05 20:05:30 -04:00
Henry Castro
0ec12fe11e loolwsd: fix child fork when debugging one child 2015-08-05 18:19:51 -04:00
Henry Castro
ec094f1601 loolwsd: remove _pendingPreSpawnedChildren.
_pendingPreSpawnedChildren is no longer need it, because
fork() is used.
Also adjusted time sleep to 1 second.
2015-07-24 15:17:46 -04:00
Henry Castro
6dafcc753f loolwsd: process sleep for amount of time ...
specified by MAINTENANCE_INTERVAL
2015-07-24 14:10:24 -04:00
Mihai Varga
8f48dabf28 loolwsd: discard requests that are in the queue already 2015-07-21 11:08:36 +03:00
Henry Castro
de3d97d5a4 loolwsd: create PID log file.
The PID log file is used by external utilities
to report processes, threads, etc.
2015-07-19 16:49:11 -04:00
Henry Castro
66756a77a9 loolwsd: change named mutex to private static. 2015-07-18 12:35:16 -04:00
Henry Castro
161e5534ec loolwsd: mutex lock when loKit initialization. 2015-07-17 21:54:26 -04:00
Henry Castro
63a33b39f6 loolwsd: moved server socket to main function. 2015-07-17 17:55:57 -04:00
Henry Castro
404b5edbc9 loolwsd: FileTransferHandler no longer need it. 2015-07-17 16:55:49 -04:00
Henry Castro
99ca81a944 loolwsd: move server socket to parent process 2015-07-17 14:04:40 -04:00
Henry Castro
061a2bfc3d loolwsd: rework child monitor status. 2015-07-16 18:05:28 -04:00
Henry Castro
fd5b676b2d loolwsd: set RTLD_NOW, all undefined symbols in
the library are resolved before dlopen() returns.
Also remove unnecessary commented code.
2015-07-15 20:57:39 -04:00
Henry Castro
3f3b9f7675 loolwsd: remove WSTOPSIG(status).
No child returns status process stop. This cause problems
when we attach one child to debug.
2015-07-15 09:15:12 -04:00
Mihai Varga
0d80d63cb4 loolwsd: don't cancel special tile requests that have an ID 2015-07-14 19:46:29 +03:00
Henry Castro
bb3611399b loolwsd: Use fork but no execve 2015-07-13 10:13:06 -04:00
Jan Holesovsky
767d6a0a32 Create /dev/*random in the chroot so that ssl works.
Also add the missing library to the systemplate.
2015-07-06 19:35:50 +02:00
Tor Lillqvist
6804750463 Don't bother with storing a ref to Application::instance() in a variable in some places 2015-06-09 18:30:21 +03:00
Tor Lillqvist
d3f4ddd355 Use a queue also in the child processes 2015-06-09 18:30:12 +03:00
Tor Lillqvist
629ba87139 Add a "canceltiles" message to the protocol and handle it
Implementing this Was harder than I first expected. The basic idea is as
follows: The master process puts each message arriving from a client that
isn't "canceltiles" into a (client-specific) queue. A separate thread that
pulls messages from the queue at its own pace and handles them as
before. Incoming "canceltiles" messages are handled specially, though: The
queue is emptied of "tile" messages.

The above sounds simple but there are several details that were a bit tricky
to get right.
2015-06-09 18:29:48 +03:00
Tor Lillqvist
ea2141ffe7 Take the tile cache directory as an option, too 2015-06-04 17:09:19 +03:00
Tor Lillqvist
bbf844f8da Fix copy/paste error in help message 2015-06-01 19:52:48 +03:00
Tor Lillqvist
1b85e8eaaa Be more consistent in using 'using' 2015-05-29 08:49:49 +03:00
Tor Lillqvist
f6a00edbee Use shared_ptr to the WebSockets for increased robustness
Why did I wait so long to do this? This is obviously the right thing to do, I
hope, and has a very significant impact on the robustness of the server...
2015-05-28 16:46:37 +03:00
Tor Lillqvist
73273eb027 Also let the nextmessage: from a child process be forwarded to the client
The loadtest program needs it as it, too, uses Poco, which currently does not
have an API to receive an arbitrarily large WebSocket message.
2015-05-28 16:46:37 +03:00
Tor Lillqvist
f7d001ed45 Bin the uid debug output 2015-05-22 17:43:45 +01:00
Tor Lillqvist
180f8fcba0 Pass the --uid option to the child too 2015-05-22 17:42:36 +01:00
Tor Lillqvist
73505aa550 On OS X libsofficeap.dylib is in Frameworks 2015-05-22 14:40:09 +01:00
Tor Lillqvist
9af39d189a Add some fairly hackish things to make this run better on OS X 2015-05-22 14:34:21 +01:00
Tor Lillqvist
8612aab7c4 Make this build on OS X
Note that I said build, not work.
2015-05-22 10:57:17 +01:00
Tor Lillqvist
bc49cccee2 Log the capabilities after dropping one 2015-05-19 13:54:12 +03:00
Tor Lillqvist
65ab397d34 We need CAP_FOWNER, too, on newer Linuxes to be able to hardlink the LO files
At least when not running as the owner of those files. Refactor the capability
dropping so that we can separately drop the CAP_FOWNER and CAP_SYS_CHROOT
capabilities. The child process never needs CAP_FOWNER and the parent process
never needs CAP_SYS_CHROOT.
2015-05-19 13:48:20 +03:00
Tor Lillqvist
e50f243897 Let's not over-complicate this 2015-05-19 07:52:42 +03:00
Tor Lillqvist
058416b9d7 Handle arbitrarily large tile: messages from child to parent
The parent currently uses a fixed-size 100000 byte buffer to receive
messages. Even with a tile size of 256x256 pixels, that is not enough for some
tiles that compress badly as PNG. Add a nextmessage: message that gives the
size of the immediately following message. Send a such before each tile:
message, and handle it appropriately. The nextmessage: message is used only
from child to parent process, it is never sent to the Websocket client.

Once Poco 1.6.1 is released, this will not be necessary.
2015-05-18 11:24:32 +03:00
Mihai Varga
7122e97382 Fixed an unused result compiler error 2015-05-15 09:23:21 +03:00
Tor Lillqvist
1e17966bb9 Drop super-user privileges if using sudo by necessity when debugging
It doesn't work to debug a program that has file capabilities set, it seems,
so to debug the loolwsd master process, one in practice needs to run sudo gdb
on it. But it is not necessarily a good idea to run all of the code as
root. When configured for debugging (--enable-debug), reset real and effective
uid to a non-root one, either one given with an --uid option (typically that
of the developer), or "nobody".
2015-05-13 17:52:20 +03:00
Mihai Varga
1f073e6219 Fixed unused result compile error 2015-05-13 13:00:33 +03:00
Tor Lillqvist
6393cbfd7d Improve help for --port a bit
It must bit be the port number used for listening for the child processes
contacting the master process.
2015-05-08 21:30:32 +03:00
Tor Lillqvist
3e9c4d4bf3 Use a separate HTTPServer listening for child processes connnecting
Otherwise, if we use the same port number and same HTTPServer, if enough
clients try to contact us and, we won't be able to accept child processes
having been spawned.

Also add some temporary debugging output here and there to debug lifecycle
management issues.
2015-05-08 21:30:32 +03:00
Tor Lillqvist
5b1233bdb4 Be sure avoid global object dtors when exiting a child process
The LO ones have a tendency to crash anyway on Solar Mutex assertions (in a
build where assertions are active, obviously).
2015-05-08 21:30:32 +03:00
Tor Lillqvist
aa40335328 Include also the childId in this (temporary) log output 2015-05-08 21:29:45 +03:00
Tor Lillqvist
de52608a35 Drop setuid-root on Linux too, if we for some reason have it 2015-05-07 18:31:59 +03:00
Tor Lillqvist
caea0f9986 Try to make the server more stable when heavily loaded by connections
Use an explicit backlog parameter to the ServerSocket, and an explicit max number
of threads to use for the HTTPServer's thread pool.
2015-05-07 18:26:03 +03:00
Tor Lillqvist
295e8305f9 Use the Linux capability API only on Linux 2015-05-04 21:00:02 +03:00
Tor Lillqvist
dce8e0870e Just _Exit() in childMain
Otherwise various LO global objects will try to run dtors and whatnot, often
crashing.
2015-04-30 21:06:52 +03:00
Tor Lillqvist
19276ed5d8 Actually drop the chroot capability also in the child process
I forgot to do it in childMain() in 28c9561722.
2015-04-28 11:24:00 +03:00
Tor Lillqvist
25575961ed We need to check for cache dir access only in the master process 2015-04-28 11:17:26 +03:00
Tor Lillqvist
2110aef06a No need for this member to be public 2015-04-28 11:02:29 +03:00
Tor Lillqvist
6df6a5d58b Spawn just one child in the --test case 2015-04-28 11:01:18 +03:00
Tor Lillqvist
88cb21867b Spawn children only after starting to listen on the server port
Otherwise some children, especially when there are more than just a few of
them to spawn, might try to contact the server before it is listening.
2015-04-28 10:57:05 +03:00
Tor Lillqvist
28c9561722 Get rid of the CHROOT capability after using it, or when not needing it 2015-04-27 21:55:36 +03:00
Tor Lillqvist
4eaffc74f0 Log the exit status of a child process, or the signal that killed it 2015-04-24 13:14:57 +03:00
Tor Lillqvist
91d0e9329c Fix the waitpid() use
We don't want to use WNOHANG, not sure where I got that idea from. That leads
to busy looping. The loop is in a thread of its own, so it is fine to just
wait ("hang") for some child to die.
2015-04-24 11:26:41 +03:00
Tor Lillqvist
4f9739854a s/localhost/127.0.0.1/
Makes the chrooted child process more reliable on diverse distros/versions.
Let's use 127.0.0.1 in all cases for consistency.
2015-04-23 18:52:19 +03:00
Jan Holesovsky
8be550056b SLEEPFORDEBUGGER is still useful for debugging, re-introduce that.
This reverts commit af3545b897.
2015-04-23 17:29:56 +02:00
Tor Lillqvist
b49d4d8885 Use shared_ptr and weak_ptr in attempt to make the pointer dance more robust
It was obviously very wrong to use both a unique_ptr to the
MasterProcessSession in WebSocketRequestHandler::handleRequest(), and then a
bare pointers to the peer object in the MasterProcessSession object. We got
crashes here and there related to the destructors.

Let's see if we can manage without mutexes.
2015-04-22 21:50:17 +03:00
Tor Lillqvist
59bd08299c _childId is used only in MasterProcessSession 2015-04-22 21:49:53 +03:00
Tor Lillqvist
a0292468da Catch (and ignore) Poco::IOException in a couple of places
There probably are more places where I should catch those and act
appropriately. At least in these places, where the websocket connection is
already closed, or being closed, anyway, the right thing to do is just to
ignore exceptions, which are generated from attempts to write to an already
closed Poco WebSocket, for instance.
2015-04-22 21:48:14 +03:00
Tor Lillqvist
fcea475bb5 Use separate classes derived from LOOLSession for parent and child processes
Work in progress. Does not work properly yet.
2015-04-22 21:48:04 +03:00
Tor Lillqvist
faec3cd961 We indeed don't need the signalfd stuff, I hope
As such it worked, but if we can manage with simpler code, no need to use it.
2015-04-22 21:47:20 +03:00
Tor Lillqvist
02f12402bf This was what I meant
But actually I wonder why I thought I would need signalfd at all; wouldn't it
be enough to just loop in the undertaker thread, calling waitpid(), as long as
there are child processes? I'll try after this commit.

(Besides, I now notice that when I client disconnects, we don't close the
websocket to the child process, so it never goes away. Will fix that.)
2015-04-22 21:46:56 +03:00
Tor Lillqvist
39b6258aa9 Clean up the jail after the prisoner has died 2015-04-22 21:46:33 +03:00
Tor Lillqvist
291710cc1c Typo 2015-04-22 21:46:23 +03:00
Tor Lillqvist
af3545b897 No need for the SLEEPFORDEBUGGER thing any more
As the child processes are pre-spawned and just hang around waiting, there is
ample time to attach one in a debugger in a controlled debugging scenario
anyway.
2015-04-22 21:46:04 +03:00
Tor Lillqvist
1b32383875 Improve help messages 2015-04-22 21:45:47 +03:00
Tor Lillqvist
b760359bda Terminology change: s/fork/spawn
We aren't doing any fork-but-not-exec trick anyway, just a straightforward
start of a child process.
2015-04-22 21:45:31 +03:00
Tor Lillqvist
3abb6d0307 Now the chroot etc re-work is getting closer to working
Works now for the trivial 'connect' test program. Still need to add
pre-spawning of a new child process as soon as an existing one from the pool
has been taking into use. And need to test with the actual JS client.
2015-04-22 21:44:17 +03:00
Tor Lillqvist
652580a761 Another intermediate commit, code still in a non-working state 2015-04-22 21:43:44 +03:00
Tor Lillqvist
0a60ea9dcc Bump Emacs fill-column to 100
The default 70 is so last century.
2015-04-22 21:43:11 +03:00
Tor Lillqvist
7f50f06bf4 Add some comments 2015-04-22 21:42:47 +03:00
Tor Lillqvist
4c7b5a39e3 master LibreOffice no longer does the "restart required" thing when used from LOKit 2015-04-22 21:42:28 +03:00
Tor Lillqvist
f9d93ea57c Work in progress: "pre-forking", chroot, etc. Non-working state
Lots of changes to the server code, LOOLWSD and LOOLSession mainly. This is an
intermediate commit.
2015-04-22 21:42:17 +03:00
Jan Holesovsky
44553f82c0 loolwsd: Don't even start when the cache dir is not available. 2015-04-21 15:51:28 +02:00
Tor Lillqvist
6d9f298ee9 Prefer C++ std headers 2015-03-28 13:57:10 +02:00
Tor Lillqvist
6e36de4534 For debugging, sleep a bit before initialising LOKit if requested
Set the SLEEPFORDEBUGGER environment variable to the number of seconds a child
process should sleep before calling lok_init(), so that you have time to
attach the process in a debugger.
2015-03-27 18:23:27 +02:00
Tor Lillqvist
cec37456ef Set no receive timeout 2015-03-27 16:53:51 +02:00
Tor Lillqvist
3cb43839ea Cosmetics 2015-03-26 17:04:08 +02:00
Tor Lillqvist
b7c08d373e WaE: private field '_helpRequested' is not used 2015-03-26 14:37:38 +02:00
Tor Lillqvist
e8aa011af4 Undo accidental indentation 2015-03-25 15:48:28 +02:00
Tor Lillqvist
4974ea15b1 Bin leftover debug output 2015-03-20 15:53:00 +02:00
Tor Lillqvist
e8ea0f0d2e Use separate child processes for LibreOfficeKit
For now, each LOOL client has a separate child process (or none at all, if it
has accessed only information found in the cache). This will obviously have to
chnage to handle collaboration. Etc.

The parent process talks the same Websocket protocol with the child
processes. When there is a child process for a client, traffic from the client
is forwarded as such to the child process and vice versa.
2015-03-18 15:38:01 +02:00
Tor Lillqvist
50e36c7ca5 Sort 'using' statements 2015-03-16 19:19:30 +02:00
Tor Lillqvist
ad3fda27af Further hacking on tile cache 2015-03-13 01:34:42 +02:00
Tor Lillqvist
79a4eff2cf Catch and log exceptions in the TestOutput thread 2015-03-12 18:58:51 +02:00
Tor Lillqvist
08583f8ebe Add first cut at caching of tiles 2015-03-12 17:26:35 +02:00
Tor Lillqvist
5c8c36b555 Simplify 2015-03-09 17:45:51 +02:00
Tor Lillqvist
163c08e62e Rename the LOOLWS class to LOOLWSD 2015-03-09 17:45:51 +02:00
Renamed from loolwsd/LOOLWS.cpp (Browse further)