GNOME Bugzilla – Bug 583778
change script-fu-server to return the output of executed commands
Last modified: 2012-12-14 18:19:32 UTC
Currently, script-fu-server will invariably return 'Success' on executing successfully a command. This is of little use, especially considering that we already have the error byte for this. A much better behavior would be to actually return the output of the executed commands and leave the error byte to indicate if the commands were successful or not. Other information:
Created attachment 135300 [details] [review] changes script-fu-server to return the output of the executed commands
Let's look at this for 2.8.
Ionutz, can you give some sample code/script that can be used to test the patch? Do you see any problems with this patch? Is there a risk it will break already existing script-fu-server clients?
Unfortunately, I can't guarantee that. I've barely managed to poke around and find something that worked for me and, apparently, didn't break something else. That patch is my one and only gimp code I've ever done.
Ok I see. To do this change that would have to be looked into though. I'm putting this bug off the 2.8 milestone for now.
Reopening as I can't see any open question.
Review of attachment 135300 [details] [review]: I don't see anything inherently wrong with the patch, someone just needs to test it thoroughly and think over the consequences.
I'd like to support Ionutz's suggestion. For some context, I'm writing a tiny Perl abstraction layer to automate sending jobs to a Gimp script-fu server. After a quick look into PDB, it looked like the following functions were perfect to make sure a connection to the server was properly opened: gimp-version gimp-image-list gimp-getpid One could imagine avoiding this or that deprecated method based on (gimp-version)'s output, picking the right image thanks to (gimp-image-list), etc. This works properly in the console, but not through a socket to the server, which isn't too nice. Implementing Ionutz's suggestion is indeed a behaviour change, and some people might rely on the server's returning “Success” all the time. Nevertheless, it looks to me like the current behaviour is kind of broken, and that those people really ought to have reported that strange behaviour. Switching from checking for “Success” as payload to checking the error code some bytes before is trivial anyway. I should be playing with that patch on top of 2.8.2 over the next few days, and I'll report back.
After a few basic tests, it looks like the patch is implementing what I would have expected; thanks! Now, what could it break? Looking at execute_command() in script-fu-server.c, and with no specific knowledge about the scheme interpreter side, one can expect the following assertions were true until now: - “Success” fits into a 64k string. - Any error message would fit into a 64k string (even though the client might craft some lengthy messages, I guess). Now, if the user would construct say a for loop returning too long a message, that wouldn't be caught by the patched code. AFAICT, response is a (GString *) with no specific limit on its length. Returning that to a client would mean announcing a <64k size (through the high/low bytes), then sending more than that (iterating until response->len is reached in the second for loop), breaking the receiving end's expectations. One could think of truncating the output without any warnings, which doesn't look too nice; or returning an error code along the “sorry, the command went OK, but its output is too long to return to you” line, which is still not nice, but a little more honest. There might be better solutions, but it's a few hours past sleepy times here… Martin: http://docs.gimp.org/2.8/en/gimp-filters-script-fu.html says servertest.py is here for that purpose. The server can be started this way: gimp --verbose -i -b '(plug-in-script-fu-server RUN-NONINTERACTIVE 10008 "mylogfile.txt")' And the client that way: python ./plug-ins/script-fu/servertest.py localhost 10008 Before: ------- Trying 127.0.0.1. Script-Fu-Remote - Testclient > (gimp-version) (OK): Success > (gimp-image-list) (OK): Success > After: ------ Trying 127.0.0.1. Script-Fu-Remote - Testclient > (gimp-version) (OK): ("2.8.2") > (gimp-image-list) (OK): (0 #()) > Hope this helps. Mraw, KiBi.
Thanks, fixed in master: commit 24ff958580bb286001b0e94605a1bc0a116e8478 Author: Ionutz Borcoman <iborco@gmail.com> Date: Fri Dec 14 19:06:49 2012 +0100 Bug 583778 - change script-fu-server to return the output of executed... Return the output of the command for the client to parse instead of always a useless "Success". plug-ins/script-fu/script-fu-server.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)