dhewm / dhewm3

dhewm 3 main repository
https://dhewm3.org/
GNU General Public License v3.0
1.81k stars 349 forks source link

Issue when launched in the background #215

Closed orbea closed 5 years ago

orbea commented 5 years ago

OS: Slackware64-current dhewm3: 1.5.0 dmenu: 4.8

When launching dhewm3 from dmenu I find that when I exit the program it gets stuck on this screen instead.

1

From here I can press Esc and it brings me back to the normal menu screen where I can then exit without further issues.

This doesn't seem to happen if I start it from an urxvt terminal instead.

Here is more information on dmenu.

http://tools.suckless.org/dmenu/

DanielGibson commented 5 years ago

does it help if you start the game with +set in_tty 0?

orbea commented 5 years ago

In dmenu I tried dhewm3 +set in_tty 0, but it did not help.

DanielGibson commented 5 years ago

can you elaborate how you use dmenu and how you configured it to run dhewm3?

orbea commented 5 years ago

I run the window manager spectrwm.

https://github.com/conformal/spectrwm

In ~/.spectrwm.conf I have the following.

program[menu] = dmenu_run -fn $bar_font -nb $bar_color -nf $bar_font_color -sb $bar_border -sf $bar_color
$ cat /usr/bin/dmenu_run 
#!/bin/sh
dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} &
$ cat /usr/bin/dmenu_path 
#!/bin/sh
cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
if [ -d "$cachedir" ]; then
    cache=$cachedir/dmenu_run
else
    cache=$HOME/.dmenu_cache # if no xdg dir, fall back to dotfile in ~
fi
IFS=:
if stest -dqr -n "$cache" $PATH; then
    stest -flx $PATH | sort -u | tee "$cache"
else
    cat "$cache"
fi

This is bound to ctrl+d where when I press it the dmenu bar opens at the top of the screen I and then type dhewm3 to start /usr/games/dhewm3 executable on my system.

DanielGibson commented 5 years ago

At least with plain dmenu 4.7 from suckless-tools on xubuntu 18.04 I can't reproduce the problem, so the bug must be either in your dmenu version or your script around it or something like that

The error message you're getting also happens if start dhewm3 like: ./dhewm3 1.5.0.1304 - could that somehow happen? Otherwise the "1.5.0.1304" could come from the terminal output (to stdout) of dhewm3 itself, so maybe dmenu or your script (or IDK what else) somehow feeds that back into dhewm3's stdin?

orbea commented 5 years ago

Okay, I see what is happening now, its not so much dmenu, but starting dhewm3 in the background that causes problems.

orbea@Linux:~$ /usr/games/dhewm3 &
[1] 2426
orbea@Linux:~$ dhewm3 1.5.0.1304 linux-x86_64 Dec 18 2018 15:22:02 using SDL v2.0.9
^C
[1]+  Stopped                 /usr/games/dhewm3

At this point dhewm3 never actually opens and I have several phantom dhewm3 process which I have to kill.

Or for a more elaborate example where it actually starts.

orbea@Linux:~$ echo /usr/games/dhewm3 | /bin/sh &
[2] 2454
orbea@Linux:~$ dhewm3 1.5.0.1304 linux-x86_64 Dec 18 2018 15:22:02 using SDL v2.0.9
terminal support disabled: stdin is not a tty
pid: 2455
7936 MB System Memory
found interface lo - loopback
found interface eth0 - 192.168.1.3/255.255.255.0
doom using MMX & SSE & SSE2 for SIMD processing
enabling Flush-To-Zero mode
enabling Denormals-Are-Zero mode
----- Initializing File System -----
Loaded pk4 /usr/share/games/dhewm3/base/pak000.pk4 with checksum 0x28d208f1
Loaded pk4 /usr/share/games/dhewm3/base/pak001.pk4 with checksum 0x40244be0
Loaded pk4 /usr/share/games/dhewm3/base/pak002.pk4 with checksum 0xc51ecdcd
Loaded pk4 /usr/share/games/dhewm3/base/pak003.pk4 with checksum 0xcd79d028
Loaded pk4 /usr/share/games/dhewm3/base/pak004.pk4 with checksum 0x765e4f8b
Loaded pk4 /usr/share/games/dhewm3/base/pak005.pk4 with checksum 0x8ffc3621
Loaded pk4 /usr/share/games/dhewm3/base/pak006.pk4 with checksum 0x95b65ab
Loaded pk4 /usr/share/games/dhewm3/base/pak007.pk4 with checksum 0x666bdb3c
Loaded pk4 /usr/share/games/dhewm3/base/pak008.pk4 with checksum 0x23ae5993
Current search path:
/home/orbea/.config/dhewm3/base
/home/orbea/.local/share/dhewm3/base
/usr/share/games/dhewm3/base
/usr/share/games/dhewm3/base/pak008.pk4 (3 files)
/usr/share/games/dhewm3/base/pak007.pk4 (38 files)
/usr/share/games/dhewm3/base/pak006.pk4 (48 files)
/usr/share/games/dhewm3/base/pak005.pk4 (63 files)
/usr/share/games/dhewm3/base/pak004.pk4 (5137 files)
/usr/share/games/dhewm3/base/pak003.pk4 (4676 files)
/usr/share/games/dhewm3/base/pak002.pk4 (6120 files)
/usr/share/games/dhewm3/base/pak001.pk4 (8972 files)
/usr/share/games/dhewm3/base/pak000.pk4 (2698 files)
Addon pk4s:
----- Initializing Decls -----
5206 strings read from strings/english.lang
Couldn't open journal files
execing editor.cfg
execing default.cfg
execing dhewm.cfg
couldn't exec autoexec.cfg
5206 strings read from strings/english.lang
----- Initializing OpenAL -----
Setup OpenAL device and context
OpenAL: found device 'ALSA Default'
OpenAL: found device 'HDA ATI SB, ALC1150 Analog (CARD=SB,DEV=0)'
OpenAL: found device 'HDA ATI SB, ALC1150 Digital (CARD=SB,DEV=1)'
OpenAL: found device 'HD-Audio Generic, HDMI 0 (CARD=Generic,DEV=3)'
OpenAL: found device 'HD-Audio Generic, HDMI 1 (CARD=Generic,DEV=7)'
OpenAL: found device 'HD-Audio Generic, HDMI 2 (CARD=Generic,DEV=8)'
OpenAL: found device 'HD-Audio Generic, HDMI 3 (CARD=Generic,DEV=9)'
OpenAL: found device 'HD-Audio Generic, HDMI 4 (CARD=Generic,DEV=10)'
OpenAL: found device 'HD-Audio Generic, HDMI 5 (CARD=Generic,DEV=11)'
OpenAL vendor: OpenAL Community
OpenAL renderer: OpenAL Soft
OpenAL version: 1.1 ALSOFT 1.18.0
OpenAL: found EFX extension
OpenAL: found 256 hardware voices
----- Initializing OpenGL -----
Initializing OpenGL subsystem
orbea@Linux:~$ Using 8 color bits, 24 depth, 8 stencil display
OpenGL vendor: X.Org
OpenGL renderer: Radeon RX Vega (VEGA10, DRM 3.27.0, 4.19.8, LLVM 7.0.0)
OpenGL version: 4.5 (Compatibility Profile) Mesa 19.0.0-devel (git-17218a0406)
...using GL_ARB_multitexture
...using GL_ARB_texture_env_combine
...using GL_ARB_texture_cube_map
...using GL_ARB_texture_env_dot3
...using GL_ARB_texture_env_add
...using GL_ARB_texture_non_power_of_two
...using GL_ARB_texture_compression
...using GL_EXT_texture_compression_s3tc
...using GL_EXT_texture_filter_anisotropic
   maxTextureAnisotropy: 16.000000
...using GL_1.4_texture_lod_bias
X..GL_EXT_shared_texture_palette not found
...using GL_EXT_texture3D
...using GL_EXT_stencil_wrap
...using GL_EXT_stencil_two_side
...using GL_ARB_vertex_buffer_object
...using GL_ARB_vertex_program
...using GL_ARB_fragment_program
...using EXT_depth_bounds_test
ARB2 renderer: Available.
----- R_ReloadARBPrograms -----
glprogs/test.vfp
glprogs/test.vfp
glprogs/interaction.vfp
glprogs/interaction.vfp
glprogs/bumpyEnvironment.vfp
glprogs/bumpyEnvironment.vfp
glprogs/ambientLight.vfp
glprogs/ambientLight.vfp
glprogs/shadow.vp
glprogs/environment.vfp
glprogs/environment.vfp
glprogs/arbVP_glasswarp.txt: File not found
glprogs/arbFP_glasswarp.txt: File not found
using ARB_vertex_buffer_object memory
using ARB2 renderSystem
loaded game library '/usr/lib64/dhewm3/base.so'.
game using MMX & SSE & SSE2 for SIMD processing
Flush-To-Zero mode is already enabled
Denormals-Are-Zero mode is already enabled
----- Initializing Game -----
gamename: baseDOOM-1
gamedate: Dec 18 2018
Initializing event system
...473 event definitions
Initializing class hierarchy
...142 classes, 764368 bytes for event callbacks
Initializing scripts
Compiled 'removeInitialSplineAngles': 635 ms
----- Compile stats -----
Memory usage:
     Strings: 79, 13232 bytes
  Statements: 67875, 2715000 bytes
   Functions: 2109, 318020 bytes
   Variables: 170888 bytes
    Mem used: 4483712 bytes
 Static data: 4214344 bytes
   Allocated: 5768260 bytes
 Thread size: 14056 bytes
...6 aas types
----- Initializing Session -----
----- Game Map Shutdown -----
Shutting down sound hardware
idRenderSystem::Shutdown()
Shutting down OpenGL subsystem
orbea@Linux:~$ ----- Game Shutdown -----
----- Game Map Shutdown -----
Shutdown event system
^C
[2]+  Done                    echo /usr/games/dhewm3 | /bin/sh

Note these three sections of the log.

$ echo /usr/games/dhewm3 | /bin/sh &
[2] 2454
orbea@Linux:~$ dhewm3 1.5.0.1304 linux-x86_64 Dec 18 2018 15:22:02 using SDL v2.0.9
terminal support disabled: stdin is not a tty
----- Initializing OpenGL -----
Initializing OpenGL subsystem
orbea@Linux:~$ Using 8 color bits, 24 depth, 8 stencil display
OpenGL vendor: X.Org
----- Game Map Shutdown -----
Shutting down sound hardware
idRenderSystem::Shutdown()
Shutting down OpenGL subsystem
orbea@Linux:~$ ----- Game Shutdown -----
----- Game Map Shutdown -----
Shutdown event system
^C
[2]+  Done                    echo /usr/games/dhewm3 | /bin/sh
DanielGibson commented 5 years ago

Uhhh.. interesting? So dhewm3 doesn't start properly when run in the background (just tested it here, it only outputs "dhewm3 1.5.1pre.1304-debug linux-x86_64 Jan 6 2019 03:29:21 using SDL v2.0.8" and no window opens) - I'll have to investigate that.

And you should probably make sure that random stuff written to stdout is not executed on your end, this could be really dangerous - imagine dhewm3 printed rm -rf / as first line ;)

DanielGibson commented 5 years ago

BTW, while ./dhewm3 & indeed fails here, ./dhewm3 +set in_tty 0 & seems to work correctly

orbea commented 5 years ago

It doesn't here, it still exits out to the shell.

$ /usr/games/dhewm3 +set in_tty 0 &
[1] 10362
orbea@Linux:~$ dhewm3 1.5.0.1304 linux-x86_64 Dec 18 2018 15:22:02 using SDL v2.0.9
terminal support disabled
pid: 10362
7936 MB System Memory
found interface lo - loopback
found interface eth0 - 192.168.1.3/255.255.255.0
doom using MMX & SSE & SSE2 for SIMD processing
enabling Flush-To-Zero mode
enabling Denormals-Are-Zero mode
----- Initializing File System -----
Loaded pk4 /usr/share/games/dhewm3/base/pak000.pk4 with checksum 0x28d208f1
Loaded pk4 /usr/share/games/dhewm3/base/pak001.pk4 with checksum 0x40244be0
Loaded pk4 /usr/share/games/dhewm3/base/pak002.pk4 with checksum 0xc51ecdcd
Loaded pk4 /usr/share/games/dhewm3/base/pak003.pk4 with checksum 0xcd79d028
Loaded pk4 /usr/share/games/dhewm3/base/pak004.pk4 with checksum 0x765e4f8b
Loaded pk4 /usr/share/games/dhewm3/base/pak005.pk4 with checksum 0x8ffc3621
Loaded pk4 /usr/share/games/dhewm3/base/pak006.pk4 with checksum 0x95b65ab
Loaded pk4 /usr/share/games/dhewm3/base/pak007.pk4 with checksum 0x666bdb3c
Loaded pk4 /usr/share/games/dhewm3/base/pak008.pk4 with checksum 0x23ae5993
Current search path:
/home/orbea/.config/dhewm3/base
/home/orbea/.local/share/dhewm3/base
/usr/share/games/dhewm3/base
/usr/share/games/dhewm3/base/pak008.pk4 (3 files)
/usr/share/games/dhewm3/base/pak007.pk4 (38 files)
/usr/share/games/dhewm3/base/pak006.pk4 (48 files)
/usr/share/games/dhewm3/base/pak005.pk4 (63 files)
/usr/share/games/dhewm3/base/pak004.pk4 (5137 files)
/usr/share/games/dhewm3/base/pak003.pk4 (4676 files)
/usr/share/games/dhewm3/base/pak002.pk4 (6120 files)
/usr/share/games/dhewm3/base/pak001.pk4 (8972 files)
/usr/share/games/dhewm3/base/pak000.pk4 (2698 files)
Addon pk4s:
----- Initializing Decls -----
5206 strings read from strings/english.lang
Couldn't open journal files
execing editor.cfg
execing default.cfg
execing dhewm.cfg
couldn't exec autoexec.cfg
5206 strings read from strings/english.lang
----- Initializing OpenAL -----
Setup OpenAL device and context
OpenAL: found device 'ALSA Default'
OpenAL: found device 'HDA ATI SB, ALC1150 Analog (CARD=SB,DEV=0)'
OpenAL: found device 'HDA ATI SB, ALC1150 Digital (CARD=SB,DEV=1)'
OpenAL: found device 'HD-Audio Generic, HDMI 0 (CARD=Generic,DEV=3)'
OpenAL: found device 'HD-Audio Generic, HDMI 1 (CARD=Generic,DEV=7)'
OpenAL: found device 'HD-Audio Generic, HDMI 2 (CARD=Generic,DEV=8)'
OpenAL: found device 'HD-Audio Generic, HDMI 3 (CARD=Generic,DEV=9)'
OpenAL: found device 'HD-Audio Generic, HDMI 4 (CARD=Generic,DEV=10)'
OpenAL: found device 'HD-Audio Generic, HDMI 5 (CARD=Generic,DEV=11)'
OpenAL vendor: OpenAL Community
OpenAL renderer: OpenAL Soft
OpenAL version: 1.1 ALSOFT 1.18.0
OpenAL: found EFX extension
OpenAL: found 256 hardware voices
----- Initializing OpenGL -----
Initializing OpenGL subsystem
orbea@Linux:~$ Using 8 color bits, 24 depth, 8 stencil display
OpenGL vendor: X.Org
OpenGL renderer: Radeon RX Vega (VEGA10, DRM 3.27.0, 4.19.8, LLVM 7.0.0)
OpenGL version: 4.5 (Compatibility Profile) Mesa 19.0.0-devel (git-17218a0406)
...using GL_ARB_multitexture
...using GL_ARB_texture_env_combine
...using GL_ARB_texture_cube_map
...using GL_ARB_texture_env_dot3
...using GL_ARB_texture_env_add
...using GL_ARB_texture_non_power_of_two
...using GL_ARB_texture_compression
...using GL_EXT_texture_compression_s3tc
...using GL_EXT_texture_filter_anisotropic
   maxTextureAnisotropy: 16.000000
...using GL_1.4_texture_lod_bias
X..GL_EXT_shared_texture_palette not found
...using GL_EXT_texture3D
...using GL_EXT_stencil_wrap
...using GL_EXT_stencil_two_side
...using GL_ARB_vertex_buffer_object
...using GL_ARB_vertex_program
...using GL_ARB_fragment_program
...using EXT_depth_bounds_test
ARB2 renderer: Available.
----- R_ReloadARBPrograms -----
glprogs/test.vfp
glprogs/test.vfp
glprogs/interaction.vfp
glprogs/interaction.vfp
glprogs/bumpyEnvironment.vfp
glprogs/bumpyEnvironment.vfp
glprogs/ambientLight.vfp
glprogs/ambientLight.vfp
glprogs/shadow.vp
glprogs/environment.vfp
glprogs/environment.vfp
glprogs/arbVP_glasswarp.txt: File not found
glprogs/arbFP_glasswarp.txt: File not found
using ARB_vertex_buffer_object memory
using ARB2 renderSystem
loaded game library '/usr/lib64/dhewm3/base.so'.
game using MMX & SSE & SSE2 for SIMD processing
Flush-To-Zero mode is already enabled
Denormals-Are-Zero mode is already enabled
----- Initializing Game -----
gamename: baseDOOM-1
gamedate: Dec 18 2018
Initializing event system
...473 event definitions
Initializing class hierarchy
...142 classes, 764368 bytes for event callbacks
Initializing scripts
Compiled 'removeInitialSplineAngles': 636 ms
----- Compile stats -----
Memory usage:
     Strings: 79, 13232 bytes
  Statements: 67875, 2715000 bytes
   Functions: 2109, 318020 bytes
   Variables: 170888 bytes
    Mem used: 4483712 bytes
 Static data: 4214344 bytes
   Allocated: 5768260 bytes
 Thread size: 14056 bytes
...6 aas types
----- Initializing Session -----
----- Game Map Shutdown -----
Shutting down sound hardware
idRenderSystem::Shutdown()
Shutting down OpenGL subsystem
orbea@Linux:~$ ----- Game Shutdown -----
----- Game Map Shutdown -----
Shutdown event system

And you should probably make sure that random stuff written to stdout is not executed on your end, this could be really dangerous - imagine dhewm3 printed rm -rf / as first line ;)

I agree, but I'm not sure what can be done about this yet and haven't seen any other programs do stuff like this...

DanielGibson commented 5 years ago

perhaps other programs don't output as much (or nothing that's a valid shell command) to stdout?

orbea commented 5 years ago

Hmm, you may be right about the second part, I'm going to have to look into why this is happening...

$ mpv &
[1] 18168
orbea@Linux:/tmp$ mpv d6d6da4 Copyright © 2000-2018 mpv/MPlayer/mplayer2 projects
 built on Fri Dec 28 10:10:36 PST 2018
ffmpeg library versions:
   libavutil       56.23.101
   libavcodec      58.39.100
   libavformat     58.22.100
   libswscale      5.4.100
   libavfilter     7.43.100
   libswresample   3.4.100
ffmpeg version: git-2018-11-08-36348d7

Usage:   mpv [options] [url|path/]filename

Basic options:
 --start=<time>    seek to given (percent, seconds, or hh:mm:ss) position
 --no-audio        do not play sound
 --no-video        do not play video
 --fs              fullscreen playback
 --sub-file=<file> specify subtitle file to use
 --playlist=<file> specify playlist file

 --list-options    list all mpv options
 --h=<string>      print options which contain the given string in their name

^C
[1]+  Done                    mpv
orbea commented 5 years ago

Here is a possible way to avoid this, but maybe it could be better.

$ nohup dhewm3 &

Or maybe better.

$ nohup dhewm3 > /dev/null 2>&1 &
orbea commented 5 years ago

Okay I made this change to dmenu_run and now this problem might be solved? It seems that way as far as dhewm3 is concerned at least.

$ cat /usr/bin/dmenu_run
#!/bin/sh
dmenu_path | dmenu "$@" | nohup "${SHELL:-/bin/sh}" >/dev/null 2>&1 &
--- dmenu_run.orig      2019-01-10 14:25:49.481217270 -0800
+++ dmenu_run   2019-01-10 14:25:52.820252350 -0800
@@ -1,2 +1,2 @@
 #!/bin/sh
-dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} &
+dmenu_path | dmenu "$@" | nohup "${SHELL:-/bin/sh}" >/dev/null 2>&1 &
DanielGibson commented 5 years ago

I don't really know what a proper solution for this would be.. I guess you should open an issue at the dmenu/suckless (not sure that name is accurate :-P) bugtracker (or post to their mailing list or however they - hopefully - communicate with their users), maybe they have an idea how to handle this properly (and hopefully securely this time).

I will look into the "dhewm3 doesn't start properly when started in background" issue when I have some time, maybe/hopefully this weekend

orbea commented 5 years ago

I think it just might be inherent to how & works and really a bug in dmenu_run where this was not properly considered. Other programs seem affected too, but by chance dhewm3 made it more obvious... I'll try contacting the suckless dmenu devs and getting back to you.

dhewg commented 5 years ago

Using isatty(fileno(stdin)) to set the default value for in_tty would probably fix the hang for launching dhewm in the background

orbea commented 5 years ago

Just to emphasize that this is a more general problem, here is a small example script which will actually start glxgears when ran in dmenu_run.

#!/bin/sh

echo glxgears
orbea commented 5 years ago

Additionally using the default dmenu_run with xbindkeys instead of the window manager keybind doesn't cause these problems...

DanielGibson commented 5 years ago

maybe xbindkeys and the window manager keybind handle stdin differently somehow

orbea commented 5 years ago

I'll ask the window manager devs.

DanielGibson commented 5 years ago

but it shouldn't matter how dmenu_run is started - it shouldn't do this in any situation

orbea commented 5 years ago

Actually this was all my fault, after being nudged in the right direction in the #suckless irc channel I moved all my configurations out of the way and found that it did not happen. So I looked closer and found that I actually unbound dmenu_run in the window manager and bound it with a wrapper script in xbindbindkeys. The problem was that the wrapper script was embarrassingly wrong..

#!/bin/bash
exe=`dmenu_run -i -nb '#000000' -nf '#B0CFA5' -sb '#446B40' -sf '#000000'` && eval "exec $exe"

I implemented this years ago and forgot, the moral of the story is don't use eval incorrectly.

So I'll close this now, thanks for the time and sorry for the noise.

DanielGibson commented 5 years ago

The issue that dhewm3 doesn't behave like it should when started in the background persists, so I reopened this.

I looked into @dhewg's idea of isatty() and that's already implemented: https://github.com/dhewm/dhewm3/blob/master/neo/sys/posix/posix_main.cpp#L369

@Yamagi suggested looking into signal handling for SIGTTIN and/or SIGTTOU - which I will. Seems like we're currently not handling any signals at all (except in the AROS port)?

orbea commented 5 years ago

Fair enough, feel free to close this when you feel is best.

DanielGibson commented 5 years ago

I just pushed a fix for this to master - would be cool if you could test if it works for you :)