mirror of
https://github.com/edeproject/ede.git
synced 2023-08-10 21:13:03 +03:00
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:
parent
64683f504e
commit
8ff399f71e
@ -19,7 +19,6 @@
|
||||
#include "Autostart.h"
|
||||
|
||||
#include <edelib/File.h>
|
||||
//#include <edelib/Regex.h>
|
||||
#include <edelib/Config.h>
|
||||
#include <edelib/DesktopFile.h>
|
||||
#include <edelib/Directory.h>
|
||||
@ -29,15 +28,12 @@
|
||||
#include <edelib/MessageBox.h>
|
||||
#include <edelib/Nls.h>
|
||||
|
||||
#include <FL/fl_ask.h>
|
||||
|
||||
#include <sys/types.h> // getpid
|
||||
#include <unistd.h> // pipe
|
||||
#include <fcntl.h> // fcntl
|
||||
#include <stdlib.h> // free
|
||||
#include <string.h> // strdup, memset
|
||||
#include <errno.h> // error codes
|
||||
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
|
||||
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) {
|
||||
|
||||
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() {
|
||||
if(logfile)
|
||||
delete logfile;
|
||||
|
||||
stop_xsettings_manager();
|
||||
stop_xsettings_manager(true);
|
||||
|
||||
if(lockfile) {
|
||||
edelib::file_remove(lockfile);
|
||||
@ -255,6 +251,7 @@ bool EvokeService::setup_logging(const char* file) {
|
||||
|
||||
if(!logfile->open(file)) {
|
||||
delete logfile;
|
||||
logfile = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -393,8 +390,8 @@ void EvokeService::init_autostart(bool safe) {
|
||||
edelib::String adir = edelib::user_config_dir();
|
||||
adir += autostart_dirname;
|
||||
|
||||
StringList dfiles, sysdirs;
|
||||
StringListIter it, it_end;
|
||||
StringList dfiles, sysdirs, tmp;
|
||||
StringListIter it, it_end, tmp_it, tmp_it_end;
|
||||
|
||||
edelib::dir_list(adir.c_str(), dfiles, true);
|
||||
|
||||
@ -402,8 +399,15 @@ void EvokeService::init_autostart(bool safe) {
|
||||
if(!sysdirs.empty()) {
|
||||
for(it = sysdirs.begin(), it_end = sysdirs.end(); it != it_end; ++it) {
|
||||
*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)) {
|
||||
int ret = edelib::ask(_("XSETTINGS manager already running on this screen. Would you like to replace it?"));
|
||||
if(ret < 1) {
|
||||
stop_xsettings_manager();
|
||||
stop_xsettings_manager(false);
|
||||
return;
|
||||
} else
|
||||
goto do_it;
|
||||
@ -475,7 +479,7 @@ void EvokeService::init_xsettings_manager(void) {
|
||||
do_it:
|
||||
if(!xsm->init(fl_display, fl_screen)) {
|
||||
edelib::alert(_("Unable to load XSETTINGS manager properly"));
|
||||
stop_xsettings_manager();
|
||||
stop_xsettings_manager(false);
|
||||
}
|
||||
|
||||
if(!xsm) return;
|
||||
@ -484,11 +488,13 @@ do_it:
|
||||
xsm->notify();
|
||||
}
|
||||
|
||||
void EvokeService::stop_xsettings_manager(void) {
|
||||
void EvokeService::stop_xsettings_manager(bool serialize) {
|
||||
if(!xsm)
|
||||
return;
|
||||
|
||||
xsm->save_serialized("ede-settings.xml");
|
||||
if(serialize)
|
||||
xsm->save_serialized("ede-settings.xml");
|
||||
|
||||
delete xsm;
|
||||
xsm = NULL;
|
||||
}
|
||||
@ -566,46 +572,30 @@ void EvokeService::quit_x11(void) {
|
||||
* This is run each time when some of the managed childs quits.
|
||||
* Instead directly running wake_up(), it will be notified wia
|
||||
* wake_up_pipe[] channel, via add_fd() monitor.
|
||||
*
|
||||
* This workaround is due races.
|
||||
*/
|
||||
void EvokeService::service_watcher(int pid, int ret) {
|
||||
puts("=== service_watcher() ===");
|
||||
printf("got %i\n", ret);
|
||||
|
||||
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");
|
||||
write(wake_up_pipe[1], &pid, sizeof(int));
|
||||
write(wake_up_pipe[1], &ret, sizeof(int));
|
||||
}
|
||||
|
||||
void EvokeService::wake_up(int fd) {
|
||||
puts("=== wake_up() ===");
|
||||
|
||||
char c;
|
||||
if(read(wake_up_pipe[0], &c, 1) != 1 || c != 'c') {
|
||||
int child_pid = -1;
|
||||
// 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");
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
EvokeProcess pc;
|
||||
bool ret;
|
||||
@ -621,7 +611,6 @@ void EvokeService::wake_up(int fd) {
|
||||
cdialog.run();
|
||||
}
|
||||
} else {
|
||||
|
||||
mutex.lock();
|
||||
unregister_process(child_pid);
|
||||
mutex.unlock();
|
||||
@ -641,10 +630,8 @@ void EvokeService::wake_up(int fd) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Execute program. It's return status
|
||||
* 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) {
|
||||
EvokeProcess pc;
|
||||
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.
|
||||
*
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
* FIXME: any better way ?
|
||||
*/
|
||||
int EvokeService::handle(const XEvent* xev) {
|
||||
EVOKE_LOG("Got event %i\n", xev->type);
|
||||
|
||||
if(xsm && xsm->should_terminate(xev)) {
|
||||
EVOKE_LOG("XSETTINGS manager shutdown\n");
|
||||
stop_xsettings_manager();
|
||||
// return 1;
|
||||
stop_xsettings_manager(true);
|
||||
}
|
||||
#if 0
|
||||
else if(xev->type == MapNotify) {
|
||||
@ -835,7 +756,6 @@ int EvokeService::handle(const XEvent* xev) {
|
||||
} else {
|
||||
EVOKE_LOG("Got _EDE_EVOKE_SPAWN with malformed data. Ignoring...\n");
|
||||
}
|
||||
// return 1;
|
||||
}
|
||||
|
||||
if(xev->xproperty.atom == _ede_evoke_quit) {
|
||||
@ -845,7 +765,6 @@ int EvokeService::handle(const XEvent* xev) {
|
||||
stop();
|
||||
} else
|
||||
EVOKE_LOG("Got _EDE_EVOKE_QUIT with bad code (%i). Ignoring...\n", val);
|
||||
// return 1;
|
||||
}
|
||||
|
||||
if(xev->xproperty.atom == _ede_shutdown_all) {
|
||||
@ -861,10 +780,9 @@ int EvokeService::handle(const XEvent* xev) {
|
||||
//quit_x11();
|
||||
} else
|
||||
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);
|
||||
}
|
||||
|
@ -66,11 +66,8 @@ class EvokeService {
|
||||
|
||||
ClientList clients;
|
||||
ProcessList processes;
|
||||
int quit_child_pid;
|
||||
int quit_child_ret;
|
||||
int wake_up_pipe[2];
|
||||
|
||||
|
||||
public:
|
||||
EvokeService();
|
||||
~EvokeService();
|
||||
@ -88,7 +85,7 @@ class EvokeService {
|
||||
void init_autostart(bool safe);
|
||||
|
||||
void init_xsettings_manager(void);
|
||||
void stop_xsettings_manager(void);
|
||||
void stop_xsettings_manager(bool serialize);
|
||||
|
||||
int handle(const XEvent* ev);
|
||||
|
||||
|
@ -24,6 +24,7 @@ SOURCE = evoke.cpp
|
||||
Autostart.cpp ;
|
||||
|
||||
LinkAgainst evoke : -lao -lvorbis -lvorbisfile ;
|
||||
#LinkAgainst evoke : -lpthread ;
|
||||
|
||||
EdeProgram evoke : $(SOURCE) ;
|
||||
FltkProgramBare test/evoke_test : test/evoke_test.cpp ;
|
||||
|
@ -17,9 +17,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/time.h> // getrlimit, setrlimit
|
||||
|
@ -30,13 +30,6 @@
|
||||
extern void service_watcher_cb(int pid, int signum);
|
||||
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) {
|
||||
if(fl_xevent->type == MapNotify || fl_xevent->type == ConfigureNotify) {
|
||||
if(splash_win) {
|
||||
@ -192,15 +185,11 @@ void Splash::run(void) {
|
||||
int sh = DisplayHeight(fl_display, fl_screen);
|
||||
position(sw/2 - w()/2, sh/2 - h()/2);
|
||||
|
||||
#if 0
|
||||
bool sound_loaded = false;
|
||||
if(sound && !sound->empty())
|
||||
sound_loaded = edelib::SoundSystem::init();
|
||||
#endif
|
||||
AutoSound sound_play;
|
||||
|
||||
show();
|
||||
|
||||
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);
|
||||
//Fl::add_handler(splash_xmessage_handler);
|
||||
#if 0
|
||||
|
||||
if(sound_loaded)
|
||||
edelib::SoundSystem::play(sound->c_str(), 0);
|
||||
#endif
|
||||
sound_play.play(sound->c_str());
|
||||
|
||||
while(shown())
|
||||
Fl::wait();
|
||||
#if 0
|
||||
|
||||
if(sound_loaded) {
|
||||
edelib::SoundSystem::stop();
|
||||
edelib::SoundSystem::shutdown();
|
||||
}
|
||||
#endif
|
||||
|
||||
splash_win = 0;
|
||||
}
|
||||
|
@ -168,5 +168,6 @@ bool Xsm::save_serialized(const char* file) {
|
||||
|
||||
setting_file.close();
|
||||
edelib::xsettings_list_free(settings);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -2,33 +2,36 @@
|
||||
# main section; must be present
|
||||
[evoke]
|
||||
Startup = edewm,eiconman,eworkpanel,xscreensaver
|
||||
DataDirectory = data
|
||||
# DataDirectory = /home/sanel/blentavo/EDE/ede2/evoke/data
|
||||
# DataDirectory = data
|
||||
DataDirectory = /home/sanel/blentavo/EDE/ede2/evoke/data
|
||||
Splash = splash-alpha1.png
|
||||
Sound = startup.ogg
|
||||
# Sound = Startup1_2.ogg
|
||||
|
||||
[edewm]
|
||||
Icon = edewm.png
|
||||
Exec = gvim
|
||||
# Exec = edewm
|
||||
# Exec = gvim
|
||||
Exec = edewm
|
||||
# Exec = fluxbox
|
||||
Description = window manager
|
||||
|
||||
[eiconman]
|
||||
Icon = eiconman.png
|
||||
Exec = mozilla
|
||||
# Exec = mozilla
|
||||
# Exec = /home/sanel/blentavo/EDE/ede2/eiconman/eiconman
|
||||
# Exec = eiconman
|
||||
Exec = eiconman
|
||||
# Exec = /home/sanel/abc
|
||||
Description = desktop
|
||||
|
||||
[eworkpanel]
|
||||
Icon = eworkpanel.png
|
||||
Exec = mrxvt -bg black
|
||||
# Exec = eworkpanel
|
||||
# Exec = mrxvt -bg black
|
||||
Exec = eworkpanel
|
||||
Description = panel
|
||||
|
||||
[xscreensaver]
|
||||
Icon = xscreensaver.png
|
||||
Exec = rxvt
|
||||
# Exec = xscreensaver -nosplash
|
||||
# Exec = rxvt
|
||||
# Exec = /home/sanel/abc
|
||||
Exec = xscreensaver -nosplash
|
||||
Description = screensaver
|
||||
|
@ -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) {
|
||||
int j = curr + 1;
|
||||
if(j >= argc)
|
||||
@ -157,9 +152,9 @@ int main(int argc, char** argv) {
|
||||
pid_file = DEFAULT_PID;
|
||||
|
||||
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");
|
||||
EVOKE_LOG("Note: if program abnormaly crashed before, just remove '%s' and start it again\n", LOCK_FILE);
|
||||
EVOKE_LOG("= "APPNAME" abrupted shutdown =\n");
|
||||
printf("Either another "APPNAME" instance is running or can't create pid file. Please correct this\n");
|
||||
printf("Note: if program abnormaly crashed before, just remove '%s' and start it again\n", LOCK_FILE);
|
||||
printf("= "APPNAME" abrupted shutdown =\n");
|
||||
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
|
||||
*/
|
||||
Fl::add_fd(ConnectionNumber(fl_display), 1, xmessage_handler);
|
||||
//Fl::add_handler(xmessage_handler2);
|
||||
|
||||
while(service->running())
|
||||
Fl::wait(FOREVER);
|
||||
|
Loading…
Reference in New Issue
Block a user