2009-04-20 16:20:40 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
2009-10-04 15:28:12 -07:00
|
|
|
|
2010-11-25 15:48:59 -08:00
|
|
|
#undef alloca
|
|
|
|
#ifdef HAVE_ALLOCA_H
|
|
|
|
# include <alloca.h>
|
|
|
|
#elif defined __GNUC__
|
|
|
|
# define alloca __builtin_alloca
|
|
|
|
#elif defined _AIX
|
|
|
|
# define alloca __alloca
|
|
|
|
#elif defined _MSC_VER
|
|
|
|
# include <malloc.h>
|
|
|
|
# define alloca _alloca
|
|
|
|
#else
|
|
|
|
# include <stddef.h>
|
|
|
|
# ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
# endif
|
|
|
|
void *alloca (size_t);
|
|
|
|
#endif
|
|
|
|
|
2011-02-07 13:33:33 -08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
2011-08-18 00:35:48 -07:00
|
|
|
#include <fcntl.h>
|
2010-11-22 06:15:50 -08:00
|
|
|
|
2010-11-26 12:48:50 -08:00
|
|
|
#include <Eet.h>
|
|
|
|
#include <Ecore.h>
|
2010-11-25 15:52:57 -08:00
|
|
|
#include <Ecore_File.h>
|
|
|
|
|
2011-02-05 11:05:55 -08:00
|
|
|
/* define macros and variable for using the eina logging system */
|
|
|
|
#define EFREET_MODULE_LOG_DOM /* no logging in this file */
|
|
|
|
|
2007-02-03 05:05:30 -08:00
|
|
|
#include "Efreet.h"
|
|
|
|
#include "efreet_private.h"
|
2009-04-20 16:20:40 -07:00
|
|
|
#include "efreet_xml.h"
|
2007-02-03 05:05:30 -08:00
|
|
|
|
2011-02-07 13:19:36 -08:00
|
|
|
/*
|
|
|
|
* Needs EAPI because of helper binaries
|
|
|
|
*/
|
2010-03-28 11:54:25 -07:00
|
|
|
EAPI int efreet_cache_update = 1;
|
|
|
|
|
2009-10-09 23:19:13 -07:00
|
|
|
static int _efreet_init_count = 0;
|
2007-02-03 05:05:30 -08:00
|
|
|
static int efreet_parsed_locale = 0;
|
2010-03-13 10:34:30 -08:00
|
|
|
static const char *efreet_lang = NULL;
|
|
|
|
static const char *efreet_lang_country = NULL;
|
|
|
|
static const char *efreet_lang_modifier = NULL;
|
2007-02-03 05:05:30 -08:00
|
|
|
static void efreet_parse_locale(void);
|
|
|
|
static int efreet_parse_locale_setting(const char *env);
|
|
|
|
|
2011-02-07 13:33:33 -08:00
|
|
|
static uid_t ruid;
|
|
|
|
static uid_t rgid;
|
|
|
|
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI int
|
2007-02-03 05:05:30 -08:00
|
|
|
efreet_init(void)
|
|
|
|
{
|
2011-02-07 13:33:33 -08:00
|
|
|
char *tmp;
|
|
|
|
|
2009-10-09 23:19:13 -07:00
|
|
|
if (++_efreet_init_count != 1)
|
|
|
|
return _efreet_init_count;
|
|
|
|
|
2011-02-07 13:33:33 -08:00
|
|
|
/* Find users real uid and gid */
|
|
|
|
tmp = getenv("SUDO_UID");
|
|
|
|
if (tmp)
|
|
|
|
ruid = strtoul(tmp, NULL, 10);
|
|
|
|
else
|
|
|
|
ruid = getuid();
|
|
|
|
|
|
|
|
tmp = getenv("SUDO_GID");
|
|
|
|
if (tmp)
|
|
|
|
rgid = strtoul(tmp, NULL, 10);
|
|
|
|
else
|
|
|
|
rgid = getgid();
|
|
|
|
|
2009-10-09 23:19:13 -07:00
|
|
|
if (!eina_init())
|
|
|
|
return --_efreet_init_count;
|
2010-11-22 06:15:40 -08:00
|
|
|
if (!eet_init())
|
2010-11-22 12:49:22 -08:00
|
|
|
goto shutdown_eina;
|
|
|
|
if (!ecore_init())
|
2010-11-22 12:50:09 -08:00
|
|
|
goto shutdown_eet;
|
2010-11-22 12:49:22 -08:00
|
|
|
if (!ecore_file_init())
|
2010-11-22 12:50:09 -08:00
|
|
|
goto shutdown_ecore;
|
2009-10-09 23:19:13 -07:00
|
|
|
|
|
|
|
if (!efreet_base_init())
|
2011-02-05 11:05:55 -08:00
|
|
|
goto shutdown_ecore_file;
|
2009-10-09 23:19:13 -07:00
|
|
|
|
2010-11-15 13:07:22 -08:00
|
|
|
if (!efreet_cache_init())
|
2010-02-04 01:12:35 -08:00
|
|
|
goto shutdown_efreet_base;
|
2010-11-15 13:07:22 -08:00
|
|
|
|
|
|
|
if (!efreet_xml_init())
|
|
|
|
goto shutdown_efreet_cache;
|
2009-10-09 23:19:13 -07:00
|
|
|
|
|
|
|
if (!efreet_icon_init())
|
2010-02-04 01:12:35 -08:00
|
|
|
goto shutdown_efreet_xml;
|
2009-10-09 23:19:13 -07:00
|
|
|
|
|
|
|
if (!efreet_ini_init())
|
2010-02-04 01:12:35 -08:00
|
|
|
goto shutdown_efreet_icon;
|
2009-10-09 23:19:13 -07:00
|
|
|
|
|
|
|
if (!efreet_desktop_init())
|
2010-02-04 01:12:35 -08:00
|
|
|
goto shutdown_efreet_ini;
|
2009-10-09 23:19:13 -07:00
|
|
|
|
|
|
|
if (!efreet_menu_init())
|
2010-02-04 01:12:35 -08:00
|
|
|
goto shutdown_efreet_desktop;
|
2009-10-09 23:19:13 -07:00
|
|
|
|
2010-03-27 12:57:47 -07:00
|
|
|
if (!efreet_util_init())
|
|
|
|
goto shutdown_efreet_menu;
|
|
|
|
|
2009-10-09 23:19:13 -07:00
|
|
|
return _efreet_init_count;
|
|
|
|
|
2010-03-27 12:57:47 -07:00
|
|
|
shutdown_efreet_menu:
|
|
|
|
efreet_menu_shutdown();
|
2010-02-04 01:12:35 -08:00
|
|
|
shutdown_efreet_desktop:
|
2009-10-09 23:19:13 -07:00
|
|
|
efreet_desktop_shutdown();
|
2010-02-04 01:12:35 -08:00
|
|
|
shutdown_efreet_ini:
|
2009-10-09 23:19:13 -07:00
|
|
|
efreet_ini_shutdown();
|
2010-02-04 01:12:35 -08:00
|
|
|
shutdown_efreet_icon:
|
2009-10-09 23:19:13 -07:00
|
|
|
efreet_icon_shutdown();
|
2010-02-04 01:12:35 -08:00
|
|
|
shutdown_efreet_xml:
|
2009-10-09 23:19:13 -07:00
|
|
|
efreet_xml_shutdown();
|
2010-11-15 13:07:22 -08:00
|
|
|
shutdown_efreet_cache:
|
|
|
|
efreet_cache_shutdown();
|
2010-02-04 01:12:35 -08:00
|
|
|
shutdown_efreet_base:
|
2009-10-09 23:19:13 -07:00
|
|
|
efreet_base_shutdown();
|
2010-11-22 12:49:22 -08:00
|
|
|
shutdown_ecore_file:
|
|
|
|
ecore_file_shutdown();
|
2010-11-22 06:15:40 -08:00
|
|
|
shutdown_ecore:
|
|
|
|
ecore_shutdown();
|
2010-11-22 12:49:22 -08:00
|
|
|
shutdown_eet:
|
|
|
|
eet_shutdown();
|
2010-02-04 01:12:35 -08:00
|
|
|
shutdown_eina:
|
2009-10-09 23:19:13 -07:00
|
|
|
eina_shutdown();
|
|
|
|
|
|
|
|
return --_efreet_init_count;
|
2007-02-03 05:05:30 -08:00
|
|
|
}
|
|
|
|
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI int
|
2007-02-03 05:05:30 -08:00
|
|
|
efreet_shutdown(void)
|
|
|
|
{
|
2012-05-30 03:08:41 -07:00
|
|
|
if (_efreet_init_count <= 0)
|
|
|
|
{
|
2012-05-30 05:34:18 -07:00
|
|
|
EINA_LOG_ERR("Init count not greater than 0 in shutdown.");
|
2012-05-30 03:08:41 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2009-10-09 23:19:13 -07:00
|
|
|
if (--_efreet_init_count != 0)
|
2010-02-04 01:12:35 -08:00
|
|
|
return _efreet_init_count;
|
2009-10-09 23:19:13 -07:00
|
|
|
|
2010-03-27 12:57:47 -07:00
|
|
|
efreet_util_shutdown();
|
2007-03-25 04:25:23 -07:00
|
|
|
efreet_menu_shutdown();
|
2007-02-03 05:05:30 -08:00
|
|
|
efreet_desktop_shutdown();
|
|
|
|
efreet_ini_shutdown();
|
|
|
|
efreet_icon_shutdown();
|
|
|
|
efreet_xml_shutdown();
|
2010-11-15 13:07:22 -08:00
|
|
|
efreet_cache_shutdown();
|
2007-02-03 05:05:30 -08:00
|
|
|
efreet_base_shutdown();
|
|
|
|
|
2010-03-13 10:34:30 -08:00
|
|
|
IF_RELEASE(efreet_lang);
|
|
|
|
IF_RELEASE(efreet_lang_country);
|
|
|
|
IF_RELEASE(efreet_lang_modifier);
|
2007-02-03 05:05:30 -08:00
|
|
|
efreet_parsed_locale = 0; /* reset this in case they init efreet again */
|
|
|
|
|
2010-11-22 12:49:22 -08:00
|
|
|
ecore_file_shutdown();
|
|
|
|
ecore_shutdown();
|
2010-03-13 11:05:11 -08:00
|
|
|
eet_shutdown();
|
|
|
|
eina_shutdown();
|
|
|
|
|
2009-10-09 23:19:13 -07:00
|
|
|
return _efreet_init_count;
|
2007-02-03 05:05:30 -08:00
|
|
|
}
|
|
|
|
|
2012-06-25 10:12:35 -07:00
|
|
|
EAPI void
|
|
|
|
efreet_lang_reset(void)
|
|
|
|
{
|
|
|
|
IF_RELEASE(efreet_lang);
|
|
|
|
IF_RELEASE(efreet_lang_country);
|
|
|
|
IF_RELEASE(efreet_lang_modifier);
|
|
|
|
efreet_parsed_locale = 0; /* reset this in case they init efreet again */
|
|
|
|
|
|
|
|
efreet_dirs_reset();
|
2012-06-25 13:54:46 -07:00
|
|
|
efreet_cache_desktop_update();
|
2012-06-25 10:12:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-02-03 05:05:30 -08:00
|
|
|
* @internal
|
|
|
|
* @return Returns the current users language setting or NULL if none set
|
|
|
|
* @brief Retrieves the current language setting
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
efreet_lang_get(void)
|
|
|
|
{
|
|
|
|
if (efreet_parsed_locale) return efreet_lang;
|
|
|
|
|
|
|
|
efreet_parse_locale();
|
|
|
|
return efreet_lang;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @return Returns the current language country setting or NULL if none set
|
|
|
|
* @brief Retrieves the current country setting for the current language or
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
efreet_lang_country_get(void)
|
|
|
|
{
|
|
|
|
if (efreet_parsed_locale) return efreet_lang_country;
|
|
|
|
|
|
|
|
efreet_parse_locale();
|
|
|
|
return efreet_lang_country;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @return Returns the current language modifier setting or NULL if none
|
|
|
|
* set.
|
|
|
|
* @brief Retrieves the modifier setting for the language.
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
efreet_lang_modifier_get(void)
|
|
|
|
{
|
|
|
|
if (efreet_parsed_locale) return efreet_lang_modifier;
|
|
|
|
|
|
|
|
efreet_parse_locale();
|
|
|
|
return efreet_lang_modifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @return Returns no value
|
|
|
|
* @brief Parses out the language, country and modifer setting from the
|
|
|
|
* LC_MESSAGES environment variable
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
efreet_parse_locale(void)
|
|
|
|
{
|
|
|
|
efreet_parsed_locale = 1;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-06-25 10:12:35 -07:00
|
|
|
if (efreet_parse_locale_setting("LANG"))
|
2007-02-03 05:05:30 -08:00
|
|
|
return;
|
|
|
|
|
2012-06-25 10:12:35 -07:00
|
|
|
if (efreet_parse_locale_setting("LC_ALL"))
|
2007-02-03 05:05:30 -08:00
|
|
|
return;
|
|
|
|
|
2012-06-25 10:12:35 -07:00
|
|
|
efreet_parse_locale_setting("LC_MESSAGES");
|
2007-02-03 05:05:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
2011-01-27 09:49:45 -08:00
|
|
|
* @param env The environment variable to grab
|
2007-02-03 05:05:30 -08:00
|
|
|
* @return Returns 1 if we parsed something of @a env, 0 otherwise
|
|
|
|
* @brief Tries to parse the lang settings out of the given environment
|
|
|
|
* variable
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
efreet_parse_locale_setting(const char *env)
|
|
|
|
{
|
|
|
|
int found = 0;
|
2010-03-30 05:22:15 -07:00
|
|
|
char *setting;
|
2007-02-03 05:05:30 -08:00
|
|
|
char *p;
|
2010-03-30 05:22:15 -07:00
|
|
|
size_t len;
|
2007-02-03 05:05:30 -08:00
|
|
|
|
2010-03-29 13:14:43 -07:00
|
|
|
p = getenv(env);
|
|
|
|
if (!p) return 0;
|
2010-03-30 05:22:15 -07:00
|
|
|
len = strlen(p) + 1;
|
|
|
|
setting = alloca(len);
|
|
|
|
memcpy(setting, p, len);
|
2007-02-03 05:05:30 -08:00
|
|
|
|
|
|
|
/* pull the modifier off the end */
|
|
|
|
p = strrchr(setting, '@');
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
*p = '\0';
|
2010-03-13 10:34:30 -08:00
|
|
|
efreet_lang_modifier = eina_stringshare_add(p + 1);
|
2007-02-03 05:05:30 -08:00
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if there is an encoding we ignore it */
|
|
|
|
p = strrchr(setting, '.');
|
|
|
|
if (p) *p = '\0';
|
|
|
|
|
|
|
|
/* get the country if available */
|
|
|
|
p = strrchr(setting, '_');
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
*p = '\0';
|
2010-03-13 10:34:30 -08:00
|
|
|
efreet_lang_country = eina_stringshare_add(p + 1);
|
2007-02-03 05:05:30 -08:00
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
2010-03-29 13:14:43 -07:00
|
|
|
if (*setting != '\0')
|
2007-02-03 05:05:30 -08:00
|
|
|
{
|
2010-03-13 10:34:30 -08:00
|
|
|
efreet_lang = eina_stringshare_add(setting);
|
2007-02-03 05:05:30 -08:00
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
2011-01-27 09:49:45 -08:00
|
|
|
* @param buffer The destination buffer
|
|
|
|
* @param size The destination buffer size
|
|
|
|
* @param strs The strings to concatenate together
|
2007-02-03 05:05:30 -08:00
|
|
|
* @return Returns the size of the string in @a buffer
|
|
|
|
* @brief Concatenates the strings in @a strs into the given @a buffer not
|
|
|
|
* exceeding the given @a size.
|
|
|
|
*/
|
|
|
|
size_t
|
|
|
|
efreet_array_cat(char *buffer, size_t size, const char *strs[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
size_t n;
|
|
|
|
for (i = 0, n = 0; n < size && strs[i]; i++)
|
|
|
|
{
|
2010-01-30 14:13:16 -08:00
|
|
|
n += eina_strlcpy(buffer + n, strs[i], size - n);
|
2007-02-03 05:05:30 -08:00
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
2011-02-07 13:33:33 -08:00
|
|
|
|
|
|
|
EAPI void
|
|
|
|
efreet_fsetowner(int fd)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (fd < 0) return;
|
|
|
|
if (fstat(fd, &st) < 0) return;
|
|
|
|
if (st.st_uid == ruid) return;
|
|
|
|
|
2011-04-07 22:57:28 -07:00
|
|
|
if (fchown(fd, ruid, rgid) != 0) return;
|
2011-02-07 13:33:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
efreet_setowner(const char *path)
|
|
|
|
{
|
2012-05-23 13:10:27 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(path);
|
|
|
|
|
2011-02-07 13:33:33 -08:00
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = open(path, O_RDONLY);
|
|
|
|
if (fd < 0) return;
|
|
|
|
efreet_fsetowner(fd);
|
|
|
|
close(fd);
|
|
|
|
}
|