Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Indent include and src using this command:
[simgrid.git] / src / gras / Virtu / rl_process.c
1 /* process_rl - GRAS process handling on real life                          */
2
3 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
4  * All rights reserved.                                                     */
5
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. */
8
9 #include "gras_modinter.h"      /* module initialization interface */
10 #include "gras/Virtu/virtu_rl.h"
11 #include "portable.h"
12
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(gras_virtu_process);
14
15 /* globals */
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;
20
21 # ifdef __APPLE__
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())
25 # else
26 #ifdef _XBT_WIN32
27                  /* the environment, as specified by the opengroup, used to initialize the process properties */
28 extern char **wenviron;
29 #else
30 extern char **environ;
31 #endif
32 # endif
33
34 void gras_process_init()
35 {
36   char **env_iter;
37   _gras_procdata = xbt_new0(gras_procdata_t, 1);
38   gras_procdata_init();
39
40   /* initialize the host & process properties */
41   _host_properties = xbt_dict_new();
42   _process_properties = xbt_dict_new();
43   env_iter = environ;
44   while (*env_iter) {
45     char *equal, *buf = xbt_strdup(*env_iter);
46     equal = strchr(buf, '=');
47     if (!equal) {
48       WARN1
49           ("The environment contains an entry without '=' char: %s (ignore it)",
50            *env_iter);
51       continue;
52     }
53     *equal = '\0';
54     xbt_dict_set(_process_properties, buf, xbt_strdup(equal + 1),
55                  xbt_free_f);
56     free(buf);
57     env_iter++;
58   }
59 }
60
61 void gras_process_exit()
62 {
63   gras_procdata_exit();
64   free(_gras_procdata);
65   xbt_dict_free(&_process_properties);
66 }
67
68 const char *xbt_procname(void)
69 {
70   if (_gras_procname)
71     return _gras_procname;
72   else
73     return "";
74 }
75
76 int gras_os_getpid(void)
77 {
78 #ifdef _XBT_WIN32
79   return (long int) GetCurrentProcessId();
80 #else
81   return (long int) getpid();
82 #endif
83 }
84
85 /* **************************************************************************
86  * Process data
87  * **************************************************************************/
88
89 gras_procdata_t *gras_procdata_get(void)
90 {
91   xbt_assert0(_gras_procdata, "Run gras_process_init (ie, gras_init)!");
92
93   return _gras_procdata;
94 }
95
96 void gras_agent_spawn(const char *name, void *data,
97                       xbt_main_func_t code, int argc, char *argv[],
98                       xbt_dict_t properties)
99 {
100   THROW_UNIMPLEMENTED;
101 }
102
103 /* **************************************************************************
104  * Properties
105  * **************************************************************************/
106
107 const char *gras_process_property_value(const char *name)
108 {
109   return xbt_dict_get_or_null(_process_properties, name);
110 }
111
112 xbt_dict_t gras_process_properties(void)
113 {
114   return _process_properties;
115 }
116
117 const char *gras_os_host_property_value(const char *name)
118 {
119   return xbt_dict_get_or_null(_host_properties, name);
120 }
121
122 xbt_dict_t gras_os_host_properties(void)
123 {
124   return _host_properties;
125 }