WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif
-#define LOG(kind,...) GNUNET_log_from (kind, "util-os-installation", __VA_ARGS__)
+#define LOG(kind, ...) \
+ GNUNET_log_from (kind, "util-os-installation", __VA_ARGS__)
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-os-installation", syscall, filename)
+#define LOG_STRERROR_FILE(kind, syscall, filename) \
+ GNUNET_log_from_strerror_file (kind, \
+ "util-os-installation", \
+ syscall, \
+ filename)
/**
GNUNET_OS_project_data_get ()
{
if (0 == gettextinit)
- {
- char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
- if (NULL != path)
- BINDTEXTDOMAIN (PACKAGE, path);
- GNUNET_free(path);
- gettextinit = 1;
- }
+ {
+ char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
+ if (NULL != path)
+ BINDTEXTDOMAIN (PACKAGE, path);
+ GNUNET_free (path);
+ gettextinit = 1;
+ }
return current_pd;
}
GNUNET_OS_init (const struct GNUNET_OS_ProjectData *pd)
{
if (0 == gettextinit)
- {
- char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
- if (NULL != path)
- BINDTEXTDOMAIN (PACKAGE, path);
- GNUNET_free(path);
- gettextinit = 1;
- }
+ {
+ char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
+ if (NULL != path)
+ BINDTEXTDOMAIN (PACKAGE, path);
+ GNUNET_free (path);
+ gettextinit = 1;
+ }
GNUNET_assert (NULL != pd);
current_pd = pd;
}
return NULL;
while (NULL != fgets (line, sizeof (line), f))
{
- if ((1 ==
- SSCANF (line, "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%1023s", dir)) &&
- (NULL != (lgu = strstr (dir,
- current_pd->libname))))
+ if ((1 == SSCANF (line,
+ "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%1023s",
+ dir)) &&
+ (NULL != (lgu = strstr (dir, current_pd->libname))))
{
lgu[0] = '\0';
FCLOSE (f);
ssize_t size;
char *lep;
- GNUNET_snprintf (fn,
- sizeof (fn),
- "/proc/%u/exe",
- getpid ());
- size = readlink (fn,
- lnk,
- sizeof (lnk) - 1);
+ GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/exe", getpid ());
+ size = readlink (fn, lnk, sizeof (lnk) - 1);
if (size <= 0)
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
- "readlink",
- fn);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "readlink", fn);
return NULL;
}
- GNUNET_assert ( ((size_t) size) < sizeof (lnk));
+ GNUNET_assert (((size_t) size) < sizeof (lnk));
lnk[size] = '\0';
while ((lnk[size] != '/') && (size > 0))
size--;
- GNUNET_asprintf (&lep,
- "/%s/libexec/",
- current_pd->project_dirname);
+ GNUNET_asprintf (&lep, "/%s/libexec/", current_pd->project_dirname);
/* test for being in lib/gnunet/libexec/ or lib/MULTIARCH/gnunet/libexec */
- if ( (((size_t) size) > strlen (lep)) &&
- (0 == strcmp (lep,
- &lnk[size - strlen (lep)])) )
+ if ((((size_t) size) > strlen (lep)) &&
+ (0 == strcmp (lep, &lnk[size - strlen (lep)])))
size -= strlen (lep) - 1;
GNUNET_free (lep);
- if ( (size < 4) ||
- (lnk[size - 4] != '/') )
+ if ((size < 4) || (lnk[size - 4] != '/'))
{
/* not installed in "/bin/" -- binary path probably useless */
return NULL;
* and hInstance saving.
*/
BOOL WINAPI
-DllMain (HINSTANCE hinstDLL,
- DWORD fdwReason,
- LPVOID lpvReserved)
+DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
- case DLL_PROCESS_ATTACH:
- dll_instance = hinstDLL;
- break;
- case DLL_THREAD_ATTACH:
- break;
- case DLL_THREAD_DETACH:
- break;
- case DLL_PROCESS_DETACH:
- break;
+ case DLL_PROCESS_ATTACH:
+ dll_instance = hinstDLL;
+ break;
+ case DLL_THREAD_ATTACH:
+ break;
+ case DLL_THREAD_DETACH:
+ break;
+ case DLL_PROCESS_DETACH:
+ break;
}
return TRUE;
}
do
{
pathlen = pathlen * 2;
- modulepath = GNUNET_realloc (modulepath,
- pathlen * sizeof (wchar_t));
+ modulepath = GNUNET_realloc (modulepath, pathlen * sizeof (wchar_t));
SetLastError (0);
- real_pathlen = GetModuleFileNameW (dll_instance,
- modulepath,
- pathlen * sizeof (wchar_t));
- } while (real_pathlen >= pathlen && pathlen < 16*1024);
+ real_pathlen =
+ GetModuleFileNameW (dll_instance, modulepath, pathlen * sizeof (wchar_t));
+ } while (real_pathlen >= pathlen && pathlen < 16 * 1024);
if (real_pathlen >= pathlen)
GNUNET_assert (0);
/* To be safe */
}
/* modulepath is GNUNET_PREFIX */
- u8_string = u16_to_u8 (modulepath, wcslen (modulepath), NULL, &u8_string_length);
+ u8_string =
+ u16_to_u8 (modulepath, wcslen (modulepath), NULL, &u8_string_length);
if (NULL == u8_string)
GNUNET_assert (0);
* @param number of bytes available in @a buf
* @return 0 on success, otherwise desired number of bytes is stored in 'bufsize'
*/
-typedef int
-(*MyNSGetExecutablePathProto) (char *buf,
- size_t *bufsize);
+typedef int (*MyNSGetExecutablePathProto) (char *buf, size_t *bufsize);
/**
MyNSGetExecutablePathProto func;
path = NULL;
- if (NULL == (func =
- (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, "_NSGetExecutablePath")))
+ if (NULL ==
+ (func = (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT,
+ "_NSGetExecutablePath")))
return NULL;
path = &zero;
len = 0;
for (i = 0; i < c; i++)
{
if (((const void *) _dyld_get_image_header (i)) !=
- ((const void *) &_mh_dylib_header) )
+ ((const void *) &_mh_dylib_header))
continue;
path = _dyld_get_image_name (i);
- if ( (NULL == path) || (0 == strlen (path)) )
+ if ((NULL == path) || (0 == strlen (path)))
continue;
p = GNUNET_strdup (path);
s = p + strlen (p);
/* On W32 look in CWD first. */
GNUNET_asprintf (&path, ".%c%s", PATH_SEPARATOR, p);
#else
- path = GNUNET_strdup (p); /* because we write on it */
+ path = GNUNET_strdup (p); /* because we write on it */
#endif
buf = GNUNET_malloc (strlen (path) + strlen (binary) + 1 + 1);
pos = path;
{
const char *p;
- if ( (NULL != current_pd->env_varname) &&
- (NULL != (p = getenv (current_pd->env_varname))) )
+ if ((NULL != current_pd->env_varname) &&
+ (NULL != (p = getenv (current_pd->env_varname))))
return GNUNET_strdup (p);
- if ( (NULL != current_pd->env_varname_alt) &&
- (NULL != (p = getenv (current_pd->env_varname_alt))) )
+ if ((NULL != current_pd->env_varname_alt) &&
+ (NULL != (p = getenv (current_pd->env_varname_alt))))
return GNUNET_strdup (p);
return NULL;
}
if (NULL != (ret = get_path_from_proc_maps ()))
return ret;
/* try path *first*, before /proc/exe, as /proc/exe can be wrong */
- if ( (NULL != current_pd->binary_name) &&
- (NULL != (ret = get_path_from_PATH (current_pd->binary_name))) )
+ if ((NULL != current_pd->binary_name) &&
+ (NULL != (ret = get_path_from_PATH (current_pd->binary_name))))
return ret;
if (NULL != (ret = get_path_from_proc_exe ()))
return ret;
if (NULL != (ret = get_path_from_NSGetExecutablePath ()))
return ret;
#endif
- if ( (NULL != current_pd->binary_name) &&
- (NULL != (ret = get_path_from_PATH (current_pd->binary_name))) )
+ if ((NULL != current_pd->binary_name) &&
+ (NULL != (ret = get_path_from_PATH (current_pd->binary_name))))
return ret;
/* other attempts here */
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Could not determine installation path for %s. Set `%s' environment variable.\n"),
+ _ (
+ "Could not determine installation path for %s. Set `%s' environment variable.\n"),
current_pd->project_dirname,
current_pd->env_varname);
return NULL;
execpath[--n] = '\0';
isbasedir = 1;
- if ((n > 6) &&
- ((0 == strcasecmp (&execpath[n - 6], "/lib32")) ||
- (0 == strcasecmp (&execpath[n - 6], "/lib64"))))
+ if ((n > 6) && ((0 == strcasecmp (&execpath[n - 6], "/lib32")) ||
+ (0 == strcasecmp (&execpath[n - 6], "/lib64"))))
{
- if ( (GNUNET_OS_IPK_LIBDIR != dirkind) &&
- (GNUNET_OS_IPK_LIBEXECDIR != dirkind) )
+ if ((GNUNET_OS_IPK_LIBDIR != dirkind) &&
+ (GNUNET_OS_IPK_LIBEXECDIR != dirkind))
{
/* strip '/lib32' or '/lib64' */
execpath[n - 6] = '\0';
else
isbasedir = 0;
}
- else if ((n > 4) &&
- ((0 == strcasecmp (&execpath[n - 4], "/bin")) ||
- (0 == strcasecmp (&execpath[n - 4], "/lib"))))
+ else if ((n > 4) && ((0 == strcasecmp (&execpath[n - 4], "/bin")) ||
+ (0 == strcasecmp (&execpath[n - 4], "/lib"))))
{
/* strip '/bin' or '/lib' */
execpath[n - 4] = '\0';
here we need to re-add 'multiarch' to lib and libexec paths later! */
multiarch = &libdir[5];
if (NULL == strchr (multiarch, '/'))
- libdir[0] = '\0'; /* Debian multiarch format, cut of from 'execpath' but preserve in multicarch */
+ libdir[0] =
+ '\0'; /* Debian multiarch format, cut of from 'execpath' but preserve in multicarch */
else
- multiarch = NULL; /* maybe not, multiarch still has a '/', which is not OK */
+ multiarch =
+ NULL; /* maybe not, multiarch still has a '/', which is not OK */
}
/* in case this was a directory named foo-bin, remove "foo-" */
while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR))
DIR_SEPARATOR_STR,
current_pd->project_dirname,
DIR_SEPARATOR_STR);
- if (GNUNET_YES ==
- GNUNET_DISK_directory_test (tmp, GNUNET_YES))
+ if (GNUNET_YES == GNUNET_DISK_directory_test (tmp, GNUNET_YES))
{
GNUNET_free (execpath);
return tmp;
dirname = NULL;
if (4 == sizeof (void *))
{
- GNUNET_asprintf (&dirname,
- DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR,
+ GNUNET_asprintf (&dirname,
+ DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR
+ "%s" DIR_SEPARATOR_STR,
current_pd->project_dirname);
- GNUNET_asprintf (&tmp,
- "%s%s",
- execpath,
- dirname);
+ GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
}
if (8 == sizeof (void *))
{
GNUNET_asprintf (&dirname,
- DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR,
+ DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR
+ "%s" DIR_SEPARATOR_STR,
current_pd->project_dirname);
- GNUNET_asprintf (&tmp,
- "%s%s",
- execpath,
- dirname);
+ GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
}
- if ( (NULL != tmp) &&
- (GNUNET_YES ==
- GNUNET_DISK_directory_test (tmp, GNUNET_YES)) )
+ if ((NULL != tmp) &&
+ (GNUNET_YES == GNUNET_DISK_directory_test (tmp, GNUNET_YES)))
{
GNUNET_free (execpath);
GNUNET_free_non_null (dirname);
break;
case GNUNET_OS_IPK_DATADIR:
GNUNET_asprintf (&dirname,
- DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR,
+ DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
+ "%s" DIR_SEPARATOR_STR,
current_pd->project_dirname);
break;
case GNUNET_OS_IPK_LOCALEDIR:
- dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale" DIR_SEPARATOR_STR);
+ dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
+ "locale" DIR_SEPARATOR_STR);
break;
case GNUNET_OS_IPK_ICONDIR:
- dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "icons" DIR_SEPARATOR_STR);
+ dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
+ "icons" DIR_SEPARATOR_STR);
break;
case GNUNET_OS_IPK_DOCDIR:
GNUNET_asprintf (&dirname,
- DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "doc" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR,
+ DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
+ "doc" DIR_SEPARATOR_STR
+ "%s" DIR_SEPARATOR_STR,
current_pd->project_dirname);
break;
case GNUNET_OS_IPK_LIBEXECDIR:
if (isbasedir)
{
GNUNET_asprintf (&dirname,
- DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR "libexec" DIR_SEPARATOR_STR,
+ DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR
+ "libexec" DIR_SEPARATOR_STR,
current_pd->project_dirname);
GNUNET_asprintf (&tmp,
"%s%s%s%s",
DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR,
(NULL != multiarch) ? multiarch : "",
dirname);
- if (GNUNET_YES ==
- GNUNET_DISK_directory_test (tmp, GNUNET_YES))
+ if (GNUNET_YES == GNUNET_DISK_directory_test (tmp, GNUNET_YES))
{
GNUNET_free (execpath);
GNUNET_free (dirname);
if (4 == sizeof (void *))
{
GNUNET_asprintf (&dirname,
- DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR "libexec" DIR_SEPARATOR_STR,
+ DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR
+ "%s" DIR_SEPARATOR_STR
+ "libexec" DIR_SEPARATOR_STR,
current_pd->project_dirname);
- GNUNET_asprintf (&tmp,
- "%s%s",
- execpath,
- dirname);
+ GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
}
if (8 == sizeof (void *))
{
- GNUNET_asprintf (&dirname,
- DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR "libexec" DIR_SEPARATOR_STR,
+ GNUNET_asprintf (&dirname,
+ DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR
+ "%s" DIR_SEPARATOR_STR
+ "libexec" DIR_SEPARATOR_STR,
current_pd->project_dirname);
- GNUNET_asprintf (&tmp,
- "%s%s",
- execpath,
- dirname);
+ GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
}
- if ( (NULL != tmp) &&
- (GNUNET_YES ==
- GNUNET_DISK_directory_test (tmp, GNUNET_YES)) )
+ if ((NULL != tmp) &&
+ (GNUNET_YES == GNUNET_DISK_directory_test (tmp, GNUNET_YES)))
{
GNUNET_free (execpath);
GNUNET_free_non_null (dirname);
GNUNET_free_non_null (dirname);
}
GNUNET_asprintf (&dirname,
- DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR "libexec" DIR_SEPARATOR_STR,
+ DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR
+ "libexec" DIR_SEPARATOR_STR,
current_pd->project_dirname);
break;
default:
GNUNET_free (execpath);
return NULL;
}
- GNUNET_asprintf (&tmp,
- "%s%s",
- execpath,
- dirname);
+ GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
GNUNET_free (dirname);
GNUNET_free (execpath);
return tmp;
char *libexecdir;
char *binary;
- if ( (DIR_SEPARATOR == progname[0]) ||
- (GNUNET_YES ==
- GNUNET_STRINGS_path_is_absolute (progname,
- GNUNET_NO,
- NULL, NULL)) )
+ if ((DIR_SEPARATOR == progname[0]) ||
+ (GNUNET_YES ==
+ GNUNET_STRINGS_path_is_absolute (progname, GNUNET_NO, NULL, NULL)))
return GNUNET_strdup (progname);
if (NULL != cache)
libexecdir = cache;
libexecdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBEXECDIR);
if (NULL == libexecdir)
return GNUNET_strdup (progname);
- GNUNET_asprintf (&binary,
- "%s%s",
- libexecdir,
- progname);
+ GNUNET_asprintf (&binary, "%s%s", libexecdir, progname);
cache = libexecdir;
return binary;
}
size_t path_len;
if (GNUNET_YES ==
- GNUNET_STRINGS_path_is_absolute (progname,
- GNUNET_NO,
- NULL, NULL))
+ GNUNET_STRINGS_path_is_absolute (progname, GNUNET_NO, NULL, NULL))
{
return GNUNET_strdup (progname);
}
"PATHS",
"SUID_BINARY_PATH",
&path);
- if (NULL == path || 0 == strlen (path))
+ if ((NULL == path)||(0 == strlen (path)))
return GNUNET_OS_get_libexec_binary_path (progname);
path_len = strlen (path);
GNUNET_asprintf (&binary,
- "%s%s%s",
- path,
- (path[path_len - 1] == DIR_SEPARATOR) ? "" : DIR_SEPARATOR_STR,
- progname);
+ "%s%s%s",
+ path,
+ (path[path_len - 1] == DIR_SEPARATOR) ? ""
+ : DIR_SEPARATOR_STR,
+ progname);
cache = path;
return binary;
}
#ifdef MINGW
char *binaryexe;
- GNUNET_asprintf (&binaryexe,
- "%s.exe",
- binary);
- if ( (GNUNET_YES ==
- GNUNET_STRINGS_path_is_absolute (binaryexe,
- GNUNET_NO,
- NULL, NULL)) ||
- (0 == strncmp (binary, "./", 2)) )
+ GNUNET_asprintf (&binaryexe, "%s.exe", binary);
+ if ((GNUNET_YES ==
+ GNUNET_STRINGS_path_is_absolute (binaryexe, GNUNET_NO, NULL, NULL)) ||
+ (0 == strncmp (binary, "./", 2)))
p = GNUNET_strdup (binaryexe);
else
{
}
GNUNET_free (binaryexe);
#else
- if ( (GNUNET_YES ==
- GNUNET_STRINGS_path_is_absolute (binary,
- GNUNET_NO,
- NULL,
- NULL)) ||
- (0 == strncmp (binary, "./", 2)) )
+ if ((GNUNET_YES ==
+ GNUNET_STRINGS_path_is_absolute (binary, GNUNET_NO, NULL, NULL)) ||
+ (0 == strncmp (binary, "./", 2)))
{
p = GNUNET_strdup (binary);
}
p = get_path_from_PATH (binary);
if (NULL != p)
{
- GNUNET_asprintf (&pf,
- "%s/%s",
- p,
- binary);
+ GNUNET_asprintf (&pf, "%s/%s", p, binary);
GNUNET_free (p);
p = pf;
}
if (NULL == p)
{
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Could not find binary `%s' in PATH!\n"),
+ _ ("Could not find binary `%s' in PATH!\n"),
binary);
return GNUNET_SYSERR;
}
- if (0 != ACCESS (p,
- X_OK))
+ if (0 != ACCESS (p, X_OK))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "access",
- p);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", p);
GNUNET_free (p);
return GNUNET_SYSERR;
}
return GNUNET_YES;
}
#endif
- if (0 != STAT (p,
- &statbuf))
+ if (0 != STAT (p, &statbuf))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "stat",
- p);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", p);
GNUNET_free (p);
return GNUNET_SYSERR;
}
{
#ifndef MINGW
(void) params;
- if ( (0 != (statbuf.st_mode & S_ISUID)) &&
- (0 == statbuf.st_uid) )
+ if ((0 != (statbuf.st_mode & S_ISUID)) && (0 == statbuf.st_uid))
{
GNUNET_free (p);
return GNUNET_YES;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Binary `%s' exists, but is not SUID\n"),
+ _ ("Binary `%s' exists, but is not SUID\n"),
p);
/* binary exists, but not SUID */
#else
PROCESS_INFORMATION proc;
DWORD exit_value;
- GNUNET_snprintf (parameters,
- sizeof (parameters),
- "-d %s", params);
+ GNUNET_snprintf (parameters, sizeof (parameters), "-d %s", params);
memset (&start, 0, sizeof (start));
start.cb = sizeof (start);
memset (&proc, 0, sizeof (proc));
// Start the child process.
- if ( ! (CreateProcess( p, // current windows (2k3 and up can handle / instead of \ in paths))
- parameters, // execute dryrun/priviliege checking mode
- NULL, // Process handle not inheritable
- NULL, // Thread handle not inheritable
- FALSE, // Set handle inheritance to FALSE
- CREATE_DEFAULT_ERROR_MODE, // No creation flags
- NULL, // Use parent's environment block
- NULL, // Use parent's starting directory
- &start, // Pointer to STARTUPINFO structure
- &proc ) // Pointer to PROCESS_INFORMATION structure
- ))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("CreateProcess failed for binary %s (%d).\n"),
- p, GetLastError());
- return GNUNET_SYSERR;
+ if (! (CreateProcess (
+ p, // current windows (2k3 and up can handle / instead of \ in paths))
+ parameters, // execute dryrun/priviliege checking mode
+ NULL, // Process handle not inheritable
+ NULL, // Thread handle not inheritable
+ FALSE, // Set handle inheritance to FALSE
+ CREATE_DEFAULT_ERROR_MODE, // No creation flags
+ NULL, // Use parent's environment block
+ NULL, // Use parent's starting directory
+ &start, // Pointer to STARTUPINFO structure
+ &proc) // Pointer to PROCESS_INFORMATION structure
+ ))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _ ("CreateProcess failed for binary %s (%d).\n"),
+ p,
+ GetLastError ());
+ return GNUNET_SYSERR;
}
// Wait until child process exits.
- WaitForSingleObject( proc.hProcess, INFINITE );
+ WaitForSingleObject (proc.hProcess, INFINITE);
- if ( ! GetExitCodeProcess (proc.hProcess, &exit_value)){
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("GetExitCodeProcess failed for binary %s (%d).\n"),
- p, GetLastError() );
- return GNUNET_SYSERR;
- }
+ if (! GetExitCodeProcess (proc.hProcess, &exit_value))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _ ("GetExitCodeProcess failed for binary %s (%d).\n"),
+ p,
+ GetLastError ());
+ return GNUNET_SYSERR;
+ }
// Close process and thread handles.
- CloseHandle( proc.hProcess );
- CloseHandle( proc.hThread );
+ CloseHandle (proc.hProcess);
+ CloseHandle (proc.hThread);
- if (!exit_value)
+ if (! exit_value)
return GNUNET_YES;
#endif
- }
+ }
GNUNET_free (p);
return GNUNET_NO;
}
#define LOG(kind,...) GNUNET_log_from (kind, "util-service", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-service", syscall)
+#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, \
+ "util-service", \
+ syscall)
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-service", syscall, filename)
+#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file ( \
+ kind, "util-service", syscall, filename)
/**
*/
enum SuspendReason
{
- /**
- * We are running normally.
- */
- SUSPEND_STATE_NONE = 0,
-
- /**
- * Application requested it.
- */
- SUSPEND_STATE_APP = 1,
-
- /**
- * OS ran out of file descriptors.
- */
- SUSPEND_STATE_EMFILE = 2,
-
- /**
- * Both reasons, APP and EMFILE apply.
- */
- SUSPEND_STATE_APP_AND_EMFILE = 3,
-
- /**
- * Suspension because service was permanently shutdown.
- */
- SUSPEND_STATE_SHUTDOWN = 4
+ /**
+ * We are running normally.
+ */
+ SUSPEND_STATE_NONE = 0,
+
+ /**
+ * Application requested it.
+ */
+ SUSPEND_STATE_APP = 1,
+
+ /**
+ * OS ran out of file descriptors.
+ */
+ SUSPEND_STATE_EMFILE = 2,
+
+ /**
+ * Both reasons, APP and EMFILE apply.
+ */
+ SUSPEND_STATE_APP_AND_EMFILE = 3,
+
+ /**
+ * Suspension because service was permanently shutdown.
+ */
+ SUSPEND_STATE_SHUTDOWN = 4
};
return GNUNET_NO;
i = 0;
while ( (0 != list[i].network.s_addr) ||
- (0 != list[i].netmask.s_addr) )
+ (0 != list[i].netmask.s_addr) )
{
if ((add->s_addr & list[i].netmask.s_addr) ==
(list[i].network.s_addr & list[i].netmask.s_addr))
if (NULL == list)
return GNUNET_NO;
i = 0;
-NEXT:
+ NEXT:
while (0 != GNUNET_is_zero (&list[i].network))
{
for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++)
LOG (GNUNET_ERROR_TYPE_DEBUG,
"service: sending message with type %u\n",
- ntohs(client->msg->type));
+ ntohs (client->msg->type));
client->send_task = NULL;
buf = (const char *) client->msg;
left = ntohs (client->msg->size) - client->msg_pos;
ret = GNUNET_NETWORK_socket_send (client->sock,
- &buf[client->msg_pos],
- left);
+ &buf[client->msg_pos],
+ left);
GNUNET_assert (ret <= (ssize_t) left);
if (0 == ret)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"no data send");
GNUNET_MQ_inject_error (client->mq,
- GNUNET_MQ_ERROR_WRITE);
+ GNUNET_MQ_ERROR_WRITE);
return;
}
if (-1 == ret)
{
if ( (EAGAIN == errno) ||
- (EINTR == errno) )
+ (EINTR == errno) )
{
/* ignore */
ret = 0;
"socket send returned with error code %i",
errno);
GNUNET_MQ_inject_error (client->mq,
- GNUNET_MQ_ERROR_WRITE);
+ GNUNET_MQ_ERROR_WRITE);
return;
}
}
GNUNET_assert (NULL == client->drop_task);
client->send_task
= GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
- client->sock,
- &do_send,
- client);
+ client->sock,
+ &do_send,
+ client);
return;
}
GNUNET_MQ_impl_send_continue (client->mq);
client->msg_pos = 0;
client->send_task
= GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
- client->sock,
- &do_send,
- client);
+ client->sock,
+ &do_send,
+ client);
}
client->warn_task
= GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
&warn_no_client_continue,
- client);
+ client);
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Processing code for message of type %u did not call `GNUNET_SERVICE_client_continue' after %s\n"),
+ _ (
+ "Processing code for message of type %u did not call `GNUNET_SERVICE_client_continue' after %s\n"),
(unsigned int) client->warn_type,
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (client->warn_start),
- GNUNET_YES));
+ GNUNET_STRINGS_relative_time_to_string (
+ GNUNET_TIME_absolute_get_duration (client->warn_start),
+ GNUNET_YES));
}
GNUNET_assert (NULL == client->warn_task);
client->warn_task
= GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &warn_no_client_continue,
- client);
+ &warn_no_client_continue,
+ client);
GNUNET_MQ_inject_message (client->mq,
message);
if (NULL != client->drop_task)
client->recv_task = NULL;
ret = GNUNET_MST_read (client->mst,
- client->sock,
- GNUNET_NO,
- GNUNET_YES);
+ client->sock,
+ GNUNET_NO,
+ GNUNET_YES);
if (GNUNET_SYSERR == ret)
{
/* client closed connection (or IO error) */
}
if (GNUNET_NO == ret)
return; /* more messages in buffer, wait for application
- to be done processing */
+ to be done processing */
GNUNET_assert (GNUNET_OK == ret);
if (GNUNET_YES == client->needs_continue)
return;
/* MST needs more data, re-schedule read job */
client->recv_task
= GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- client->sock,
- &service_client_recv,
- client);
+ client->sock,
+ &service_client_recv,
+ client);
}
&service_mq_error_handler,
client);
client->mst = GNUNET_MST_create (&service_client_mst_cb,
- client);
+ client);
if (NULL != sh->connect_cb)
client->user_context = sh->connect_cb (sh->cb_cls,
client,
client->user_context);
client->recv_task
= GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- client->sock,
- &service_client_recv,
- client);
+ client->sock,
+ &service_client_recv,
+ client);
}
addrlen = sizeof (sa);
sock = GNUNET_NETWORK_socket_accept (slc->listen_socket,
- (struct sockaddr *) &sa,
- &addrlen);
+ (struct sockaddr *) &sa,
+ &addrlen);
if (NULL == sock)
{
if (EMFILE == errno)
GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
v4 = (const struct sockaddr_in *) &sa;
ok = ( ( (NULL == sh->v4_allowed) ||
- (check_ipv4_listed (sh->v4_allowed,
- &v4->sin_addr))) &&
- ( (NULL == sh->v4_denied) ||
- (! check_ipv4_listed (sh->v4_denied,
- &v4->sin_addr)) ) );
+ (check_ipv4_listed (sh->v4_allowed,
+ &v4->sin_addr))) &&
+ ( (NULL == sh->v4_denied) ||
+ (! check_ipv4_listed (sh->v4_denied,
+ &v4->sin_addr)) ) );
break;
case AF_INET6:
GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
v6 = (const struct sockaddr_in6 *) &sa;
ok = ( ( (NULL == sh->v6_allowed) ||
- (check_ipv6_listed (sh->v6_allowed,
- &v6->sin6_addr))) &&
- ( (NULL == sh->v6_denied) ||
- (! check_ipv6_listed (sh->v6_denied,
- &v6->sin6_addr)) ) );
+ (check_ipv6_listed (sh->v6_allowed,
+ &v6->sin6_addr))) &&
+ ( (NULL == sh->v6_denied) ||
+ (! check_ipv6_listed (sh->v6_denied,
+ &v6->sin6_addr)) ) );
break;
#ifndef WINDOWS
case AF_UNIX:
#endif
default:
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Unknown address family %d\n"),
- sa.ss_family);
+ _ ("Unknown address family %d\n"),
+ sa.ss_family);
return;
}
if (! ok)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Service rejected incoming connection from %s due to policy.\n",
- GNUNET_a2s ((const struct sockaddr *) &sa,
- addrlen));
+ "Service rejected incoming connection from %s due to policy.\n",
+ GNUNET_a2s ((const struct sockaddr *) &sa,
+ addrlen));
GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (sock));
+ GNUNET_NETWORK_socket_close (sock));
continue;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Service accepted incoming connection from %s.\n",
- GNUNET_a2s ((const struct sockaddr *) &sa,
- addrlen));
+ "Service accepted incoming connection from %s.\n",
+ GNUNET_a2s ((const struct sockaddr *) &sa,
+ addrlen));
start_client (slc->sh,
- sock);
+ sock);
}
if (0 != sh->suspend_state)
return;
slc->listen_task
= GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- slc->listen_socket,
- &accept_client,
- slc);
+ slc->listen_socket,
+ &accept_client,
+ slc);
}
GNUNET_assert (NULL == slc->listen_task);
slc->listen_task
= GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- slc->listen_socket,
- &accept_client,
- slc);
+ slc->listen_socket,
+ &accept_client,
+ slc);
}
}
if (NULL != sh->service_init_cb)
sh->service_init_cb (sh->cb_cls,
- sh->cfg,
- sh);
+ sh->cfg,
+ sh);
}
char *opt;
if (! GNUNET_CONFIGURATION_have_value (sh->cfg,
- sh->service_name,
- option))
+ sh->service_name,
+ option))
{
*ret = NULL;
return GNUNET_OK;
GNUNET_CONFIGURATION_get_value_string (sh->cfg,
sh->service_name,
option,
- &opt));
+ &opt));
if (NULL == (*ret = GNUNET_STRINGS_parse_ipv4_policy (opt)))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
+ _ ("Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
opt,
- sh->service_name,
- option);
+ sh->service_name,
+ option);
GNUNET_free (opt);
return GNUNET_SYSERR;
}
char *opt;
if (! GNUNET_CONFIGURATION_have_value (sh->cfg,
- sh->service_name,
- option))
+ sh->service_name,
+ option))
{
*ret = NULL;
return GNUNET_OK;
GNUNET_CONFIGURATION_get_value_string (sh->cfg,
sh->service_name,
option,
- &opt));
+ &opt));
if (NULL == (*ret = GNUNET_STRINGS_parse_ipv6_policy (opt)))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
+ _ ("Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
opt,
- sh->service_name,
- option);
+ sh->service_name,
+ option);
GNUNET_free (opt);
return GNUNET_SYSERR;
}
un = GNUNET_new (struct sockaddr_un);
un->sun_family = AF_UNIX;
GNUNET_strlcpy (un->sun_path,
- unixpath,
- sizeof (un->sun_path));
+ unixpath,
+ sizeof (un->sun_path));
#ifdef LINUX
if (GNUNET_YES == abstract)
un->sun_path[0] = '\0';
*/
static int
get_server_addresses (const char *service_name,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct sockaddr ***addrs,
- socklen_t **addr_lens)
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct sockaddr ***addrs,
+ socklen_t **addr_lens)
{
int disablev6;
struct GNUNET_NETWORK_Handle *desc;
desc = NULL;
disablev6 = GNUNET_NO;
if ( (GNUNET_NO ==
- GNUNET_NETWORK_test_pf (PF_INET6)) ||
+ GNUNET_NETWORK_test_pf (PF_INET6)) ||
(GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- service_name,
- "DISABLEV6") ) )
+ GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ service_name,
+ "DISABLEV6") ) )
disablev6 = GNUNET_YES;
port = 0;
if (GNUNET_CONFIGURATION_have_value (cfg,
- service_name,
- "PORT"))
+ service_name,
+ "PORT"))
{
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- service_name,
- "PORT",
- &port))
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ service_name,
+ "PORT",
+ &port))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Require valid port number for service `%s' in configuration!\n"),
+ _ ("Require valid port number for service `%s' in configuration!\n"),
service_name);
}
if (port > 65535)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Require valid port number for service `%s' in configuration!\n"),
+ _ ("Require valid port number for service `%s' in configuration!\n"),
service_name);
return GNUNET_SYSERR;
}
}
if (GNUNET_CONFIGURATION_have_value (cfg,
- service_name,
- "BINDTO"))
+ service_name,
+ "BINDTO"))
{
GNUNET_break (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg,
- service_name,
+ service_name,
"BINDTO",
- &hostname));
+ &hostname));
}
else
hostname = NULL;
#ifdef AF_UNIX
if ((GNUNET_YES ==
GNUNET_CONFIGURATION_have_value (cfg,
- service_name,
- "UNIXPATH")) &&
+ service_name,
+ "UNIXPATH")) &&
(GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_filename (cfg,
- service_name,
- "UNIXPATH",
- &unixpath)) &&
+ service_name,
+ "UNIXPATH",
+ &unixpath)) &&
(0 < strlen (unixpath)))
{
/* probe UNIX support */
if (strlen (unixpath) >= sizeof (s_un.sun_path))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("UNIXPATH `%s' too long, maximum length is %llu\n"),
- unixpath,
+ _ ("UNIXPATH `%s' too long, maximum length is %llu\n"),
+ unixpath,
(unsigned long long) sizeof (s_un.sun_path));
unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Using `%s' instead\n"),
+ _ ("Using `%s' instead\n"),
unixpath);
}
#ifdef LINUX
abstract = GNUNET_NO;
#endif
if ( (GNUNET_YES != abstract) &&
- (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (unixpath)) )
+ (GNUNET_OK !=
+ GNUNET_DISK_directory_create_for_file (unixpath)) )
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "mkdir",
- unixpath);
+ "mkdir",
+ unixpath);
}
if (NULL != unixpath)
{
desc = GNUNET_NETWORK_socket_create (AF_UNIX,
- SOCK_STREAM,
- 0);
+ SOCK_STREAM,
+ 0);
if (NULL == desc)
{
if ((ENOBUFS == errno) ||
- (ENOMEM == errno) ||
- (ENFILE == errno) ||
+ (ENOMEM == errno) ||
+ (ENFILE == errno) ||
(EACCES == errno))
{
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "socket");
+ "socket");
GNUNET_free_non_null (hostname);
GNUNET_free (unixpath);
return GNUNET_SYSERR;
}
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
+ _ (
+ "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
service_name,
STRERROR (errno));
GNUNET_free (unixpath);
else
{
GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (desc));
+ GNUNET_NETWORK_socket_close (desc));
desc = NULL;
}
}
if ((0 == port) && (NULL == unixpath))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
+ _ (
+ "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
service_name);
GNUNET_free_non_null (hostname);
return GNUNET_SYSERR;
if (0 == port)
{
saddrs = GNUNET_new_array (2,
- struct sockaddr *);
+ struct sockaddr *);
saddrlens = GNUNET_new_array (2,
- socklen_t);
+ socklen_t);
add_unixpath (saddrs,
- saddrlens,
- unixpath,
- abstract);
+ saddrlens,
+ unixpath,
+ abstract);
GNUNET_free_non_null (unixpath);
GNUNET_free_non_null (hostname);
*addrs = saddrs;
hostname,
service_name);
memset (&hints,
- 0,
- sizeof (struct addrinfo));
+ 0,
+ sizeof (struct addrinfo));
if (disablev6)
hints.ai_family = AF_INET;
hints.ai_protocol = IPPROTO_TCP;
if ((0 != (ret = getaddrinfo (hostname,
- NULL,
- &hints,
- &res))) ||
+ NULL,
+ &hints,
+ &res))) ||
(NULL == res))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to resolve `%s': %s\n"),
+ _ ("Failed to resolve `%s': %s\n"),
hostname,
gai_strerror (ret));
GNUNET_free (hostname);
{
next = pos->ai_next;
if ( (disablev6) &&
- (pos->ai_family == AF_INET6) )
+ (pos->ai_family == AF_INET6) )
continue;
i++;
}
if (0 == i)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to find %saddress for `%s'.\n"),
+ _ ("Failed to find %saddress for `%s'.\n"),
disablev6 ? "IPv4 " : "",
hostname);
freeaddrinfo (res);
if (NULL != unixpath)
resi++;
saddrs = GNUNET_new_array (resi + 1,
- struct sockaddr *);
+ struct sockaddr *);
saddrlens = GNUNET_new_array (resi + 1,
- socklen_t);
+ socklen_t);
i = 0;
if (NULL != unixpath)
{
add_unixpath (saddrs,
- saddrlens,
- unixpath,
- abstract);
+ saddrlens,
+ unixpath,
+ abstract);
i++;
}
next = res;
{
next = pos->ai_next;
if ( (disablev6) &&
- (AF_INET6 == pos->ai_family) )
+ (AF_INET6 == pos->ai_family) )
continue;
if ( (IPPROTO_TCP != pos->ai_protocol) &&
- (0 != pos->ai_protocol) )
+ (0 != pos->ai_protocol) )
continue; /* not TCP */
if ( (SOCK_STREAM != pos->ai_socktype) &&
- (0 != pos->ai_socktype) )
+ (0 != pos->ai_socktype) )
continue; /* huh? */
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Service `%s' will bind to `%s'\n",
+ "Service `%s' will bind to `%s'\n",
service_name,
- GNUNET_a2s (pos->ai_addr,
- pos->ai_addrlen));
+ GNUNET_a2s (pos->ai_addr,
+ pos->ai_addrlen));
if (AF_INET == pos->ai_family)
{
GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen);
saddrlens[i] = pos->ai_addrlen;
saddrs[i] = GNUNET_malloc (saddrlens[i]);
GNUNET_memcpy (saddrs[i],
- pos->ai_addr,
- saddrlens[i]);
+ pos->ai_addr,
+ saddrlens[i]);
((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
}
else
saddrlens[i] = pos->ai_addrlen;
saddrs[i] = GNUNET_malloc (saddrlens[i]);
GNUNET_memcpy (saddrs[i],
- pos->ai_addr,
- saddrlens[i]);
+ pos->ai_addr,
+ saddrlens[i]);
((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
}
i++;
resi++;
i = 0;
saddrs = GNUNET_new_array (resi + 1,
- struct sockaddr *);
+ struct sockaddr *);
saddrlens = GNUNET_new_array (resi + 1,
- socklen_t);
+ socklen_t);
if (NULL != unixpath)
{
add_unixpath (saddrs,
- saddrlens,
- unixpath,
- abstract);
+ saddrlens,
+ unixpath,
+ abstract);
i++;
}
saddrlens[i] = sizeof (struct sockaddr_in);
if (NULL != unixpath)
resi++;
saddrs = GNUNET_new_array (resi + 1,
- struct sockaddr *);
+ struct sockaddr *);
saddrlens = GNUNET_new_array (resi + 1,
- socklen_t);
+ socklen_t);
i = 0;
if (NULL != unixpath)
{
add_unixpath (saddrs,
- saddrlens,
- unixpath,
- abstract);
+ saddrlens,
+ unixpath,
+ abstract);
i++;
}
saddrlens[i] = sizeof (struct sockaddr_in6);
* to create a GNUnet API that boxes a HANDLE (the way it is done with socks)
*/
lsocks_pipe = (HANDLE) strtoul (env_buf,
- NULL,
- 10);
+ NULL,
+ 10);
if ( (0 == lsocks_pipe) ||
(INVALID_HANDLE_VALUE == lsocks_pipe))
return NULL;
DWORD rd;
ret = ReadFile (lsocks_pipe,
- &count,
- sizeof (count),
- &rd,
- NULL);
+ &count,
+ sizeof (count),
+ &rd,
+ NULL);
if ( (0 == ret) ||
- (sizeof (count) != rd) ||
- (0 == count) )
+ (sizeof (count) != rd) ||
+ (0 == count) )
break;
lsocks = GNUNET_new_array (count + 1,
- struct GNUNET_NETWORK_Handle *);
+ struct GNUNET_NETWORK_Handle *);
fail2 = 1;
for (i = 0; i < count; i++)
SOCKET s;
ret = ReadFile (lsocks_pipe,
- &size,
- sizeof (size),
- &rd,
- NULL);
+ &size,
+ sizeof (size),
+ &rd,
+ NULL);
if ( (0 == ret) ||
- (sizeof (size) != rd) ||
- (sizeof (pi) != size) )
+ (sizeof (size) != rd) ||
+ (sizeof (pi) != size) )
break;
ret = ReadFile (lsocks_pipe,
- &pi,
- sizeof (pi),
- &rd,
- NULL);
+ &pi,
+ sizeof (pi),
+ &rd,
+ NULL);
if ( (0 == ret) ||
- (sizeof (pi) != rd))
+ (sizeof (pi) != rd))
break;
s = WSASocketA (pi.iAddressFamily,
- pi.iSocketType,
- pi.iProtocol,
- &pi,
- 0,
- WSA_FLAG_OVERLAPPED);
+ pi.iSocketType,
+ pi.iProtocol,
+ &pi,
+ 0,
+ WSA_FLAG_OVERLAPPED);
lsocks[i] = GNUNET_NETWORK_socket_box_native (s);
if (NULL == lsocks[i])
break;
if (fail)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Could not access a pre-bound socket, will try to bind myself\n"));
+ _ ("Could not access a pre-bound socket, will try to bind myself\n"));
for (i = 0; (i < count) && (NULL != lsocks[i]); i++)
GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (lsocks[i]));
+ GNUNET_NETWORK_socket_close (lsocks[i]));
GNUNET_free (lsocks);
return NULL;
}
*/
static struct GNUNET_NETWORK_Handle *
open_listen_socket (const struct sockaddr *server_addr,
- socklen_t socklen)
+ socklen_t socklen)
{
struct GNUNET_NETWORK_Handle *sock;
uint16_t port;
break;
}
sock = GNUNET_NETWORK_socket_create (server_addr->sa_family,
- SOCK_STREAM,
- 0);
+ SOCK_STREAM,
+ 0);
if (NULL == sock)
{
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "socket");
+ "socket");
errno = 0;
return NULL;
}
/* bind the socket */
if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock,
- server_addr,
- socklen))
+ server_addr,
+ socklen))
{
eno = errno;
if (EADDRINUSE != errno)
* fail if we already took the port on IPv6; if both IPv4 and
* IPv6 binds fail, then our caller will log using the
* errno preserved in 'eno' */
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "bind");
if (0 != port)
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed for port %d (%s).\n"),
+ _ ("`%s' failed for port %d (%s).\n"),
"bind",
port,
(AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
+ else
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
+ "bind");
eno = 0;
}
else
{
if (0 != port)
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("`%s' failed for port %d (%s): address already in use\n"),
+ _ ("`%s' failed for port %d (%s): address already in use\n"),
"bind", port,
(AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
else if (AF_UNIX == server_addr->sa_family)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("`%s' failed for `%s': address already in use\n"),
+ _ ("`%s' failed for `%s': address already in use\n"),
"bind",
GNUNET_a2s (server_addr, socklen));
}
}
GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (sock));
+ GNUNET_NETWORK_socket_close (sock));
errno = eno;
return NULL;
}
if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock,
- 5))
+ 5))
{
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
"listen");
GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (sock));
+ GNUNET_NETWORK_socket_close (sock));
errno = 0;
return NULL;
}
#endif
if (GNUNET_CONFIGURATION_have_value
- (sh->cfg,
- sh->service_name,
- "TOLERANT"))
+ (sh->cfg,
+ sh->service_name,
+ "TOLERANT"))
{
if (GNUNET_SYSERR ==
(tolerant =
- GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
- sh->service_name,
- "TOLERANT")))
+ GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
+ sh->service_name,
+ "TOLERANT")))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Specified value for `%s' of service `%s' is invalid\n"),
+ _ ("Specified value for `%s' of service `%s' is invalid\n"),
"TOLERANT",
- sh->service_name);
+ sh->service_name);
return GNUNET_SYSERR;
}
}
errno = 0;
if ( (NULL != (nfds = getenv ("LISTEN_FDS"))) &&
(1 == SSCANF (nfds,
- "%u%1s",
- &cnt,
- dummy)) &&
+ "%u%1s",
+ &cnt,
+ dummy)) &&
(cnt > 0) &&
(cnt < FD_SETSIZE) &&
(cnt + 4 < FD_SETSIZE) )
{
lsocks = GNUNET_new_array (cnt + 1,
- struct GNUNET_NETWORK_Handle *);
+ struct GNUNET_NETWORK_Handle *);
while (0 < cnt--)
{
flags = fcntl (3 + cnt,
- F_GETFD);
+ F_GETFD);
if ( (flags < 0) ||
- (0 != (flags & FD_CLOEXEC)) ||
- (NULL ==
- (lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
+ (0 != (flags & FD_CLOEXEC)) ||
+ (NULL ==
+ (lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Could not access pre-bound socket %u, will try to bind myself\n"),
+ _ (
+ "Could not access pre-bound socket %u, will try to bind myself\n"),
(unsigned int) 3 + cnt);
cnt++;
while (NULL != lsocks[cnt])
GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (lsocks[cnt++]));
+ GNUNET_NETWORK_socket_close (lsocks[cnt++]));
GNUNET_free (lsocks);
lsocks = NULL;
break;
slc->sh = sh;
slc->listen_socket = *ls;
GNUNET_CONTAINER_DLL_insert (sh->slc_head,
- sh->slc_tail,
- slc);
+ sh->slc_tail,
+ slc);
}
GNUNET_free (lsocks);
}
int num;
num = get_server_addresses (sh->service_name,
- sh->cfg,
- &addrs,
- &addrlens);
+ sh->cfg,
+ &addrs,
+ &addrlens);
if (GNUNET_SYSERR == num)
return GNUNET_SYSERR;
slc = GNUNET_new (struct ServiceListenContext);
slc->sh = sh;
slc->listen_socket = open_listen_socket (addrs[i],
- addrlens[i]);
+ addrlens[i]);
GNUNET_free (addrs[i]);
if (NULL == slc->listen_socket)
{
continue;
}
GNUNET_CONTAINER_DLL_insert (sh->slc_head,
- sh->slc_tail,
- slc);
+ sh->slc_tail,
+ slc);
}
GNUNET_free_non_null (addrlens);
GNUNET_free_non_null (addrs);
{
/* All attempts to bind failed, hard failure */
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not bind to any of the ports I was supposed to, refusing to run!\n"));
+ _ (
+ "Could not bind to any of the ports I was supposed to, refusing to run!\n"));
return GNUNET_SYSERR;
}
}
sh->require_found = tolerant ? GNUNET_NO : GNUNET_YES;
sh->match_uid
= GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
- sh->service_name,
+ sh->service_name,
"UNIX_MATCH_UID");
sh->match_gid
= GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
- sh->service_name,
+ sh->service_name,
"UNIX_MATCH_GID");
process_acl4 (&sh->v4_denied,
- sh,
- "REJECT_FROM");
+ sh,
+ "REJECT_FROM");
process_acl4 (&sh->v4_allowed,
- sh,
- "ACCEPT_FROM");
+ sh,
+ "ACCEPT_FROM");
process_acl6 (&sh->v6_denied,
- sh,
- "REJECT_FROM6");
+ sh,
+ "REJECT_FROM6");
process_acl6 (&sh->v6_allowed,
- sh,
- "ACCEPT_FROM6");
+ sh,
+ "ACCEPT_FROM6");
return GNUNET_OK;
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
- sh->service_name,
+ sh->service_name,
"USERNAME",
- &un))
+ &un))
return NULL;
return un;
}
if (NULL == pws)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Cannot obtain information about user `%s': %s\n"),
- user,
- errno == 0 ? _("No such user") : STRERROR (errno));
+ _ ("Cannot obtain information about user `%s': %s\n"),
+ user,
+ errno == 0 ? _ ("No such user") : STRERROR (errno));
GNUNET_free (user);
return GNUNET_SYSERR;
}
(0 != setegid (pws->pw_gid)) ||
#if HAVE_INITGROUPS
(0 != initgroups (user,
- pws->pw_gid)) ||
+ pws->pw_gid)) ||
#endif
(0 != setuid (pws->pw_uid)) ||
(0 != seteuid (pws->pw_uid)))
{
if ((0 != setregid (pws->pw_gid,
- pws->pw_gid)) ||
+ pws->pw_gid)) ||
(0 != setreuid (pws->pw_uid,
- pws->pw_uid)))
+ pws->pw_uid)))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Cannot change user/group to `%s': %s\n"),
+ _ ("Cannot change user/group to `%s': %s\n"),
user,
- STRERROR (errno));
+ STRERROR (errno));
GNUNET_free (user);
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
- sh->service_name,
+ sh->service_name,
"PIDFILE",
- &pif))
+ &pif))
return NULL;
return pif;
}
return; /* no PID file */
if (0 != UNLINK (pif))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- pif);
+ "unlink",
+ pif);
GNUNET_free (pif);
}
if (0 != PIPE (filedes))
{
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "pipe");
+ "pipe");
return GNUNET_SYSERR;
}
pid = fork ();
if (pid < 0)
{
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "fork");
+ "fork");
return GNUNET_SYSERR;
}
if (0 != pid)
GNUNET_break (0 == CLOSE (filedes[1]));
c = 'X';
if (1 != READ (filedes[0],
- &c,
- sizeof (char)))
+ &c,
+ sizeof (char)))
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "read");
+ "read");
fflush (stdout);
switch (c)
{
exit (0);
case 'I':
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Service process failed to initialize\n"));
+ _ ("Service process failed to initialize\n"));
break;
case 'S':
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Service process could not initialize server function\n"));
+ _ ("Service process could not initialize server function\n"));
break;
case 'X':
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Service process failed to report status\n"));
+ _ ("Service process failed to report status\n"));
break;
}
exit (1); /* child reported error */
GNUNET_break (0 == CLOSE (1));
GNUNET_break (0 == CLOSE (filedes[0]));
nullfd = OPEN ("/dev/null",
- O_RDWR | O_APPEND);
+ O_RDWR | O_APPEND);
if (nullfd < 0)
return GNUNET_SYSERR;
/* set stdin/stdout to /dev/null */
(dup2 (nullfd, 1) < 0) )
{
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "dup2");
+ "dup2");
(void) CLOSE (nullfd);
return GNUNET_SYSERR;
}
pid = setsid ();
if (-1 == pid)
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "setsid");
+ "setsid");
sh->ready_confirm_fd = filedes[1];
#else
/* FIXME: we probably need to do something else
if (NULL != slc->listen_task)
GNUNET_SCHEDULER_cancel (slc->listen_task);
GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (slc->listen_socket));
+ GNUNET_NETWORK_socket_close (slc->listen_socket));
GNUNET_free (slc);
}
}
slen);
mq = GNUNET_SERVICE_client_get_mq (client);
GNUNET_MQ_send (mq,
- env);
+ env);
GNUNET_SERVICE_client_continue (client);
}
GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
GNUNET_GETOPT_option_flag ('d',
"daemonize",
- gettext_noop ("do daemonize (detach from terminal)"),
+ gettext_noop (
+ "do daemonize (detach from terminal)"),
&do_daemonize),
GNUNET_GETOPT_option_help (NULL),
GNUNET_GETOPT_option_loglevel (&loglev),
err = 1;
memset (&sh,
- 0,
- sizeof (sh));
+ 0,
+ sizeof (sh));
xdg = getenv ("XDG_CONFIG_HOME");
if (NULL != xdg)
GNUNET_asprintf (&cfg_filename,
DIR_SEPARATOR_STR,
GNUNET_OS_project_data_get ()->config_file);
else
- cfg_filename = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
+ cfg_filename = GNUNET_strdup (
+ GNUNET_OS_project_data_get ()->user_config_file);
sh.ready_confirm_fd = -1;
sh.options = options;
sh.cfg = cfg = GNUNET_CONFIGURATION_create ();
opt_cfg_filename = NULL;
do_daemonize = 0;
ret = GNUNET_GETOPT_run (service_name,
- service_options,
- argc,
- argv);
+ service_options,
+ argc,
+ argv);
if (GNUNET_SYSERR == ret)
goto shutdown;
if (GNUNET_NO == ret)
goto shutdown;
}
if (GNUNET_OK != GNUNET_log_setup (service_name,
- loglev,
- logfile))
+ loglev,
+ logfile))
{
GNUNET_break (0);
goto shutdown;
if (NULL != opt_cfg_filename)
{
if ( (GNUNET_YES !=
- GNUNET_DISK_file_test (opt_cfg_filename)) ||
- (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (cfg,
- opt_cfg_filename)) )
+ GNUNET_DISK_file_test (opt_cfg_filename)) ||
+ (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_load (cfg,
+ opt_cfg_filename)) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Malformed configuration file `%s', exit ...\n"),
- opt_cfg_filename);
+ _ ("Malformed configuration file `%s', exit ...\n"),
+ opt_cfg_filename);
goto shutdown;
}
}
else
{
if (GNUNET_YES ==
- GNUNET_DISK_file_test (cfg_filename))
+ GNUNET_DISK_file_test (cfg_filename))
{
if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (cfg,
- cfg_filename))
+ GNUNET_CONFIGURATION_load (cfg,
+ cfg_filename))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Malformed configuration file `%s', exit ...\n"),
- cfg_filename);
- goto shutdown;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Malformed configuration file `%s', exit ...\n"),
+ cfg_filename);
+ goto shutdown;
}
}
else
{
if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (cfg,
- NULL))
+ GNUNET_CONFIGURATION_load (cfg,
+ NULL))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Malformed configuration, exit ...\n"));
- goto shutdown;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Malformed configuration, exit ...\n"));
+ goto shutdown;
}
}
}
(NULL != opt_cfg_filename) ? opt_cfg_filename : cfg_filename);
if ((GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_number (sh.cfg,
- "TESTING",
+ "TESTING",
"SKEW_OFFSET",
- &skew_offset)) &&
+ &skew_offset)) &&
(GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_number (sh.cfg,
- "TESTING",
+ "TESTING",
"SKEW_VARIANCE",
- &skew_variance)))
+ &skew_variance)))
{
clock_offset = skew_offset - skew_variance;
GNUNET_TIME_set_offset (clock_offset);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Skewing clock by %dll ms\n",
- clock_offset);
+ "Skewing clock by %dll ms\n",
+ clock_offset);
}
GNUNET_RESOLVER_connect (sh.cfg);
/* actually run service */
err = 0;
GNUNET_SCHEDULER_run (&service_main,
- &sh);
+ &sh);
/* shutdown */
if (1 == do_daemonize)
pid_file_delete (&sh);
-shutdown:
+ shutdown:
if (-1 != sh.ready_confirm_fd)
{
if (1 != WRITE (sh.ready_confirm_fd,
- err ? "I" : "S",
- 1))
+ err ? "I" : "S",
+ 1))
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "write");
+ "write");
GNUNET_break (0 == CLOSE (sh.ready_confirm_fd));
}
#if HAVE_MALLINFO
char *counter;
if ( (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (sh.cfg,
- service_name,
- "GAUGER_HEAP")) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (sh.cfg,
- service_name,
- "GAUGER_HEAP",
- &counter)) )
+ GNUNET_CONFIGURATION_have_value (sh.cfg,
+ service_name,
+ "GAUGER_HEAP")) &&
+ (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (sh.cfg,
+ service_name,
+ "GAUGER_HEAP",
+ &counter)) )
{
struct mallinfo mi;
mi = mallinfo ();
GAUGER (service_name,
- counter,
- mi.usmblks,
- "blocks");
+ counter,
+ mi.usmblks,
+ "blocks");
GNUNET_free (counter);
}
}
c->recv_task = NULL;
/* first, check if there is still something in the buffer */
ret = GNUNET_MST_next (c->mst,
- GNUNET_YES);
+ GNUNET_YES);
if (GNUNET_SYSERR == ret)
{
if (NULL == c->drop_task)
return;
c->recv_task
= GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- c->sock,
- &service_client_recv,
- c);
+ c->sock,
+ &service_client_recv,
+ c);
}
}
c->recv_task
= GNUNET_SCHEDULER_add_now (&resume_client_receive,
- c);
+ c);
}
if (GNUNET_NO == c->persist)
{
GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (c->sock));
+ GNUNET_NETWORK_socket_close (c->sock));
if ( (0 != (SUSPEND_STATE_EMFILE & sh->suspend_state)) &&
(0 == (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)) )
do_resume (sh,
GNUNET_SERVICE_client_mark_monitor (struct GNUNET_SERVICE_Client *c)
{
c->is_monitor = GNUNET_YES;
- if ( (0 != (SUSPEND_STATE_SHUTDOWN & c->sh->suspend_state) &&
+ if ( ((0 != (SUSPEND_STATE_SHUTDOWN & c->sh->suspend_state))&&
(GNUNET_NO == have_non_monitor_clients (c->sh)) ) )
GNUNET_SERVICE_shutdown (c->sh);
}