ipc socket setup will be much more robust now. relies on E_IPC_SOCKET

environment var (but every subprocess of e should inherit this - like DISPLAY).


SVN revision: 23714
This commit is contained in:
Carsten Haitzler 2006-07-04 18:36:29 +00:00
parent 349071a114
commit cda26e2af7
3 changed files with 71 additions and 71 deletions

View File

@ -16,13 +16,64 @@ e_ipc_init(void)
{ {
#ifdef USE_IPC #ifdef USE_IPC
char buf[1024]; char buf[1024];
char *disp; char *tmp, *user, *disp;
int pid;
tmp = getenv("TMPDIR");
if (!tmp) tmp = "/tmp";
user = getenv("USER");
if (!user) user = "__unknown__";
disp = getenv("DISPLAY"); disp = getenv("DISPLAY");
if (!disp) disp = ":0"; if (!disp) disp = ":0";
snprintf(buf, sizeof(buf), "enlightenment-(%s)", disp); pid = (int)getpid();
_e_ipc_server = ecore_ipc_server_add(ECORE_IPC_LOCAL_USER, buf, 0, NULL); snprintf(buf, sizeof(buf), "%s/enlightenment-%s", tmp, user);
if (mkdir(buf, S_IRWXU) == 0)
{
}
else
{
struct stat st;
if (stat(buf, &st) == 0)
{
if ((st.st_uid ==
getuid()) &&
((st.st_mode & S_IFDIR|S_IRWXU|S_IRWXG|S_IRWXO) ==
S_IRWXU|S_IFDIR))
{
}
else
{
snprintf(buf, sizeof(buf),
_("Possible IPC Hack Attempt. The IPC socket\n"
"directory already exists BUT has permissions\n"
"that are too leanient (must only be readable\n"
"and writable by the owner, and nobody else)\n"
"or is not owned by you. Please check:\n"
"%s/enlightenment-%s\n"),
tmp, user);
e_error_message_show(buf);
return 0;
}
}
else
{
snprintf(buf, sizeof(buf),
_("The IPC socket directory cannot be created or\n"
"examined.\n"
"Please check:\n"
"%s/enlightenment-%s\n"),
tmp, user);
e_error_message_show(buf);
return 0;
}
}
snprintf(buf, sizeof(buf), "%s/enlightenment-%s/disp-%s-%i", tmp, user, disp, pid);
_e_ipc_server = ecore_ipc_server_add(ECORE_IPC_LOCAL_SYSTEM, buf, 0, NULL);
e_util_env_set("E_IPC_SOCKET", "");
if (!_e_ipc_server) return 0; if (!_e_ipc_server) return 0;
e_util_env_set("E_IPC_SOCKET", buf);
printf("INFO: E_IPC_SOCKET=%s\n", buf);
ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD, _e_ipc_cb_client_add, NULL); ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD, _e_ipc_cb_client_add, NULL);
ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL, _e_ipc_cb_client_del, NULL); ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL, _e_ipc_cb_client_del, NULL);
ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA, _e_ipc_cb_client_data, NULL); ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA, _e_ipc_cb_client_data, NULL);

View File

@ -554,19 +554,7 @@ main(int argc, char **argv)
e_error_gui_set(1); e_error_gui_set(1);
/* setup e ipc service */ /* setup e ipc service */
if (!_e_main_ipc_init()) if (_e_main_ipc_init())
{
e_error_message_show(_("Enlightenment cannot set up the IPC socket.\n"
"It likely is already in use by an existing copy of Enlightenment.\n"
"Double check to see if Enlightenment is not already on this display,\n"
"but if that fails try deleting all files in ~/.ecore/enlightenment-*\n"
"and try running again.\n"
"\n"
"If you use AFS then maybe you might want to make a symlink from\n"
"~/.ecore to /tmp/my_directory/ecore where sockets can be made."));
ipc_failed = 1;
}
else
_e_main_shutdown_push(_e_main_ipc_shutdown); _e_main_shutdown_push(_e_main_ipc_shutdown);
/* setup generic msg handling etc */ /* setup generic msg handling etc */
@ -641,14 +629,6 @@ main(int argc, char **argv)
} }
/* _e_main_shutdown_push(e_desklock_shutdown); */ /* _e_main_shutdown_push(e_desklock_shutdown); */
if (ipc_failed)
e_error_dialog_show(_("Enlightenment IPC setup error!"),
_("Enlightenment cannot set up the IPC socket.\n"
"It likely is already in use by an existing copy of Enlightenment.\n"
"Double check to see if Enlightenment is not already on this display,\n"
"but if that fails try deleting all files in ~/.ecore/enlightenment-*\n"
"and try running again."));
/* add in a handler that just before we go idle we flush x */ /* add in a handler that just before we go idle we flush x */
_e_main_idle_enterer_flusher = ecore_idle_enterer_add(_e_main_cb_x_flusher, NULL); _e_main_idle_enterer_flusher = ecore_idle_enterer_add(_e_main_cb_x_flusher, NULL);
@ -1132,11 +1112,7 @@ _e_main_path_shutdown(void)
static int static int
_e_main_ipc_init(void) _e_main_ipc_init(void)
{ {
if (!e_ipc_init()) if (!e_ipc_init()) return 0;
{
e_error_message_show("Cannot init IPC subsystem!\n");
return 0;
}
return 1; return 1;
} }

View File

@ -43,44 +43,15 @@ main(int argc, char **argv)
{ {
#ifdef USE_IPC #ifdef USE_IPC
int i; int i;
char *s, buf[1024];
/* fix up DISPLAY to be :N.0 if no .screen is in it */
s = getenv("DISPLAY");
if (s)
{
char *p;
p = strrchr(s, ':');
if (!p)
{
snprintf(buf, sizeof(buf), "DISPLAY=%s:0.0", s);
putenv(strdup(buf));
}
else
{
p = strrchr(p, '.');
if (!p)
{
snprintf(buf, sizeof(buf), "DISPLAY=%s.0", s);
putenv(strdup(buf));
}
}
}
/* handle some command-line parameters */ /* handle some command-line parameters */
display_name = (const char *)getenv("DISPLAY"); display_name = (const char *)getenv("DISPLAY");
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
if ((!strcmp(argv[i], "-display")) && (i < (argc - 1))) if ((!strcmp(argv[i], "-h")) ||
{ (!strcmp(argv[i], "-help")) ||
i++; (!strcmp(argv[i], "--h")) ||
display_name = argv[i]; (!strcmp(argv[i], "--help")))
}
else if ((!strcmp(argv[i], "-h")) ||
(!strcmp(argv[i], "-help")) ||
(!strcmp(argv[i], "--h")) ||
(!strcmp(argv[i], "--help")))
{ {
_e_help(); _e_help();
exit(0); exit(0);
@ -145,15 +116,18 @@ _e_cb_signal_exit(void *data, int ev_type, void *ev)
static int static int
_e_ipc_init(void) _e_ipc_init(void)
{ {
char buf[1024]; char *sdir;
char *disp;
disp = (char *)display_name; sdir = getenv("E_IPC_SOCKET");
if (!disp) disp = ":0"; if (!sdir)
snprintf(buf, sizeof(buf), "enlightenment-(%s)", disp); {
_e_ipc_server = ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, buf, 0, NULL); printf("The E_IPC_SOCKET environment variable is not set. This is\n"
/* FIXME: we shoudl also try the generic ":0" if the display is ":0.0" */ "exported by Enlightenment to all processes it launches.\n"
/* similar... */ "This environment variable must be set and must point to\n"
"Enlightenment's IPC socket file (minus port number).\n");
return 0;
}
_e_ipc_server = ecore_ipc_server_connect(ECORE_IPC_LOCAL_SYSTEM, sdir, 0, NULL);
if (!_e_ipc_server) return 0; if (!_e_ipc_server) return 0;
ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD, _e_ipc_cb_server_add, NULL); ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD, _e_ipc_cb_server_add, NULL);
@ -260,7 +234,6 @@ _e_help(void)
printf(" -help This help\n"); printf(" -help This help\n");
printf(" --help This help\n"); printf(" --help This help\n");
printf(" --h This help\n"); printf(" --h This help\n");
printf(" -display OPT1 Connect to E running on display 'OPT1'\n");
for (j = 0; j < (int)(sizeof(opts) / sizeof(Opt)); j++) for (j = 0; j < (int)(sizeof(opts) / sizeof(Opt)); j++)
{ {
Opt *opt; Opt *opt;