Changing the timeout until Wine closes

Questions about Wine on Linux
Locked
Sworddragon
Level 2
Level 2
Posts: 19
Joined: Thu Sep 27, 2012 5:32 pm

Changing the timeout until Wine closes

Post by Sworddragon »

Normally if all applications related to the Wine instance are closed there will remain a few processes (/usr/bin/wineserver, C:\windows\system32\services.exe, C:\windows\system32\winedevice.exe MountMgr, C:\windows\system32\plugplay.exe, C:\windows\system32\explorer.exe /desktop) for several seconds until Wine is completely closed. Is there maybe a way to change the timeout then these processes will awake and exit? In my case I would prefer if these processes would close immediately if all applications are closed.
User avatar
olivierfrdierick
Level 5
Level 5
Posts: 258
Joined: Thu Sep 13, 2012 12:09 pm

Re: Changing the timeout until Wine closes

Post by olivierfrdierick »

There is a -p option to the wineserver command line.
It is documented here: http://www.winehq.org/docs/wineserver

I made some tests with it but could not make wineserver quit sooner than the 3 seconds default delay.
Longer delay works as expected, but shorter has no visible effect, at least on my computer.

For the record, to use the -p command line option without running wineserver explicitly I followed these steps:
  1. Rename the wineserver executable to something else.

    Code: Select all

    sudo mv /usr/lib/i386-linux-gnu/wine/wineserver /usr/lib/i386-linux-gnu/wine/realwineserver
  2. Create a wrapper script that replaces the wineserver executable:

    Code: Select all

    sudo nano /usr/lib/i386-linux-gnu/wine/wineserver
  3. Put this content into the wrapper script:

    Code: Select all

    #!/bin/bash
    /usr/lib/i386-linux-gnu/wine/realwineserver -p0 "$@"
    "$@" is to pass any options given to the wrapper script to realwineserver.
  4. Make the wrapper script executable:

    Code: Select all

    sudo chmod +x /usr/lib/i386-linux-gnu/wine/wineserver
Remarks
  • Setting wineserver command line options directly in the WINESERVER variable is invalid and the variable is then simply ignored.
  • The name and directory where the wrapper script is located can be anything as long as you set the WINESERVER variable to point to it before running any WINE command.
    If you set the name and directory of the wrapper script to the original name and location of the wineserver executable, then you do not need to set WINESERVER.
  • The wineserver executable had to be renamed otherwise the command line options are ignored even if they are passed by the wrapper script.
  • The above instructions must be adapted to whatever configuration you have and I do not guarantee it'll work.
If you try this and manage to get a shorter delay, or any different result, then it'll be nice to tell us.
Sworddragon
Level 2
Level 2
Posts: 19
Joined: Thu Sep 27, 2012 5:32 pm

Re: Changing the timeout until Wine closes

Post by Sworddragon »

Thanks for the information. I have tried this now and increasing and even decreasing the timeout works as expected (I'm on Wine 1.7.19). Also using -p0 does immediately close the wineserver which I was looking for. But I'm wondering if there is a less hackish way to achieve a different default option than using a wrapper script (for example registry keys for default options).
User avatar
olivierfrdierick
Level 5
Level 5
Posts: 258
Joined: Thu Sep 13, 2012 12:09 pm

Re: Changing the timeout until Wine closes

Post by olivierfrdierick »

I couldn't find any other way to set wineserver options other than on the command line.
The only other way I can think of is to modify the source code to either change the default persistence value or add code to use a config file, which are not viable solutions.

All of this is going to break when Wine gets updated.
My wrapper script would also break.

If it wasn't necessary to rename the wineserver executable then script solution wouldn't break.
I have to rename that file because the WINESERVER variable is ignored when wine finds its wineserver executable where it expects it to be.
Only if the wineserver file is missing do wine use the WINESERVER variable (Or at least it does so on my computer).
I've seen this with wine 1.4.1 from debian stable repository and wine 1.7.19 from playonlinux (both x86 and amd64).

Before filing a bug about this I would like other people to confirm that the WINESERVER variable works as expected or not.

To test the WINESERVER variable I did:
  1. Code: Select all

    sudo cp /usr/lib/i386-linux-gnu/wine/wineserver /usr/lib/i386-linux-gnu/wine/wineserver-olivier
    WINESERVER=/usr/lib/i386-linux-gnu/wine/wineserver-olivier wine notepad.exe
  2. Open system monitor in parallel and check wineserver process name.
    It was wineserver
  3. Quit notepad, and wait for wineserver process to finish. Then
  4. Code: Select all

    sudo mv /usr/lib/i386-linux-gnu/wine/wineserver /usr/lib/i386-linux-gnu/wine/wineserver-cannot-be-found
    WINESERVER=/usr/lib/i386-linux-gnu/wine/wineserver-olivier wine notepad.exe
  5. Check the winserver process name in system monitor.
    It is wineserver-olivier
  6. Close notepad, wait for wineserver-olivier process to finish.
  7. Then

    Code: Select all

    wine notepad.exe
    wine outputs

    Code: Select all

    wine: could not exec wineserver
  8. Then replace every thing where it should be

    Code: Select all

    sudo mv /usr/lib/i386-linux-gnu/wine/wineserver-cannot-be-found /usr/lib/i386-linux-gnu/wine/wineserver
    sudo rm /usr/lib/i386-linux-gnu/wine/wineserver-olivier
If what I did is correct then there's something wrong in the way Wine handles the WINESERVER variable.

Furthermore, I also found that copying the wineserver executable in a directory that comes first in the PATH variable is ignored by Wine:

Code: Select all

mkdir -P /home/olivier/thisisatest/bin
sudo cp /usr/lib/i386-linux-gnu/wine/wineserver /home/olivier/thisisatest/bin/wineserver
PATH="/home/olivier/thisisatest/bin:$PATH"
wine notepad.exe
Still uses wineserver from /usr/lib/i386-linux-gun/wine (Of course I made sure no other WINESERVER or WINE* variable where set).
But again, if wineserver is moved from /usr/lib/i386-linux-gnu/wine, then wine finds the wineserver in /home/olivier/thisisatest/bin.

If this last snipet of code did work, it would have been easier to setup the wrapper script as a user.

By the way, someone filed an enhancement request for a variable to disable wineserver persistence.
A variable to SET persistence would be better, but anyway maybe you can join him to support his request? bug 36040
Sworddragon
Level 2
Level 2
Posts: 19
Joined: Thu Sep 27, 2012 5:32 pm

Re: Changing the timeout until Wine closes

Post by Sworddragon »

olivierfrdierick wrote:I have to rename that file because the WINESERVER variable is ignored when wine finds its wineserver executable where it expects it to be.
I remember that I got on my testing some troubles there too. On making now a test again:

/tmp/wineserver contains:

Code: Select all

#!/bin/bash

/usr/bin/wineserver -p0
Executing "WINESERVER=/tmp/wineserver winecfg" in a terminal results that /usr/bin/wineserver without -p0 is started (so the wrapper script got not executed). Renaming/deleting /usr/bin/wineserver and executing the same command again results that the wrapper script is claiming that /usr/bin/wineserver is missing (so it got now executed).

olivierfrdierick wrote:Furthermore, I also found that copying the wineserver executable in a directory that comes first in the PATH variable is ignored by Wine
The manpage says that this is the correct behavior if WINESERVER is not set.

olivierfrdierick wrote:By the way, someone filed an enhancement request for a variable to disable wineserver persistence.
A variable to SET persistence would be better, but anyway maybe you can join him to support his request? bug 36040
I have made now a post there to suggest to control the timeout instead using a flag with an environment variable.


I have also made some tests how to solve this problem. My idea was to use aliases but I could only partly solve the problem. Here is the current code:

Code: Select all

function wineserver_wrapper
{
	arguments=
	explicit_persistent=false
	while [ "$1" != '' ]
	do
		if [[ "$1" =~ ^-p[0-9]*?$ ]]
		then
			explicit_persistent=true
		fi
		arguments="$arguments"' '"$1"
		shift
	done
	if [ $explicit_persistent = false ]
	then
		arguments=-p0' '"$arguments"
	fi
	wineserver $arguments
}

alias wine='wineserver; wine'
alias wineserver=wineserver_wrapper
If wine or wineserver is called it will start the wineserver with -p0 (except if a -p value is explicitly given - it will then be used instead) and all other given arguments. I have put it into ~/.bash_aliases and it currently works if wine or wineserver is called directly. Unfortunately using absolute paths or environment variables causes the old behavior. But maybe somebody else has a better solution.
Locked