This code demonstrates how to use ungetch() to send keystrokes to the debugger screen and call into the debugger to execute them. It lets you start RDEBUG remotely, without pressing Alt-Alt-Ctrl-Esc on the server console. You can modify StringToUngetch[] to run other debugger commands.
#include <nwconio.h>
#include <nwdebug.h>
#include <nwerrno.h>
#include <nwthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static char StringToUngetch[] = "rdebug e\r";
int main( void) {
int screen_id = 0;
char screen_name[ 72];
int screen_handle;
size_t i;
while (( screen_id = ScanScreens( screen_id, screen_name, NULL)) != 0) {
if ( strcmp( screen_name, "Debugger Screen") == 0) break;
}
if ( screen_id != 0) {
screen_handle = CreateScreen(( char*) screen_id, 0);
if ( screen_handle == 0 || screen_handle == EFAILURE) {
puts( "CreateScreen failed");
return EXIT_FAILURE;
}
SetCurrentScreen( screen_handle);
for ( i = 0; i < sizeof( StringToUngetch) - 1; ++i) {
ungetch( StringToUngetch[ i]);
}
EnterDebugger();
}
return EXIT_SUCCESS;
}
© 2009 Novell, Inc. All Rights Reserved.