entrance: improve log, some fixes

SVN revision: 76474
This commit is contained in:
Michael BOUCHAUD 2012-09-11 19:29:11 +00:00
parent 3254d5845f
commit a1c7376558
8 changed files with 138 additions and 123 deletions

View File

@ -6,23 +6,15 @@
#include <xcb/xcb.h> #include <xcb/xcb.h>
#define ENTRANCE_DISPLAY ":0.0" #define ENTRANCE_DISPLAY ":0.0"
time_t current_time;
#define PT(x) \ struct tm *local_time;
{ \ char entrance_time_d[4096];
ct = time(NULL); \
lc = localtime(&ct); \
memset(entrance_time_d, 0, sizeof(entrance_time_d)); \
strftime(entrance_time_d, sizeof(entrance_time_d), \
"%b %_2d %T", lc); \
fprintf(stderr, "(%s) "PACKAGE": %s\n", entrance_time_d, x); \
}
static Eina_Bool _open_log(); static Eina_Bool _open_log();
static int _entrance_main(const char *dname); static int _entrance_main(const char *dname);
static void _remove_lock(); static void _remove_lock();
static void _signal_cb(); static void _signal_cb(int sig);
static void _signal_log(); static void _signal_log(int sig);
static Eina_Bool _entrance_client_del(void *data, int type, void *event); static Eina_Bool _entrance_client_del(void *data, int type, void *event);
static Eina_Bool _testing = 0; static Eina_Bool _testing = 0;
@ -34,7 +26,9 @@ static Ecore_Exe *_entrance_client = NULL;
static void static void
_signal_cb(int sig) _signal_cb(int sig)
{ {
fprintf(stderr, PACKAGE": signal %d received\n", sig); char buf[1024];
snprintf(buf, sizeof(buf), "signal %d received\n", sig);
PT(buf);
//FIXME if I don't have main loop at this time ? //FIXME if I don't have main loop at this time ?
if (_entrance_client) ecore_exe_terminate(_entrance_client); if (_entrance_client) ecore_exe_terminate(_entrance_client);
/* /*
@ -45,9 +39,9 @@ _signal_cb(int sig)
} }
static void static void
_signal_log(int sig) _signal_log(int sig __UNUSED__)
{ {
fprintf(stderr, PACKAGE": signal %d received reopen the log file\n", sig); PT("reopen the log file\n");
entrance_close_log(); entrance_close_log();
_open_log(); _open_log();
} }
@ -67,15 +61,14 @@ _get_lock()
f = fopen(entrance_config->lockfile, "w"); f = fopen(entrance_config->lockfile, "w");
if (!f) if (!f)
{ {
fprintf(stderr, PACKAGE": Couldn't create lockfile %s!\n", PT("Couldn't create lockfile!\n");
entrance_config->lockfile);
return (EINA_FALSE); return (EINA_FALSE);
} }
snprintf(buf, sizeof(buf), "%d\n", my_pid); snprintf(buf, sizeof(buf), "%d\n", my_pid);
if (!fwrite(buf, strlen(buf), 1, f)) if (!fwrite(buf, strlen(buf), 1, f))
{ {
fclose(f); fclose(f);
fprintf(stderr, PACKAGE": Couldn't write the lockfile\n"); PT("Couldn't write the lockfile\n");
return EINA_FALSE; return EINA_FALSE;
} }
fclose(f); fclose(f);
@ -89,7 +82,8 @@ _get_lock()
fclose(f); fclose(f);
if (pid == my_pid) if (pid == my_pid)
return EINA_TRUE; return EINA_TRUE;
fprintf(stderr, "A lock file are present another instance are present ?\n");
PT("A lock file are present another instance are present ?\n");
return EINA_FALSE; return EINA_FALSE;
} }
@ -104,7 +98,7 @@ _update_lock()
f = fopen(entrance_config->lockfile, "w"); f = fopen(entrance_config->lockfile, "w");
snprintf(buf, sizeof(buf), "%d\n", getpid()); snprintf(buf, sizeof(buf), "%d\n", getpid());
if (!fwrite(buf, strlen(buf), 1, f)) if (!fwrite(buf, strlen(buf), 1, f))
fprintf(stderr, PACKAGE": Coudn't update lockfile\n"); PT("Coudn't update lockfile\n");
fclose(f); fclose(f);
} }
@ -121,16 +115,15 @@ _open_log()
elog = fopen(entrance_config->logfile, "a"); elog = fopen(entrance_config->logfile, "a");
if (!elog) if (!elog)
{ {
fprintf(stderr, PACKAGE": could not open logfile %s!!!\n", PT("could not open logfile !\n");
entrance_config->logfile);
return EINA_FALSE; return EINA_FALSE;
} }
fclose(elog); fclose(elog);
if (!freopen(entrance_config->logfile, "a", stdout)) if (!freopen(entrance_config->logfile, "a", stdout))
fprintf(stderr, PACKAGE": Error on reopen stdout\n"); PT("Error on reopen stdout\n");
setvbuf(stdout, NULL, _IOLBF, BUFSIZ); setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
if (!freopen(entrance_config->logfile, "a", stderr)) if (!freopen(entrance_config->logfile, "a", stderr))
fprintf(stderr, PACKAGE": Error on reopen stderr\n"); PT("Error on reopen stderr\n");
setvbuf(stderr, NULL, _IONBF, BUFSIZ); setvbuf(stderr, NULL, _IONBF, BUFSIZ);
return EINA_TRUE; return EINA_TRUE;
} }
@ -148,7 +141,8 @@ static void
_entrance_wait() _entrance_wait()
{ {
execl(PACKAGE_BIN_DIR"/entrance_wait", "/usr/sbin/entrance", NULL); execl(PACKAGE_BIN_DIR"/entrance_wait", "/usr/sbin/entrance", NULL);
fprintf(stderr, PACKAGE": HUM HUM HUM ...\n\n\n"); PT("HUM HUM HUM can't wait ...\n\n\n");
_exit(1);
} }
static int static int
@ -161,7 +155,7 @@ _entrance_main(const char *dname)
char buf[PATH_MAX]; char buf[PATH_MAX];
ecore_event_handler_add(ECORE_EXE_EVENT_DEL, ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
_entrance_client_del, NULL); _entrance_client_del, NULL);
fprintf(stderr, PACKAGE": Exec entrance_client\n"); PT("Exec entrance_client\n");
snprintf(buf, sizeof(buf), snprintf(buf, sizeof(buf),
PACKAGE_BIN_DIR"/entrance_client -d %s -t %s", PACKAGE_BIN_DIR"/entrance_client -d %s -t %s",
dname, entrance_config->theme); dname, entrance_config->theme);
@ -183,7 +177,7 @@ _entrance_client_del(void *data __UNUSED__, int type __UNUSED__, void *event)
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
ecore_main_loop_quit(); ecore_main_loop_quit();
_entrance_client = NULL; _entrance_client = NULL;
fprintf(stderr, PACKAGE": client have terminated\n"); PT("client have terminated\n");
return ECORE_CALLBACK_DONE; return ECORE_CALLBACK_DONE;
} }
@ -219,9 +213,6 @@ main (int argc, char ** argv)
char *entrance_user = NULL; char *entrance_user = NULL;
unsigned char nodaemon = 0; unsigned char nodaemon = 0;
unsigned char quit_option = 0; unsigned char quit_option = 0;
time_t ct;
struct tm *lc;
char entrance_time_d[4096];
Ecore_Getopt_Value values[] = Ecore_Getopt_Value values[] =
{ {
@ -238,7 +229,7 @@ main (int argc, char ** argv)
args = ecore_getopt_parse(&options, values, argc, argv); args = ecore_getopt_parse(&options, values, argc, argv);
if (args < 0) if (args < 0)
{ {
fprintf(stderr, PACKAGE": ERROR: could not parse options.\n"); PT("ERROR: could not parse options.\n");
return -1; return -1;
} }
@ -265,7 +256,7 @@ main (int argc, char ** argv)
{ {
if (daemon(0, 1) == -1) if (daemon(0, 1) == -1)
{ {
fprintf(stderr, PACKAGE": Error on daemonize !"); PT("Error on daemonize !\n");
quit_option = EINA_TRUE; quit_option = EINA_TRUE;
} }
_update_lock(); _update_lock();
@ -284,7 +275,7 @@ main (int argc, char ** argv)
} }
if (!_open_log()) if (!_open_log())
{ {
fprintf(stderr, PACKAGE": Can't open log file !!!!\n"); PT("Can't open log file !!!!\n");
entrance_config_shutdown(); entrance_config_shutdown();
exit(1); exit(1);
} }
@ -306,16 +297,17 @@ main (int argc, char ** argv)
unsetenv("ENTRANCE_QUIT"); unsetenv("ENTRANCE_QUIT");
_remove_lock(); _remove_lock();
entrance_config_shutdown(); entrance_config_shutdown();
PT("Good bye"); PT("Good bye\n");
entrance_close_log(); entrance_close_log();
exit(0); exit(0);
} }
entrance_close_log(); entrance_close_log();
PT("Nice to see you again."); PT("Nice to see you again.\n");
exit(1); exit(1);
} }
PT("Welcome"); PT("Welcome\n");
ecore_init(); ecore_init();
efreet_init();
/* Initialise event handler */ /* Initialise event handler */
signal(SIGQUIT, _signal_cb); signal(SIGQUIT, _signal_cb);
@ -327,69 +319,70 @@ main (int argc, char ** argv)
signal(SIGALRM, _signal_cb); signal(SIGALRM, _signal_cb);
signal(SIGUSR2, _signal_log); signal(SIGUSR2, _signal_log);
PT("session init"); PT("session init\n");
entrance_session_init(entrance_config->command.xauth_file); entrance_session_init(entrance_config->command.xauth_file);
PT("xserver init"); PT("xserver init\n");
pid = entrance_xserver_init(_entrance_main, dname); pid = entrance_xserver_init(_entrance_main, dname);
PT("history init"); PT("history init\n");
entrance_history_init(); entrance_history_init();
if (entrance_config->autologin && !entrance_user) if (entrance_config->autologin && !entrance_user)
{ {
PT("autologin init"); PT("autologin init\n");
xcb_connection_t *disp = NULL; xcb_connection_t *disp = NULL;
disp = xcb_connect(dname, NULL); disp = xcb_connect(dname, NULL);
PT("main loop begin"); PT("main loop begin\n");
ecore_main_loop_begin(); ecore_main_loop_begin();
PT("auth user"); PT("auth user\n");
#ifdef HAVE_PAM #ifdef HAVE_PAM
entrance_pam_item_set(ENTRANCE_PAM_ITEM_USER, entrance_config->userlogin); entrance_pam_item_set(ENTRANCE_PAM_ITEM_USER, entrance_config->userlogin);
#endif #endif
PT("login user"); PT("login user\n");
entrance_session_login(entrance_config->command.session_login, EINA_FALSE); entrance_session_login(entrance_config->command.session_login, EINA_FALSE);
sleep(30); sleep(30);
xcb_disconnect(disp); xcb_disconnect(disp);
} }
else else
{ {
PT("action init"); PT("action init\n");
entrance_action_init(); entrance_action_init();
PT("server init"); PT("server init\n");
entrance_server_init(); entrance_server_init();
PT("starting main loop"); PT("starting main loop\n");
ecore_main_loop_begin(); ecore_main_loop_begin();
PT("main loop end"); PT("main loop end\n");
entrance_server_shutdown(); entrance_server_shutdown();
PT("server shutdown"); PT("server shutdown\n");
entrance_action_shutdown(); entrance_action_shutdown();
PT("action shutdown"); PT("action shutdown\n");
} }
entrance_history_shutdown(); entrance_history_shutdown();
PT("history shutdown"); PT("history shutdown\n");
entrance_xserver_shutdown(); entrance_xserver_shutdown();
PT("xserver shutdown"); PT("xserver shutdown\n");
#ifdef HAVE_PAM #ifdef HAVE_PAM
entrance_pam_shutdown(); entrance_pam_shutdown();
PT("pam shutdown"); PT("pam shutdown\n");
#endif #endif
efreet_shutdown();
ecore_shutdown(); ecore_shutdown();
PT("ecore shutdown"); PT("ecore shutdown\n");
entrance_config_shutdown(); entrance_config_shutdown();
PT("config shutdown"); PT("config shutdown\n");
entrance_session_shutdown(); entrance_session_shutdown();
PT("session shutdown"); PT("session shutdown\n");
eet_shutdown(); eet_shutdown();
PT("eet shutdown"); PT("eet shutdown\n");
free(dname); free(dname);
if (entrance_session_logged_get()) if (entrance_session_logged_get())
{ {
PT("Bye user logged, see you."); PT("Bye user logged, see you.\n");
entrance_close_log(); entrance_close_log();
_entrance_wait(); _entrance_wait();
} }
PT("ending xserver"); PT("ending xserver\n");
kill(pid, SIGTERM); kill(pid, SIGTERM);
entrance_xserver_end(); entrance_xserver_end();
PT("Bye, see you.\n"); PT("Bye, see you.\n\n");
entrance_close_log(); entrance_close_log();
return 0; return 0;
} }

View File

@ -11,6 +11,7 @@
#include <Eet.h> #include <Eet.h>
#include <Ecore.h> #include <Ecore.h>
#include <Ecore_File.h> #include <Ecore_File.h>
#include <Efreet.h>
#include "entrance_session.h" #include "entrance_session.h"
#ifdef HAVE_PAM #ifdef HAVE_PAM
@ -23,6 +24,20 @@
#include "entrance_action.h" #include "entrance_action.h"
#include "../event/entrance_event.h" #include "../event/entrance_event.h"
#define PT(x) \
{ \
current_time = time(NULL); \
local_time = localtime(&current_time); \
memset(entrance_time_d, 0, sizeof(entrance_time_d)); \
strftime(entrance_time_d, sizeof(entrance_time_d), \
"%b %_2d %T", local_time); \
fprintf(stderr, "(%s) "PACKAGE": %s", entrance_time_d, x); \
}
extern time_t current_time;
extern struct tm *local_time;
extern char entrance_time_d[4096];
void entrance_close_log(); void entrance_close_log();
#endif /* ENTRANCE_H_ */ #endif /* ENTRANCE_H_ */

View File

@ -172,7 +172,7 @@ _entrance_action_grub2_get(void)
char *s; char *s;
int i; int i;
fprintf(stderr, PACKAGE": trying to open "GRUB2_FILE); PT("trying to open "GRUB2_FILE);
f = eina_file_open(GRUB2_FILE, EINA_FALSE); f = eina_file_open(GRUB2_FILE, EINA_FALSE);
if (!f) return ; if (!f) return ;
fprintf(stderr, " o"); fprintf(stderr, " o");
@ -211,7 +211,7 @@ _entrance_action_grub2_get(void)
if (!grub2_ok) if (!grub2_ok)
{ {
grub2_ok = 1; grub2_ok = 1;
fprintf(stderr, PACKAGE": GRUB2 save mode found \n"); PT("GRUB2 save mode found \n");
} }
else else
{ {
@ -238,7 +238,7 @@ _entrance_action_grub2_get(void)
if (!action) goto end_line; if (!action) goto end_line;
sprintf(action, "Reboot on %s", local); sprintf(action, "Reboot on %s", local);
fprintf(stderr, PACKAGE": GRUB2 '%s'\n", action); PT("GRUB2 '%s'\n", action);
_entrance_actions = _entrance_actions =
eina_list_append(_entrance_actions, eina_list_append(_entrance_actions,
_entrance_action_add(action, _entrance_action_add(action,

View File

@ -56,7 +56,7 @@ _entrance_history_read()
EET_FILE_MODE_READ_WRITE); EET_FILE_MODE_READ_WRITE);
if (!(ef) || !(_entrance_history = eet_data_read(ef, _eddh, ENTRANCE_SESSION_KEY))) if (!(ef) || !(_entrance_history = eet_data_read(ef, _eddh, ENTRANCE_SESSION_KEY)))
{ {
fprintf(stderr, PACKAGE": Error on reading last session login\n"); PT("Error on reading last session login\n");
_entrance_history = calloc(1, sizeof(Entrance_History)); _entrance_history = calloc(1, sizeof(Entrance_History));
} }
eet_close(ef); eet_close(ef);
@ -71,7 +71,7 @@ _entrance_history_write()
if (_history_update) if (_history_update)
{ {
fprintf(stderr, PACKAGE": writing history file\n"); PT("writing history file\n");
ef = eet_open("/var/cache/"PACKAGE"/"ENTRANCE_HISTORY_FILE, ef = eet_open("/var/cache/"PACKAGE"/"ENTRANCE_HISTORY_FILE,
EET_FILE_MODE_READ_WRITE); EET_FILE_MODE_READ_WRITE);
if (!ef) if (!ef)
@ -79,7 +79,7 @@ _entrance_history_write()
EET_FILE_MODE_WRITE); EET_FILE_MODE_WRITE);
if (!eet_data_write(ef, _eddh, ENTRANCE_SESSION_KEY, _entrance_history, 1)) if (!eet_data_write(ef, _eddh, ENTRANCE_SESSION_KEY, _entrance_history, 1))
fprintf(stderr, PACKAGE": Error on updating last session login\n"); PT("Error on updating last session login\n");
eet_close(ef); eet_close(ef);
} }

View File

@ -44,25 +44,26 @@ _entrance_pam_conv(int num_msg, const struct pam_message **msg,
switch(msg[i]->msg_style){ switch(msg[i]->msg_style){
case PAM_PROMPT_ECHO_ON: case PAM_PROMPT_ECHO_ON:
// We assume PAM is asking for the username // We assume PAM is asking for the username
fprintf(stderr, PACKAGE": echo on\n"); PT("echo on\n");
resp[i]->resp = _login; resp[i]->resp = _login;
break; break;
case PAM_PROMPT_ECHO_OFF: case PAM_PROMPT_ECHO_OFF:
fprintf(stderr, PACKAGE": echo off\n"); PT("echo off\n");
resp[i]->resp = _passwd; resp[i]->resp = _passwd;
_passwd = NULL; _passwd = NULL;
break; break;
case PAM_ERROR_MSG: case PAM_ERROR_MSG:
fprintf(stderr, PACKAGE": error msg\n"); PT("error msg\n");
case PAM_TEXT_INFO: case PAM_TEXT_INFO:
fprintf(stderr, PACKAGE": info %s\n", msg[i]->msg); PT("info ");
fprintf(stderr, "%s\n", msg[i]->msg);
break; break;
case PAM_SUCCESS: case PAM_SUCCESS:
fprintf(stderr, PACKAGE": success :)\n"); PT("success :)\n");
break; break;
default: default:
fprintf(stderr, PACKAGE": default\n"); PT("default\n");
} }
if (result != PAM_SUCCESS) break; if (result != PAM_SUCCESS) break;
@ -99,14 +100,14 @@ entrance_pam_open_session()
{ {
case PAM_CRED_ERR: case PAM_CRED_ERR:
case PAM_USER_UNKNOWN: case PAM_USER_UNKNOWN:
fprintf(stderr, PACKAGE": PAM user unknow\n"); PT("PAM user unknow\n");
return 1; return 1;
case PAM_AUTH_ERR: case PAM_AUTH_ERR:
case PAM_PERM_DENIED: case PAM_PERM_DENIED:
fprintf(stderr, PACKAGE": PAM error on login password\n"); PT("PAM error on login password\n");
return 1; return 1;
default: default:
fprintf(stderr, PACKAGE": PAM open warning unknow error\n"); PT("PAM open warning unknow error\n");
return 1; return 1;
case PAM_SUCCESS: case PAM_SUCCESS:
break; break;
@ -126,7 +127,7 @@ entrance_pam_open_session()
void void
entrance_pam_close_session() { entrance_pam_close_session() {
fprintf(stderr, PACKAGE": PAM close session\n"); PT("PAM close session\n");
last_result = pam_close_session(_pam_handle, PAM_SILENT); last_result = pam_close_session(_pam_handle, PAM_SILENT);
switch (last_result) { switch (last_result) {
default: default:
@ -166,24 +167,24 @@ entrance_pam_authenticate()
{ {
case PAM_ABORT: case PAM_ABORT:
case PAM_AUTHINFO_UNAVAIL: case PAM_AUTHINFO_UNAVAIL:
fprintf(stderr, PACKAGE": PAM error !\n"); PT("PAM error !\n");
entrance_pam_end(); entrance_pam_end();
return 1; return 1;
case PAM_USER_UNKNOWN: case PAM_USER_UNKNOWN:
fprintf(stderr, PACKAGE": PAM user unknow error !\n"); PT("PAM user unknow error !\n");
return 1; return 1;
case PAM_MAXTRIES: case PAM_MAXTRIES:
fprintf(stderr, PACKAGE": PAM max tries error !\n"); PT("PAM max tries error !\n");
entrance_server_client_wait(); entrance_server_client_wait();
return 1; return 1;
case PAM_CRED_INSUFFICIENT: case PAM_CRED_INSUFFICIENT:
fprintf(stderr, PACKAGE": PAM %s don't have sufficient credential to authenticate !\n", PACKAGE); PT("PAM don't have sufficient credential to authenticate !\n");
return 1; return 1;
case PAM_AUTH_ERR: case PAM_AUTH_ERR:
fprintf(stderr, PACKAGE": PAM authenticate error !\n"); PT("PAM authenticate error !\n");
return 1; return 1;
default: default:
fprintf(stderr, PACKAGE": PAM auth warning unknow error\n"); PT("PAM auth warning unknow error\n");
return 1; return 1;
case PAM_SUCCESS: case PAM_SUCCESS:
break; break;
@ -218,8 +219,6 @@ entrance_pam_init(const char *service, const char *display, const char *user) {
_pam_conversation.conv = _entrance_pam_conv; _pam_conversation.conv = _entrance_pam_conv;
_pam_conversation.appdata_ptr = NULL; _pam_conversation.appdata_ptr = NULL;
fprintf(stderr, PACKAGE": Pam init with name %s\n", service);
if (_pam_handle) entrance_pam_end(); if (_pam_handle) entrance_pam_end();
status = pam_start(service, user, &_pam_conversation, &_pam_handle); status = pam_start(service, user, &_pam_conversation, &_pam_handle);
@ -233,17 +232,22 @@ entrance_pam_init(const char *service, const char *display, const char *user) {
return 0; return 0;
pam_error: pam_error:
fprintf(stderr, PACKAGE": PAM error !!!\n"); PT("PAM error !!!\n");
return 1; return 1;
} }
int int
entrance_pam_item_set(ENTRANCE_PAM_ITEM_TYPE type, const void *value) { entrance_pam_item_set(ENTRANCE_PAM_ITEM_TYPE type, const void *value)
{
char buf[4096];
last_result = pam_set_item(_pam_handle, type, value); last_result = pam_set_item(_pam_handle, type, value);
if (last_result == PAM_SUCCESS) { if (last_result == PAM_SUCCESS) {
return 0; return 0;
} }
fprintf(stderr, PACKAGE": PAM error: %d on %d", last_result, type);
snprintf(buf, sizeof(buf), "PAM error: %d on %d", last_result, type);
PT(buf);
return 1; return 1;
} }
@ -255,7 +259,7 @@ entrance_pam_item_get(ENTRANCE_PAM_ITEM_TYPE type) {
default: default:
case PAM_SYSTEM_ERR: case PAM_SYSTEM_ERR:
entrance_pam_end(); entrance_pam_end();
fprintf(stderr, PACKAGE": error on pam item get\n"); PT("error on pam item get\n");
case PAM_PERM_DENIED: /* Here data was NULL */ case PAM_PERM_DENIED: /* Here data was NULL */
case PAM_SUCCESS: case PAM_SUCCESS:
break; break;
@ -290,7 +294,6 @@ entrance_pam_env_list_get() {
void void
entrance_pam_shutdown() { entrance_pam_shutdown() {
fprintf(stderr, PACKAGE": Pam shutdown\n");
} }
int int

View File

@ -52,7 +52,7 @@ _entrance_server_add(void *data __UNUSED__, int type __UNUSED__, void *event)
void *enc; void *enc;
int size; int size;
fprintf(stderr, PACKAGE": server client connected\n"); PT("server client connected\n");
eeu.type = ENTRANCE_EVENT_USERS; eeu.type = ENTRANCE_EVENT_USERS;
eeu.event.users.users = entrance_history_get(); eeu.event.users.users = entrance_history_get();
enc = entrance_event_encode(&eeu, &size); enc = entrance_event_encode(&eeu, &size);
@ -77,7 +77,7 @@ _entrance_server_del(void *data __UNUSED__, int type __UNUSED__, void *event)
{ {
Ecore_Con_Event_Client_Del *ev; Ecore_Con_Event_Client_Del *ev;
ev = event; ev = event;
fprintf(stderr, PACKAGE": server client disconnected\n"); PT("server client disconnected\n");
return ECORE_CALLBACK_RENEW; return ECORE_CALLBACK_RENEW;
} }
@ -101,12 +101,12 @@ _entrance_server_data(void *data __UNUSED__, int type __UNUSED__, void *event)
{ {
entrance_session_login(eev->event.auth.session, EINA_TRUE); entrance_session_login(eev->event.auth.session, EINA_TRUE);
neev.event.status.granted = EINA_TRUE; neev.event.status.granted = EINA_TRUE;
fprintf(stderr, PACKAGE": server authenticate granted\n"); PT("server authenticate granted\n");
} }
else else
{ {
neev.event.status.granted = EINA_FALSE; neev.event.status.granted = EINA_FALSE;
fprintf(stderr, PACKAGE": server authenticate error\n"); PT("server authenticate error\n");
} }
enc = entrance_event_encode(&neev, &size); enc = entrance_event_encode(&neev, &size);
ecore_con_client_send(ev->client, enc, size); ecore_con_client_send(ev->client, enc, size);
@ -114,7 +114,7 @@ _entrance_server_data(void *data __UNUSED__, int type __UNUSED__, void *event)
else if (eev->type == ENTRANCE_EVENT_ACTION) else if (eev->type == ENTRANCE_EVENT_ACTION)
entrance_action_run(eev->event.action.action); entrance_action_run(eev->event.action.action);
else else
fprintf(stderr, PACKAGE": UNKNOW signal server\n"); PT("UNKNOW signal server\n");
return ECORE_CALLBACK_RENEW; return ECORE_CALLBACK_RENEW;
} }
@ -127,7 +127,7 @@ entrance_server_init()
_entrance_server = ecore_con_server_add(ECORE_CON_LOCAL_SYSTEM, _entrance_server = ecore_con_server_add(ECORE_CON_LOCAL_SYSTEM,
"entrance", 42, NULL); "entrance", 42, NULL);
if (!_entrance_server) if (!_entrance_server)
fprintf(stderr, PACKAGE": server init fail\n"); PT("server init fail\n");
h = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, h = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD,
_entrance_server_add, NULL); _entrance_server_add, NULL);

View File

@ -6,8 +6,6 @@
#include <crypt.h> #include <crypt.h>
#endif #endif
#include <Ecore_File.h>
#include <Efreet.h>
#include "entrance.h" #include "entrance.h"
#define HAVE_SHADOW 1 #define HAVE_SHADOW 1
@ -50,13 +48,18 @@ _entrance_session_cookie_add(const char *mcookie, const char *display,
if (!xauth_cmd || !auth_file) return 1; if (!xauth_cmd || !auth_file) return 1;
snprintf(buf, sizeof(buf), "%s -f %s -q", xauth_cmd, auth_file); snprintf(buf, sizeof(buf), "%s -f %s -q", xauth_cmd, auth_file);
fprintf(stderr, PACKAGE": write auth '%s'\n", buf); PT("write auth");
cmd = popen(buf, "w"); cmd = popen(buf, "w");
if (!cmd) return 1; if (!cmd)
{
fprintf(stderr, " fail !\n");
return 1;
}
fprintf(cmd, "remove %s\n", display); fprintf(cmd, "remove %s\n", display);
fprintf(cmd, "add %s . %s\n", display, mcookie); fprintf(cmd, "add %s . %s\n", display, mcookie);
fprintf(cmd, "exit\n"); fprintf(cmd, "exit\n");
pclose(cmd); pclose(cmd);
fprintf(stderr, " done\n");
return 0; return 0;
} }
@ -65,26 +68,26 @@ _entrance_session_userid_set(struct passwd *pwd)
{ {
if (!pwd) if (!pwd)
{ {
fprintf(stderr, PACKAGE": no passwd !\n"); PT("no passwd !\n");
return 1; return 1;
} }
if (initgroups(pwd->pw_name, pwd->pw_gid) != 0) if (initgroups(pwd->pw_name, pwd->pw_gid) != 0)
{ {
fprintf(stderr, PACKAGE": can't init group\n"); PT("can't init group\n");
return 1; return 1;
} }
if (setgid(pwd->pw_gid) != 0) if (setgid(pwd->pw_gid) != 0)
{ {
fprintf(stderr, PACKAGE": can't set gid\n"); PT("can't set gid\n");
return 1; return 1;
} }
if (setuid(pwd->pw_uid) != 0) if (setuid(pwd->pw_uid) != 0)
{ {
fprintf(stderr, PACKAGE": can't set uid\n"); PT("can't set uid\n");
return 1; return 1;
} }
/* fprintf(stderr, PACKAGE": name -> %s, gid -> %d, uid -> %d\n", /* PT("name -> %s, gid -> %d, uid -> %d\n",
pwd->pw_name, pwd->pw_gid, pwd->pw_uid); */ pwd->pw_name, pwd->pw_gid, pwd->pw_uid); */
return 0; return 0;
} }
@ -92,7 +95,7 @@ _entrance_session_userid_set(struct passwd *pwd)
static Eina_Bool static Eina_Bool
_entrance_session_begin(struct passwd *pwd, const char *cookie) _entrance_session_begin(struct passwd *pwd, const char *cookie)
{ {
fprintf(stderr, PACKAGE": Session Init\n"); PT("Session Init\n");
if (pwd->pw_shell[0] == '\0') if (pwd->pw_shell[0] == '\0')
{ {
setusershell(); setusershell();
@ -125,7 +128,7 @@ _entrance_session_run(struct passwd *pwd, const char *cmd, const char *cookie)
if (pid == 0) if (pid == 0)
{ {
fprintf(stderr, PACKAGE": Session Run\n"); PT("Session Run\n");
#ifdef HAVE_PAM #ifdef HAVE_PAM
env = entrance_pam_env_list_get(); env = entrance_pam_env_list_get();
entrance_pam_end(); entrance_pam_end();
@ -161,16 +164,16 @@ _entrance_session_run(struct passwd *pwd, const char *cmd, const char *cookie)
entrance_config->command.session_start, entrance_config->command.session_start,
pwd->pw_name); pwd->pw_name);
if (-1 == system(buf)) if (-1 == system(buf))
fprintf(stderr, PACKAGE": Error on session start command %s\n", buf); PT("Error on session start command\n");
if(_entrance_session_userid_set(pwd)) return; if(_entrance_session_userid_set(pwd)) return;
_entrance_session_cookie_add(_mcookie, ":0", _entrance_session_cookie_add(_mcookie, ":0",
entrance_config->command.xauth_path, cookie); entrance_config->command.xauth_path, cookie);
if (chdir(pwd->pw_dir)) if (chdir(pwd->pw_dir))
{ {
fprintf(stderr, PACKAGE": change directory for user fail\n"); PT("change directory for user fail");
return; return;
} }
// fprintf(stderr, PACKAGE": Open %s`s session\n", pwd->pw_name); // PT("Open %s`s session\n", pwd->pw_name);
snprintf(buf, sizeof(buf), "%s/.entrance_session.log", pwd->pw_dir); snprintf(buf, sizeof(buf), "%s/.entrance_session.log", pwd->pw_dir);
remove(buf); remove(buf);
@ -182,7 +185,7 @@ _entrance_session_run(struct passwd *pwd, const char *cmd, const char *cookie)
cmd, pwd->pw_dir); cmd, pwd->pw_dir);
#endif #endif
execle(pwd->pw_shell, pwd->pw_shell, "-c", buf, NULL, env); execle(pwd->pw_shell, pwd->pw_shell, "-c", buf, NULL, env);
fprintf(stderr, PACKAGE": The Xsessions are not launched :(\n"); PT("The Xsessions are not launched :(\n");
} }
} }
@ -193,7 +196,7 @@ entrance_session_end(const char *user)
snprintf(buf, sizeof(buf), snprintf(buf, sizeof(buf),
"%s %s ", entrance_config->command.session_stop, user); "%s %s ", entrance_config->command.session_stop, user);
if (-1 == system(buf)) if (-1 == system(buf))
fprintf(stderr, PACKAGE": Error on session stop command %s", buf); PT("Error on session stop command\n");
#ifdef HAVE_PAM #ifdef HAVE_PAM
entrance_pam_close_session(); entrance_pam_close_session();
entrance_pam_end(); entrance_pam_end();
@ -224,7 +227,7 @@ entrance_session_init(const char *file)
int i; int i;
char buf[PATH_MAX]; char buf[PATH_MAX];
fprintf(stderr, PACKAGE": Session init '%s'\n", file); PT("Session init\n");
_mcookie = calloc(33, sizeof(char)); _mcookie = calloc(33, sizeof(char));
_mcookie[0] = 'a'; _mcookie[0] = 'a';
@ -240,10 +243,10 @@ entrance_session_init(const char *file)
_mcookie[i+2] = dig[hi & 0x0f]; _mcookie[i+2] = dig[hi & 0x0f];
_mcookie[i+3] = dig[hi >> 4]; _mcookie[i+3] = dig[hi >> 4];
} }
remove(file); // remove(file);
snprintf(buf, sizeof(buf), "XAUTHORITY=%s", file); snprintf(buf, sizeof(buf), "XAUTHORITY=%s", file);
putenv(strdup(buf)); putenv(strdup(buf));
//fprintf(stderr, PACKAGE": cookie %s \n", _mcookie); //PT("cookie %s \n", _mcookie);
_entrance_session_cookie_add(_mcookie, ":0", _entrance_session_cookie_add(_mcookie, ":0",
entrance_config->command.xauth_path, file); entrance_config->command.xauth_path, file);
_entrance_session_desktops_init(); _entrance_session_desktops_init();
@ -325,7 +328,8 @@ entrance_session_login(const char *session, Eina_Bool push)
} }
if (push) entrance_history_push(pwd->pw_name, session); if (push) entrance_history_push(pwd->pw_name, session);
cmd = _entrance_session_find_command(pwd->pw_dir, session); cmd = _entrance_session_find_command(pwd->pw_dir, session);
fprintf(stderr, PACKAGE": launching %s for user %s\n", cmd, _login); PT("launching session for user ");
fprintf(stderr, "%s\n", _login);
_entrance_session_run(pwd, cmd, buf); _entrance_session_run(pwd, cmd, buf);
return ECORE_CALLBACK_CANCEL; return ECORE_CALLBACK_CANCEL;
} }
@ -385,8 +389,8 @@ _entrance_session_desktops_init()
xsession->icon = eina_stringshare_add("entrance/system"); xsession->icon = eina_stringshare_add("entrance/system");
_xsessions = eina_list_append(_xsessions, xsession); _xsessions = eina_list_append(_xsessions, xsession);
efreet_init();
efreet_desktop_type_alias(EFREET_DESKTOP_TYPE_APPLICATION, "XSession"); efreet_desktop_type_alias(EFREET_DESKTOP_TYPE_APPLICATION, "XSession");
PT("scanning directory: ");
/* Maybee need to scan other directories ? /* Maybee need to scan other directories ?
* _entrance_session_desktops_scan("/etc/share/xsessions"); * _entrance_session_desktops_scan("/etc/share/xsessions");
*/ */
@ -399,7 +403,8 @@ _entrance_session_desktops_init()
snprintf(buf, sizeof(buf), "%s/xsessions", path); snprintf(buf, sizeof(buf), "%s/xsessions", path);
_entrance_session_desktops_scan(buf); _entrance_session_desktops_scan(buf);
} }
efreet_shutdown(); fprintf(stderr, "\n");
PT("scan directory end\n");
} }
static void static void
@ -411,7 +416,7 @@ _entrance_session_desktops_scan(const char *dir)
if (ecore_file_is_dir(dir)) if (ecore_file_is_dir(dir))
{ {
fprintf(stderr, PACKAGE": scanning directory %s\n", dir); fprintf(stderr, "%s", dir);
files = ecore_file_ls(dir); files = ecore_file_ls(dir);
EINA_LIST_FREE(files, filename) EINA_LIST_FREE(files, filename)
{ {
@ -452,7 +457,6 @@ _entrance_session_desktops_scan_file(const char *path)
xsession->name = eina_stringshare_add(desktop->name); xsession->name = eina_stringshare_add(desktop->name);
if (desktop->icon) xsession->icon = eina_stringshare_add(desktop->icon); if (desktop->icon) xsession->icon = eina_stringshare_add(desktop->icon);
_xsessions = eina_list_append(_xsessions, xsession); _xsessions = eina_list_append(_xsessions, xsession);
fprintf(stderr, PACKAGE": client find sessions %s\n", desktop->name);
} }
EINA_LIST_FREE(commands, command) EINA_LIST_FREE(commands, command)
free(command); free(command);

View File

@ -85,7 +85,7 @@ _xserver_start()
execv(args[0], args); execv(args[0], args);
if (buf) free(buf); if (buf) free(buf);
if (args) free(args); if (args) free(args);
fprintf(stderr, PACKAGE": Couldn't launch Xserver ...\n"); PT("Couldn't launch Xserver ...\n");
} }
return pid; return pid;
xserver_error: xserver_error:
@ -95,7 +95,7 @@ xserver_error:
static Eina_Bool static Eina_Bool
_xserver_started(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__) _xserver_started(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
{ {
fprintf(stderr, PACKAGE": xserver started\n"); PT("xserver started\n");
_env_set(_xserver->dname); _env_set(_xserver->dname);
_xserver->start(_xserver->dname); _xserver->start(_xserver->dname);
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
@ -109,7 +109,7 @@ entrance_xserver_init(Entrance_X_Cb start, const char *dname)
sigset_t newset; sigset_t newset;
sigemptyset(&newset); sigemptyset(&newset);
fprintf(stderr, PACKAGE": xserver init\n"); PT("xserver init\n");
_xserver = calloc(1, sizeof(Entrance_Xserver)); _xserver = calloc(1, sizeof(Entrance_Xserver));
_xserver->dname = eina_stringshare_add(dname); _xserver->dname = eina_stringshare_add(dname);
_xserver->start = start; _xserver->start = start;
@ -125,7 +125,7 @@ entrance_xserver_init(Entrance_X_Cb start, const char *dname)
void void
entrance_xserver_end() entrance_xserver_end()
{ {
fprintf(stderr, PACKAGE": xserver end\n"); PT("xserver end\n");
unsetenv("ENTRANCE_XPID"); unsetenv("ENTRANCE_XPID");
} }