~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/uti/sge_env.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 * 
 
4
 *  The Contents of thiz file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 * 
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 * 
 
9
 * 
 
10
 *  Sun Industry Standards Source License Version 1.2
 
11
 *  =================================================
 
12
 *  The contents of thiz file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use thiz file
 
14
 *  except in compliance with the License. You may obtain a copy of the
 
15
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
16
 * 
 
17
 *  Software provided under thiz License is provided on an "AS IS" basis,
 
18
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
19
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
20
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
21
 *  See the License for the specific provisions governing your rights and
 
22
 *  obligations concerning the Software.
 
23
 * 
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 * 
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 * 
 
28
 *   All Rights Reserved.
 
29
 * 
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
 
 
33
#include <netdb.h>
 
34
#include <stdlib.h>
 
35
#include <stdio.h>
 
36
#include <string.h>
 
37
#include <pwd.h>
 
38
#include <errno.h>
 
39
#include <pthread.h>
 
40
#include <sys/types.h>
 
41
#include <sys/socket.h>  
 
42
 
 
43
#include "sge.h"
 
44
#include "sgermon.h"
 
45
#include "sge_hostname.h"
 
46
#include "sge_log.h"
 
47
#include "sge_stdlib.h"
 
48
#include "sge_string.h"
 
49
#include "sge_unistd.h"
 
50
#include "sge_answer.h"
 
51
 
 
52
#include "sge_env.h"
 
53
 
 
54
typedef struct {
 
55
   char*       sge_root;
 
56
   char*       sge_cell;
 
57
   u_long32    sge_qmaster_port;
 
58
   u_long32    sge_execd_port;
 
59
   bool        from_services;
 
60
   bool        qmaster_internal;
 
61
} sge_env_state_t;
 
62
 
 
63
static bool sge_env_state_setup(sge_env_state_class_t *thiz, 
 
64
                                const char *sge_root, 
 
65
                                const char *sge_cell, 
 
66
                                u_long32 sge_qmaster_port, 
 
67
                                u_long32 sge_execd_port, 
 
68
                                bool from_services,
 
69
                                bool is_qmaster_internal,
 
70
                                sge_error_class_t *eh);
 
71
static void sge_env_state_destroy(void *theState);
 
72
static void sge_env_state_dprintf(sge_env_state_class_t *thiz);
 
73
static const char* get_sge_root(sge_env_state_class_t *thiz);
 
74
static const char* get_sge_cell(sge_env_state_class_t *thiz);
 
75
static u_long32 get_sge_qmaster_port(sge_env_state_class_t *thiz);
 
76
static u_long32 get_sge_execd_port(sge_env_state_class_t *thiz);
 
77
static bool is_from_services(sge_env_state_class_t *thiz);
 
78
static bool is_qmaster_internal(sge_env_state_class_t *thiz);
 
79
static void set_sge_root(sge_env_state_class_t *thiz, const char *sge_root);
 
80
static void set_sge_cell(sge_env_state_class_t *thiz, const char *sge_cell);
 
81
static void set_from_services(sge_env_state_class_t *thiz, bool from_services);
 
82
static void set_qmaster_internal(sge_env_state_class_t *thiz, bool qmaster_internal);
 
83
static void set_sge_qmaster_port(sge_env_state_class_t *thiz, u_long32 sge_qmaster_port);
 
84
static void set_sge_execd_port(sge_env_state_class_t *thiz, u_long32 sge_qmaster_port);
 
85
 
 
86
sge_env_state_class_t *sge_env_state_class_create(const char *sge_root, const char *sge_cell, int sge_qmaster_port, int sge_execd_port, bool from_services, bool qmaster_internal, sge_error_class_t *eh)
 
87
{
 
88
   sge_env_state_class_t *ret = (sge_env_state_class_t *)sge_malloc(sizeof(sge_env_state_class_t));
 
89
 
 
90
   DENTER(TOP_LAYER, "sge_env_state_class_create");
 
91
   if (!ret) {
 
92
      eh->error(eh, STATUS_EMALLOC, ANSWER_QUALITY_ERROR, MSG_MEMORY_MALLOCFAILED);
 
93
      DEXIT;
 
94
      return NULL;
 
95
   }   
 
96
   
 
97
   ret->dprintf = sge_env_state_dprintf;
 
98
   
 
99
   ret->get_sge_root = get_sge_root;
 
100
   ret->get_sge_cell = get_sge_cell;
 
101
   ret->get_sge_qmaster_port = get_sge_qmaster_port;
 
102
   ret->get_sge_execd_port = get_sge_execd_port;
 
103
   ret->is_from_services = is_from_services;
 
104
   ret->is_qmaster_internal = is_qmaster_internal;
 
105
 
 
106
   ret->set_sge_root = set_sge_root;
 
107
   ret->set_sge_cell = set_sge_cell;
 
108
   ret->set_sge_qmaster_port = set_sge_qmaster_port;
 
109
   ret->set_sge_execd_port = set_sge_execd_port;
 
110
 
 
111
   ret->sge_env_state_handle = (sge_env_state_t*)sge_malloc(sizeof(sge_env_state_t));
 
112
   if (ret->sge_env_state_handle == NULL) {
 
113
      eh->error(eh, STATUS_EMALLOC, ANSWER_QUALITY_ERROR, MSG_MEMORY_MALLOCFAILED);
 
114
      sge_env_state_class_destroy(&ret);
 
115
      DEXIT;
 
116
      return NULL;
 
117
   }
 
118
   memset(ret->sge_env_state_handle, 0, sizeof(sge_env_state_t));
 
119
 
 
120
   if (!sge_env_state_setup(ret, sge_root, sge_cell, sge_qmaster_port, sge_execd_port, from_services, qmaster_internal, eh)) {
 
121
      sge_env_state_class_destroy(&ret);
 
122
      DEXIT;
 
123
      return NULL;
 
124
   }
 
125
 
 
126
   DEXIT;
 
127
   return ret;
 
128
}   
 
129
 
 
130
void sge_env_state_class_destroy(sge_env_state_class_t **pst)
 
131
{
 
132
   DENTER(TOP_LAYER, "sge_env_state_class_destroy");
 
133
 
 
134
   if (!pst || !*pst) {
 
135
      DEXIT;
 
136
      return;
 
137
   }   
 
138
   sge_env_state_destroy((*pst)->sge_env_state_handle);
 
139
   FREE(*pst);
 
140
   *pst = NULL;
 
141
   DEXIT;
 
142
}
 
143
 
 
144
static bool sge_env_state_setup(sge_env_state_class_t *thiz, const char *sge_root, const char *sge_cell, u_long32 sge_qmaster_port, u_long32 sge_execd_port, bool from_services, bool qmaster_internal, sge_error_class_t *eh)
 
145
{
 
146
   DENTER(TOP_LAYER, "sge_env_state_setup");
 
147
 
 
148
   thiz->set_sge_qmaster_port(thiz, sge_qmaster_port);
 
149
   thiz->set_sge_execd_port(thiz, sge_execd_port);
 
150
   thiz->set_sge_root(thiz, sge_root);
 
151
   thiz->set_sge_cell(thiz, sge_cell);
 
152
   set_from_services(thiz, from_services);
 
153
   set_qmaster_internal(thiz, qmaster_internal);
 
154
 
 
155
   /*thiz->dprintf(thiz);*/
 
156
 
 
157
   DEXIT;
 
158
   return true;
 
159
}
 
160
 
 
161
static void sge_env_state_destroy(void *theState)
 
162
{
 
163
   sge_env_state_t *s = (sge_env_state_t *)theState;
 
164
 
 
165
   DENTER(TOP_LAYER, "sge_env_state_destroy");
 
166
 
 
167
   FREE(s->sge_root);
 
168
   FREE(s->sge_cell);
 
169
   sge_free((char*)s);
 
170
 
 
171
   DEXIT;
 
172
}
 
173
 
 
174
static void sge_env_state_dprintf(sge_env_state_class_t *thiz)
 
175
{
 
176
   sge_env_state_t *es = (sge_env_state_t *)thiz->sge_env_state_handle;
 
177
 
 
178
   DENTER(TOP_LAYER, "sge_env_state_dprintf");
 
179
 
 
180
   DPRINTF(("sge_root            >%s<\n", es->sge_root ? es->sge_root : "NA"));
 
181
   DPRINTF(("sge_cell            >%s<\n", es->sge_cell ? es->sge_cell : "NA"));
 
182
   DPRINTF(("sge_qmaster_port    >%d<\n", es->sge_qmaster_port));
 
183
   DPRINTF(("sge_execd_port      >%d<\n", es->sge_execd_port));
 
184
   DPRINTF(("from_services       >%s<\n", es->from_services ? "true" : "false"));
 
185
   DPRINTF(("qmaster_internal    >%s<\n", es->qmaster_internal ? "true" : "false"));
 
186
 
 
187
   DEXIT;
 
188
}
 
189
 
 
190
static const char* get_sge_root(sge_env_state_class_t *thiz) 
 
191
{
 
192
   sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
 
193
   return es->sge_root;
 
194
}
 
195
 
 
196
static const char* get_sge_cell(sge_env_state_class_t *thiz) 
 
197
{
 
198
   sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
 
199
   return es->sge_cell;
 
200
}
 
201
 
 
202
static u_long32 get_sge_qmaster_port(sge_env_state_class_t *thiz)
 
203
{
 
204
   sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
 
205
   return es->sge_qmaster_port;
 
206
}
 
207
 
 
208
static u_long32 get_sge_execd_port(sge_env_state_class_t *thiz)
 
209
{
 
210
   sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
 
211
   return es->sge_execd_port;
 
212
}
 
213
 
 
214
static bool is_from_services(sge_env_state_class_t *thiz) 
 
215
{
 
216
   sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
 
217
   return es->from_services;
 
218
}
 
219
 
 
220
static bool is_qmaster_internal(sge_env_state_class_t *thiz) 
 
221
{
 
222
   sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
 
223
   return es->qmaster_internal;
 
224
}
 
225
 
 
226
static void set_sge_root(sge_env_state_class_t *thiz, const char *sge_root)
 
227
{
 
228
   sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
 
229
   es->sge_root = sge_strdup(es->sge_root, sge_root);
 
230
}
 
231
 
 
232
static void set_sge_cell(sge_env_state_class_t *thiz, const char *sge_cell)
 
233
{
 
234
   sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
 
235
   es->sge_cell = sge_strdup(es->sge_cell, sge_cell);
 
236
}
 
237
 
 
238
static void set_sge_qmaster_port(sge_env_state_class_t *thiz, u_long32 sge_qmaster_port)
 
239
{
 
240
   sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
 
241
   es->sge_qmaster_port = sge_qmaster_port; 
 
242
}
 
243
 
 
244
static void set_sge_execd_port(sge_env_state_class_t *thiz, u_long32 sge_execd_port)
 
245
{
 
246
   sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
 
247
   es->sge_execd_port = sge_execd_port; 
 
248
}
 
249
 
 
250
static void set_from_services(sge_env_state_class_t *thiz, bool from_services)
 
251
{
 
252
   sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
 
253
   es->from_services = from_services;
 
254
}
 
255
 
 
256
static void set_qmaster_internal(sge_env_state_class_t *thiz, bool qmaster_internal)
 
257
{
 
258
   sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
 
259
   es->qmaster_internal = qmaster_internal;
 
260
}
 
261