Enlightenment CVS committal
Author : lordchaos
Project : e17
Module : apps/evfs
Dir : e17/apps/evfs/src/lib
Modified Files:
Makefile.am libevfs.c
Log Message:
Spawn an evfs server from libevfs if one is not found
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/evfs/src/lib/Makefile.am,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- Makefile.am 30 Aug 2005 19:05:29 -0000 1.4
+++ Makefile.am 19 Oct 2005 13:51:37 -0000 1.5
@@ -1,6 +1,7 @@
lib_LTLIBRARIES = libevfs.la
-INCLUDES = @ecore_cflags@ @xml2_cflags@ $(DEBUGFLAGS) -I. -I$(top_srcdir)
-I$(top_srcdir)/src/include
+INCLUDES = @ecore_cflags@ @xml2_cflags@ $(DEBUGFLAGS) -I. -I$(top_srcdir)
-I$(top_srcdir)/src/include \
+ -DBINDIR=\""$(bindir)"\"
libevfs_la_SOURCES = \
../include/evfs.h \
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/evfs/src/lib/libevfs.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -3 -r1.11 -r1.12
--- libevfs.c 19 Oct 2005 12:50:13 -0000 1.11
+++ libevfs.c 19 Oct 2005 13:51:37 -0000 1.12
@@ -1,9 +1,12 @@
#include "evfs.h"
+#define MAX_ATTEMPTS 5
+
Ecore_List* client_list = NULL;
static int libevfs_registered_callback = 0;
+/*It would seem a good idea to convert this to a hash - but we'd need the
actual pointer to the int, or make an ecore_int_hash*/
evfs_connection* evfs_get_connection_for_id(int id) {
evfs_connection* conn;
@@ -82,9 +85,27 @@
}
}
+int evfs_server_spawn() {
+ const char* server_exe = BINDIR "/evfs";
+
+ if (!access(server_exe, X_OK | R_OK)) {
+ setsid();
+ if (fork() == 0) {
+ execl(server_exe, server_exe, NULL);
+ }
+ return 1;
+ } else {
+ fprintf(stderr, "You don't have rights to execute the
server\n");
+ return 1;
+ }
+
+ return 0;
+}
+
evfs_connection* evfs_connect(void (*callback_func)(void*)) {
ecore_init();
ecore_ipc_init();
+ int connect_attempts = 0;
evfs_connection* connection = NEW(evfs_connection);
connection->id = MAX_CLIENT;
@@ -101,11 +122,27 @@
ecore_list_prepend(client_list, connection);
}
+ retry:
+
+ if (connect_attempts > MAX_ATTEMPTS) {
+ fprintf(stderr, "Could not start server after max attempts\n");
+ exit(1); /*We shouldn't really kill the libraries parent!*/
+ return NULL;
+ }
+
if ( !(connection->server =
ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, EVFS_IPC_TITLE, 0, NULL)) ) {
- fprintf(stderr, "Cannot connect to evfs server with '%s'..\n",
EVFS_IPC_TITLE);
- exit(1);
+ fprintf(stderr, "Cannot connect to evfs server with '%s',
making new server and trying again..\n", EVFS_IPC_TITLE);
+
+ if (!connect_attempts) {
+ if (evfs_server_spawn()) {
+ printf ("Failure to start evfs server!\n");
+ }
+ }
+
+ connect_attempts++;
+ usleep(100000*connect_attempts);
+ goto retry;
- return NULL;
}
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs