1 /* process_rl - GRAS process handling on real life */
3 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "gras_modinter.h" /* module initialization interface */
10 #include "gras/Virtu/virtu_rl.h"
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(gras_virtu_process);
16 static gras_procdata_t *_gras_procdata = NULL;
17 XBT_EXPORT_NO_IMPORT(char const *) _gras_procname = NULL;
18 static xbt_dict_t _process_properties = NULL;
19 static xbt_dict_t _host_properties = NULL;
22 /* 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 */
23 # include <crt_externs.h>
24 # define environ (*_NSGetEnviron())
26 /* the environment, as specified by the opengroup, used to initialize the process properties */
27 extern char **environ;
30 void gras_process_init()
33 _gras_procdata = xbt_new0(gras_procdata_t, 1);
36 /* initialize the host & process properties */
37 _host_properties = xbt_dict_new();
38 _process_properties = xbt_dict_new();
41 char *equal, *buf = xbt_strdup(*env_iter);
42 equal = strchr(buf, '=');
45 ("The environment contains an entry without '=' char: %s (ignore it)",
50 xbt_dict_set(_process_properties, buf, xbt_strdup(equal + 1), xbt_free_f);
56 void gras_process_exit()
60 xbt_dict_free(&_process_properties);
63 const char *xbt_procname(void)
66 return _gras_procname;
71 int gras_os_getpid(void)
74 return (long int) GetCurrentProcessId();
76 return (long int) getpid();
80 /* **************************************************************************
82 * **************************************************************************/
84 gras_procdata_t *gras_procdata_get(void)
86 xbt_assert0(_gras_procdata, "Run gras_process_init (ie, gras_init)!");
88 return _gras_procdata;
91 void gras_agent_spawn(const char *name, void *data,
92 xbt_main_func_t code, int argc, char *argv[],
93 xbt_dict_t properties)
98 /* **************************************************************************
100 * **************************************************************************/
102 const char *gras_process_property_value(const char *name)
104 return xbt_dict_get_or_null(_process_properties, name);
107 xbt_dict_t gras_process_properties(void)
109 return _process_properties;
112 const char *gras_os_host_property_value(const char *name)
114 return xbt_dict_get_or_null(_host_properties, name);
117 xbt_dict_t gras_os_host_properties(void)
119 return _host_properties;