diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-07-14 23:12:36 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-07-14 23:12:36 +0000 |
commit | 0a1b3b517fa78d24e4fbf2d961b5c1681df4944e (patch) | |
tree | 663e1d9b189a0a3299f9be9ebcead49fba756e12 /src/util/os_installation.c | |
parent | 0fee351877c8b33fa2c029817f0e7780ed9e221a (diff) | |
download | gnunet-0a1b3b517fa78d24e4fbf2d961b5c1681df4944e.tar.gz gnunet-0a1b3b517fa78d24e4fbf2d961b5c1681df4944e.zip |
-code cleanup
Diffstat (limited to 'src/util/os_installation.c')
-rw-r--r-- | src/util/os_installation.c | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/src/util/os_installation.c b/src/util/os_installation.c index 34ddd4372..c52628dcd 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c | |||
@@ -46,6 +46,8 @@ | |||
46 | #if LINUX | 46 | #if LINUX |
47 | /** | 47 | /** |
48 | * Try to determine path by reading /proc/PID/exe | 48 | * Try to determine path by reading /proc/PID/exe |
49 | * | ||
50 | * @return NULL on error | ||
49 | */ | 51 | */ |
50 | static char * | 52 | static char * |
51 | get_path_from_proc_maps () | 53 | get_path_from_proc_maps () |
@@ -77,6 +79,8 @@ get_path_from_proc_maps () | |||
77 | 79 | ||
78 | /** | 80 | /** |
79 | * Try to determine path by reading /proc/PID/exe | 81 | * Try to determine path by reading /proc/PID/exe |
82 | * | ||
83 | * @return NULL on error | ||
80 | */ | 84 | */ |
81 | static char * | 85 | static char * |
82 | get_path_from_proc_exe () | 86 | get_path_from_proc_exe () |
@@ -109,6 +113,8 @@ get_path_from_proc_exe () | |||
109 | #if WINDOWS | 113 | #if WINDOWS |
110 | /** | 114 | /** |
111 | * Try to determine path with win32-specific function | 115 | * Try to determine path with win32-specific function |
116 | * | ||
117 | * @return NULL on error | ||
112 | */ | 118 | */ |
113 | static char * | 119 | static char * |
114 | get_path_from_module_filename () | 120 | get_path_from_module_filename () |
@@ -130,9 +136,21 @@ get_path_from_module_filename () | |||
130 | #endif | 136 | #endif |
131 | 137 | ||
132 | #if DARWIN | 138 | #if DARWIN |
139 | /** | ||
140 | * Signature of the '_NSGetExecutablePath" function. | ||
141 | * | ||
142 | * @param buf where to write the path | ||
143 | * @param number of bytes available in 'buf' | ||
144 | * @return 0 on success, otherwise desired number of bytes is stored in 'bufsize' | ||
145 | */ | ||
133 | typedef int (*MyNSGetExecutablePathProto) (char *buf, size_t * bufsize); | 146 | typedef int (*MyNSGetExecutablePathProto) (char *buf, size_t * bufsize); |
134 | 147 | ||
135 | 148 | ||
149 | /** | ||
150 | * Try to obtain the path of our executable using '_NSGetExecutablePath'. | ||
151 | * | ||
152 | * @return NULL on error | ||
153 | */ | ||
136 | static char * | 154 | static char * |
137 | get_path_from_NSGetExecutablePath () | 155 | get_path_from_NSGetExecutablePath () |
138 | { | 156 | { |
@@ -148,7 +166,7 @@ get_path_from_NSGetExecutablePath () | |||
148 | path = &zero; | 166 | path = &zero; |
149 | len = 0; | 167 | len = 0; |
150 | /* get the path len, including the trailing \0 */ | 168 | /* get the path len, including the trailing \0 */ |
151 | func (path, &len); | 169 | (void) func (path, &len); |
152 | if (0 == len) | 170 | if (0 == len) |
153 | return NULL; | 171 | return NULL; |
154 | path = GNUNET_malloc (len); | 172 | path = GNUNET_malloc (len); |
@@ -165,6 +183,11 @@ get_path_from_NSGetExecutablePath () | |||
165 | } | 183 | } |
166 | 184 | ||
167 | 185 | ||
186 | /** | ||
187 | * Try to obtain the path of our executable using '_dyld_image' API. | ||
188 | * | ||
189 | * @return NULL on error | ||
190 | */ | ||
168 | static char * | 191 | static char * |
169 | get_path_from_dyld_image () | 192 | get_path_from_dyld_image () |
170 | { | 193 | { |
@@ -252,6 +275,12 @@ get_path_from_PATH (const char *binary) | |||
252 | } | 275 | } |
253 | 276 | ||
254 | 277 | ||
278 | /** | ||
279 | * Try to obtain the installation path using the "GNUNET_PREFIX" environment | ||
280 | * variable. | ||
281 | * | ||
282 | * @return NULL on error (environment variable not set) | ||
283 | */ | ||
255 | static char * | 284 | static char * |
256 | get_path_from_GNUNET_PREFIX () | 285 | get_path_from_GNUNET_PREFIX () |
257 | { | 286 | { |
@@ -302,7 +331,8 @@ os_get_gnunet_path () | |||
302 | return NULL; | 331 | return NULL; |
303 | } | 332 | } |
304 | 333 | ||
305 | /* | 334 | |
335 | /** | ||
306 | * @brief get the path to current app's bin/ | 336 | * @brief get the path to current app's bin/ |
307 | * @author Milan | 337 | * @author Milan |
308 | * | 338 | * |
@@ -330,7 +360,6 @@ os_get_exec_path () | |||
330 | } | 360 | } |
331 | 361 | ||
332 | 362 | ||
333 | |||
334 | /** | 363 | /** |
335 | * @brief get the path to a specific GNUnet installation directory or, | 364 | * @brief get the path to a specific GNUnet installation directory or, |
336 | * with GNUNET_IPK_SELF_PREFIX, the current running apps installation directory | 365 | * with GNUNET_IPK_SELF_PREFIX, the current running apps installation directory |
@@ -500,8 +529,7 @@ GNUNET_OS_check_helper_binary (const char *binary) | |||
500 | } | 529 | } |
501 | if (0 != ACCESS (p, X_OK)) | 530 | if (0 != ACCESS (p, X_OK)) |
502 | { | 531 | { |
503 | LOG (GNUNET_ERROR_TYPE_WARNING, _("access (%s, X_OK) failed: %s\n"), p, | 532 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", p); |
504 | STRERROR (errno)); | ||
505 | GNUNET_free (p); | 533 | GNUNET_free (p); |
506 | return GNUNET_SYSERR; | 534 | return GNUNET_SYSERR; |
507 | } | 535 | } |
@@ -515,13 +543,12 @@ GNUNET_OS_check_helper_binary (const char *binary) | |||
515 | #endif | 543 | #endif |
516 | if (0 != STAT (p, &statbuf)) | 544 | if (0 != STAT (p, &statbuf)) |
517 | { | 545 | { |
518 | LOG (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p, | 546 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", p); |
519 | STRERROR (errno)); | ||
520 | GNUNET_free (p); | 547 | GNUNET_free (p); |
521 | return GNUNET_SYSERR; | 548 | return GNUNET_SYSERR; |
522 | } | 549 | } |
523 | #ifndef MINGW | 550 | #ifndef MINGW |
524 | if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0)) | 551 | if ((0 != (statbuf.st_mode & S_ISUID)) && (0 == statbuf.st_uid)) |
525 | { | 552 | { |
526 | GNUNET_free (p); | 553 | GNUNET_free (p); |
527 | return GNUNET_YES; | 554 | return GNUNET_YES; |
@@ -541,7 +568,7 @@ GNUNET_OS_check_helper_binary (const char *binary) | |||
541 | { | 568 | { |
542 | DWORD err = GetLastError (); | 569 | DWORD err = GetLastError (); |
543 | 570 | ||
544 | LOG (GNUNET_ERROR_TYPE_INFO, | 571 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
545 | "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) failed! GLE = %d\n", err); | 572 | "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) failed! GLE = %d\n", err); |
546 | once = -1; | 573 | once = -1; |
547 | return GNUNET_NO; /* not running as administrator */ | 574 | return GNUNET_NO; /* not running as administrator */ |