diff options
author | Sebastian Dransfeld <sebastian.dransfeld@sintef.no> | 2013-06-20 10:00:19 +0200 |
---|---|---|
committer | Sebastian Dransfeld <sebastian.dransfeld@sintef.no> | 2013-06-20 11:56:46 +0200 |
commit | c504706873af0a69268c996a1d08ffdadd100dbd (patch) | |
tree | 2c752bd674a9d0e48c884cab35161e5787b7344e /src/lib/efreet | |
parent | e8ff0e7b688d80dece749f595ece3ed65f2ccc6a (diff) |
efreet: Init variables in init
Make functions threadsafe
Diffstat (limited to 'src/lib/efreet')
-rw-r--r-- | src/lib/efreet/efreet_base.c | 144 |
1 files changed, 72 insertions, 72 deletions
diff --git a/src/lib/efreet/efreet_base.c b/src/lib/efreet/efreet_base.c index 10f171ea84..22217bafc3 100644 --- a/src/lib/efreet/efreet_base.c +++ b/src/lib/efreet/efreet_base.c | |||
@@ -44,6 +44,7 @@ static const char *xdg_pictures_dir = NULL; | |||
44 | static const char *xdg_videos_dir = NULL; | 44 | static const char *xdg_videos_dir = NULL; |
45 | static const char *hostname = NULL; | 45 | static const char *hostname = NULL; |
46 | 46 | ||
47 | static void efreet_dirs_init(void); | ||
47 | static const char *efreet_dir_get(const char *key, const char *fallback); | 48 | static const char *efreet_dir_get(const char *key, const char *fallback); |
48 | static Eina_List *efreet_dirs_get(const char *key, | 49 | static Eina_List *efreet_dirs_get(const char *key, |
49 | const char *fallback); | 50 | const char *fallback); |
@@ -64,6 +65,7 @@ efreet_base_init(void) | |||
64 | EINA_LOG_ERR("Efreet: Could not create a log domain for efreet_base.\n"); | 65 | EINA_LOG_ERR("Efreet: Could not create a log domain for efreet_base.\n"); |
65 | return 0; | 66 | return 0; |
66 | } | 67 | } |
68 | efreet_dirs_init(); | ||
67 | return 1; | 69 | return 1; |
68 | } | 70 | } |
69 | 71 | ||
@@ -107,18 +109,6 @@ efreet_base_shutdown(void) | |||
107 | const char * | 109 | const char * |
108 | efreet_home_dir_get(void) | 110 | efreet_home_dir_get(void) |
109 | { | 111 | { |
110 | if (efreet_home_dir) return efreet_home_dir; | ||
111 | |||
112 | efreet_home_dir = getenv("HOME"); | ||
113 | #ifdef _WIN32 | ||
114 | if (!efreet_home_dir || efreet_home_dir[0] == '\0') | ||
115 | efreet_home_dir = getenv("USERPROFILE"); | ||
116 | #endif | ||
117 | if (!efreet_home_dir || efreet_home_dir[0] == '\0') | ||
118 | efreet_home_dir = "/tmp"; | ||
119 | |||
120 | efreet_home_dir = eina_stringshare_add(efreet_home_dir); | ||
121 | |||
122 | return efreet_home_dir; | 112 | return efreet_home_dir; |
123 | } | 113 | } |
124 | 114 | ||
@@ -192,102 +182,42 @@ efreet_videos_dir_get(void) | |||
192 | EAPI const char * | 182 | EAPI const char * |
193 | efreet_data_home_get(void) | 183 | efreet_data_home_get(void) |
194 | { | 184 | { |
195 | if (xdg_data_home) return xdg_data_home; | ||
196 | xdg_data_home = efreet_dir_get("XDG_DATA_HOME", "/.local/share"); | ||
197 | return xdg_data_home; | 185 | return xdg_data_home; |
198 | } | 186 | } |
199 | 187 | ||
200 | EAPI Eina_List * | 188 | EAPI Eina_List * |
201 | efreet_data_dirs_get(void) | 189 | efreet_data_dirs_get(void) |
202 | { | 190 | { |
203 | #ifdef _WIN32 | ||
204 | char buf[4096]; | ||
205 | #endif | ||
206 | |||
207 | if (xdg_data_dirs) return xdg_data_dirs; | ||
208 | |||
209 | #ifdef _WIN32 | ||
210 | snprintf(buf, 4096, "%s\\Efl;" DATA_DIR ";/usr/share;/usr/local/share", getenv("APPDATA")); | ||
211 | xdg_data_dirs = efreet_dirs_get("XDG_DATA_DIRS", buf); | ||
212 | #else | ||
213 | xdg_data_dirs = efreet_dirs_get("XDG_DATA_DIRS", | ||
214 | DATA_DIR ":/usr/share:/usr/local/share"); | ||
215 | #endif | ||
216 | return xdg_data_dirs; | 191 | return xdg_data_dirs; |
217 | } | 192 | } |
218 | 193 | ||
219 | EAPI const char * | 194 | EAPI const char * |
220 | efreet_config_home_get(void) | 195 | efreet_config_home_get(void) |
221 | { | 196 | { |
222 | if (xdg_config_home) return xdg_config_home; | ||
223 | xdg_config_home = efreet_dir_get("XDG_CONFIG_HOME", "/.config"); | ||
224 | return xdg_config_home; | 197 | return xdg_config_home; |
225 | } | 198 | } |
226 | 199 | ||
227 | EAPI Eina_List * | 200 | EAPI Eina_List * |
228 | efreet_config_dirs_get(void) | 201 | efreet_config_dirs_get(void) |
229 | { | 202 | { |
230 | if (xdg_config_dirs) return xdg_config_dirs; | ||
231 | xdg_config_dirs = efreet_dirs_get("XDG_CONFIG_DIRS", "/etc/xdg"); | ||
232 | return xdg_config_dirs; | 203 | return xdg_config_dirs; |
233 | } | 204 | } |
234 | 205 | ||
235 | EAPI const char * | 206 | EAPI const char * |
236 | efreet_cache_home_get(void) | 207 | efreet_cache_home_get(void) |
237 | { | 208 | { |
238 | if (xdg_cache_home) return xdg_cache_home; | ||
239 | xdg_cache_home = efreet_dir_get("XDG_CACHE_HOME", "/.cache"); | ||
240 | return xdg_cache_home; | 209 | return xdg_cache_home; |
241 | } | 210 | } |
242 | 211 | ||
243 | EAPI const char * | 212 | EAPI const char * |
244 | efreet_runtime_dir_get(void) | 213 | efreet_runtime_dir_get(void) |
245 | { | 214 | { |
246 | struct stat st; | ||
247 | if (xdg_runtime_dir) return xdg_runtime_dir; | ||
248 | xdg_runtime_dir = efreet_dir_get("XDG_RUNTIME_DIR", "/tmp"); | ||
249 | if (stat(xdg_runtime_dir, &st) == -1) | ||
250 | { | ||
251 | ERR("$XDG_RUNTIME_DIR did not exist, creating '%s' (breaks spec)", | ||
252 | xdg_runtime_dir); | ||
253 | if (ecore_file_mkpath(xdg_runtime_dir)) | ||
254 | chmod(xdg_runtime_dir, 0700); | ||
255 | else | ||
256 | { | ||
257 | CRITICAL("Failed to create XDG_RUNTIME_DIR=%s", xdg_runtime_dir); | ||
258 | eina_stringshare_replace(&xdg_runtime_dir, NULL); | ||
259 | } | ||
260 | } | ||
261 | else if (!S_ISDIR(st.st_mode)) | ||
262 | { | ||
263 | CRITICAL("XDG_RUNTIME_DIR=%s is not a directory!", xdg_runtime_dir); | ||
264 | eina_stringshare_replace(&xdg_runtime_dir, NULL); | ||
265 | } | ||
266 | else if ((st.st_mode & 0777) != 0700) | ||
267 | { | ||
268 | ERR("XDG_RUNTIME_DIR=%s is mode %o, changing to 0700", | ||
269 | xdg_runtime_dir, st.st_mode & 0777); | ||
270 | if (chmod(xdg_runtime_dir, 0700) != 0) | ||
271 | { | ||
272 | CRITICAL("Cannot fix XDG_RUNTIME_DIR=%s incorrect mode %o: %s", | ||
273 | xdg_runtime_dir, st.st_mode & 0777, strerror(errno)); | ||
274 | eina_stringshare_replace(&xdg_runtime_dir, NULL); | ||
275 | } | ||
276 | } | ||
277 | |||
278 | return xdg_runtime_dir; | 215 | return xdg_runtime_dir; |
279 | } | 216 | } |
280 | 217 | ||
281 | EAPI const char * | 218 | EAPI const char * |
282 | efreet_hostname_get(void) | 219 | efreet_hostname_get(void) |
283 | { | 220 | { |
284 | char buf[256]; | ||
285 | |||
286 | if (hostname) return hostname; | ||
287 | if (gethostname(buf, sizeof(buf)) < 0) | ||
288 | hostname = eina_stringshare_add(""); | ||
289 | else | ||
290 | hostname = eina_stringshare_add(buf); | ||
291 | return hostname; | 221 | return hostname; |
292 | } | 222 | } |
293 | 223 | ||
@@ -339,6 +269,76 @@ efreet_dirs_reset(void) | |||
339 | eina_stringshare_replace(&xdg_videos_dir, NULL); | 269 | eina_stringshare_replace(&xdg_videos_dir, NULL); |
340 | } | 270 | } |
341 | 271 | ||
272 | static void | ||
273 | efreet_dirs_init(void) | ||
274 | { | ||
275 | char buf[4096]; | ||
276 | struct stat st; | ||
277 | |||
278 | /* efreet_home_dir */ | ||
279 | efreet_home_dir = getenv("HOME"); | ||
280 | #ifdef _WIN32 | ||
281 | if (!efreet_home_dir || efreet_home_dir[0] == '\0') | ||
282 | efreet_home_dir = getenv("USERPROFILE"); | ||
283 | #endif | ||
284 | if (!efreet_home_dir || efreet_home_dir[0] == '\0') | ||
285 | efreet_home_dir = "/tmp"; | ||
286 | |||
287 | efreet_home_dir = eina_stringshare_add(efreet_home_dir); | ||
288 | |||
289 | /* xdg_<dir>_home */ | ||
290 | xdg_data_home = efreet_dir_get("XDG_DATA_HOME", "/.local/share"); | ||
291 | xdg_config_home = efreet_dir_get("XDG_CONFIG_HOME", "/.config"); | ||
292 | xdg_cache_home = efreet_dir_get("XDG_CACHE_HOME", "/.cache"); | ||
293 | |||
294 | /* xdg_data_dirs */ | ||
295 | #ifdef _WIN32 | ||
296 | snprintf(buf, 4096, "%s\\Efl;" DATA_DIR ";/usr/share;/usr/local/share", getenv("APPDATA")); | ||
297 | xdg_data_dirs = efreet_dirs_get("XDG_DATA_DIRS", buf); | ||
298 | #else | ||
299 | xdg_data_dirs = efreet_dirs_get("XDG_DATA_DIRS", | ||
300 | DATA_DIR ":/usr/share:/usr/local/share"); | ||
301 | #endif | ||
302 | /* xdg_config_dirs */ | ||
303 | xdg_config_dirs = efreet_dirs_get("XDG_CONFIG_DIRS", "/etc/xdg"); | ||
304 | |||
305 | /* xdg_runtime_dir */ | ||
306 | xdg_runtime_dir = efreet_dir_get("XDG_RUNTIME_DIR", "/tmp"); | ||
307 | if (stat(xdg_runtime_dir, &st) == -1) | ||
308 | { | ||
309 | ERR("$XDG_RUNTIME_DIR did not exist, creating '%s' (breaks spec)", | ||
310 | xdg_runtime_dir); | ||
311 | if (ecore_file_mkpath(xdg_runtime_dir)) | ||
312 | chmod(xdg_runtime_dir, 0700); | ||
313 | else | ||
314 | { | ||
315 | CRITICAL("Failed to create XDG_RUNTIME_DIR=%s", xdg_runtime_dir); | ||
316 | eina_stringshare_replace(&xdg_runtime_dir, NULL); | ||
317 | } | ||
318 | } | ||
319 | else if (!S_ISDIR(st.st_mode)) | ||
320 | { | ||
321 | CRITICAL("XDG_RUNTIME_DIR=%s is not a directory!", xdg_runtime_dir); | ||
322 | eina_stringshare_replace(&xdg_runtime_dir, NULL); | ||
323 | } | ||
324 | else if ((st.st_mode & 0777) != 0700) | ||
325 | { | ||
326 | ERR("XDG_RUNTIME_DIR=%s is mode %o, changing to 0700", | ||
327 | xdg_runtime_dir, st.st_mode & 0777); | ||
328 | if (chmod(xdg_runtime_dir, 0700) != 0) | ||
329 | { | ||
330 | CRITICAL("Cannot fix XDG_RUNTIME_DIR=%s incorrect mode %o: %s", | ||
331 | xdg_runtime_dir, st.st_mode & 0777, strerror(errno)); | ||
332 | eina_stringshare_replace(&xdg_runtime_dir, NULL); | ||
333 | } | ||
334 | } | ||
335 | /* hostname */ | ||
336 | if (gethostname(buf, sizeof(buf)) < 0) | ||
337 | hostname = eina_stringshare_add(""); | ||
338 | else | ||
339 | hostname = eina_stringshare_add(buf); | ||
340 | } | ||
341 | |||
342 | /** | 342 | /** |
343 | * @internal | 343 | * @internal |
344 | * @param key The environment key to lookup | 344 | * @param key The environment key to lookup |