Commit Graph

12 Commits

Author SHA1 Message Date
Wolfgang Bumiller
2311859b0d fork_worker: guard more setup code with eval
As it might die with an error which should end up in the
_exit() code path rather than bailing out into the upper
scope.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Reviewed-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-01-10 14:12:34 +01:00
Wolfgang Bumiller
4d9f4d62e4 fork_worker: use correct handle type for POSIX::write
$resfh can be a pipe from POSIX::pipe() or the upid output
handle, which is an IO::File, so we need to take its
fileno().

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Fixes: ed52a8435a ("fork_worker: use separate pipe for status messages")
Reviewed-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-01-10 14:12:34 +01:00
Thomas Lamprecht
3e2da21600 fork_worker: factor out synced worker output mirroring
When running in sync (CLI environment) we mirror the workers output
to both, STDOUT and th task log file, a similar function as the unix
comand line tool tee provides, thus we borrow its name for the
factored out sub method.

This moves ~60 lines of code out of the big fork_worker sub and makes
it easier to read track what happens there.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2017-12-18 13:37:05 +01:00
Thomas Lamprecht
ed52a8435a fork_worker: use separate pipe for status messages
We forced line wise flushing of the workers STDOUT and STDERR to
capture the final status (TASK OK/TASK ERROR).
Thus, if the code executed in the worker wanted to flush explicitly,
e.g., when the last output wasn't new line terminated but needed to
reach the users eyes, the parent just ignored that.
This leads to confusing results in CLI handlers using fork_workers.

So remove the buffering logic completely and introduce a separate
pipe for sending the final status.
Said pipe gets once read after the child closes (EOF) its STDOUT.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2017-12-18 13:37:05 +01:00
Thomas Lamprecht
95109cc44e fork_worker: refactor passing $upid to parent for sync
STDOUT and $psync[1] are the same here, so no need to differ.
Also we do this only for letting the parent know tha we're ready, the
parent knows the UPID already as it was generated before forking.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2017-12-18 13:37:05 +01:00
Thomas Lamprecht
9a42d8a201 restenv: catch broadcast_tasklist errors gracefully
Don't die because the tasklist could not be broadcasted, just log the
error.
Else we may hinder all task to run with a quite confusing error (i.e.
"ipcc_send_rec: file to big").

This may happen if there are a lot currently running tasks at once.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2017-08-18 10:39:36 +02:00
Thomas Lamprecht
08b0c7c800 restenv: remove unused variable 'ctime'
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2017-08-18 10:21:50 +02:00
Thomas Lamprecht
ad7962b47e restenv: remove unnecessary if
we return early from this function if the $rest_env singleton doesn't
evaluates to true yet, so this check is useless here.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2017-08-18 10:21:50 +02:00
Dietmar Maurer
8e6019b12c PVE::RESTEnvironment::get_user - add $noerr parameter 2017-04-29 08:27:09 +02:00
Dietmar Maurer
dc9c3ffa6c RESTEnvironment->init_request: reset result_attributes 2017-02-24 06:30:16 +01:00
Wolfgang Bumiller
a313fe7335 RESTEnvironment: let check_worker take a $self 2017-01-27 10:27:38 +01:00
Dietmar Maurer
d9072797ea PVE::RESTEnvironment: new base class for PVE::RPCEnvironment
Copied most code from PVE::RPCEnvironment.
2017-01-18 13:12:49 +01:00