Removed obsolete code.

Adapted new dir_list.
Now pid and status for childs are reported directly via channel instead
storing (and locking) them in global variables.
This commit is contained in:
Sanel Zukan 2007-12-03 13:39:22 +00:00
parent 64683f504e
commit 8ff399f71e
8 changed files with 58 additions and 158 deletions

View File

@ -19,7 +19,6 @@
#include "Autostart.h" #include "Autostart.h"
#include <edelib/File.h> #include <edelib/File.h>
//#include <edelib/Regex.h>
#include <edelib/Config.h> #include <edelib/Config.h>
#include <edelib/DesktopFile.h> #include <edelib/DesktopFile.h>
#include <edelib/Directory.h> #include <edelib/Directory.h>
@ -29,15 +28,12 @@
#include <edelib/MessageBox.h> #include <edelib/MessageBox.h>
#include <edelib/Nls.h> #include <edelib/Nls.h>
#include <FL/fl_ask.h>
#include <sys/types.h> // getpid #include <sys/types.h> // getpid
#include <unistd.h> // pipe #include <unistd.h> // pipe
#include <fcntl.h> // fcntl #include <fcntl.h> // fcntl
#include <stdlib.h> // free #include <stdlib.h> // free
#include <string.h> // strdup, memset #include <string.h> // strdup, memset
#include <errno.h> // error codes #include <errno.h>
#include <signal.h> #include <signal.h>
void resolve_path(const edelib::String& datadir, edelib::String& item, bool have_datadir) { void resolve_path(const edelib::String& datadir, edelib::String& item, bool have_datadir) {
@ -206,14 +202,14 @@ EvokeService::EvokeService() :
is_running(0), logfile(NULL), xsm(NULL), pidfile(NULL), lockfile(NULL) { is_running(0), logfile(NULL), xsm(NULL), pidfile(NULL), lockfile(NULL) {
wake_up_pipe[0] = wake_up_pipe[1] = -1; wake_up_pipe[0] = wake_up_pipe[1] = -1;
quit_child_pid = quit_child_ret = -1; //quit_child_pid = quit_child_ret = -1;
} }
EvokeService::~EvokeService() { EvokeService::~EvokeService() {
if(logfile) if(logfile)
delete logfile; delete logfile;
stop_xsettings_manager(); stop_xsettings_manager(true);
if(lockfile) { if(lockfile) {
edelib::file_remove(lockfile); edelib::file_remove(lockfile);
@ -255,6 +251,7 @@ bool EvokeService::setup_logging(const char* file) {
if(!logfile->open(file)) { if(!logfile->open(file)) {
delete logfile; delete logfile;
logfile = NULL;
return false; return false;
} }
@ -393,8 +390,8 @@ void EvokeService::init_autostart(bool safe) {
edelib::String adir = edelib::user_config_dir(); edelib::String adir = edelib::user_config_dir();
adir += autostart_dirname; adir += autostart_dirname;
StringList dfiles, sysdirs; StringList dfiles, sysdirs, tmp;
StringListIter it, it_end; StringListIter it, it_end, tmp_it, tmp_it_end;
edelib::dir_list(adir.c_str(), dfiles, true); edelib::dir_list(adir.c_str(), dfiles, true);
@ -402,8 +399,15 @@ void EvokeService::init_autostart(bool safe) {
if(!sysdirs.empty()) { if(!sysdirs.empty()) {
for(it = sysdirs.begin(), it_end = sysdirs.end(); it != it_end; ++it) { for(it = sysdirs.begin(), it_end = sysdirs.end(); it != it_end; ++it) {
*it += autostart_dirname; *it += autostart_dirname;
// append content
edelib::dir_list((*it).c_str(), dfiles, true, false, false); /*
* append content
* FIXME: too much of copying. There should be some way to merge list items
* probably via merge() member
*/
edelib::dir_list((*it).c_str(), tmp, true);
for(tmp_it = tmp.begin(), tmp_it_end = tmp.end(); tmp_it != tmp_it_end; ++tmp_it)
dfiles.push_back(*tmp_it);
} }
} }
@ -466,7 +470,7 @@ void EvokeService::init_xsettings_manager(void) {
if(Xsm::manager_running(fl_display, fl_screen)) { if(Xsm::manager_running(fl_display, fl_screen)) {
int ret = edelib::ask(_("XSETTINGS manager already running on this screen. Would you like to replace it?")); int ret = edelib::ask(_("XSETTINGS manager already running on this screen. Would you like to replace it?"));
if(ret < 1) { if(ret < 1) {
stop_xsettings_manager(); stop_xsettings_manager(false);
return; return;
} else } else
goto do_it; goto do_it;
@ -475,7 +479,7 @@ void EvokeService::init_xsettings_manager(void) {
do_it: do_it:
if(!xsm->init(fl_display, fl_screen)) { if(!xsm->init(fl_display, fl_screen)) {
edelib::alert(_("Unable to load XSETTINGS manager properly")); edelib::alert(_("Unable to load XSETTINGS manager properly"));
stop_xsettings_manager(); stop_xsettings_manager(false);
} }
if(!xsm) return; if(!xsm) return;
@ -484,11 +488,13 @@ do_it:
xsm->notify(); xsm->notify();
} }
void EvokeService::stop_xsettings_manager(void) { void EvokeService::stop_xsettings_manager(bool serialize) {
if(!xsm) if(!xsm)
return; return;
xsm->save_serialized("ede-settings.xml"); if(serialize)
xsm->save_serialized("ede-settings.xml");
delete xsm; delete xsm;
xsm = NULL; xsm = NULL;
} }
@ -566,46 +572,30 @@ void EvokeService::quit_x11(void) {
* This is run each time when some of the managed childs quits. * This is run each time when some of the managed childs quits.
* Instead directly running wake_up(), it will be notified wia * Instead directly running wake_up(), it will be notified wia
* wake_up_pipe[] channel, via add_fd() monitor. * wake_up_pipe[] channel, via add_fd() monitor.
*
* This workaround is due races.
*/ */
void EvokeService::service_watcher(int pid, int ret) { void EvokeService::service_watcher(int pid, int ret) {
puts("=== service_watcher() ==="); write(wake_up_pipe[1], &pid, sizeof(int));
printf("got %i\n", ret); write(wake_up_pipe[1], &ret, sizeof(int));
Mutex mutex;
mutex.lock();
quit_child_ret = ret;
quit_child_pid = pid;
mutex.unlock();
if(write(wake_up_pipe[1], "c", 1) != 1)
puts("error write");
} }
void EvokeService::wake_up(int fd) { void EvokeService::wake_up(int fd) {
puts("=== wake_up() ==="); puts("=== wake_up() ===");
char c; int child_pid = -1;
if(read(wake_up_pipe[0], &c, 1) != 1 || c != 'c') { // child can return anything so there is no default value
int child_ret;
if(read(wake_up_pipe[0], &child_pid, sizeof(int)) == -1 || child_pid == -1) {
puts("unable to read from channel");
return;
}
if(read(wake_up_pipe[0], &child_ret, sizeof(int)) == -1) {
puts("unable to read from channel"); puts("unable to read from channel");
return; return;
} }
Mutex mutex; Mutex mutex;
mutex.lock();
int child_ret = quit_child_ret;
int child_pid = quit_child_pid;
mutex.unlock();
//EASSERT(child_ret != -1 && child_pid != -1);
mutex.lock();
quit_child_ret = quit_child_pid = -1;
mutex.unlock();
if(child_ret == SPAWN_CHILD_CRASHED) { if(child_ret == SPAWN_CHILD_CRASHED) {
EvokeProcess pc; EvokeProcess pc;
bool ret; bool ret;
@ -621,7 +611,6 @@ void EvokeService::wake_up(int fd) {
cdialog.run(); cdialog.run();
} }
} else { } else {
mutex.lock(); mutex.lock();
unregister_process(child_pid); unregister_process(child_pid);
mutex.unlock(); mutex.unlock();
@ -641,10 +630,8 @@ void EvokeService::wake_up(int fd) {
break; break;
} }
} }
} }
/* /*
* Execute program. It's return status * Execute program. It's return status
* will be reported via service_watcher() * will be reported via service_watcher()
@ -682,69 +669,6 @@ void EvokeService::run_program(const char* cmd, bool enable_vars) {
} }
} }
#if 0
void EvokeService::heuristic_run_program(const char* cmd) {
if(strncmp(cmd, "$TERM ", 6) == 0) {
run_program(cmd);
return;
}
edelib::String ldd = edelib::file_path("ldd");
if(ldd.empty()) {
run_program(cmd);
return;
}
ldd += " ";
ldd += edelib::file_path(cmd);
int r = spawn_program(ldd.c_str(), 0, 0, "/tmp/eshrun");
printf("%s\n", ldd.c_str());
if(r != 0) {
printf("spawn %i\n", r);
return;
}
sleep(1);
//edelib::File f;
FILE* f = fopen("/tmp/eshrun", "r");
if(!f) {
puts("File::open");
return;
} else {
puts("opened /tmp/eshrun");
}
edelib::Regex rx;
rx.compile("^\\s*libX11");
char buff[1024];
bool is_gui = 0;
while(fgets(buff, sizeof(buff)-1, f)) {
printf("checking %s\n", buff);
if(rx.match(buff)) {
printf("found libX11\n");
is_gui = 1;
//break;
}
}
fclose(f);
edelib::String fcmd;
if(!is_gui) {
fcmd = "$TERM ";
fcmd += cmd;
} else {
fcmd = cmd;
}
run_program(fcmd.c_str());
}
#endif
void EvokeService::register_process(const char* cmd, pid_t pid) { void EvokeService::register_process(const char* cmd, pid_t pid) {
EvokeProcess pc; EvokeProcess pc;
pc.cmd = cmd; pc.cmd = cmd;
@ -795,20 +719,17 @@ bool EvokeService::find_and_unregister_process(pid_t pid, EvokeProcess& pc) {
/* /*
* Main loop for processing got X events. * Main loop for processing got X events.
* *
* Great care must be taken to route this events to fltk too (via fl_handle()), since * Great care must be taken to route this events to FLTK too (via fl_handle()), since
* add_fd() (in evoke.cpp) will not do that. If events are not routed to fltk, popped * add_fd() (in evoke.cpp) will not do that. If events are not routed to fltk, popped
* dialogs, especially from service_watcher() will not be correctly drawn and will hand * dialogs, especially from service_watcher() will not be correctly drawn and will hang
* whole program. * whole program.
*
* FIXME: any better way ?
*/ */
int EvokeService::handle(const XEvent* xev) { int EvokeService::handle(const XEvent* xev) {
EVOKE_LOG("Got event %i\n", xev->type); EVOKE_LOG("Got event %i\n", xev->type);
if(xsm && xsm->should_terminate(xev)) { if(xsm && xsm->should_terminate(xev)) {
EVOKE_LOG("XSETTINGS manager shutdown\n"); EVOKE_LOG("XSETTINGS manager shutdown\n");
stop_xsettings_manager(); stop_xsettings_manager(true);
// return 1;
} }
#if 0 #if 0
else if(xev->type == MapNotify) { else if(xev->type == MapNotify) {
@ -835,7 +756,6 @@ int EvokeService::handle(const XEvent* xev) {
} else { } else {
EVOKE_LOG("Got _EDE_EVOKE_SPAWN with malformed data. Ignoring...\n"); EVOKE_LOG("Got _EDE_EVOKE_SPAWN with malformed data. Ignoring...\n");
} }
// return 1;
} }
if(xev->xproperty.atom == _ede_evoke_quit) { if(xev->xproperty.atom == _ede_evoke_quit) {
@ -845,7 +765,6 @@ int EvokeService::handle(const XEvent* xev) {
stop(); stop();
} else } else
EVOKE_LOG("Got _EDE_EVOKE_QUIT with bad code (%i). Ignoring...\n", val); EVOKE_LOG("Got _EDE_EVOKE_QUIT with bad code (%i). Ignoring...\n", val);
// return 1;
} }
if(xev->xproperty.atom == _ede_shutdown_all) { if(xev->xproperty.atom == _ede_shutdown_all) {
@ -861,10 +780,9 @@ int EvokeService::handle(const XEvent* xev) {
//quit_x11(); //quit_x11();
} else } else
EVOKE_LOG("Got _EDE_EVOKE_SHUTDOWN_ALL with bad code (%i). Ignoring...\n", val); EVOKE_LOG("Got _EDE_EVOKE_SHUTDOWN_ALL with bad code (%i). Ignoring...\n", val);
// return 1;
} }
} }
//return 0; // let FLTK handle the rest
return fl_handle(*xev); return fl_handle(*xev);
} }

View File

@ -66,11 +66,8 @@ class EvokeService {
ClientList clients; ClientList clients;
ProcessList processes; ProcessList processes;
int quit_child_pid;
int quit_child_ret;
int wake_up_pipe[2]; int wake_up_pipe[2];
public: public:
EvokeService(); EvokeService();
~EvokeService(); ~EvokeService();
@ -88,7 +85,7 @@ class EvokeService {
void init_autostart(bool safe); void init_autostart(bool safe);
void init_xsettings_manager(void); void init_xsettings_manager(void);
void stop_xsettings_manager(void); void stop_xsettings_manager(bool serialize);
int handle(const XEvent* ev); int handle(const XEvent* ev);

View File

@ -24,6 +24,7 @@ SOURCE = evoke.cpp
Autostart.cpp ; Autostart.cpp ;
LinkAgainst evoke : -lao -lvorbis -lvorbisfile ; LinkAgainst evoke : -lao -lvorbis -lvorbisfile ;
#LinkAgainst evoke : -lpthread ;
EdeProgram evoke : $(SOURCE) ; EdeProgram evoke : $(SOURCE) ;
FltkProgramBare test/evoke_test : test/evoke_test.cpp ; FltkProgramBare test/evoke_test : test/evoke_test.cpp ;

View File

@ -17,9 +17,9 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/time.h> // getrlimit, setrlimit #include <sys/time.h> // getrlimit, setrlimit

View File

@ -30,13 +30,6 @@
extern void service_watcher_cb(int pid, int signum); extern void service_watcher_cb(int pid, int signum);
Fl_Double_Window* splash_win = 0; Fl_Double_Window* splash_win = 0;
class AutoSound {
public:
AutoSound() { edelib::SoundSystem::init(); }
~AutoSound() { if(edelib::SoundSystem::inited()) edelib::SoundSystem::shutdown(); }
void play(const char* file) { if(edelib::SoundSystem::inited()) edelib::SoundSystem::play(file, 0); }
};
int splash_xmessage_handler(int e) { int splash_xmessage_handler(int e) {
if(fl_xevent->type == MapNotify || fl_xevent->type == ConfigureNotify) { if(fl_xevent->type == MapNotify || fl_xevent->type == ConfigureNotify) {
if(splash_win) { if(splash_win) {
@ -192,15 +185,11 @@ void Splash::run(void) {
int sh = DisplayHeight(fl_display, fl_screen); int sh = DisplayHeight(fl_display, fl_screen);
position(sw/2 - w()/2, sh/2 - h()/2); position(sw/2 - w()/2, sh/2 - h()/2);
#if 0
bool sound_loaded = false; bool sound_loaded = false;
if(sound && !sound->empty()) if(sound && !sound->empty())
sound_loaded = edelib::SoundSystem::init(); sound_loaded = edelib::SoundSystem::init();
#endif
AutoSound sound_play;
show(); show();
Fl::add_timeout(TIMEOUT_START, runner_cb, this); Fl::add_timeout(TIMEOUT_START, runner_cb, this);
/* /*
@ -212,20 +201,17 @@ void Splash::run(void) {
//XSelectInput(fl_display, RootWindow(fl_display, fl_screen), SubstructureNotifyMask); //XSelectInput(fl_display, RootWindow(fl_display, fl_screen), SubstructureNotifyMask);
//Fl::add_handler(splash_xmessage_handler); //Fl::add_handler(splash_xmessage_handler);
#if 0
if(sound_loaded) if(sound_loaded)
edelib::SoundSystem::play(sound->c_str(), 0); edelib::SoundSystem::play(sound->c_str(), 0);
#endif
sound_play.play(sound->c_str());
while(shown()) while(shown())
Fl::wait(); Fl::wait();
#if 0
if(sound_loaded) { if(sound_loaded) {
edelib::SoundSystem::stop(); edelib::SoundSystem::stop();
edelib::SoundSystem::shutdown(); edelib::SoundSystem::shutdown();
} }
#endif
splash_win = 0; splash_win = 0;
} }

View File

@ -168,5 +168,6 @@ bool Xsm::save_serialized(const char* file) {
setting_file.close(); setting_file.close();
edelib::xsettings_list_free(settings); edelib::xsettings_list_free(settings);
return true; return true;
} }

View File

@ -2,33 +2,36 @@
# main section; must be present # main section; must be present
[evoke] [evoke]
Startup = edewm,eiconman,eworkpanel,xscreensaver Startup = edewm,eiconman,eworkpanel,xscreensaver
DataDirectory = data # DataDirectory = data
# DataDirectory = /home/sanel/blentavo/EDE/ede2/evoke/data DataDirectory = /home/sanel/blentavo/EDE/ede2/evoke/data
Splash = splash-alpha1.png Splash = splash-alpha1.png
Sound = startup.ogg Sound = startup.ogg
# Sound = Startup1_2.ogg # Sound = Startup1_2.ogg
[edewm] [edewm]
Icon = edewm.png Icon = edewm.png
Exec = gvim # Exec = gvim
# Exec = edewm Exec = edewm
# Exec = fluxbox
Description = window manager Description = window manager
[eiconman] [eiconman]
Icon = eiconman.png Icon = eiconman.png
Exec = mozilla # Exec = mozilla
# Exec = /home/sanel/blentavo/EDE/ede2/eiconman/eiconman # Exec = /home/sanel/blentavo/EDE/ede2/eiconman/eiconman
# Exec = eiconman Exec = eiconman
# Exec = /home/sanel/abc
Description = desktop Description = desktop
[eworkpanel] [eworkpanel]
Icon = eworkpanel.png Icon = eworkpanel.png
Exec = mrxvt -bg black # Exec = mrxvt -bg black
# Exec = eworkpanel Exec = eworkpanel
Description = panel Description = panel
[xscreensaver] [xscreensaver]
Icon = xscreensaver.png Icon = xscreensaver.png
Exec = rxvt # Exec = rxvt
# Exec = xscreensaver -nosplash # Exec = /home/sanel/abc
Exec = xscreensaver -nosplash
Description = screensaver Description = screensaver

View File

@ -48,11 +48,6 @@ void xmessage_handler(int, void*) {
} }
} }
int xmessage_handler2(int e) {
return EvokeService::instance()->handle(fl_xevent);
}
const char* next_param(int curr, char** argv, int argc) { const char* next_param(int curr, char** argv, int argc) {
int j = curr + 1; int j = curr + 1;
if(j >= argc) if(j >= argc)
@ -157,9 +152,9 @@ int main(int argc, char** argv) {
pid_file = DEFAULT_PID; pid_file = DEFAULT_PID;
if(!service->setup_pid(pid_file, LOCK_FILE)) { if(!service->setup_pid(pid_file, LOCK_FILE)) {
EVOKE_LOG("Either another "APPNAME" instance is running or can't create pid file. Please correct this\n"); printf("Either another "APPNAME" instance is running or can't create pid file. Please correct this\n");
EVOKE_LOG("Note: if program abnormaly crashed before, just remove '%s' and start it again\n", LOCK_FILE); printf("Note: if program abnormaly crashed before, just remove '%s' and start it again\n", LOCK_FILE);
EVOKE_LOG("= "APPNAME" abrupted shutdown =\n"); printf("= "APPNAME" abrupted shutdown =\n");
return 1; return 1;
} }
@ -212,7 +207,6 @@ int main(int argc, char** argv) {
* Also note that '1' parameter means POLLIN, and for the details see Fl_x.cxx * Also note that '1' parameter means POLLIN, and for the details see Fl_x.cxx
*/ */
Fl::add_fd(ConnectionNumber(fl_display), 1, xmessage_handler); Fl::add_fd(ConnectionNumber(fl_display), 1, xmessage_handler);
//Fl::add_handler(xmessage_handler2);
while(service->running()) while(service->running())
Fl::wait(FOREVER); Fl::wait(FOREVER);