/********************************************************************* ** ** PROGRAM: NS-Killer.epplet ** ** PURPOSE: Kill hung ns processes and restart netscape ** ** DATE: ver 0.1 20 Jun 2001 ** ver 0.2 11 Apr 2002 ** ver 0.9 18 Apr 2002 ** ** AUTHOR: Jed Record - ** ** LICENSE: Copyright (c) 2001, 2002 Jed Record ** See the file "COPYING" for details ** ** NOTES: Updates should available at: ** http://www.linuxbuilt.com/jed/projects/epplets/NS-Killer ** **********************************************************************/ /* c headers */ #include #include #include #include /* enlightenment headers */ #include /* define constants */ #define MY_NAME "NS-Killer" #define MY_VER "0.1" #define MY_INFO "none" #define MY_DATA EROOT "/epplet_data/" MY_NAME "/files/" #define MY_IMAGE MY_DATA "background.png" #define MY_BUTTON MY_DATA "button.png" /* we look for the the sound player in the makefile * * if it's not found we use this as the default. */ #if !defined(PLYSND) #define PLYSND "/usr/bin/esdplay" #endif #define PLAY_SOUND1 PLYSND " " MY_DATA "NS-Killer.wav" #define PLAY_SOUND2 PLYSND " " MY_DATA "NS-Killer2.wav" /* declare variables */ Window win; Epplet_gadget w_close, s_help, my_button; char *myimg = MY_IMAGE; char *mybtn = MY_BUTTON; char *mysnd1 = PLAY_SOUND1; char *mysnd2 = PLAY_SOUND2; int focus; int sound_count = 1; /* baic events */ static void window_close(void *data); static void show_help(void *data); static void ns_expose(void *data, Window win, int x, int y, int w, int h); static void restart_ns(void *data); /* Focus behavior */ static void in_focus(void *data, Window win); static void out_focus(void *data, Window win); static void window_close(void *data) { Epplet_unremember(); Esync(); data = NULL; exit(0); } static void show_help(void *data) { Epplet_show_about("NS-Killer"); return; data = NULL; } static void out_focus(void *data, Window win) { if( win == Epplet_get_main_window() ) { Epplet_gadget_hide(w_close); Epplet_gadget_hide(s_help); Epplet_gadget_hide(my_button); } return; data = NULL; } static void in_focus(void *data, Window win) { if( win == Epplet_get_main_window() ) { Epplet_gadget_show(w_close); Epplet_gadget_show(s_help); Epplet_gadget_show(my_button); } return; data = NULL; } static void ns_expose(void *data, Window win, int x, int y, int w, int h) { return; data = NULL; win = (Window) 0; x = y = w = h = 0; } static void restart_ns(void *data) { int buffsize = 512; int nspid; char buffer[buffsize]; char *lockpref; char *pidstr; char *homeptr; char mylock[buffsize]; homeptr = getenv("HOME"); strcpy(mylock, homeptr); strcat(mylock, "/.netscape/lock"); /* is there a lockfile? */ if( readlink(mylock,buffer,buffsize) < 0 ) { /* no lock, user was probably taking a shortcut */ Epplet_spawn_command("netscape"); Esync(); return; data = NULL; } lockpref = strtok(buffer, ":"); pidstr = strtok(NULL, ":"); nspid = atoi(pidstr); /* try and kill netscape */ if( kill(nspid, 9) == 0 ) { /* success! remove the lock, and play smash sound */ unlink(mylock); if( sound_count ) { system(mysnd1); --sound_count; } else { system(mysnd2); ++sound_count; } } Epplet_spawn_command("netscape"); Esync(); return; data = NULL; } /* main body */ int main(int argc, char **argv) { /* make sure we exit nicely */ atexit(Epplet_cleanup); /* initialize the epplet with enlightenment */ Epplet_Init(MY_NAME, MY_VER, MY_INFO, 3, 3, argc, argv, 0); w_close = Epplet_create_button(NULL, NULL, 2, 2, 0, 0, "CLOSE", 0, NULL, window_close, NULL); s_help = Epplet_create_button(NULL, NULL, 34, 2, 0, 0, "HELP", 0, NULL, show_help, NULL); my_button = Epplet_create_text_button("Kill NS!", 3, 20, 40, 15, restart_ns, NULL); Epplet_gadget_show( Epplet_create_image(2, 2, 44, 44, myimg) ); Epplet_register_focus_in_handler(in_focus, NULL); Epplet_register_focus_out_handler(out_focus, NULL); Epplet_register_expose_handler(ns_expose, NULL); win = Epplet_get_main_window(); Epplet_show(); Epplet_Loop(); return 0; }