*** empty log message ***

This commit is contained in:
dockes 2006-12-23 12:23:15 +00:00
parent 9d9348f472
commit 1a1f97a745
3 changed files with 99 additions and 0 deletions

View File

@ -80,6 +80,13 @@ trconftree.o : conftree.cpp
$(CXX) $(ALL_CXXFLAGS) -DTEST_CONFTREE -c -o trconftree.o \
conftree.cpp
X11MON_OBJS= trx11mon.o x11mon.o
trx11mon : $(X11MON_OBJS)
$(CXX) $(ALL_CXXFLAGS) -o trx11mon $(X11MON_OBJS) -L/usr/X11R6/lib -lX11
trx11mon.o : x11mon.cpp x11mon.h
$(CXX) -o trx11mon.o -c $(ALL_CXXFLAGS) -DTEST_X11MON x11mon.cpp
x11mon.o: x11mon.cpp
$(CXX) -c -I/usr/X11R6/include $(ALL_CXXFLAGS) x11mon.cpp
clean:
rm -f *.o $(PROGS)

84
src/utils/x11mon.cpp Normal file
View File

@ -0,0 +1,84 @@
#ifndef TEST_X11MON
#ifndef lint
static char rcsid[] = "@(#$Id: x11mon.cpp,v 1.1 2006-12-23 12:23:15 dockes Exp $ (C) 2006 J.F.Dockes";
#endif
// Poll state of X11 connectibility (to detect end of user session).
#include <stdio.h>
#include <X11/Xlib.h>
#include <signal.h>
#include <setjmp.h>
#define DODEBUG
#ifdef DODEBUG
#define DEBUG(X) fprintf X
#else
#define DEBUG(X) fprintf X
#endif
static Display *m_display;
static bool m_ok;
static jmp_buf env;
static int errorHandler(Display *, XErrorEvent*)
{
DEBUG((stderr, "x11mon: error handler: Got X11 error\n"));
m_ok = false;
return 0;
}
static int ioErrorHandler(Display *)
{
DEBUG((stderr, "x11mon: error handler: Got X11 IO error\n"));
m_ok = false;
m_display = 0;
longjmp(env, 1);
}
bool x11IsAlive()
{
// Xlib always exits on IO errors. Need a setjmp to avoid this (will jump
// from IO error handler instead of returning).
if (setjmp(env)) {
DEBUG((stderr, "x11IsAlive: Long jump\n"));
return false;
}
if (m_display == 0) {
signal(SIGPIPE, SIG_IGN);
XSetErrorHandler(errorHandler);
XSetIOErrorHandler(ioErrorHandler);
if ((m_display = XOpenDisplay(0)) == 0) {
DEBUG((stderr, "x11IsAlive: cant connect\n"));
m_ok = false;
return false;
}
}
m_ok = true;
bool sync= XSynchronize(m_display, true);
XNoOp(m_display);
XSynchronize(m_display, sync);
return m_ok;
}
#else
// Test driver
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "x11mon.h"
int main(int argc, char **argv)
{
for (;;) {
if (!x11IsAlive()) {
fprintf(stderr, "x11IsAlive failed\n");
} else {
fprintf(stderr, "x11IsAlive Ok\n");
}
sleep(1);
}
}
#endif

8
src/utils/x11mon.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef _X11MON_H_INCLUDED_
#define _X11MON_H_INCLUDED_
/* @(#$Id: x11mon.h,v 1.1 2006-12-23 12:23:15 dockes Exp $ (C) 2006 J.F.Dockes */
/** Poll X11 server status and connectivity */
extern bool x11IsAlive();
#endif /* _X11MON_H_INCLUDED_ */