Bug 30879 - Libreoffice StarDesktop.terminate() macro behaviour
Summary: Libreoffice StarDesktop.terminate() macro behaviour
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: Other Linux (All)
: medium normal
Assignee: Noel Power
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-14 11:59 UTC by Callegar
Modified: 2011-02-09 02:51 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments
Test case (9.36 KB, application/vnd.oasis.opendocument.text)
2011-02-03 01:10 UTC, Callegar
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Callegar 2010-10-14 11:59:06 UTC
Hi

I have a document containing just a couple of macros which I use for document conversion. The macros are

SaveSlidesAsPDF(<filename>) 

Shutdown()

the first one opens the file passed as an argument and exports it as PDF /including the notes pages/. The second one simply quits openoffice/libreoffice.

With openoffice I can use this nicely to perform document conversion with customized options wrt standard ones. Also I find it very convenient to have the macros in a file, rather than to install them directly inside the application.

In this way, carrying with me just the macro file and a script I can do my conversions regardless of the specific instance of openoffice I am on.

Now this thing that works perfectly in openoffice, does not work with libreoffice. The issue seems to be the Shutdown macro not working in libre.
Its content is

Sub Shutdown()
oDoc=ThisComponent
oDoc.close(True)
StarDesktop.terminate()
End Sub

Any clue why does this not work in libreoffice and works in openoffice?
Comment 1 Callegar 2010-10-14 12:44:15 UTC
StarDesktop.Terminate() indeed appears to be broken in libreoffice.

If you have a code snippet like the following

Sub Shutdown()
  msgbox("ONE")
  StarDesktop.Terminate()
  msgbox("TWO")
End Sub

libreoffice on invocation displays both the box "ONE" and then the box "TWO", then hangs with no window.
Comment 2 Michael Meeks 2010-10-14 13:00:26 UTC
Good catch; thanks. Noel ? :-)
Comment 3 Callegar 2010-10-14 13:57:19 UTC
found a possibly simpler testcase

libreoffice ".uno:Quit"

does not work (libreoffice remains open)

soffice ".uno:Quit"

works (openoffice opens and closes)
Comment 4 Noel Power 2010-10-15 02:18:25 UTC
(In reply to comment #0)

> Sub Shutdown()
> oDoc=ThisComponent
> oDoc.close(True)
> StarDesktop.terminate()
> End Sub
> 
> Any clue why does this not work in libreoffice and works in openoffice?
Works for me!! I can think of no changes that would impact this behaviour. Additionally I would stress that calling Stardesktop.terminate in this way is unwise, I suspect that only by luck this doesn't core dump, tearing the ground from underneath basic whilst it's still running doesn't sound like a good idea ;-) 
Is the quickstarter running ? I see the behaviour you describe in that scenario
Comment 5 Noel Power 2010-10-15 02:20:53 UTC
Sergio, putting the bug into needs info ( see Whiteboard and keywords above ) please remove them when you can provide the info
Comment 6 Noel Power 2010-10-15 02:23:08 UTC
(In reply to comment #3)
> found a possibly simpler testcase
> 
> libreoffice ".uno:Quit"
> 
> does not work (libreoffice remains open)
> 
> soffice ".uno:Quit"
> 
> works (openoffice opens and closes)

can you please open a seperate bug for that behaviour I think it is a completely different issue.
Comment 7 Callegar 2010-10-15 04:28:59 UTC
Hi,

in reply to Noel's first message:

thanks for looking it... I strongly suspected that calling stardesktop.terminate in this way could be problematic, yet it was the suggested way on one of openoffice wikis (cannot remember where i got it, but I can try looking into it). If there is a better way to achieve the goal I would be happy to know. Maybe can you hint me a pointer (even out of this bug report, if it is inappropriate here).

For the note about "quickstarter..." I am on linux... I thought it was not available on this platform, is it?

for the "works for me" bit... I noticed this weird behaviour...

libreoffice helper.odt macro://helper/Standard.Module1.Shutdown\(\)

libreoffice opens and closes just fine. But if I call

libreoffice helper.odt macro://helper/Standard.Module1.DoSomething\(\) macro://helper/Standard.Module1.Shutdown\(\)

libreoffice opens, executes the DoSomething task just fine, then executes Shutdown, but does not close on the stardesktop.terminate()

... and in reply to the second one:

I run into the ".uno:Quit" because on one of the openoffice mailing list I found it indicated as a way to "test" the stardesktop.terminate() behaviour. If I remember correctly the entry was saying something like ".uno:Quit" goes through the dispatcher, but ultimately calls the stardesktop.terminate() api.

If appropriate, I will definitively open a different bug.

Note that if the ".uno:Quit" is made to work, I can modify my scripts to do

libreoffice helper.odt macro://helper/Standard.Module1.DoSomething\(\) ".uno:Quit"

(this works on openoffice.org).  BTW would this be a more appropriate way to shut down openoffice after having executed a task?
Comment 8 Callegar 2010-10-31 04:13:34 UTC
I have seen that a quickstarter is in fact available on this version of the code.

The problem is present either with or without the quickstarter, though.
Comment 9 Callegar 2011-02-03 01:10:38 UTC
Created attachment 42886 [details]
Test case

Created a test case, a document with just the following macro:

Sub Shutdown()
  msgbox("Ready to quit")
  StarDesktop.Terminate()
End Sub

I have the following results in linux (ubuntu maverick 64bit) where both libreoffice 3.3 and openoffice.org 3.3 are installed

Test 1)

soffice prova.odt macro://prova/Standard.Module1.Shutdown\(\)

openoffice.org opens, opens the (empty) file prova.odt, prints the dialog "Ready to quit" on click on the OK button exits.

This is a nice behavior. Means that one can put macro code in a helper document and use it to script operations to be applied on other documents without any need to install a macro set within openoffice.  Document automation can work under the following lines

soffice -headless helper.odt macro://helper.Standard.Module1.Process\(target_document.odt\)

This, assuming that the helper document contains a macro named process that does something on a target document and then invokes StarDesktop.Terminate()

On the invokation of the above command, soffice starts, performs the desired operation on the target document and quits.  Also this is great for office automation, since it works anywhere, with no need to install anything apart, just providing the helper.

Since this has been the standard behavior of openoffice.org for ages, I came to rely on it and now I have many helper scripts that I use in this way.


Test 2)

libreoffice prova.odt macro://prova/Standard.Module1.Shutdown\(\)

libreoffice opens, opens the (empty) file prova.odt, prints the dialog "Ready to quit" on click on the OK button closes its window, then happyly reopens it and stays alive.

This is an unfortunate behavior. I cannot anymore do document automation like before. If I assume to have an helper script like before and I put something like

libreoffice -headless helper.odt macro://helper.Standard.Module1.Process\(target_document.odt\)

the script will hang forever, since libreoffice does not terminate after having performed its duty.

Also this is incosistent with openoffice.org and means that anyone having document automation scripts like mine cannot migrate to libreoffice.


Notes:

1) Using the same approach as in "unoconv" does not seem to be an option to solve my document automation problem. Unoconv developers report themselves that they cannot start and stop reliably openoffice as a listener.

2) In the libreoffice test the quickstarter is disabled.

3) As already mentioned, the same kind of inconsistency between openoffice.org and libreoffice can be seen by

soffice ".uno:Quit"

openoffice.org starts and terminates

libreoffice ".uno:Quit"

libreoffice starts and does not terminate.



Please do not disregard this inconsistency between libreoffice and openoffice.org.  It is not just something to put on a wishlist.  It means that 
anyone relying on document automation solutions developed for openoffice.org now 
 cannot migrate to libreoffice.
Comment 10 Noel Power 2011-02-04 04:44:17 UTC
(In reply to comment #9)

> 3) As already mentioned, the same kind of inconsistency between openoffice.org
> and libreoffice can be seen by
> 
> soffice ".uno:Quit"
> 
> openoffice.org starts and terminates
> 
> libreoffice ".uno:Quit"
> 
> libreoffice starts and does not terminate.
> 
> 
I think that this is the key problem and ( the quit command ) is imho a bug, regarding the use of terminate from within a macro to shutdown the office I still remain unconvinced that it is wise. But.. I also begin to think the root cause of the behaviour of the macro and this above is the same
Comment 11 Noel Power 2011-02-04 08:23:18 UTC
fixed on master, should appear in 3.3.1 ( thanks for the example doc and description it helped alot )
Comment 12 Callegar 2011-02-05 07:14:10 UTC
This is great news, many thanks!