cnping

Minimal Graphical Ping Tool
git clone https://git.sinitax.com/cnlohr/cnping
Log | Files | Refs | Submodules | README | LICENSE | sfeed.txt

commit e3178ca4f4fbcd53fccf91335b14f92006453ceb
parent f50885b2661457a0c89e77372b1eb5347baad010
Author: David Auer <dreua@posteo.de>
Date:   Thu,  7 Feb 2019 12:39:20 +0100

Handle XDisplay being null

Prints a warning and grecefully exits instead of segmentaiton fault.
This can happen e.g. using SSH or in text mode.

Diffstat:
MCNFGXDriver.c | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/CNFGXDriver.c b/CNFGXDriver.c @@ -91,9 +91,8 @@ void CNFGSetupFullscreen( const char * WindowName, int screen_no ) int screen = XDefaultScreen(CNFGDisplay); int xpos, ypos; - if (!XShapeQueryExtension(CNFGDisplay, &event_basep, &error_basep)) - { - fprintf( stderr, "X-Server does not support shape extension" ); + if (!XShapeQueryExtension(CNFGDisplay, &event_basep, &error_basep)) { + fprintf( stderr, "X-Server does not support shape extension\n" ); exit( 1 ); } @@ -164,6 +163,11 @@ void CNFGTearDown() void CNFGSetup( const char * WindowName, int w, int h ) { CNFGDisplay = XOpenDisplay(NULL); + if ( !CNFGDisplay ) { + fprintf( stderr, "Could not get an X Display.\n%s", + "Are you in text mode or using SSH without X11-Forwarding?\n" ); + exit( 1 ); + } atexit( CNFGTearDown ); XGetWindowAttributes( CNFGDisplay, RootWindow(CNFGDisplay, 0), &CNFGWinAtt );