int mod_sm_init() { if(ioncore_g.sm_client_id!=NULL) mod_sm_set_ion_id(ioncore_g.sm_client_id); if(!mod_sm_init_session()) goto err; if(extl_sessiondir()==NULL) mod_sm_set_sessiondir(); if(!mod_sm_register_exports()) goto err; ioncore_set_sm_callbacks(mod_sm_add_match, mod_sm_get_configuration); hook_add(clientwin_do_manage_alt, (WHookDummy*)sm_do_manage); ioncore_set_smhook(mod_sm_smhook); return TRUE; err: mod_sm_deinit(); return FALSE; }
bool mod_sm_init_session() { char error_str[256]; char *new_client_id=NULL; SmcCallbacks smcall; if(getenv("SESSION_MANAGER")==0){ warn(TR("SESSION_MANAGER environment variable not set.")); return FALSE; } if(IceAddConnectionWatch(&sm_ice_watch_fd, NULL) == 0){ warn(TR("Session Manager: IceAddConnectionWatch failed.")); return FALSE; } memset(&smcall, 0, sizeof(smcall)); smcall.save_yourself.callback=&sm_save_yourself; smcall.save_yourself.client_data=NULL; smcall.die.callback=&sm_die; smcall.die.client_data=NULL; smcall.save_complete.callback=&sm_save_complete; smcall.save_complete.client_data=NULL; smcall.shutdown_cancelled.callback=&sm_shutdown_cancelled; smcall.shutdown_cancelled.client_data=NULL; if((sm_conn=SmcOpenConnection(NULL, /* network ids */ NULL, /* context */ 1, 0, /* protocol major, minor */ SmcSaveYourselfProcMask | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask | SmcDieProcMask, &smcall, sm_client_id, &new_client_id, sizeof(error_str), error_str)) == NULL) { warn(TR("Unable to connect to the session manager.")); return FALSE; } mod_sm_set_ion_id(new_client_id); free(new_client_id); ice_sm_conn=SmcGetIceConnection(sm_conn); return TRUE; }