X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e3e2024b794b44875934f421a156dcc7fcfd7341..0f5e8daaa6e9f74521068aa75837200bcd182ea6:/src/gras/Virtu/rl_process.c diff --git a/src/gras/Virtu/rl_process.c b/src/gras/Virtu/rl_process.c index 13b37571b3..e6a6672f6a 100644 --- a/src/gras/Virtu/rl_process.c +++ b/src/gras/Virtu/rl_process.c @@ -1,13 +1,12 @@ -/* $Id$ */ - /* process_rl - GRAS process handling on real life */ -/* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved. */ +/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team. + * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "gras_modinter.h" /* module initialization interface */ +#include "gras_modinter.h" /* module initialization interface */ #include "gras/Virtu/virtu_rl.h" #include "portable.h" @@ -19,47 +18,67 @@ XBT_EXPORT_NO_IMPORT(char const *) _gras_procname = NULL; static xbt_dict_t _process_properties = NULL; static xbt_dict_t _host_properties = NULL; -/* the environment, as specified by the opengroup, used to initialize the process properties */ -extern char **environ; +# ifdef __APPLE__ + /* under darwin, the environment gets added to the process at startup time. So, it's not defined at library link time, forcing us to extra tricks */ +# include +# define environ (*_NSGetEnviron()) +# else +#ifdef _XBT_WIN32 + /* the environment, as specified by the opengroup, used to initialize the process properties */ +extern char **wenviron; +#else +extern char **environ; +#endif +# endif -void gras_process_init() { +void gras_process_init() +{ char **env_iter; - _gras_procdata=xbt_new0(gras_procdata_t,1); + _gras_procdata = xbt_new0(gras_procdata_t, 1); gras_procdata_init(); - + /* initialize the host & process properties */ _host_properties = xbt_dict_new(); _process_properties = xbt_dict_new(); env_iter = environ; while (*env_iter) { - char *equal, *buf = xbt_strdup(*env_iter); - equal = strchr(buf, '='); - if (!equal) { - WARN1("The environment contains an entry without '=' char: %s (ignore it)",*env_iter); - continue; - } - *equal = '\0'; - xbt_dict_set(_process_properties,buf,xbt_strdup(equal + 1),xbt_free_f); - free(buf); - env_iter++; - } + char *equal, *buf = xbt_strdup(*env_iter); + equal = strchr(buf, '='); + if (!equal) { + WARN1 + ("The environment contains an entry without '=' char: %s (ignore it)", + *env_iter); + continue; + } + *equal = '\0'; + xbt_dict_set(_process_properties, buf, xbt_strdup(equal + 1), + xbt_free_f); + free(buf); + env_iter++; + } } -void gras_process_exit() { + +void gras_process_exit() +{ gras_procdata_exit(); free(_gras_procdata); xbt_dict_free(&_process_properties); } -const char *xbt_procname(void) { - if(_gras_procname) return _gras_procname; - else return ""; +const char *xbt_procname(void) +{ + if (_gras_procname) + return _gras_procname; + else + return ""; } -int gras_os_getpid(void) { -#ifdef _WIN32 - return (long int) GetCurrentProcessId(); +int gras_os_getpid(void) +{ +#ifdef _XBT_WIN32 + return (long int) GetCurrentProcessId(); #else - return (long int) getpid(); + return (long int) getpid(); #endif } @@ -67,31 +86,40 @@ int gras_os_getpid(void) { * Process data * **************************************************************************/ -gras_procdata_t *gras_procdata_get(void) { - xbt_assert0(_gras_procdata,"Run gras_process_init (ie, gras_init)!"); +gras_procdata_t *gras_procdata_get(void) +{ + xbt_assert0(_gras_procdata, "Run gras_process_init (ie, gras_init)!"); return _gras_procdata; } -void gras_agent_spawn(const char *name, void *data, - xbt_main_func_t code, int argc, char *argv[], xbt_dict_t properties) { - THROW_UNIMPLEMENTED; +void gras_agent_spawn(const char *name, void *data, + xbt_main_func_t code, int argc, char *argv[], + xbt_dict_t properties) +{ + THROW_UNIMPLEMENTED; } /* ************************************************************************** * Properties * **************************************************************************/ -const char* gras_process_property_value(const char* name) { - return xbt_dict_get_or_null(_process_properties,name); +const char *gras_process_property_value(const char *name) +{ + return xbt_dict_get_or_null(_process_properties, name); } -xbt_dict_t gras_process_properties(void) { - return _process_properties; + +xbt_dict_t gras_process_properties(void) +{ + return _process_properties; } -const char* gras_os_host_property_value(const char* name) { - return xbt_dict_get_or_null(_host_properties,name); +const char *gras_os_host_property_value(const char *name) +{ + return xbt_dict_get_or_null(_host_properties, name); } -xbt_dict_t gras_os_host_properties(void) { - return _host_properties; + +xbt_dict_t gras_os_host_properties(void) +{ + return _host_properties; }