aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-09-05 11:35:44 +0200
committerChristian Grothoff <christian@grothoff.org>2019-09-05 11:47:44 +0200
commitb0918f1e382ac02b8529c365ab69cf6194d12fd3 (patch)
tree7c3754f073a10d5387f5761b43a58efb4392f0e0 /src
parent74c328220897196de3d93710e74666230a57cfee (diff)
downloadgnunet-b0918f1e382ac02b8529c365ab69cf6194d12fd3.tar.gz
gnunet-b0918f1e382ac02b8529c365ab69cf6194d12fd3.zip
fix logging issue reported by Raphael
Diffstat (limited to 'src')
-rw-r--r--src/util/os_installation.c378
-rw-r--r--src/util/service.c690
2 files changed, 522 insertions, 546 deletions
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index f51bfd287..8dacd431d 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -44,9 +44,14 @@
44#endif 44#endif
45 45
46 46
47#define LOG(kind,...) GNUNET_log_from (kind, "util-os-installation", __VA_ARGS__) 47#define LOG(kind, ...) \
48 GNUNET_log_from (kind, "util-os-installation", __VA_ARGS__)
48 49
49#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-os-installation", syscall, filename) 50#define LOG_STRERROR_FILE(kind, syscall, filename) \
51 GNUNET_log_from_strerror_file (kind, \
52 "util-os-installation", \
53 syscall, \
54 filename)
50 55
51 56
52/** 57/**
@@ -99,13 +104,13 @@ const struct GNUNET_OS_ProjectData *
99GNUNET_OS_project_data_get () 104GNUNET_OS_project_data_get ()
100{ 105{
101 if (0 == gettextinit) 106 if (0 == gettextinit)
102 { 107 {
103 char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); 108 char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
104 if (NULL != path) 109 if (NULL != path)
105 BINDTEXTDOMAIN (PACKAGE, path); 110 BINDTEXTDOMAIN (PACKAGE, path);
106 GNUNET_free(path); 111 GNUNET_free (path);
107 gettextinit = 1; 112 gettextinit = 1;
108 } 113 }
109 return current_pd; 114 return current_pd;
110} 115}
111 116
@@ -119,13 +124,13 @@ void
119GNUNET_OS_init (const struct GNUNET_OS_ProjectData *pd) 124GNUNET_OS_init (const struct GNUNET_OS_ProjectData *pd)
120{ 125{
121 if (0 == gettextinit) 126 if (0 == gettextinit)
122 { 127 {
123 char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); 128 char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
124 if (NULL != path) 129 if (NULL != path)
125 BINDTEXTDOMAIN (PACKAGE, path); 130 BINDTEXTDOMAIN (PACKAGE, path);
126 GNUNET_free(path); 131 GNUNET_free (path);
127 gettextinit = 1; 132 gettextinit = 1;
128 } 133 }
129 GNUNET_assert (NULL != pd); 134 GNUNET_assert (NULL != pd);
130 current_pd = pd; 135 current_pd = pd;
131} 136}
@@ -151,10 +156,10 @@ get_path_from_proc_maps ()
151 return NULL; 156 return NULL;
152 while (NULL != fgets (line, sizeof (line), f)) 157 while (NULL != fgets (line, sizeof (line), f))
153 { 158 {
154 if ((1 == 159 if ((1 == SSCANF (line,
155 SSCANF (line, "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%1023s", dir)) && 160 "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%1023s",
156 (NULL != (lgu = strstr (dir, 161 dir)) &&
157 current_pd->libname)))) 162 (NULL != (lgu = strstr (dir, current_pd->libname))))
158 { 163 {
159 lgu[0] = '\0'; 164 lgu[0] = '\0';
160 FCLOSE (f); 165 FCLOSE (f);
@@ -179,35 +184,24 @@ get_path_from_proc_exe ()
179 ssize_t size; 184 ssize_t size;
180 char *lep; 185 char *lep;
181 186
182 GNUNET_snprintf (fn, 187 GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/exe", getpid ());
183 sizeof (fn), 188 size = readlink (fn, lnk, sizeof (lnk) - 1);
184 "/proc/%u/exe",
185 getpid ());
186 size = readlink (fn,
187 lnk,
188 sizeof (lnk) - 1);
189 if (size <= 0) 189 if (size <= 0)
190 { 190 {
191 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, 191 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "readlink", fn);
192 "readlink",
193 fn);
194 return NULL; 192 return NULL;
195 } 193 }
196 GNUNET_assert ( ((size_t) size) < sizeof (lnk)); 194 GNUNET_assert (((size_t) size) < sizeof (lnk));
197 lnk[size] = '\0'; 195 lnk[size] = '\0';
198 while ((lnk[size] != '/') && (size > 0)) 196 while ((lnk[size] != '/') && (size > 0))
199 size--; 197 size--;
200 GNUNET_asprintf (&lep, 198 GNUNET_asprintf (&lep, "/%s/libexec/", current_pd->project_dirname);
201 "/%s/libexec/",
202 current_pd->project_dirname);
203 /* test for being in lib/gnunet/libexec/ or lib/MULTIARCH/gnunet/libexec */ 199 /* test for being in lib/gnunet/libexec/ or lib/MULTIARCH/gnunet/libexec */
204 if ( (((size_t) size) > strlen (lep)) && 200 if ((((size_t) size) > strlen (lep)) &&
205 (0 == strcmp (lep, 201 (0 == strcmp (lep, &lnk[size - strlen (lep)])))
206 &lnk[size - strlen (lep)])) )
207 size -= strlen (lep) - 1; 202 size -= strlen (lep) - 1;
208 GNUNET_free (lep); 203 GNUNET_free (lep);
209 if ( (size < 4) || 204 if ((size < 4) || (lnk[size - 4] != '/'))
210 (lnk[size - 4] != '/') )
211 { 205 {
212 /* not installed in "/bin/" -- binary path probably useless */ 206 /* not installed in "/bin/" -- binary path probably useless */
213 return NULL; 207 return NULL;
@@ -228,21 +222,19 @@ static HINSTANCE dll_instance;
228 * and hInstance saving. 222 * and hInstance saving.
229 */ 223 */
230BOOL WINAPI 224BOOL WINAPI
231DllMain (HINSTANCE hinstDLL, 225DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
232 DWORD fdwReason,
233 LPVOID lpvReserved)
234{ 226{
235 switch (fdwReason) 227 switch (fdwReason)
236 { 228 {
237 case DLL_PROCESS_ATTACH: 229 case DLL_PROCESS_ATTACH:
238 dll_instance = hinstDLL; 230 dll_instance = hinstDLL;
239 break; 231 break;
240 case DLL_THREAD_ATTACH: 232 case DLL_THREAD_ATTACH:
241 break; 233 break;
242 case DLL_THREAD_DETACH: 234 case DLL_THREAD_DETACH:
243 break; 235 break;
244 case DLL_PROCESS_DETACH: 236 case DLL_PROCESS_DETACH:
245 break; 237 break;
246 } 238 }
247 return TRUE; 239 return TRUE;
248} 240}
@@ -271,13 +263,11 @@ get_path_from_module_filename ()
271 do 263 do
272 { 264 {
273 pathlen = pathlen * 2; 265 pathlen = pathlen * 2;
274 modulepath = GNUNET_realloc (modulepath, 266 modulepath = GNUNET_realloc (modulepath, pathlen * sizeof (wchar_t));
275 pathlen * sizeof (wchar_t));
276 SetLastError (0); 267 SetLastError (0);
277 real_pathlen = GetModuleFileNameW (dll_instance, 268 real_pathlen =
278 modulepath, 269 GetModuleFileNameW (dll_instance, modulepath, pathlen * sizeof (wchar_t));
279 pathlen * sizeof (wchar_t)); 270 } while (real_pathlen >= pathlen && pathlen < 16 * 1024);
280 } while (real_pathlen >= pathlen && pathlen < 16*1024);
281 if (real_pathlen >= pathlen) 271 if (real_pathlen >= pathlen)
282 GNUNET_assert (0); 272 GNUNET_assert (0);
283 /* To be safe */ 273 /* To be safe */
@@ -319,7 +309,8 @@ get_path_from_module_filename ()
319 } 309 }
320 310
321 /* modulepath is GNUNET_PREFIX */ 311 /* modulepath is GNUNET_PREFIX */
322 u8_string = u16_to_u8 (modulepath, wcslen (modulepath), NULL, &u8_string_length); 312 u8_string =
313 u16_to_u8 (modulepath, wcslen (modulepath), NULL, &u8_string_length);
323 if (NULL == u8_string) 314 if (NULL == u8_string)
324 GNUNET_assert (0); 315 GNUNET_assert (0);
325 316
@@ -343,9 +334,7 @@ get_path_from_module_filename ()
343 * @param number of bytes available in @a buf 334 * @param number of bytes available in @a buf
344 * @return 0 on success, otherwise desired number of bytes is stored in 'bufsize' 335 * @return 0 on success, otherwise desired number of bytes is stored in 'bufsize'
345 */ 336 */
346typedef int 337typedef int (*MyNSGetExecutablePathProto) (char *buf, size_t *bufsize);
347(*MyNSGetExecutablePathProto) (char *buf,
348 size_t *bufsize);
349 338
350 339
351/** 340/**
@@ -362,8 +351,9 @@ get_path_from_NSGetExecutablePath ()
362 MyNSGetExecutablePathProto func; 351 MyNSGetExecutablePathProto func;
363 352
364 path = NULL; 353 path = NULL;
365 if (NULL == (func = 354 if (NULL ==
366 (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, "_NSGetExecutablePath"))) 355 (func = (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT,
356 "_NSGetExecutablePath")))
367 return NULL; 357 return NULL;
368 path = &zero; 358 path = &zero;
369 len = 0; 359 len = 0;
@@ -403,10 +393,10 @@ get_path_from_dyld_image ()
403 for (i = 0; i < c; i++) 393 for (i = 0; i < c; i++)
404 { 394 {
405 if (((const void *) _dyld_get_image_header (i)) != 395 if (((const void *) _dyld_get_image_header (i)) !=
406 ((const void *) &_mh_dylib_header) ) 396 ((const void *) &_mh_dylib_header))
407 continue; 397 continue;
408 path = _dyld_get_image_name (i); 398 path = _dyld_get_image_name (i);
409 if ( (NULL == path) || (0 == strlen (path)) ) 399 if ((NULL == path) || (0 == strlen (path)))
410 continue; 400 continue;
411 p = GNUNET_strdup (path); 401 p = GNUNET_strdup (path);
412 s = p + strlen (p); 402 s = p + strlen (p);
@@ -443,7 +433,7 @@ get_path_from_PATH (const char *binary)
443 /* On W32 look in CWD first. */ 433 /* On W32 look in CWD first. */
444 GNUNET_asprintf (&path, ".%c%s", PATH_SEPARATOR, p); 434 GNUNET_asprintf (&path, ".%c%s", PATH_SEPARATOR, p);
445#else 435#else
446 path = GNUNET_strdup (p); /* because we write on it */ 436 path = GNUNET_strdup (p); /* because we write on it */
447#endif 437#endif
448 buf = GNUNET_malloc (strlen (path) + strlen (binary) + 1 + 1); 438 buf = GNUNET_malloc (strlen (path) + strlen (binary) + 1 + 1);
449 pos = path; 439 pos = path;
@@ -485,11 +475,11 @@ get_path_from_GNUNET_PREFIX ()
485{ 475{
486 const char *p; 476 const char *p;
487 477
488 if ( (NULL != current_pd->env_varname) && 478 if ((NULL != current_pd->env_varname) &&
489 (NULL != (p = getenv (current_pd->env_varname))) ) 479 (NULL != (p = getenv (current_pd->env_varname))))
490 return GNUNET_strdup (p); 480 return GNUNET_strdup (p);
491 if ( (NULL != current_pd->env_varname_alt) && 481 if ((NULL != current_pd->env_varname_alt) &&
492 (NULL != (p = getenv (current_pd->env_varname_alt))) ) 482 (NULL != (p = getenv (current_pd->env_varname_alt))))
493 return GNUNET_strdup (p); 483 return GNUNET_strdup (p);
494 return NULL; 484 return NULL;
495} 485}
@@ -512,8 +502,8 @@ os_get_gnunet_path ()
512 if (NULL != (ret = get_path_from_proc_maps ())) 502 if (NULL != (ret = get_path_from_proc_maps ()))
513 return ret; 503 return ret;
514 /* try path *first*, before /proc/exe, as /proc/exe can be wrong */ 504 /* try path *first*, before /proc/exe, as /proc/exe can be wrong */
515 if ( (NULL != current_pd->binary_name) && 505 if ((NULL != current_pd->binary_name) &&
516 (NULL != (ret = get_path_from_PATH (current_pd->binary_name))) ) 506 (NULL != (ret = get_path_from_PATH (current_pd->binary_name))))
517 return ret; 507 return ret;
518 if (NULL != (ret = get_path_from_proc_exe ())) 508 if (NULL != (ret = get_path_from_proc_exe ()))
519 return ret; 509 return ret;
@@ -528,12 +518,13 @@ os_get_gnunet_path ()
528 if (NULL != (ret = get_path_from_NSGetExecutablePath ())) 518 if (NULL != (ret = get_path_from_NSGetExecutablePath ()))
529 return ret; 519 return ret;
530#endif 520#endif
531 if ( (NULL != current_pd->binary_name) && 521 if ((NULL != current_pd->binary_name) &&
532 (NULL != (ret = get_path_from_PATH (current_pd->binary_name))) ) 522 (NULL != (ret = get_path_from_PATH (current_pd->binary_name))))
533 return ret; 523 return ret;
534 /* other attempts here */ 524 /* other attempts here */
535 LOG (GNUNET_ERROR_TYPE_ERROR, 525 LOG (GNUNET_ERROR_TYPE_ERROR,
536 _("Could not determine installation path for %s. Set `%s' environment variable.\n"), 526 _ (
527 "Could not determine installation path for %s. Set `%s' environment variable.\n"),
537 current_pd->project_dirname, 528 current_pd->project_dirname,
538 current_pd->env_varname); 529 current_pd->env_varname);
539 return NULL; 530 return NULL;
@@ -606,12 +597,11 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
606 execpath[--n] = '\0'; 597 execpath[--n] = '\0';
607 598
608 isbasedir = 1; 599 isbasedir = 1;
609 if ((n > 6) && 600 if ((n > 6) && ((0 == strcasecmp (&execpath[n - 6], "/lib32")) ||
610 ((0 == strcasecmp (&execpath[n - 6], "/lib32")) || 601 (0 == strcasecmp (&execpath[n - 6], "/lib64"))))
611 (0 == strcasecmp (&execpath[n - 6], "/lib64"))))
612 { 602 {
613 if ( (GNUNET_OS_IPK_LIBDIR != dirkind) && 603 if ((GNUNET_OS_IPK_LIBDIR != dirkind) &&
614 (GNUNET_OS_IPK_LIBEXECDIR != dirkind) ) 604 (GNUNET_OS_IPK_LIBEXECDIR != dirkind))
615 { 605 {
616 /* strip '/lib32' or '/lib64' */ 606 /* strip '/lib32' or '/lib64' */
617 execpath[n - 6] = '\0'; 607 execpath[n - 6] = '\0';
@@ -620,9 +610,8 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
620 else 610 else
621 isbasedir = 0; 611 isbasedir = 0;
622 } 612 }
623 else if ((n > 4) && 613 else if ((n > 4) && ((0 == strcasecmp (&execpath[n - 4], "/bin")) ||
624 ((0 == strcasecmp (&execpath[n - 4], "/bin")) || 614 (0 == strcasecmp (&execpath[n - 4], "/lib"))))
625 (0 == strcasecmp (&execpath[n - 4], "/lib"))))
626 { 615 {
627 /* strip '/bin' or '/lib' */ 616 /* strip '/bin' or '/lib' */
628 execpath[n - 4] = '\0'; 617 execpath[n - 4] = '\0';
@@ -635,9 +624,11 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
635 here we need to re-add 'multiarch' to lib and libexec paths later! */ 624 here we need to re-add 'multiarch' to lib and libexec paths later! */
636 multiarch = &libdir[5]; 625 multiarch = &libdir[5];
637 if (NULL == strchr (multiarch, '/')) 626 if (NULL == strchr (multiarch, '/'))
638 libdir[0] = '\0'; /* Debian multiarch format, cut of from 'execpath' but preserve in multicarch */ 627 libdir[0] =
628 '\0'; /* Debian multiarch format, cut of from 'execpath' but preserve in multicarch */
639 else 629 else
640 multiarch = NULL; /* maybe not, multiarch still has a '/', which is not OK */ 630 multiarch =
631 NULL; /* maybe not, multiarch still has a '/', which is not OK */
641 } 632 }
642 /* in case this was a directory named foo-bin, remove "foo-" */ 633 /* in case this was a directory named foo-bin, remove "foo-" */
643 while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) 634 while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR))
@@ -663,8 +654,7 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
663 DIR_SEPARATOR_STR, 654 DIR_SEPARATOR_STR,
664 current_pd->project_dirname, 655 current_pd->project_dirname,
665 DIR_SEPARATOR_STR); 656 DIR_SEPARATOR_STR);
666 if (GNUNET_YES == 657 if (GNUNET_YES == GNUNET_DISK_directory_test (tmp, GNUNET_YES))
667 GNUNET_DISK_directory_test (tmp, GNUNET_YES))
668 { 658 {
669 GNUNET_free (execpath); 659 GNUNET_free (execpath);
670 return tmp; 660 return tmp;
@@ -674,28 +664,23 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
674 dirname = NULL; 664 dirname = NULL;
675 if (4 == sizeof (void *)) 665 if (4 == sizeof (void *))
676 { 666 {
677 GNUNET_asprintf (&dirname, 667 GNUNET_asprintf (&dirname,
678 DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR, 668 DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR
669 "%s" DIR_SEPARATOR_STR,
679 current_pd->project_dirname); 670 current_pd->project_dirname);
680 GNUNET_asprintf (&tmp, 671 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
681 "%s%s",
682 execpath,
683 dirname);
684 } 672 }
685 if (8 == sizeof (void *)) 673 if (8 == sizeof (void *))
686 { 674 {
687 GNUNET_asprintf (&dirname, 675 GNUNET_asprintf (&dirname,
688 DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR, 676 DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR
677 "%s" DIR_SEPARATOR_STR,
689 current_pd->project_dirname); 678 current_pd->project_dirname);
690 GNUNET_asprintf (&tmp, 679 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
691 "%s%s",
692 execpath,
693 dirname);
694 } 680 }
695 681
696 if ( (NULL != tmp) && 682 if ((NULL != tmp) &&
697 (GNUNET_YES == 683 (GNUNET_YES == GNUNET_DISK_directory_test (tmp, GNUNET_YES)))
698 GNUNET_DISK_directory_test (tmp, GNUNET_YES)) )
699 { 684 {
700 GNUNET_free (execpath); 685 GNUNET_free (execpath);
701 GNUNET_free_non_null (dirname); 686 GNUNET_free_non_null (dirname);
@@ -710,25 +695,31 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
710 break; 695 break;
711 case GNUNET_OS_IPK_DATADIR: 696 case GNUNET_OS_IPK_DATADIR:
712 GNUNET_asprintf (&dirname, 697 GNUNET_asprintf (&dirname,
713 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR, 698 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
699 "%s" DIR_SEPARATOR_STR,
714 current_pd->project_dirname); 700 current_pd->project_dirname);
715 break; 701 break;
716 case GNUNET_OS_IPK_LOCALEDIR: 702 case GNUNET_OS_IPK_LOCALEDIR:
717 dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale" DIR_SEPARATOR_STR); 703 dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
704 "locale" DIR_SEPARATOR_STR);
718 break; 705 break;
719 case GNUNET_OS_IPK_ICONDIR: 706 case GNUNET_OS_IPK_ICONDIR:
720 dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "icons" DIR_SEPARATOR_STR); 707 dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
708 "icons" DIR_SEPARATOR_STR);
721 break; 709 break;
722 case GNUNET_OS_IPK_DOCDIR: 710 case GNUNET_OS_IPK_DOCDIR:
723 GNUNET_asprintf (&dirname, 711 GNUNET_asprintf (&dirname,
724 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "doc" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR, 712 DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
713 "doc" DIR_SEPARATOR_STR
714 "%s" DIR_SEPARATOR_STR,
725 current_pd->project_dirname); 715 current_pd->project_dirname);
726 break; 716 break;
727 case GNUNET_OS_IPK_LIBEXECDIR: 717 case GNUNET_OS_IPK_LIBEXECDIR:
728 if (isbasedir) 718 if (isbasedir)
729 { 719 {
730 GNUNET_asprintf (&dirname, 720 GNUNET_asprintf (&dirname,
731 DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR "libexec" DIR_SEPARATOR_STR, 721 DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR
722 "libexec" DIR_SEPARATOR_STR,
732 current_pd->project_dirname); 723 current_pd->project_dirname);
733 GNUNET_asprintf (&tmp, 724 GNUNET_asprintf (&tmp,
734 "%s%s%s%s", 725 "%s%s%s%s",
@@ -736,8 +727,7 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
736 DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR, 727 DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR,
737 (NULL != multiarch) ? multiarch : "", 728 (NULL != multiarch) ? multiarch : "",
738 dirname); 729 dirname);
739 if (GNUNET_YES == 730 if (GNUNET_YES == GNUNET_DISK_directory_test (tmp, GNUNET_YES))
740 GNUNET_DISK_directory_test (tmp, GNUNET_YES))
741 { 731 {
742 GNUNET_free (execpath); 732 GNUNET_free (execpath);
743 GNUNET_free (dirname); 733 GNUNET_free (dirname);
@@ -749,26 +739,23 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
749 if (4 == sizeof (void *)) 739 if (4 == sizeof (void *))
750 { 740 {
751 GNUNET_asprintf (&dirname, 741 GNUNET_asprintf (&dirname,
752 DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR "libexec" DIR_SEPARATOR_STR, 742 DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR
743 "%s" DIR_SEPARATOR_STR
744 "libexec" DIR_SEPARATOR_STR,
753 current_pd->project_dirname); 745 current_pd->project_dirname);
754 GNUNET_asprintf (&tmp, 746 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
755 "%s%s",
756 execpath,
757 dirname);
758 } 747 }
759 if (8 == sizeof (void *)) 748 if (8 == sizeof (void *))
760 { 749 {
761 GNUNET_asprintf (&dirname, 750 GNUNET_asprintf (&dirname,
762 DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR "libexec" DIR_SEPARATOR_STR, 751 DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR
752 "%s" DIR_SEPARATOR_STR
753 "libexec" DIR_SEPARATOR_STR,
763 current_pd->project_dirname); 754 current_pd->project_dirname);
764 GNUNET_asprintf (&tmp, 755 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
765 "%s%s",
766 execpath,
767 dirname);
768 } 756 }
769 if ( (NULL != tmp) && 757 if ((NULL != tmp) &&
770 (GNUNET_YES == 758 (GNUNET_YES == GNUNET_DISK_directory_test (tmp, GNUNET_YES)))
771 GNUNET_DISK_directory_test (tmp, GNUNET_YES)) )
772 { 759 {
773 GNUNET_free (execpath); 760 GNUNET_free (execpath);
774 GNUNET_free_non_null (dirname); 761 GNUNET_free_non_null (dirname);
@@ -778,17 +765,15 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
778 GNUNET_free_non_null (dirname); 765 GNUNET_free_non_null (dirname);
779 } 766 }
780 GNUNET_asprintf (&dirname, 767 GNUNET_asprintf (&dirname,
781 DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR "libexec" DIR_SEPARATOR_STR, 768 DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR
769 "libexec" DIR_SEPARATOR_STR,
782 current_pd->project_dirname); 770 current_pd->project_dirname);
783 break; 771 break;
784 default: 772 default:
785 GNUNET_free (execpath); 773 GNUNET_free (execpath);
786 return NULL; 774 return NULL;
787 } 775 }
788 GNUNET_asprintf (&tmp, 776 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
789 "%s%s",
790 execpath,
791 dirname);
792 GNUNET_free (dirname); 777 GNUNET_free (dirname);
793 GNUNET_free (execpath); 778 GNUNET_free (execpath);
794 return tmp; 779 return tmp;
@@ -810,11 +795,9 @@ GNUNET_OS_get_libexec_binary_path (const char *progname)
810 char *libexecdir; 795 char *libexecdir;
811 char *binary; 796 char *binary;
812 797
813 if ( (DIR_SEPARATOR == progname[0]) || 798 if ((DIR_SEPARATOR == progname[0]) ||
814 (GNUNET_YES == 799 (GNUNET_YES ==
815 GNUNET_STRINGS_path_is_absolute (progname, 800 GNUNET_STRINGS_path_is_absolute (progname, GNUNET_NO, NULL, NULL)))
816 GNUNET_NO,
817 NULL, NULL)) )
818 return GNUNET_strdup (progname); 801 return GNUNET_strdup (progname);
819 if (NULL != cache) 802 if (NULL != cache)
820 libexecdir = cache; 803 libexecdir = cache;
@@ -822,10 +805,7 @@ GNUNET_OS_get_libexec_binary_path (const char *progname)
822 libexecdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBEXECDIR); 805 libexecdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBEXECDIR);
823 if (NULL == libexecdir) 806 if (NULL == libexecdir)
824 return GNUNET_strdup (progname); 807 return GNUNET_strdup (progname);
825 GNUNET_asprintf (&binary, 808 GNUNET_asprintf (&binary, "%s%s", libexecdir, progname);
826 "%s%s",
827 libexecdir,
828 progname);
829 cache = libexecdir; 809 cache = libexecdir;
830 return binary; 810 return binary;
831} 811}
@@ -853,9 +833,7 @@ GNUNET_OS_get_suid_binary_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
853 size_t path_len; 833 size_t path_len;
854 834
855 if (GNUNET_YES == 835 if (GNUNET_YES ==
856 GNUNET_STRINGS_path_is_absolute (progname, 836 GNUNET_STRINGS_path_is_absolute (progname, GNUNET_NO, NULL, NULL))
857 GNUNET_NO,
858 NULL, NULL))
859 { 837 {
860 return GNUNET_strdup (progname); 838 return GNUNET_strdup (progname);
861 } 839 }
@@ -866,14 +844,15 @@ GNUNET_OS_get_suid_binary_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
866 "PATHS", 844 "PATHS",
867 "SUID_BINARY_PATH", 845 "SUID_BINARY_PATH",
868 &path); 846 &path);
869 if (NULL == path || 0 == strlen (path)) 847 if ((NULL == path)||(0 == strlen (path)))
870 return GNUNET_OS_get_libexec_binary_path (progname); 848 return GNUNET_OS_get_libexec_binary_path (progname);
871 path_len = strlen (path); 849 path_len = strlen (path);
872 GNUNET_asprintf (&binary, 850 GNUNET_asprintf (&binary,
873 "%s%s%s", 851 "%s%s%s",
874 path, 852 path,
875 (path[path_len - 1] == DIR_SEPARATOR) ? "" : DIR_SEPARATOR_STR, 853 (path[path_len - 1] == DIR_SEPARATOR) ? ""
876 progname); 854 : DIR_SEPARATOR_STR,
855 progname);
877 cache = path; 856 cache = path;
878 return binary; 857 return binary;
879} 858}
@@ -906,14 +885,10 @@ GNUNET_OS_check_helper_binary (const char *binary,
906#ifdef MINGW 885#ifdef MINGW
907 char *binaryexe; 886 char *binaryexe;
908 887
909 GNUNET_asprintf (&binaryexe, 888 GNUNET_asprintf (&binaryexe, "%s.exe", binary);
910 "%s.exe", 889 if ((GNUNET_YES ==
911 binary); 890 GNUNET_STRINGS_path_is_absolute (binaryexe, GNUNET_NO, NULL, NULL)) ||
912 if ( (GNUNET_YES == 891 (0 == strncmp (binary, "./", 2)))
913 GNUNET_STRINGS_path_is_absolute (binaryexe,
914 GNUNET_NO,
915 NULL, NULL)) ||
916 (0 == strncmp (binary, "./", 2)) )
917 p = GNUNET_strdup (binaryexe); 892 p = GNUNET_strdup (binaryexe);
918 else 893 else
919 { 894 {
@@ -927,12 +902,9 @@ GNUNET_OS_check_helper_binary (const char *binary,
927 } 902 }
928 GNUNET_free (binaryexe); 903 GNUNET_free (binaryexe);
929#else 904#else
930 if ( (GNUNET_YES == 905 if ((GNUNET_YES ==
931 GNUNET_STRINGS_path_is_absolute (binary, 906 GNUNET_STRINGS_path_is_absolute (binary, GNUNET_NO, NULL, NULL)) ||
932 GNUNET_NO, 907 (0 == strncmp (binary, "./", 2)))
933 NULL,
934 NULL)) ||
935 (0 == strncmp (binary, "./", 2)) )
936 { 908 {
937 p = GNUNET_strdup (binary); 909 p = GNUNET_strdup (binary);
938 } 910 }
@@ -941,10 +913,7 @@ GNUNET_OS_check_helper_binary (const char *binary,
941 p = get_path_from_PATH (binary); 913 p = get_path_from_PATH (binary);
942 if (NULL != p) 914 if (NULL != p)
943 { 915 {
944 GNUNET_asprintf (&pf, 916 GNUNET_asprintf (&pf, "%s/%s", p, binary);
945 "%s/%s",
946 p,
947 binary);
948 GNUNET_free (p); 917 GNUNET_free (p);
949 p = pf; 918 p = pf;
950 } 919 }
@@ -953,16 +922,13 @@ GNUNET_OS_check_helper_binary (const char *binary,
953 if (NULL == p) 922 if (NULL == p)
954 { 923 {
955 LOG (GNUNET_ERROR_TYPE_INFO, 924 LOG (GNUNET_ERROR_TYPE_INFO,
956 _("Could not find binary `%s' in PATH!\n"), 925 _ ("Could not find binary `%s' in PATH!\n"),
957 binary); 926 binary);
958 return GNUNET_SYSERR; 927 return GNUNET_SYSERR;
959 } 928 }
960 if (0 != ACCESS (p, 929 if (0 != ACCESS (p, X_OK))
961 X_OK))
962 { 930 {
963 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 931 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", p);
964 "access",
965 p);
966 GNUNET_free (p); 932 GNUNET_free (p);
967 return GNUNET_SYSERR; 933 return GNUNET_SYSERR;
968 } 934 }
@@ -974,12 +940,9 @@ GNUNET_OS_check_helper_binary (const char *binary,
974 return GNUNET_YES; 940 return GNUNET_YES;
975 } 941 }
976#endif 942#endif
977 if (0 != STAT (p, 943 if (0 != STAT (p, &statbuf))
978 &statbuf))
979 { 944 {
980 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 945 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", p);
981 "stat",
982 p);
983 GNUNET_free (p); 946 GNUNET_free (p);
984 return GNUNET_SYSERR; 947 return GNUNET_SYSERR;
985 } 948 }
@@ -987,14 +950,13 @@ GNUNET_OS_check_helper_binary (const char *binary,
987 { 950 {
988#ifndef MINGW 951#ifndef MINGW
989 (void) params; 952 (void) params;
990 if ( (0 != (statbuf.st_mode & S_ISUID)) && 953 if ((0 != (statbuf.st_mode & S_ISUID)) && (0 == statbuf.st_uid))
991 (0 == statbuf.st_uid) )
992 { 954 {
993 GNUNET_free (p); 955 GNUNET_free (p);
994 return GNUNET_YES; 956 return GNUNET_YES;
995 } 957 }
996 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 958 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
997 _("Binary `%s' exists, but is not SUID\n"), 959 _ ("Binary `%s' exists, but is not SUID\n"),
998 p); 960 p);
999 /* binary exists, but not SUID */ 961 /* binary exists, but not SUID */
1000#else 962#else
@@ -1003,50 +965,52 @@ GNUNET_OS_check_helper_binary (const char *binary,
1003 PROCESS_INFORMATION proc; 965 PROCESS_INFORMATION proc;
1004 DWORD exit_value; 966 DWORD exit_value;
1005 967
1006 GNUNET_snprintf (parameters, 968 GNUNET_snprintf (parameters, sizeof (parameters), "-d %s", params);
1007 sizeof (parameters),
1008 "-d %s", params);
1009 memset (&start, 0, sizeof (start)); 969 memset (&start, 0, sizeof (start));
1010 start.cb = sizeof (start); 970 start.cb = sizeof (start);
1011 memset (&proc, 0, sizeof (proc)); 971 memset (&proc, 0, sizeof (proc));
1012 972
1013 973
1014 // Start the child process. 974 // Start the child process.
1015 if ( ! (CreateProcess( p, // current windows (2k3 and up can handle / instead of \ in paths)) 975 if (! (CreateProcess (
1016 parameters, // execute dryrun/priviliege checking mode 976 p, // current windows (2k3 and up can handle / instead of \ in paths))
1017 NULL, // Process handle not inheritable 977 parameters, // execute dryrun/priviliege checking mode
1018 NULL, // Thread handle not inheritable 978 NULL, // Process handle not inheritable
1019 FALSE, // Set handle inheritance to FALSE 979 NULL, // Thread handle not inheritable
1020 CREATE_DEFAULT_ERROR_MODE, // No creation flags 980 FALSE, // Set handle inheritance to FALSE
1021 NULL, // Use parent's environment block 981 CREATE_DEFAULT_ERROR_MODE, // No creation flags
1022 NULL, // Use parent's starting directory 982 NULL, // Use parent's environment block
1023 &start, // Pointer to STARTUPINFO structure 983 NULL, // Use parent's starting directory
1024 &proc ) // Pointer to PROCESS_INFORMATION structure 984 &start, // Pointer to STARTUPINFO structure
1025 )) 985 &proc) // Pointer to PROCESS_INFORMATION structure
1026 { 986 ))
1027 LOG (GNUNET_ERROR_TYPE_ERROR, 987 {
1028 _("CreateProcess failed for binary %s (%d).\n"), 988 LOG (GNUNET_ERROR_TYPE_ERROR,
1029 p, GetLastError()); 989 _ ("CreateProcess failed for binary %s (%d).\n"),
1030 return GNUNET_SYSERR; 990 p,
991 GetLastError ());
992 return GNUNET_SYSERR;
1031 } 993 }
1032 994
1033 // Wait until child process exits. 995 // Wait until child process exits.
1034 WaitForSingleObject( proc.hProcess, INFINITE ); 996 WaitForSingleObject (proc.hProcess, INFINITE);
1035 997
1036 if ( ! GetExitCodeProcess (proc.hProcess, &exit_value)){ 998 if (! GetExitCodeProcess (proc.hProcess, &exit_value))
1037 LOG (GNUNET_ERROR_TYPE_ERROR, 999 {
1038 _("GetExitCodeProcess failed for binary %s (%d).\n"), 1000 LOG (GNUNET_ERROR_TYPE_ERROR,
1039 p, GetLastError() ); 1001 _ ("GetExitCodeProcess failed for binary %s (%d).\n"),
1040 return GNUNET_SYSERR; 1002 p,
1041 } 1003 GetLastError ());
1004 return GNUNET_SYSERR;
1005 }
1042 // Close process and thread handles. 1006 // Close process and thread handles.
1043 CloseHandle( proc.hProcess ); 1007 CloseHandle (proc.hProcess);
1044 CloseHandle( proc.hThread ); 1008 CloseHandle (proc.hThread);
1045 1009
1046 if (!exit_value) 1010 if (! exit_value)
1047 return GNUNET_YES; 1011 return GNUNET_YES;
1048#endif 1012#endif
1049 } 1013 }
1050 GNUNET_free (p); 1014 GNUNET_free (p);
1051 return GNUNET_NO; 1015 return GNUNET_NO;
1052} 1016}
diff --git a/src/util/service.c b/src/util/service.c
index ba0271a38..73a73cbea 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -39,9 +39,12 @@
39 39
40#define LOG(kind,...) GNUNET_log_from (kind, "util-service", __VA_ARGS__) 40#define LOG(kind,...) GNUNET_log_from (kind, "util-service", __VA_ARGS__)
41 41
42#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-service", syscall) 42#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, \
43 "util-service", \
44 syscall)
43 45
44#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-service", syscall, filename) 46#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file ( \
47 kind, "util-service", syscall, filename)
45 48
46 49
47/** 50/**
@@ -83,30 +86,30 @@ struct ServiceListenContext
83 */ 86 */
84enum SuspendReason 87enum SuspendReason
85{ 88{
86 /** 89 /**
87 * We are running normally. 90 * We are running normally.
88 */ 91 */
89 SUSPEND_STATE_NONE = 0, 92 SUSPEND_STATE_NONE = 0,
90 93
91 /** 94 /**
92 * Application requested it. 95 * Application requested it.
93 */ 96 */
94 SUSPEND_STATE_APP = 1, 97 SUSPEND_STATE_APP = 1,
95 98
96 /** 99 /**
97 * OS ran out of file descriptors. 100 * OS ran out of file descriptors.
98 */ 101 */
99 SUSPEND_STATE_EMFILE = 2, 102 SUSPEND_STATE_EMFILE = 2,
100 103
101 /** 104 /**
102 * Both reasons, APP and EMFILE apply. 105 * Both reasons, APP and EMFILE apply.
103 */ 106 */
104 SUSPEND_STATE_APP_AND_EMFILE = 3, 107 SUSPEND_STATE_APP_AND_EMFILE = 3,
105 108
106 /** 109 /**
107 * Suspension because service was permanently shutdown. 110 * Suspension because service was permanently shutdown.
108 */ 111 */
109 SUSPEND_STATE_SHUTDOWN = 4 112 SUSPEND_STATE_SHUTDOWN = 4
110}; 113};
111 114
112 115
@@ -449,7 +452,7 @@ check_ipv4_listed (const struct GNUNET_STRINGS_IPv4NetworkPolicy *list,
449 return GNUNET_NO; 452 return GNUNET_NO;
450 i = 0; 453 i = 0;
451 while ( (0 != list[i].network.s_addr) || 454 while ( (0 != list[i].network.s_addr) ||
452 (0 != list[i].netmask.s_addr) ) 455 (0 != list[i].netmask.s_addr) )
453 { 456 {
454 if ((add->s_addr & list[i].netmask.s_addr) == 457 if ((add->s_addr & list[i].netmask.s_addr) ==
455 (list[i].network.s_addr & list[i].netmask.s_addr)) 458 (list[i].network.s_addr & list[i].netmask.s_addr))
@@ -477,7 +480,7 @@ check_ipv6_listed (const struct GNUNET_STRINGS_IPv6NetworkPolicy *list,
477 if (NULL == list) 480 if (NULL == list)
478 return GNUNET_NO; 481 return GNUNET_NO;
479 i = 0; 482 i = 0;
480NEXT: 483 NEXT:
481 while (0 != GNUNET_is_zero (&list[i].network)) 484 while (0 != GNUNET_is_zero (&list[i].network))
482 { 485 {
483 for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++) 486 for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++)
@@ -509,28 +512,28 @@ do_send (void *cls)
509 512
510 LOG (GNUNET_ERROR_TYPE_DEBUG, 513 LOG (GNUNET_ERROR_TYPE_DEBUG,
511 "service: sending message with type %u\n", 514 "service: sending message with type %u\n",
512 ntohs(client->msg->type)); 515 ntohs (client->msg->type));
513 516
514 517
515 client->send_task = NULL; 518 client->send_task = NULL;
516 buf = (const char *) client->msg; 519 buf = (const char *) client->msg;
517 left = ntohs (client->msg->size) - client->msg_pos; 520 left = ntohs (client->msg->size) - client->msg_pos;
518 ret = GNUNET_NETWORK_socket_send (client->sock, 521 ret = GNUNET_NETWORK_socket_send (client->sock,
519 &buf[client->msg_pos], 522 &buf[client->msg_pos],
520 left); 523 left);
521 GNUNET_assert (ret <= (ssize_t) left); 524 GNUNET_assert (ret <= (ssize_t) left);
522 if (0 == ret) 525 if (0 == ret)
523 { 526 {
524 LOG (GNUNET_ERROR_TYPE_DEBUG, 527 LOG (GNUNET_ERROR_TYPE_DEBUG,
525 "no data send"); 528 "no data send");
526 GNUNET_MQ_inject_error (client->mq, 529 GNUNET_MQ_inject_error (client->mq,
527 GNUNET_MQ_ERROR_WRITE); 530 GNUNET_MQ_ERROR_WRITE);
528 return; 531 return;
529 } 532 }
530 if (-1 == ret) 533 if (-1 == ret)
531 { 534 {
532 if ( (EAGAIN == errno) || 535 if ( (EAGAIN == errno) ||
533 (EINTR == errno) ) 536 (EINTR == errno) )
534 { 537 {
535 /* ignore */ 538 /* ignore */
536 ret = 0; 539 ret = 0;
@@ -544,7 +547,7 @@ do_send (void *cls)
544 "socket send returned with error code %i", 547 "socket send returned with error code %i",
545 errno); 548 errno);
546 GNUNET_MQ_inject_error (client->mq, 549 GNUNET_MQ_inject_error (client->mq,
547 GNUNET_MQ_ERROR_WRITE); 550 GNUNET_MQ_ERROR_WRITE);
548 return; 551 return;
549 } 552 }
550 } 553 }
@@ -558,9 +561,9 @@ do_send (void *cls)
558 GNUNET_assert (NULL == client->drop_task); 561 GNUNET_assert (NULL == client->drop_task);
559 client->send_task 562 client->send_task
560 = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 563 = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
561 client->sock, 564 client->sock,
562 &do_send, 565 &do_send,
563 client); 566 client);
564 return; 567 return;
565 } 568 }
566 GNUNET_MQ_impl_send_continue (client->mq); 569 GNUNET_MQ_impl_send_continue (client->mq);
@@ -594,9 +597,9 @@ service_mq_send (struct GNUNET_MQ_Handle *mq,
594 client->msg_pos = 0; 597 client->msg_pos = 0;
595 client->send_task 598 client->send_task
596 = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 599 = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
597 client->sock, 600 client->sock,
598 &do_send, 601 &do_send,
599 client); 602 client);
600} 603}
601 604
602 605
@@ -663,12 +666,14 @@ warn_no_client_continue (void *cls)
663 client->warn_task 666 client->warn_task
664 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 667 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
665 &warn_no_client_continue, 668 &warn_no_client_continue,
666 client); 669 client);
667 LOG (GNUNET_ERROR_TYPE_WARNING, 670 LOG (GNUNET_ERROR_TYPE_WARNING,
668 _("Processing code for message of type %u did not call `GNUNET_SERVICE_client_continue' after %s\n"), 671 _ (
672 "Processing code for message of type %u did not call `GNUNET_SERVICE_client_continue' after %s\n"),
669 (unsigned int) client->warn_type, 673 (unsigned int) client->warn_type,
670 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (client->warn_start), 674 GNUNET_STRINGS_relative_time_to_string (
671 GNUNET_YES)); 675 GNUNET_TIME_absolute_get_duration (client->warn_start),
676 GNUNET_YES));
672} 677}
673 678
674 679
@@ -700,8 +705,8 @@ service_client_mst_cb (void *cls,
700 GNUNET_assert (NULL == client->warn_task); 705 GNUNET_assert (NULL == client->warn_task);
701 client->warn_task 706 client->warn_task
702 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 707 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
703 &warn_no_client_continue, 708 &warn_no_client_continue,
704 client); 709 client);
705 GNUNET_MQ_inject_message (client->mq, 710 GNUNET_MQ_inject_message (client->mq,
706 message); 711 message);
707 if (NULL != client->drop_task) 712 if (NULL != client->drop_task)
@@ -724,9 +729,9 @@ service_client_recv (void *cls)
724 729
725 client->recv_task = NULL; 730 client->recv_task = NULL;
726 ret = GNUNET_MST_read (client->mst, 731 ret = GNUNET_MST_read (client->mst,
727 client->sock, 732 client->sock,
728 GNUNET_NO, 733 GNUNET_NO,
729 GNUNET_YES); 734 GNUNET_YES);
730 if (GNUNET_SYSERR == ret) 735 if (GNUNET_SYSERR == ret)
731 { 736 {
732 /* client closed connection (or IO error) */ 737 /* client closed connection (or IO error) */
@@ -739,7 +744,7 @@ service_client_recv (void *cls)
739 } 744 }
740 if (GNUNET_NO == ret) 745 if (GNUNET_NO == ret)
741 return; /* more messages in buffer, wait for application 746 return; /* more messages in buffer, wait for application
742 to be done processing */ 747 to be done processing */
743 GNUNET_assert (GNUNET_OK == ret); 748 GNUNET_assert (GNUNET_OK == ret);
744 if (GNUNET_YES == client->needs_continue) 749 if (GNUNET_YES == client->needs_continue)
745 return; 750 return;
@@ -748,9 +753,9 @@ service_client_recv (void *cls)
748 /* MST needs more data, re-schedule read job */ 753 /* MST needs more data, re-schedule read job */
749 client->recv_task 754 client->recv_task
750 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 755 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
751 client->sock, 756 client->sock,
752 &service_client_recv, 757 &service_client_recv,
753 client); 758 client);
754} 759}
755 760
756 761
@@ -781,7 +786,7 @@ start_client (struct GNUNET_SERVICE_Handle *sh,
781 &service_mq_error_handler, 786 &service_mq_error_handler,
782 client); 787 client);
783 client->mst = GNUNET_MST_create (&service_client_mst_cb, 788 client->mst = GNUNET_MST_create (&service_client_mst_cb,
784 client); 789 client);
785 if (NULL != sh->connect_cb) 790 if (NULL != sh->connect_cb)
786 client->user_context = sh->connect_cb (sh->cb_cls, 791 client->user_context = sh->connect_cb (sh->cb_cls,
787 client, 792 client,
@@ -790,9 +795,9 @@ start_client (struct GNUNET_SERVICE_Handle *sh,
790 client->user_context); 795 client->user_context);
791 client->recv_task 796 client->recv_task
792 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 797 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
793 client->sock, 798 client->sock,
794 &service_client_recv, 799 &service_client_recv,
795 client); 800 client);
796} 801}
797 802
798 803
@@ -820,8 +825,8 @@ accept_client (void *cls)
820 825
821 addrlen = sizeof (sa); 826 addrlen = sizeof (sa);
822 sock = GNUNET_NETWORK_socket_accept (slc->listen_socket, 827 sock = GNUNET_NETWORK_socket_accept (slc->listen_socket,
823 (struct sockaddr *) &sa, 828 (struct sockaddr *) &sa,
824 &addrlen); 829 &addrlen);
825 if (NULL == sock) 830 if (NULL == sock)
826 { 831 {
827 if (EMFILE == errno) 832 if (EMFILE == errno)
@@ -838,21 +843,21 @@ accept_client (void *cls)
838 GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); 843 GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
839 v4 = (const struct sockaddr_in *) &sa; 844 v4 = (const struct sockaddr_in *) &sa;
840 ok = ( ( (NULL == sh->v4_allowed) || 845 ok = ( ( (NULL == sh->v4_allowed) ||
841 (check_ipv4_listed (sh->v4_allowed, 846 (check_ipv4_listed (sh->v4_allowed,
842 &v4->sin_addr))) && 847 &v4->sin_addr))) &&
843 ( (NULL == sh->v4_denied) || 848 ( (NULL == sh->v4_denied) ||
844 (! check_ipv4_listed (sh->v4_denied, 849 (! check_ipv4_listed (sh->v4_denied,
845 &v4->sin_addr)) ) ); 850 &v4->sin_addr)) ) );
846 break; 851 break;
847 case AF_INET6: 852 case AF_INET6:
848 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); 853 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
849 v6 = (const struct sockaddr_in6 *) &sa; 854 v6 = (const struct sockaddr_in6 *) &sa;
850 ok = ( ( (NULL == sh->v6_allowed) || 855 ok = ( ( (NULL == sh->v6_allowed) ||
851 (check_ipv6_listed (sh->v6_allowed, 856 (check_ipv6_listed (sh->v6_allowed,
852 &v6->sin6_addr))) && 857 &v6->sin6_addr))) &&
853 ( (NULL == sh->v6_denied) || 858 ( (NULL == sh->v6_denied) ||
854 (! check_ipv6_listed (sh->v6_denied, 859 (! check_ipv6_listed (sh->v6_denied,
855 &v6->sin6_addr)) ) ); 860 &v6->sin6_addr)) ) );
856 break; 861 break;
857#ifndef WINDOWS 862#ifndef WINDOWS
858 case AF_UNIX: 863 case AF_UNIX:
@@ -861,34 +866,34 @@ accept_client (void *cls)
861#endif 866#endif
862 default: 867 default:
863 LOG (GNUNET_ERROR_TYPE_WARNING, 868 LOG (GNUNET_ERROR_TYPE_WARNING,
864 _("Unknown address family %d\n"), 869 _ ("Unknown address family %d\n"),
865 sa.ss_family); 870 sa.ss_family);
866 return; 871 return;
867 } 872 }
868 if (! ok) 873 if (! ok)
869 { 874 {
870 LOG (GNUNET_ERROR_TYPE_DEBUG, 875 LOG (GNUNET_ERROR_TYPE_DEBUG,
871 "Service rejected incoming connection from %s due to policy.\n", 876 "Service rejected incoming connection from %s due to policy.\n",
872 GNUNET_a2s ((const struct sockaddr *) &sa, 877 GNUNET_a2s ((const struct sockaddr *) &sa,
873 addrlen)); 878 addrlen));
874 GNUNET_break (GNUNET_OK == 879 GNUNET_break (GNUNET_OK ==
875 GNUNET_NETWORK_socket_close (sock)); 880 GNUNET_NETWORK_socket_close (sock));
876 continue; 881 continue;
877 } 882 }
878 LOG (GNUNET_ERROR_TYPE_DEBUG, 883 LOG (GNUNET_ERROR_TYPE_DEBUG,
879 "Service accepted incoming connection from %s.\n", 884 "Service accepted incoming connection from %s.\n",
880 GNUNET_a2s ((const struct sockaddr *) &sa, 885 GNUNET_a2s ((const struct sockaddr *) &sa,
881 addrlen)); 886 addrlen));
882 start_client (slc->sh, 887 start_client (slc->sh,
883 sock); 888 sock);
884 } 889 }
885 if (0 != sh->suspend_state) 890 if (0 != sh->suspend_state)
886 return; 891 return;
887 slc->listen_task 892 slc->listen_task
888 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 893 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
889 slc->listen_socket, 894 slc->listen_socket,
890 &accept_client, 895 &accept_client,
891 slc); 896 slc);
892} 897}
893 898
894 899
@@ -915,9 +920,9 @@ do_resume (struct GNUNET_SERVICE_Handle *sh,
915 GNUNET_assert (NULL == slc->listen_task); 920 GNUNET_assert (NULL == slc->listen_task);
916 slc->listen_task 921 slc->listen_task
917 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 922 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
918 slc->listen_socket, 923 slc->listen_socket,
919 &accept_client, 924 &accept_client,
920 slc); 925 slc);
921 } 926 }
922} 927}
923 928
@@ -949,8 +954,8 @@ service_main (void *cls)
949 954
950 if (NULL != sh->service_init_cb) 955 if (NULL != sh->service_init_cb)
951 sh->service_init_cb (sh->cb_cls, 956 sh->service_init_cb (sh->cb_cls,
952 sh->cfg, 957 sh->cfg,
953 sh); 958 sh);
954} 959}
955 960
956 961
@@ -971,8 +976,8 @@ process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret,
971 char *opt; 976 char *opt;
972 977
973 if (! GNUNET_CONFIGURATION_have_value (sh->cfg, 978 if (! GNUNET_CONFIGURATION_have_value (sh->cfg,
974 sh->service_name, 979 sh->service_name,
975 option)) 980 option))
976 { 981 {
977 *ret = NULL; 982 *ret = NULL;
978 return GNUNET_OK; 983 return GNUNET_OK;
@@ -981,14 +986,14 @@ process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret,
981 GNUNET_CONFIGURATION_get_value_string (sh->cfg, 986 GNUNET_CONFIGURATION_get_value_string (sh->cfg,
982 sh->service_name, 987 sh->service_name,
983 option, 988 option,
984 &opt)); 989 &opt));
985 if (NULL == (*ret = GNUNET_STRINGS_parse_ipv4_policy (opt))) 990 if (NULL == (*ret = GNUNET_STRINGS_parse_ipv4_policy (opt)))
986 { 991 {
987 LOG (GNUNET_ERROR_TYPE_WARNING, 992 LOG (GNUNET_ERROR_TYPE_WARNING,
988 _("Could not parse IPv4 network specification `%s' for `%s:%s'\n"), 993 _ ("Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
989 opt, 994 opt,
990 sh->service_name, 995 sh->service_name,
991 option); 996 option);
992 GNUNET_free (opt); 997 GNUNET_free (opt);
993 return GNUNET_SYSERR; 998 return GNUNET_SYSERR;
994 } 999 }
@@ -1014,8 +1019,8 @@ process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret,
1014 char *opt; 1019 char *opt;
1015 1020
1016 if (! GNUNET_CONFIGURATION_have_value (sh->cfg, 1021 if (! GNUNET_CONFIGURATION_have_value (sh->cfg,
1017 sh->service_name, 1022 sh->service_name,
1018 option)) 1023 option))
1019 { 1024 {
1020 *ret = NULL; 1025 *ret = NULL;
1021 return GNUNET_OK; 1026 return GNUNET_OK;
@@ -1024,14 +1029,14 @@ process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret,
1024 GNUNET_CONFIGURATION_get_value_string (sh->cfg, 1029 GNUNET_CONFIGURATION_get_value_string (sh->cfg,
1025 sh->service_name, 1030 sh->service_name,
1026 option, 1031 option,
1027 &opt)); 1032 &opt));
1028 if (NULL == (*ret = GNUNET_STRINGS_parse_ipv6_policy (opt))) 1033 if (NULL == (*ret = GNUNET_STRINGS_parse_ipv6_policy (opt)))
1029 { 1034 {
1030 LOG (GNUNET_ERROR_TYPE_WARNING, 1035 LOG (GNUNET_ERROR_TYPE_WARNING,
1031 _("Could not parse IPv6 network specification `%s' for `%s:%s'\n"), 1036 _ ("Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
1032 opt, 1037 opt,
1033 sh->service_name, 1038 sh->service_name,
1034 option); 1039 option);
1035 GNUNET_free (opt); 1040 GNUNET_free (opt);
1036 return GNUNET_SYSERR; 1041 return GNUNET_SYSERR;
1037 } 1042 }
@@ -1062,8 +1067,8 @@ add_unixpath (struct sockaddr **saddrs,
1062 un = GNUNET_new (struct sockaddr_un); 1067 un = GNUNET_new (struct sockaddr_un);
1063 un->sun_family = AF_UNIX; 1068 un->sun_family = AF_UNIX;
1064 GNUNET_strlcpy (un->sun_path, 1069 GNUNET_strlcpy (un->sun_path,
1065 unixpath, 1070 unixpath,
1066 sizeof (un->sun_path)); 1071 sizeof (un->sun_path));
1067#ifdef LINUX 1072#ifdef LINUX
1068 if (GNUNET_YES == abstract) 1073 if (GNUNET_YES == abstract)
1069 un->sun_path[0] = '\0'; 1074 un->sun_path[0] = '\0';
@@ -1103,9 +1108,9 @@ add_unixpath (struct sockaddr **saddrs,
1103 */ 1108 */
1104static int 1109static int
1105get_server_addresses (const char *service_name, 1110get_server_addresses (const char *service_name,
1106 const struct GNUNET_CONFIGURATION_Handle *cfg, 1111 const struct GNUNET_CONFIGURATION_Handle *cfg,
1107 struct sockaddr ***addrs, 1112 struct sockaddr ***addrs,
1108 socklen_t **addr_lens) 1113 socklen_t **addr_lens)
1109{ 1114{
1110 int disablev6; 1115 int disablev6;
1111 struct GNUNET_NETWORK_Handle *desc; 1116 struct GNUNET_NETWORK_Handle *desc;
@@ -1128,46 +1133,46 @@ get_server_addresses (const char *service_name,
1128 desc = NULL; 1133 desc = NULL;
1129 disablev6 = GNUNET_NO; 1134 disablev6 = GNUNET_NO;
1130 if ( (GNUNET_NO == 1135 if ( (GNUNET_NO ==
1131 GNUNET_NETWORK_test_pf (PF_INET6)) || 1136 GNUNET_NETWORK_test_pf (PF_INET6)) ||
1132 (GNUNET_YES == 1137 (GNUNET_YES ==
1133 GNUNET_CONFIGURATION_get_value_yesno (cfg, 1138 GNUNET_CONFIGURATION_get_value_yesno (cfg,
1134 service_name, 1139 service_name,
1135 "DISABLEV6") ) ) 1140 "DISABLEV6") ) )
1136 disablev6 = GNUNET_YES; 1141 disablev6 = GNUNET_YES;
1137 1142
1138 port = 0; 1143 port = 0;
1139 if (GNUNET_CONFIGURATION_have_value (cfg, 1144 if (GNUNET_CONFIGURATION_have_value (cfg,
1140 service_name, 1145 service_name,
1141 "PORT")) 1146 "PORT"))
1142 { 1147 {
1143 if (GNUNET_OK != 1148 if (GNUNET_OK !=
1144 GNUNET_CONFIGURATION_get_value_number (cfg, 1149 GNUNET_CONFIGURATION_get_value_number (cfg,
1145 service_name, 1150 service_name,
1146 "PORT", 1151 "PORT",
1147 &port)) 1152 &port))
1148 { 1153 {
1149 LOG (GNUNET_ERROR_TYPE_ERROR, 1154 LOG (GNUNET_ERROR_TYPE_ERROR,
1150 _("Require valid port number for service `%s' in configuration!\n"), 1155 _ ("Require valid port number for service `%s' in configuration!\n"),
1151 service_name); 1156 service_name);
1152 } 1157 }
1153 if (port > 65535) 1158 if (port > 65535)
1154 { 1159 {
1155 LOG (GNUNET_ERROR_TYPE_ERROR, 1160 LOG (GNUNET_ERROR_TYPE_ERROR,
1156 _("Require valid port number for service `%s' in configuration!\n"), 1161 _ ("Require valid port number for service `%s' in configuration!\n"),
1157 service_name); 1162 service_name);
1158 return GNUNET_SYSERR; 1163 return GNUNET_SYSERR;
1159 } 1164 }
1160 } 1165 }
1161 1166
1162 if (GNUNET_CONFIGURATION_have_value (cfg, 1167 if (GNUNET_CONFIGURATION_have_value (cfg,
1163 service_name, 1168 service_name,
1164 "BINDTO")) 1169 "BINDTO"))
1165 { 1170 {
1166 GNUNET_break (GNUNET_OK == 1171 GNUNET_break (GNUNET_OK ==
1167 GNUNET_CONFIGURATION_get_value_string (cfg, 1172 GNUNET_CONFIGURATION_get_value_string (cfg,
1168 service_name, 1173 service_name,
1169 "BINDTO", 1174 "BINDTO",
1170 &hostname)); 1175 &hostname));
1171 } 1176 }
1172 else 1177 else
1173 hostname = NULL; 1178 hostname = NULL;
@@ -1177,13 +1182,13 @@ get_server_addresses (const char *service_name,
1177#ifdef AF_UNIX 1182#ifdef AF_UNIX
1178 if ((GNUNET_YES == 1183 if ((GNUNET_YES ==
1179 GNUNET_CONFIGURATION_have_value (cfg, 1184 GNUNET_CONFIGURATION_have_value (cfg,
1180 service_name, 1185 service_name,
1181 "UNIXPATH")) && 1186 "UNIXPATH")) &&
1182 (GNUNET_OK == 1187 (GNUNET_OK ==
1183 GNUNET_CONFIGURATION_get_value_filename (cfg, 1188 GNUNET_CONFIGURATION_get_value_filename (cfg,
1184 service_name, 1189 service_name,
1185 "UNIXPATH", 1190 "UNIXPATH",
1186 &unixpath)) && 1191 &unixpath)) &&
1187 (0 < strlen (unixpath))) 1192 (0 < strlen (unixpath)))
1188 { 1193 {
1189 /* probe UNIX support */ 1194 /* probe UNIX support */
@@ -1192,12 +1197,12 @@ get_server_addresses (const char *service_name,
1192 if (strlen (unixpath) >= sizeof (s_un.sun_path)) 1197 if (strlen (unixpath) >= sizeof (s_un.sun_path))
1193 { 1198 {
1194 LOG (GNUNET_ERROR_TYPE_WARNING, 1199 LOG (GNUNET_ERROR_TYPE_WARNING,
1195 _("UNIXPATH `%s' too long, maximum length is %llu\n"), 1200 _ ("UNIXPATH `%s' too long, maximum length is %llu\n"),
1196 unixpath, 1201 unixpath,
1197 (unsigned long long) sizeof (s_un.sun_path)); 1202 (unsigned long long) sizeof (s_un.sun_path));
1198 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); 1203 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
1199 LOG (GNUNET_ERROR_TYPE_INFO, 1204 LOG (GNUNET_ERROR_TYPE_INFO,
1200 _("Using `%s' instead\n"), 1205 _ ("Using `%s' instead\n"),
1201 unixpath); 1206 unixpath);
1202 } 1207 }
1203#ifdef LINUX 1208#ifdef LINUX
@@ -1208,32 +1213,33 @@ get_server_addresses (const char *service_name,
1208 abstract = GNUNET_NO; 1213 abstract = GNUNET_NO;
1209#endif 1214#endif
1210 if ( (GNUNET_YES != abstract) && 1215 if ( (GNUNET_YES != abstract) &&
1211 (GNUNET_OK != 1216 (GNUNET_OK !=
1212 GNUNET_DISK_directory_create_for_file (unixpath)) ) 1217 GNUNET_DISK_directory_create_for_file (unixpath)) )
1213 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 1218 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1214 "mkdir", 1219 "mkdir",
1215 unixpath); 1220 unixpath);
1216 } 1221 }
1217 if (NULL != unixpath) 1222 if (NULL != unixpath)
1218 { 1223 {
1219 desc = GNUNET_NETWORK_socket_create (AF_UNIX, 1224 desc = GNUNET_NETWORK_socket_create (AF_UNIX,
1220 SOCK_STREAM, 1225 SOCK_STREAM,
1221 0); 1226 0);
1222 if (NULL == desc) 1227 if (NULL == desc)
1223 { 1228 {
1224 if ((ENOBUFS == errno) || 1229 if ((ENOBUFS == errno) ||
1225 (ENOMEM == errno) || 1230 (ENOMEM == errno) ||
1226 (ENFILE == errno) || 1231 (ENFILE == errno) ||
1227 (EACCES == errno)) 1232 (EACCES == errno))
1228 { 1233 {
1229 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 1234 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
1230 "socket"); 1235 "socket");
1231 GNUNET_free_non_null (hostname); 1236 GNUNET_free_non_null (hostname);
1232 GNUNET_free (unixpath); 1237 GNUNET_free (unixpath);
1233 return GNUNET_SYSERR; 1238 return GNUNET_SYSERR;
1234 } 1239 }
1235 LOG (GNUNET_ERROR_TYPE_INFO, 1240 LOG (GNUNET_ERROR_TYPE_INFO,
1236 _("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), 1241 _ (
1242 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
1237 service_name, 1243 service_name,
1238 STRERROR (errno)); 1244 STRERROR (errno));
1239 GNUNET_free (unixpath); 1245 GNUNET_free (unixpath);
@@ -1242,7 +1248,7 @@ get_server_addresses (const char *service_name,
1242 else 1248 else
1243 { 1249 {
1244 GNUNET_break (GNUNET_OK == 1250 GNUNET_break (GNUNET_OK ==
1245 GNUNET_NETWORK_socket_close (desc)); 1251 GNUNET_NETWORK_socket_close (desc));
1246 desc = NULL; 1252 desc = NULL;
1247 } 1253 }
1248 } 1254 }
@@ -1251,7 +1257,8 @@ get_server_addresses (const char *service_name,
1251 if ((0 == port) && (NULL == unixpath)) 1257 if ((0 == port) && (NULL == unixpath))
1252 { 1258 {
1253 LOG (GNUNET_ERROR_TYPE_ERROR, 1259 LOG (GNUNET_ERROR_TYPE_ERROR,
1254 _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), 1260 _ (
1261 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
1255 service_name); 1262 service_name);
1256 GNUNET_free_non_null (hostname); 1263 GNUNET_free_non_null (hostname);
1257 return GNUNET_SYSERR; 1264 return GNUNET_SYSERR;
@@ -1259,13 +1266,13 @@ get_server_addresses (const char *service_name,
1259 if (0 == port) 1266 if (0 == port)
1260 { 1267 {
1261 saddrs = GNUNET_new_array (2, 1268 saddrs = GNUNET_new_array (2,
1262 struct sockaddr *); 1269 struct sockaddr *);
1263 saddrlens = GNUNET_new_array (2, 1270 saddrlens = GNUNET_new_array (2,
1264 socklen_t); 1271 socklen_t);
1265 add_unixpath (saddrs, 1272 add_unixpath (saddrs,
1266 saddrlens, 1273 saddrlens,
1267 unixpath, 1274 unixpath,
1268 abstract); 1275 abstract);
1269 GNUNET_free_non_null (unixpath); 1276 GNUNET_free_non_null (unixpath);
1270 GNUNET_free_non_null (hostname); 1277 GNUNET_free_non_null (hostname);
1271 *addrs = saddrs; 1278 *addrs = saddrs;
@@ -1280,19 +1287,19 @@ get_server_addresses (const char *service_name,
1280 hostname, 1287 hostname,
1281 service_name); 1288 service_name);
1282 memset (&hints, 1289 memset (&hints,
1283 0, 1290 0,
1284 sizeof (struct addrinfo)); 1291 sizeof (struct addrinfo));
1285 if (disablev6) 1292 if (disablev6)
1286 hints.ai_family = AF_INET; 1293 hints.ai_family = AF_INET;
1287 hints.ai_protocol = IPPROTO_TCP; 1294 hints.ai_protocol = IPPROTO_TCP;
1288 if ((0 != (ret = getaddrinfo (hostname, 1295 if ((0 != (ret = getaddrinfo (hostname,
1289 NULL, 1296 NULL,
1290 &hints, 1297 &hints,
1291 &res))) || 1298 &res))) ||
1292 (NULL == res)) 1299 (NULL == res))
1293 { 1300 {
1294 LOG (GNUNET_ERROR_TYPE_ERROR, 1301 LOG (GNUNET_ERROR_TYPE_ERROR,
1295 _("Failed to resolve `%s': %s\n"), 1302 _ ("Failed to resolve `%s': %s\n"),
1296 hostname, 1303 hostname,
1297 gai_strerror (ret)); 1304 gai_strerror (ret));
1298 GNUNET_free (hostname); 1305 GNUNET_free (hostname);
@@ -1305,14 +1312,14 @@ get_server_addresses (const char *service_name,
1305 { 1312 {
1306 next = pos->ai_next; 1313 next = pos->ai_next;
1307 if ( (disablev6) && 1314 if ( (disablev6) &&
1308 (pos->ai_family == AF_INET6) ) 1315 (pos->ai_family == AF_INET6) )
1309 continue; 1316 continue;
1310 i++; 1317 i++;
1311 } 1318 }
1312 if (0 == i) 1319 if (0 == i)
1313 { 1320 {
1314 LOG (GNUNET_ERROR_TYPE_ERROR, 1321 LOG (GNUNET_ERROR_TYPE_ERROR,
1315 _("Failed to find %saddress for `%s'.\n"), 1322 _ ("Failed to find %saddress for `%s'.\n"),
1316 disablev6 ? "IPv4 " : "", 1323 disablev6 ? "IPv4 " : "",
1317 hostname); 1324 hostname);
1318 freeaddrinfo (res); 1325 freeaddrinfo (res);
@@ -1324,16 +1331,16 @@ get_server_addresses (const char *service_name,
1324 if (NULL != unixpath) 1331 if (NULL != unixpath)
1325 resi++; 1332 resi++;
1326 saddrs = GNUNET_new_array (resi + 1, 1333 saddrs = GNUNET_new_array (resi + 1,
1327 struct sockaddr *); 1334 struct sockaddr *);
1328 saddrlens = GNUNET_new_array (resi + 1, 1335 saddrlens = GNUNET_new_array (resi + 1,
1329 socklen_t); 1336 socklen_t);
1330 i = 0; 1337 i = 0;
1331 if (NULL != unixpath) 1338 if (NULL != unixpath)
1332 { 1339 {
1333 add_unixpath (saddrs, 1340 add_unixpath (saddrs,
1334 saddrlens, 1341 saddrlens,
1335 unixpath, 1342 unixpath,
1336 abstract); 1343 abstract);
1337 i++; 1344 i++;
1338 } 1345 }
1339 next = res; 1346 next = res;
@@ -1341,27 +1348,27 @@ get_server_addresses (const char *service_name,
1341 { 1348 {
1342 next = pos->ai_next; 1349 next = pos->ai_next;
1343 if ( (disablev6) && 1350 if ( (disablev6) &&
1344 (AF_INET6 == pos->ai_family) ) 1351 (AF_INET6 == pos->ai_family) )
1345 continue; 1352 continue;
1346 if ( (IPPROTO_TCP != pos->ai_protocol) && 1353 if ( (IPPROTO_TCP != pos->ai_protocol) &&
1347 (0 != pos->ai_protocol) ) 1354 (0 != pos->ai_protocol) )
1348 continue; /* not TCP */ 1355 continue; /* not TCP */
1349 if ( (SOCK_STREAM != pos->ai_socktype) && 1356 if ( (SOCK_STREAM != pos->ai_socktype) &&
1350 (0 != pos->ai_socktype) ) 1357 (0 != pos->ai_socktype) )
1351 continue; /* huh? */ 1358 continue; /* huh? */
1352 LOG (GNUNET_ERROR_TYPE_DEBUG, 1359 LOG (GNUNET_ERROR_TYPE_DEBUG,
1353 "Service `%s' will bind to `%s'\n", 1360 "Service `%s' will bind to `%s'\n",
1354 service_name, 1361 service_name,
1355 GNUNET_a2s (pos->ai_addr, 1362 GNUNET_a2s (pos->ai_addr,
1356 pos->ai_addrlen)); 1363 pos->ai_addrlen));
1357 if (AF_INET == pos->ai_family) 1364 if (AF_INET == pos->ai_family)
1358 { 1365 {
1359 GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen); 1366 GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen);
1360 saddrlens[i] = pos->ai_addrlen; 1367 saddrlens[i] = pos->ai_addrlen;
1361 saddrs[i] = GNUNET_malloc (saddrlens[i]); 1368 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1362 GNUNET_memcpy (saddrs[i], 1369 GNUNET_memcpy (saddrs[i],
1363 pos->ai_addr, 1370 pos->ai_addr,
1364 saddrlens[i]); 1371 saddrlens[i]);
1365 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); 1372 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1366 } 1373 }
1367 else 1374 else
@@ -1371,8 +1378,8 @@ get_server_addresses (const char *service_name,
1371 saddrlens[i] = pos->ai_addrlen; 1378 saddrlens[i] = pos->ai_addrlen;
1372 saddrs[i] = GNUNET_malloc (saddrlens[i]); 1379 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1373 GNUNET_memcpy (saddrs[i], 1380 GNUNET_memcpy (saddrs[i],
1374 pos->ai_addr, 1381 pos->ai_addr,
1375 saddrlens[i]); 1382 saddrlens[i]);
1376 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); 1383 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1377 } 1384 }
1378 i++; 1385 i++;
@@ -1392,15 +1399,15 @@ get_server_addresses (const char *service_name,
1392 resi++; 1399 resi++;
1393 i = 0; 1400 i = 0;
1394 saddrs = GNUNET_new_array (resi + 1, 1401 saddrs = GNUNET_new_array (resi + 1,
1395 struct sockaddr *); 1402 struct sockaddr *);
1396 saddrlens = GNUNET_new_array (resi + 1, 1403 saddrlens = GNUNET_new_array (resi + 1,
1397 socklen_t); 1404 socklen_t);
1398 if (NULL != unixpath) 1405 if (NULL != unixpath)
1399 { 1406 {
1400 add_unixpath (saddrs, 1407 add_unixpath (saddrs,
1401 saddrlens, 1408 saddrlens,
1402 unixpath, 1409 unixpath,
1403 abstract); 1410 abstract);
1404 i++; 1411 i++;
1405 } 1412 }
1406 saddrlens[i] = sizeof (struct sockaddr_in); 1413 saddrlens[i] = sizeof (struct sockaddr_in);
@@ -1418,16 +1425,16 @@ get_server_addresses (const char *service_name,
1418 if (NULL != unixpath) 1425 if (NULL != unixpath)
1419 resi++; 1426 resi++;
1420 saddrs = GNUNET_new_array (resi + 1, 1427 saddrs = GNUNET_new_array (resi + 1,
1421 struct sockaddr *); 1428 struct sockaddr *);
1422 saddrlens = GNUNET_new_array (resi + 1, 1429 saddrlens = GNUNET_new_array (resi + 1,
1423 socklen_t); 1430 socklen_t);
1424 i = 0; 1431 i = 0;
1425 if (NULL != unixpath) 1432 if (NULL != unixpath)
1426 { 1433 {
1427 add_unixpath (saddrs, 1434 add_unixpath (saddrs,
1428 saddrlens, 1435 saddrlens,
1429 unixpath, 1436 unixpath,
1430 abstract); 1437 abstract);
1431 i++; 1438 i++;
1432 } 1439 }
1433 saddrlens[i] = sizeof (struct sockaddr_in6); 1440 saddrlens[i] = sizeof (struct sockaddr_in6);
@@ -1481,8 +1488,8 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
1481 * to create a GNUnet API that boxes a HANDLE (the way it is done with socks) 1488 * to create a GNUnet API that boxes a HANDLE (the way it is done with socks)
1482 */ 1489 */
1483 lsocks_pipe = (HANDLE) strtoul (env_buf, 1490 lsocks_pipe = (HANDLE) strtoul (env_buf,
1484 NULL, 1491 NULL,
1485 10); 1492 10);
1486 if ( (0 == lsocks_pipe) || 1493 if ( (0 == lsocks_pipe) ||
1487 (INVALID_HANDLE_VALUE == lsocks_pipe)) 1494 (INVALID_HANDLE_VALUE == lsocks_pipe))
1488 return NULL; 1495 return NULL;
@@ -1494,16 +1501,16 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
1494 DWORD rd; 1501 DWORD rd;
1495 1502
1496 ret = ReadFile (lsocks_pipe, 1503 ret = ReadFile (lsocks_pipe,
1497 &count, 1504 &count,
1498 sizeof (count), 1505 sizeof (count),
1499 &rd, 1506 &rd,
1500 NULL); 1507 NULL);
1501 if ( (0 == ret) || 1508 if ( (0 == ret) ||
1502 (sizeof (count) != rd) || 1509 (sizeof (count) != rd) ||
1503 (0 == count) ) 1510 (0 == count) )
1504 break; 1511 break;
1505 lsocks = GNUNET_new_array (count + 1, 1512 lsocks = GNUNET_new_array (count + 1,
1506 struct GNUNET_NETWORK_Handle *); 1513 struct GNUNET_NETWORK_Handle *);
1507 1514
1508 fail2 = 1; 1515 fail2 = 1;
1509 for (i = 0; i < count; i++) 1516 for (i = 0; i < count; i++)
@@ -1513,28 +1520,28 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
1513 SOCKET s; 1520 SOCKET s;
1514 1521
1515 ret = ReadFile (lsocks_pipe, 1522 ret = ReadFile (lsocks_pipe,
1516 &size, 1523 &size,
1517 sizeof (size), 1524 sizeof (size),
1518 &rd, 1525 &rd,
1519 NULL); 1526 NULL);
1520 if ( (0 == ret) || 1527 if ( (0 == ret) ||
1521 (sizeof (size) != rd) || 1528 (sizeof (size) != rd) ||
1522 (sizeof (pi) != size) ) 1529 (sizeof (pi) != size) )
1523 break; 1530 break;
1524 ret = ReadFile (lsocks_pipe, 1531 ret = ReadFile (lsocks_pipe,
1525 &pi, 1532 &pi,
1526 sizeof (pi), 1533 sizeof (pi),
1527 &rd, 1534 &rd,
1528 NULL); 1535 NULL);
1529 if ( (0 == ret) || 1536 if ( (0 == ret) ||
1530 (sizeof (pi) != rd)) 1537 (sizeof (pi) != rd))
1531 break; 1538 break;
1532 s = WSASocketA (pi.iAddressFamily, 1539 s = WSASocketA (pi.iAddressFamily,
1533 pi.iSocketType, 1540 pi.iSocketType,
1534 pi.iProtocol, 1541 pi.iProtocol,
1535 &pi, 1542 &pi,
1536 0, 1543 0,
1537 WSA_FLAG_OVERLAPPED); 1544 WSA_FLAG_OVERLAPPED);
1538 lsocks[i] = GNUNET_NETWORK_socket_box_native (s); 1545 lsocks[i] = GNUNET_NETWORK_socket_box_native (s);
1539 if (NULL == lsocks[i]) 1546 if (NULL == lsocks[i])
1540 break; 1547 break;
@@ -1552,10 +1559,10 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
1552 if (fail) 1559 if (fail)
1553 { 1560 {
1554 LOG (GNUNET_ERROR_TYPE_ERROR, 1561 LOG (GNUNET_ERROR_TYPE_ERROR,
1555 _("Could not access a pre-bound socket, will try to bind myself\n")); 1562 _ ("Could not access a pre-bound socket, will try to bind myself\n"));
1556 for (i = 0; (i < count) && (NULL != lsocks[i]); i++) 1563 for (i = 0; (i < count) && (NULL != lsocks[i]); i++)
1557 GNUNET_break (GNUNET_OK == 1564 GNUNET_break (GNUNET_OK ==
1558 GNUNET_NETWORK_socket_close (lsocks[i])); 1565 GNUNET_NETWORK_socket_close (lsocks[i]));
1559 GNUNET_free (lsocks); 1566 GNUNET_free (lsocks);
1560 return NULL; 1567 return NULL;
1561 } 1568 }
@@ -1573,7 +1580,7 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
1573 */ 1580 */
1574static struct GNUNET_NETWORK_Handle * 1581static struct GNUNET_NETWORK_Handle *
1575open_listen_socket (const struct sockaddr *server_addr, 1582open_listen_socket (const struct sockaddr *server_addr,
1576 socklen_t socklen) 1583 socklen_t socklen)
1577{ 1584{
1578 struct GNUNET_NETWORK_Handle *sock; 1585 struct GNUNET_NETWORK_Handle *sock;
1579 uint16_t port; 1586 uint16_t port;
@@ -1596,19 +1603,19 @@ open_listen_socket (const struct sockaddr *server_addr,
1596 break; 1603 break;
1597 } 1604 }
1598 sock = GNUNET_NETWORK_socket_create (server_addr->sa_family, 1605 sock = GNUNET_NETWORK_socket_create (server_addr->sa_family,
1599 SOCK_STREAM, 1606 SOCK_STREAM,
1600 0); 1607 0);
1601 if (NULL == sock) 1608 if (NULL == sock)
1602 { 1609 {
1603 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 1610 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
1604 "socket"); 1611 "socket");
1605 errno = 0; 1612 errno = 0;
1606 return NULL; 1613 return NULL;
1607 } 1614 }
1608 /* bind the socket */ 1615 /* bind the socket */
1609 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, 1616 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock,
1610 server_addr, 1617 server_addr,
1611 socklen)) 1618 socklen))
1612 { 1619 {
1613 eno = errno; 1620 eno = errno;
1614 if (EADDRINUSE != errno) 1621 if (EADDRINUSE != errno)
@@ -1617,43 +1624,44 @@ open_listen_socket (const struct sockaddr *server_addr,
1617 * fail if we already took the port on IPv6; if both IPv4 and 1624 * fail if we already took the port on IPv6; if both IPv4 and
1618 * IPv6 binds fail, then our caller will log using the 1625 * IPv6 binds fail, then our caller will log using the
1619 * errno preserved in 'eno' */ 1626 * errno preserved in 'eno' */
1620 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
1621 "bind");
1622 if (0 != port) 1627 if (0 != port)
1623 LOG (GNUNET_ERROR_TYPE_ERROR, 1628 LOG (GNUNET_ERROR_TYPE_ERROR,
1624 _("`%s' failed for port %d (%s).\n"), 1629 _ ("`%s' failed for port %d (%s).\n"),
1625 "bind", 1630 "bind",
1626 port, 1631 port,
1627 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6"); 1632 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
1633 else
1634 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
1635 "bind");
1628 eno = 0; 1636 eno = 0;
1629 } 1637 }
1630 else 1638 else
1631 { 1639 {
1632 if (0 != port) 1640 if (0 != port)
1633 LOG (GNUNET_ERROR_TYPE_WARNING, 1641 LOG (GNUNET_ERROR_TYPE_WARNING,
1634 _("`%s' failed for port %d (%s): address already in use\n"), 1642 _ ("`%s' failed for port %d (%s): address already in use\n"),
1635 "bind", port, 1643 "bind", port,
1636 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6"); 1644 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
1637 else if (AF_UNIX == server_addr->sa_family) 1645 else if (AF_UNIX == server_addr->sa_family)
1638 { 1646 {
1639 LOG (GNUNET_ERROR_TYPE_WARNING, 1647 LOG (GNUNET_ERROR_TYPE_WARNING,
1640 _("`%s' failed for `%s': address already in use\n"), 1648 _ ("`%s' failed for `%s': address already in use\n"),
1641 "bind", 1649 "bind",
1642 GNUNET_a2s (server_addr, socklen)); 1650 GNUNET_a2s (server_addr, socklen));
1643 } 1651 }
1644 } 1652 }
1645 GNUNET_break (GNUNET_OK == 1653 GNUNET_break (GNUNET_OK ==
1646 GNUNET_NETWORK_socket_close (sock)); 1654 GNUNET_NETWORK_socket_close (sock));
1647 errno = eno; 1655 errno = eno;
1648 return NULL; 1656 return NULL;
1649 } 1657 }
1650 if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 1658 if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock,
1651 5)) 1659 5))
1652 { 1660 {
1653 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 1661 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
1654 "listen"); 1662 "listen");
1655 GNUNET_break (GNUNET_OK == 1663 GNUNET_break (GNUNET_OK ==
1656 GNUNET_NETWORK_socket_close (sock)); 1664 GNUNET_NETWORK_socket_close (sock));
1657 errno = 0; 1665 errno = 0;
1658 return NULL; 1666 return NULL;
1659 } 1667 }
@@ -1694,20 +1702,20 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
1694#endif 1702#endif
1695 1703
1696 if (GNUNET_CONFIGURATION_have_value 1704 if (GNUNET_CONFIGURATION_have_value
1697 (sh->cfg, 1705 (sh->cfg,
1698 sh->service_name, 1706 sh->service_name,
1699 "TOLERANT")) 1707 "TOLERANT"))
1700 { 1708 {
1701 if (GNUNET_SYSERR == 1709 if (GNUNET_SYSERR ==
1702 (tolerant = 1710 (tolerant =
1703 GNUNET_CONFIGURATION_get_value_yesno (sh->cfg, 1711 GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
1704 sh->service_name, 1712 sh->service_name,
1705 "TOLERANT"))) 1713 "TOLERANT")))
1706 { 1714 {
1707 LOG (GNUNET_ERROR_TYPE_ERROR, 1715 LOG (GNUNET_ERROR_TYPE_ERROR,
1708 _("Specified value for `%s' of service `%s' is invalid\n"), 1716 _ ("Specified value for `%s' of service `%s' is invalid\n"),
1709 "TOLERANT", 1717 "TOLERANT",
1710 sh->service_name); 1718 sh->service_name);
1711 return GNUNET_SYSERR; 1719 return GNUNET_SYSERR;
1712 } 1720 }
1713 } 1721 }
@@ -1719,31 +1727,32 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
1719 errno = 0; 1727 errno = 0;
1720 if ( (NULL != (nfds = getenv ("LISTEN_FDS"))) && 1728 if ( (NULL != (nfds = getenv ("LISTEN_FDS"))) &&
1721 (1 == SSCANF (nfds, 1729 (1 == SSCANF (nfds,
1722 "%u%1s", 1730 "%u%1s",
1723 &cnt, 1731 &cnt,
1724 dummy)) && 1732 dummy)) &&
1725 (cnt > 0) && 1733 (cnt > 0) &&
1726 (cnt < FD_SETSIZE) && 1734 (cnt < FD_SETSIZE) &&
1727 (cnt + 4 < FD_SETSIZE) ) 1735 (cnt + 4 < FD_SETSIZE) )
1728 { 1736 {
1729 lsocks = GNUNET_new_array (cnt + 1, 1737 lsocks = GNUNET_new_array (cnt + 1,
1730 struct GNUNET_NETWORK_Handle *); 1738 struct GNUNET_NETWORK_Handle *);
1731 while (0 < cnt--) 1739 while (0 < cnt--)
1732 { 1740 {
1733 flags = fcntl (3 + cnt, 1741 flags = fcntl (3 + cnt,
1734 F_GETFD); 1742 F_GETFD);
1735 if ( (flags < 0) || 1743 if ( (flags < 0) ||
1736 (0 != (flags & FD_CLOEXEC)) || 1744 (0 != (flags & FD_CLOEXEC)) ||
1737 (NULL == 1745 (NULL ==
1738 (lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt)))) 1746 (lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
1739 { 1747 {
1740 LOG (GNUNET_ERROR_TYPE_ERROR, 1748 LOG (GNUNET_ERROR_TYPE_ERROR,
1741 _("Could not access pre-bound socket %u, will try to bind myself\n"), 1749 _ (
1750 "Could not access pre-bound socket %u, will try to bind myself\n"),
1742 (unsigned int) 3 + cnt); 1751 (unsigned int) 3 + cnt);
1743 cnt++; 1752 cnt++;
1744 while (NULL != lsocks[cnt]) 1753 while (NULL != lsocks[cnt])
1745 GNUNET_break (GNUNET_OK == 1754 GNUNET_break (GNUNET_OK ==
1746 GNUNET_NETWORK_socket_close (lsocks[cnt++])); 1755 GNUNET_NETWORK_socket_close (lsocks[cnt++]));
1747 GNUNET_free (lsocks); 1756 GNUNET_free (lsocks);
1748 lsocks = NULL; 1757 lsocks = NULL;
1749 break; 1758 break;
@@ -1772,8 +1781,8 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
1772 slc->sh = sh; 1781 slc->sh = sh;
1773 slc->listen_socket = *ls; 1782 slc->listen_socket = *ls;
1774 GNUNET_CONTAINER_DLL_insert (sh->slc_head, 1783 GNUNET_CONTAINER_DLL_insert (sh->slc_head,
1775 sh->slc_tail, 1784 sh->slc_tail,
1776 slc); 1785 slc);
1777 } 1786 }
1778 GNUNET_free (lsocks); 1787 GNUNET_free (lsocks);
1779 } 1788 }
@@ -1784,9 +1793,9 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
1784 int num; 1793 int num;
1785 1794
1786 num = get_server_addresses (sh->service_name, 1795 num = get_server_addresses (sh->service_name,
1787 sh->cfg, 1796 sh->cfg,
1788 &addrs, 1797 &addrs,
1789 &addrlens); 1798 &addrlens);
1790 if (GNUNET_SYSERR == num) 1799 if (GNUNET_SYSERR == num)
1791 return GNUNET_SYSERR; 1800 return GNUNET_SYSERR;
1792 1801
@@ -1797,7 +1806,7 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
1797 slc = GNUNET_new (struct ServiceListenContext); 1806 slc = GNUNET_new (struct ServiceListenContext);
1798 slc->sh = sh; 1807 slc->sh = sh;
1799 slc->listen_socket = open_listen_socket (addrs[i], 1808 slc->listen_socket = open_listen_socket (addrs[i],
1800 addrlens[i]); 1809 addrlens[i]);
1801 GNUNET_free (addrs[i]); 1810 GNUNET_free (addrs[i]);
1802 if (NULL == slc->listen_socket) 1811 if (NULL == slc->listen_socket)
1803 { 1812 {
@@ -1807,8 +1816,8 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
1807 continue; 1816 continue;
1808 } 1817 }
1809 GNUNET_CONTAINER_DLL_insert (sh->slc_head, 1818 GNUNET_CONTAINER_DLL_insert (sh->slc_head,
1810 sh->slc_tail, 1819 sh->slc_tail,
1811 slc); 1820 slc);
1812 } 1821 }
1813 GNUNET_free_non_null (addrlens); 1822 GNUNET_free_non_null (addrlens);
1814 GNUNET_free_non_null (addrs); 1823 GNUNET_free_non_null (addrs);
@@ -1817,7 +1826,8 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
1817 { 1826 {
1818 /* All attempts to bind failed, hard failure */ 1827 /* All attempts to bind failed, hard failure */
1819 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1828 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1820 _("Could not bind to any of the ports I was supposed to, refusing to run!\n")); 1829 _ (
1830 "Could not bind to any of the ports I was supposed to, refusing to run!\n"));
1821 return GNUNET_SYSERR; 1831 return GNUNET_SYSERR;
1822 } 1832 }
1823 } 1833 }
@@ -1825,24 +1835,24 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
1825 sh->require_found = tolerant ? GNUNET_NO : GNUNET_YES; 1835 sh->require_found = tolerant ? GNUNET_NO : GNUNET_YES;
1826 sh->match_uid 1836 sh->match_uid
1827 = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg, 1837 = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
1828 sh->service_name, 1838 sh->service_name,
1829 "UNIX_MATCH_UID"); 1839 "UNIX_MATCH_UID");
1830 sh->match_gid 1840 sh->match_gid
1831 = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg, 1841 = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
1832 sh->service_name, 1842 sh->service_name,
1833 "UNIX_MATCH_GID"); 1843 "UNIX_MATCH_GID");
1834 process_acl4 (&sh->v4_denied, 1844 process_acl4 (&sh->v4_denied,
1835 sh, 1845 sh,
1836 "REJECT_FROM"); 1846 "REJECT_FROM");
1837 process_acl4 (&sh->v4_allowed, 1847 process_acl4 (&sh->v4_allowed,
1838 sh, 1848 sh,
1839 "ACCEPT_FROM"); 1849 "ACCEPT_FROM");
1840 process_acl6 (&sh->v6_denied, 1850 process_acl6 (&sh->v6_denied,
1841 sh, 1851 sh,
1842 "REJECT_FROM6"); 1852 "REJECT_FROM6");
1843 process_acl6 (&sh->v6_allowed, 1853 process_acl6 (&sh->v6_allowed,
1844 sh, 1854 sh,
1845 "ACCEPT_FROM6"); 1855 "ACCEPT_FROM6");
1846 return GNUNET_OK; 1856 return GNUNET_OK;
1847} 1857}
1848 1858
@@ -1861,9 +1871,9 @@ get_user_name (struct GNUNET_SERVICE_Handle *sh)
1861 1871
1862 if (GNUNET_OK != 1872 if (GNUNET_OK !=
1863 GNUNET_CONFIGURATION_get_value_filename (sh->cfg, 1873 GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
1864 sh->service_name, 1874 sh->service_name,
1865 "USERNAME", 1875 "USERNAME",
1866 &un)) 1876 &un))
1867 return NULL; 1877 return NULL;
1868 return un; 1878 return un;
1869} 1879}
@@ -1890,9 +1900,9 @@ set_user_id (struct GNUNET_SERVICE_Handle *sh)
1890 if (NULL == pws) 1900 if (NULL == pws)
1891 { 1901 {
1892 LOG (GNUNET_ERROR_TYPE_ERROR, 1902 LOG (GNUNET_ERROR_TYPE_ERROR,
1893 _("Cannot obtain information about user `%s': %s\n"), 1903 _ ("Cannot obtain information about user `%s': %s\n"),
1894 user, 1904 user,
1895 errno == 0 ? _("No such user") : STRERROR (errno)); 1905 errno == 0 ? _ ("No such user") : STRERROR (errno));
1896 GNUNET_free (user); 1906 GNUNET_free (user);
1897 return GNUNET_SYSERR; 1907 return GNUNET_SYSERR;
1898 } 1908 }
@@ -1900,20 +1910,20 @@ set_user_id (struct GNUNET_SERVICE_Handle *sh)
1900 (0 != setegid (pws->pw_gid)) || 1910 (0 != setegid (pws->pw_gid)) ||
1901#if HAVE_INITGROUPS 1911#if HAVE_INITGROUPS
1902 (0 != initgroups (user, 1912 (0 != initgroups (user,
1903 pws->pw_gid)) || 1913 pws->pw_gid)) ||
1904#endif 1914#endif
1905 (0 != setuid (pws->pw_uid)) || 1915 (0 != setuid (pws->pw_uid)) ||
1906 (0 != seteuid (pws->pw_uid))) 1916 (0 != seteuid (pws->pw_uid)))
1907 { 1917 {
1908 if ((0 != setregid (pws->pw_gid, 1918 if ((0 != setregid (pws->pw_gid,
1909 pws->pw_gid)) || 1919 pws->pw_gid)) ||
1910 (0 != setreuid (pws->pw_uid, 1920 (0 != setreuid (pws->pw_uid,
1911 pws->pw_uid))) 1921 pws->pw_uid)))
1912 { 1922 {
1913 LOG (GNUNET_ERROR_TYPE_ERROR, 1923 LOG (GNUNET_ERROR_TYPE_ERROR,
1914 _("Cannot change user/group to `%s': %s\n"), 1924 _ ("Cannot change user/group to `%s': %s\n"),
1915 user, 1925 user,
1916 STRERROR (errno)); 1926 STRERROR (errno));
1917 GNUNET_free (user); 1927 GNUNET_free (user);
1918 return GNUNET_SYSERR; 1928 return GNUNET_SYSERR;
1919 } 1929 }
@@ -1938,9 +1948,9 @@ get_pid_file_name (struct GNUNET_SERVICE_Handle *sh)
1938 1948
1939 if (GNUNET_OK != 1949 if (GNUNET_OK !=
1940 GNUNET_CONFIGURATION_get_value_filename (sh->cfg, 1950 GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
1941 sh->service_name, 1951 sh->service_name,
1942 "PIDFILE", 1952 "PIDFILE",
1943 &pif)) 1953 &pif))
1944 return NULL; 1954 return NULL;
1945 return pif; 1955 return pif;
1946} 1956}
@@ -1960,8 +1970,8 @@ pid_file_delete (struct GNUNET_SERVICE_Handle *sh)
1960 return; /* no PID file */ 1970 return; /* no PID file */
1961 if (0 != UNLINK (pif)) 1971 if (0 != UNLINK (pif))
1962 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 1972 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
1963 "unlink", 1973 "unlink",
1964 pif); 1974 pif);
1965 GNUNET_free (pif); 1975 GNUNET_free (pif);
1966} 1976}
1967 1977
@@ -1983,14 +1993,14 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh)
1983 if (0 != PIPE (filedes)) 1993 if (0 != PIPE (filedes))
1984 { 1994 {
1985 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 1995 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
1986 "pipe"); 1996 "pipe");
1987 return GNUNET_SYSERR; 1997 return GNUNET_SYSERR;
1988 } 1998 }
1989 pid = fork (); 1999 pid = fork ();
1990 if (pid < 0) 2000 if (pid < 0)
1991 { 2001 {
1992 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 2002 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
1993 "fork"); 2003 "fork");
1994 return GNUNET_SYSERR; 2004 return GNUNET_SYSERR;
1995 } 2005 }
1996 if (0 != pid) 2006 if (0 != pid)
@@ -2001,10 +2011,10 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh)
2001 GNUNET_break (0 == CLOSE (filedes[1])); 2011 GNUNET_break (0 == CLOSE (filedes[1]));
2002 c = 'X'; 2012 c = 'X';
2003 if (1 != READ (filedes[0], 2013 if (1 != READ (filedes[0],
2004 &c, 2014 &c,
2005 sizeof (char))) 2015 sizeof (char)))
2006 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, 2016 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
2007 "read"); 2017 "read");
2008 fflush (stdout); 2018 fflush (stdout);
2009 switch (c) 2019 switch (c)
2010 { 2020 {
@@ -2012,15 +2022,15 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh)
2012 exit (0); 2022 exit (0);
2013 case 'I': 2023 case 'I':
2014 LOG (GNUNET_ERROR_TYPE_INFO, 2024 LOG (GNUNET_ERROR_TYPE_INFO,
2015 _("Service process failed to initialize\n")); 2025 _ ("Service process failed to initialize\n"));
2016 break; 2026 break;
2017 case 'S': 2027 case 'S':
2018 LOG (GNUNET_ERROR_TYPE_INFO, 2028 LOG (GNUNET_ERROR_TYPE_INFO,
2019 _("Service process could not initialize server function\n")); 2029 _ ("Service process could not initialize server function\n"));
2020 break; 2030 break;
2021 case 'X': 2031 case 'X':
2022 LOG (GNUNET_ERROR_TYPE_INFO, 2032 LOG (GNUNET_ERROR_TYPE_INFO,
2023 _("Service process failed to report status\n")); 2033 _ ("Service process failed to report status\n"));
2024 break; 2034 break;
2025 } 2035 }
2026 exit (1); /* child reported error */ 2036 exit (1); /* child reported error */
@@ -2029,7 +2039,7 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh)
2029 GNUNET_break (0 == CLOSE (1)); 2039 GNUNET_break (0 == CLOSE (1));
2030 GNUNET_break (0 == CLOSE (filedes[0])); 2040 GNUNET_break (0 == CLOSE (filedes[0]));
2031 nullfd = OPEN ("/dev/null", 2041 nullfd = OPEN ("/dev/null",
2032 O_RDWR | O_APPEND); 2042 O_RDWR | O_APPEND);
2033 if (nullfd < 0) 2043 if (nullfd < 0)
2034 return GNUNET_SYSERR; 2044 return GNUNET_SYSERR;
2035 /* set stdin/stdout to /dev/null */ 2045 /* set stdin/stdout to /dev/null */
@@ -2037,7 +2047,7 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh)
2037 (dup2 (nullfd, 1) < 0) ) 2047 (dup2 (nullfd, 1) < 0) )
2038 { 2048 {
2039 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 2049 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
2040 "dup2"); 2050 "dup2");
2041 (void) CLOSE (nullfd); 2051 (void) CLOSE (nullfd);
2042 return GNUNET_SYSERR; 2052 return GNUNET_SYSERR;
2043 } 2053 }
@@ -2046,7 +2056,7 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh)
2046 pid = setsid (); 2056 pid = setsid ();
2047 if (-1 == pid) 2057 if (-1 == pid)
2048 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 2058 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
2049 "setsid"); 2059 "setsid");
2050 sh->ready_confirm_fd = filedes[1]; 2060 sh->ready_confirm_fd = filedes[1];
2051#else 2061#else
2052 /* FIXME: we probably need to do something else 2062 /* FIXME: we probably need to do something else
@@ -2080,7 +2090,7 @@ teardown_service (struct GNUNET_SERVICE_Handle *sh)
2080 if (NULL != slc->listen_task) 2090 if (NULL != slc->listen_task)
2081 GNUNET_SCHEDULER_cancel (slc->listen_task); 2091 GNUNET_SCHEDULER_cancel (slc->listen_task);
2082 GNUNET_break (GNUNET_OK == 2092 GNUNET_break (GNUNET_OK ==
2083 GNUNET_NETWORK_socket_close (slc->listen_socket)); 2093 GNUNET_NETWORK_socket_close (slc->listen_socket));
2084 GNUNET_free (slc); 2094 GNUNET_free (slc);
2085 } 2095 }
2086} 2096}
@@ -2112,7 +2122,7 @@ return_agpl (void *cls,
2112 slen); 2122 slen);
2113 mq = GNUNET_SERVICE_client_get_mq (client); 2123 mq = GNUNET_SERVICE_client_get_mq (client);
2114 GNUNET_MQ_send (mq, 2124 GNUNET_MQ_send (mq,
2115 env); 2125 env);
2116 GNUNET_SERVICE_client_continue (client); 2126 GNUNET_SERVICE_client_continue (client);
2117} 2127}
2118 2128
@@ -2273,7 +2283,8 @@ GNUNET_SERVICE_run_ (int argc,
2273 GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename), 2283 GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
2274 GNUNET_GETOPT_option_flag ('d', 2284 GNUNET_GETOPT_option_flag ('d',
2275 "daemonize", 2285 "daemonize",
2276 gettext_noop ("do daemonize (detach from terminal)"), 2286 gettext_noop (
2287 "do daemonize (detach from terminal)"),
2277 &do_daemonize), 2288 &do_daemonize),
2278 GNUNET_GETOPT_option_help (NULL), 2289 GNUNET_GETOPT_option_help (NULL),
2279 GNUNET_GETOPT_option_loglevel (&loglev), 2290 GNUNET_GETOPT_option_loglevel (&loglev),
@@ -2284,8 +2295,8 @@ GNUNET_SERVICE_run_ (int argc,
2284 2295
2285 err = 1; 2296 err = 1;
2286 memset (&sh, 2297 memset (&sh,
2287 0, 2298 0,
2288 sizeof (sh)); 2299 sizeof (sh));
2289 xdg = getenv ("XDG_CONFIG_HOME"); 2300 xdg = getenv ("XDG_CONFIG_HOME");
2290 if (NULL != xdg) 2301 if (NULL != xdg)
2291 GNUNET_asprintf (&cfg_filename, 2302 GNUNET_asprintf (&cfg_filename,
@@ -2294,7 +2305,8 @@ GNUNET_SERVICE_run_ (int argc,
2294 DIR_SEPARATOR_STR, 2305 DIR_SEPARATOR_STR,
2295 GNUNET_OS_project_data_get ()->config_file); 2306 GNUNET_OS_project_data_get ()->config_file);
2296 else 2307 else
2297 cfg_filename = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file); 2308 cfg_filename = GNUNET_strdup (
2309 GNUNET_OS_project_data_get ()->user_config_file);
2298 sh.ready_confirm_fd = -1; 2310 sh.ready_confirm_fd = -1;
2299 sh.options = options; 2311 sh.options = options;
2300 sh.cfg = cfg = GNUNET_CONFIGURATION_create (); 2312 sh.cfg = cfg = GNUNET_CONFIGURATION_create ();
@@ -2311,9 +2323,9 @@ GNUNET_SERVICE_run_ (int argc,
2311 opt_cfg_filename = NULL; 2323 opt_cfg_filename = NULL;
2312 do_daemonize = 0; 2324 do_daemonize = 0;
2313 ret = GNUNET_GETOPT_run (service_name, 2325 ret = GNUNET_GETOPT_run (service_name,
2314 service_options, 2326 service_options,
2315 argc, 2327 argc,
2316 argv); 2328 argv);
2317 if (GNUNET_SYSERR == ret) 2329 if (GNUNET_SYSERR == ret)
2318 goto shutdown; 2330 goto shutdown;
2319 if (GNUNET_NO == ret) 2331 if (GNUNET_NO == ret)
@@ -2322,8 +2334,8 @@ GNUNET_SERVICE_run_ (int argc,
2322 goto shutdown; 2334 goto shutdown;
2323 } 2335 }
2324 if (GNUNET_OK != GNUNET_log_setup (service_name, 2336 if (GNUNET_OK != GNUNET_log_setup (service_name,
2325 loglev, 2337 loglev,
2326 logfile)) 2338 logfile))
2327 { 2339 {
2328 GNUNET_break (0); 2340 GNUNET_break (0);
2329 goto shutdown; 2341 goto shutdown;
@@ -2331,41 +2343,41 @@ GNUNET_SERVICE_run_ (int argc,
2331 if (NULL != opt_cfg_filename) 2343 if (NULL != opt_cfg_filename)
2332 { 2344 {
2333 if ( (GNUNET_YES != 2345 if ( (GNUNET_YES !=
2334 GNUNET_DISK_file_test (opt_cfg_filename)) || 2346 GNUNET_DISK_file_test (opt_cfg_filename)) ||
2335 (GNUNET_SYSERR == 2347 (GNUNET_SYSERR ==
2336 GNUNET_CONFIGURATION_load (cfg, 2348 GNUNET_CONFIGURATION_load (cfg,
2337 opt_cfg_filename)) ) 2349 opt_cfg_filename)) )
2338 { 2350 {
2339 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2340 _("Malformed configuration file `%s', exit ...\n"), 2352 _ ("Malformed configuration file `%s', exit ...\n"),
2341 opt_cfg_filename); 2353 opt_cfg_filename);
2342 goto shutdown; 2354 goto shutdown;
2343 } 2355 }
2344 } 2356 }
2345 else 2357 else
2346 { 2358 {
2347 if (GNUNET_YES == 2359 if (GNUNET_YES ==
2348 GNUNET_DISK_file_test (cfg_filename)) 2360 GNUNET_DISK_file_test (cfg_filename))
2349 { 2361 {
2350 if (GNUNET_SYSERR == 2362 if (GNUNET_SYSERR ==
2351 GNUNET_CONFIGURATION_load (cfg, 2363 GNUNET_CONFIGURATION_load (cfg,
2352 cfg_filename)) 2364 cfg_filename))
2353 { 2365 {
2354 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2366 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2355 _("Malformed configuration file `%s', exit ...\n"), 2367 _ ("Malformed configuration file `%s', exit ...\n"),
2356 cfg_filename); 2368 cfg_filename);
2357 goto shutdown; 2369 goto shutdown;
2358 } 2370 }
2359 } 2371 }
2360 else 2372 else
2361 { 2373 {
2362 if (GNUNET_SYSERR == 2374 if (GNUNET_SYSERR ==
2363 GNUNET_CONFIGURATION_load (cfg, 2375 GNUNET_CONFIGURATION_load (cfg,
2364 NULL)) 2376 NULL))
2365 { 2377 {
2366 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2378 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2367 _("Malformed configuration, exit ...\n")); 2379 _ ("Malformed configuration, exit ...\n"));
2368 goto shutdown; 2380 goto shutdown;
2369 } 2381 }
2370 } 2382 }
2371 } 2383 }
@@ -2385,39 +2397,39 @@ GNUNET_SERVICE_run_ (int argc,
2385 (NULL != opt_cfg_filename) ? opt_cfg_filename : cfg_filename); 2397 (NULL != opt_cfg_filename) ? opt_cfg_filename : cfg_filename);
2386 if ((GNUNET_OK == 2398 if ((GNUNET_OK ==
2387 GNUNET_CONFIGURATION_get_value_number (sh.cfg, 2399 GNUNET_CONFIGURATION_get_value_number (sh.cfg,
2388 "TESTING", 2400 "TESTING",
2389 "SKEW_OFFSET", 2401 "SKEW_OFFSET",
2390 &skew_offset)) && 2402 &skew_offset)) &&
2391 (GNUNET_OK == 2403 (GNUNET_OK ==
2392 GNUNET_CONFIGURATION_get_value_number (sh.cfg, 2404 GNUNET_CONFIGURATION_get_value_number (sh.cfg,
2393 "TESTING", 2405 "TESTING",
2394 "SKEW_VARIANCE", 2406 "SKEW_VARIANCE",
2395 &skew_variance))) 2407 &skew_variance)))
2396 { 2408 {
2397 clock_offset = skew_offset - skew_variance; 2409 clock_offset = skew_offset - skew_variance;
2398 GNUNET_TIME_set_offset (clock_offset); 2410 GNUNET_TIME_set_offset (clock_offset);
2399 LOG (GNUNET_ERROR_TYPE_DEBUG, 2411 LOG (GNUNET_ERROR_TYPE_DEBUG,
2400 "Skewing clock by %dll ms\n", 2412 "Skewing clock by %dll ms\n",
2401 clock_offset); 2413 clock_offset);
2402 } 2414 }
2403 GNUNET_RESOLVER_connect (sh.cfg); 2415 GNUNET_RESOLVER_connect (sh.cfg);
2404 2416
2405 /* actually run service */ 2417 /* actually run service */
2406 err = 0; 2418 err = 0;
2407 GNUNET_SCHEDULER_run (&service_main, 2419 GNUNET_SCHEDULER_run (&service_main,
2408 &sh); 2420 &sh);
2409 /* shutdown */ 2421 /* shutdown */
2410 if (1 == do_daemonize) 2422 if (1 == do_daemonize)
2411 pid_file_delete (&sh); 2423 pid_file_delete (&sh);
2412 2424
2413shutdown: 2425 shutdown:
2414 if (-1 != sh.ready_confirm_fd) 2426 if (-1 != sh.ready_confirm_fd)
2415 { 2427 {
2416 if (1 != WRITE (sh.ready_confirm_fd, 2428 if (1 != WRITE (sh.ready_confirm_fd,
2417 err ? "I" : "S", 2429 err ? "I" : "S",
2418 1)) 2430 1))
2419 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, 2431 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
2420 "write"); 2432 "write");
2421 GNUNET_break (0 == CLOSE (sh.ready_confirm_fd)); 2433 GNUNET_break (0 == CLOSE (sh.ready_confirm_fd));
2422 } 2434 }
2423#if HAVE_MALLINFO 2435#if HAVE_MALLINFO
@@ -2425,22 +2437,22 @@ shutdown:
2425 char *counter; 2437 char *counter;
2426 2438
2427 if ( (GNUNET_YES == 2439 if ( (GNUNET_YES ==
2428 GNUNET_CONFIGURATION_have_value (sh.cfg, 2440 GNUNET_CONFIGURATION_have_value (sh.cfg,
2429 service_name, 2441 service_name,
2430 "GAUGER_HEAP")) && 2442 "GAUGER_HEAP")) &&
2431 (GNUNET_OK == 2443 (GNUNET_OK ==
2432 GNUNET_CONFIGURATION_get_value_string (sh.cfg, 2444 GNUNET_CONFIGURATION_get_value_string (sh.cfg,
2433 service_name, 2445 service_name,
2434 "GAUGER_HEAP", 2446 "GAUGER_HEAP",
2435 &counter)) ) 2447 &counter)) )
2436 { 2448 {
2437 struct mallinfo mi; 2449 struct mallinfo mi;
2438 2450
2439 mi = mallinfo (); 2451 mi = mallinfo ();
2440 GAUGER (service_name, 2452 GAUGER (service_name,
2441 counter, 2453 counter,
2442 mi.usmblks, 2454 mi.usmblks,
2443 "blocks"); 2455 "blocks");
2444 GNUNET_free (counter); 2456 GNUNET_free (counter);
2445 } 2457 }
2446 } 2458 }
@@ -2500,7 +2512,7 @@ resume_client_receive (void *cls)
2500 c->recv_task = NULL; 2512 c->recv_task = NULL;
2501 /* first, check if there is still something in the buffer */ 2513 /* first, check if there is still something in the buffer */
2502 ret = GNUNET_MST_next (c->mst, 2514 ret = GNUNET_MST_next (c->mst,
2503 GNUNET_YES); 2515 GNUNET_YES);
2504 if (GNUNET_SYSERR == ret) 2516 if (GNUNET_SYSERR == ret)
2505 { 2517 {
2506 if (NULL == c->drop_task) 2518 if (NULL == c->drop_task)
@@ -2517,9 +2529,9 @@ resume_client_receive (void *cls)
2517 return; 2529 return;
2518 c->recv_task 2530 c->recv_task
2519 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 2531 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
2520 c->sock, 2532 c->sock,
2521 &service_client_recv, 2533 &service_client_recv,
2522 c); 2534 c);
2523} 2535}
2524 2536
2525 2537
@@ -2543,7 +2555,7 @@ GNUNET_SERVICE_client_continue (struct GNUNET_SERVICE_Client *c)
2543 } 2555 }
2544 c->recv_task 2556 c->recv_task
2545 = GNUNET_SCHEDULER_add_now (&resume_client_receive, 2557 = GNUNET_SCHEDULER_add_now (&resume_client_receive,
2546 c); 2558 c);
2547} 2559}
2548 2560
2549 2561
@@ -2587,7 +2599,7 @@ finish_client_drop (void *cls)
2587 if (GNUNET_NO == c->persist) 2599 if (GNUNET_NO == c->persist)
2588 { 2600 {
2589 GNUNET_break (GNUNET_OK == 2601 GNUNET_break (GNUNET_OK ==
2590 GNUNET_NETWORK_socket_close (c->sock)); 2602 GNUNET_NETWORK_socket_close (c->sock));
2591 if ( (0 != (SUSPEND_STATE_EMFILE & sh->suspend_state)) && 2603 if ( (0 != (SUSPEND_STATE_EMFILE & sh->suspend_state)) &&
2592 (0 == (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)) ) 2604 (0 == (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)) )
2593 do_resume (sh, 2605 do_resume (sh,
@@ -2704,7 +2716,7 @@ void
2704GNUNET_SERVICE_client_mark_monitor (struct GNUNET_SERVICE_Client *c) 2716GNUNET_SERVICE_client_mark_monitor (struct GNUNET_SERVICE_Client *c)
2705{ 2717{
2706 c->is_monitor = GNUNET_YES; 2718 c->is_monitor = GNUNET_YES;
2707 if ( (0 != (SUSPEND_STATE_SHUTDOWN & c->sh->suspend_state) && 2719 if ( ((0 != (SUSPEND_STATE_SHUTDOWN & c->sh->suspend_state))&&
2708 (GNUNET_NO == have_non_monitor_clients (c->sh)) ) ) 2720 (GNUNET_NO == have_non_monitor_clients (c->sh)) ) )
2709 GNUNET_SERVICE_shutdown (c->sh); 2721 GNUNET_SERVICE_shutdown (c->sh);
2710} 2722}