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

« back to all changes in this revision

Viewing changes to source/libs/uti/sge_arch.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 this 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 this file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use this 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 this 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 <string.h>
 
34
#include <stdlib.h>
 
35
#include <stdio.h>
 
36
 
 
37
#include "sge_stdlib.h"
 
38
#include "sgermon.h"
 
39
#include "rmon.h"
 
40
#include "sge_log.h"
 
41
#include "sge.h"
 
42
#include "msg_utilib.h"
 
43
#include "msg_common.h"
 
44
#include "sge_unistd.h"
 
45
#include "sge_arch.h"
 
46
#include "sge_string.h"
 
47
 
 
48
/****** uti/prog/sge_get_arch() ************************************************
 
49
*  NAME
 
50
*     sge_get_arch() -- SGE/EE architecture string
 
51
*
 
52
*  SYNOPSIS
 
53
*     const char* sge_get_arch(void) 
 
54
*
 
55
*  FUNCTION
 
56
*     This function returns the SGE/EE architecture string of that
 
57
*     host where the application is running which called this 
 
58
*     functionon.
 
59
*
 
60
*  NOTES:
 
61
*     MT-NOTE: sge_get_arch() is MT safe
 
62
*
 
63
*  RESULT
 
64
*     const char* - architecture string
 
65
******************************************************************************/
 
66
const char *sge_get_arch(void)
 
67
{
 
68
#ifndef SGE_ARCH_STRING
 
69
#   pragma "Define an architecture for SGE"
 
70
#endif
 
71
 
 
72
#define xstr(s) str(s)
 
73
#define str(s) #s
 
74
 
 
75
   return xstr(SGE_ARCH_STRING);
 
76
}
 
77
 
 
78
/****** uti/prog/sge_get_root_dir() *******************************************
 
79
*  NAME
 
80
*     sge_get_root_dir() -- SGE/SGEEE installation directory 
 
81
*
 
82
*  SYNOPSIS
 
83
*     const char* sge_get_root_dir(int do_exit, 
 
84
*                                  char *buffer, 
 
85
*                                  size_t size,
 
86
*                                  int do_error_log ) 
 
87
*
 
88
*  FUNCTION
 
89
*     This function returns the installation directory of SGE/SGEEE.
 
90
*     This directory is defined by the SGE_ROOT environment variable 
 
91
*     of the calling process. 
 
92
*     If the environment variable does not exist or is not set then
 
93
*     this function will handle this as error and return NULL 
 
94
*     (do_exit = 0). If 'do_exit' is 1 and an error occures, the 
 
95
*     function will terminate the  calling application.
 
96
*
 
97
*  INPUTS
 
98
*     int do_exit - Terminate the application in case of an error
 
99
*     char *buffer - buffer to be used for error message
 
100
*     size_t size - size of buffer
 
101
*     int do_error_log - enable/disable error logging
 
102
*
 
103
*  RESULT
 
104
*     const char* - Root directory of the SGE/SGEEE installation
 
105
*
 
106
*  NOTES
 
107
*     MT-NOTE: sge_get_arch() is MT safe
 
108
*******************************************************************************/
 
109
const char *sge_get_root_dir(int do_exit, char *buffer, size_t size, int do_error_log)
 
110
{
 
111
   char *sge_root; 
 
112
   char *s;
 
113
 
 
114
   DENTER_(TOP_LAYER, "sge_get_root_dir");
 
115
 
 
116
   /*
 
117
    * Read some env variables
 
118
    */
 
119
   sge_root = getenv("SGE_ROOT");
 
120
 
 
121
   /*
 
122
    * Check the env variables
 
123
    */
 
124
   if (sge_root) {
 
125
      s = sge_root;
 
126
   } else {
 
127
      goto error;
 
128
   } 
 
129
   if (!s || strlen(s)==0) { 
 
130
      goto error;
 
131
   } else {
 
132
      /*
 
133
       * Get rid of trailing slash
 
134
       */ 
 
135
      if (s[strlen(s)-1] == '/') { 
 
136
         s[strlen(s)-1] = '\0';
 
137
      }
 
138
   }
 
139
   DRETURN_(s);
 
140
 
 
141
error:
 
142
   if (do_error_log) {
 
143
      if (buffer != NULL) {
 
144
         sge_strlcpy(buffer, MSG_SGEROOTNOTSET, size);
 
145
      } else {
 
146
         CRITICAL((SGE_EVENT, MSG_SGEROOTNOTSET));
 
147
      }
 
148
   }
 
149
 
 
150
   DEXIT_;
 
151
   if (do_exit) {
 
152
      SGE_EXIT(NULL, 1);   
 
153
   }
 
154
   return NULL;
 
155
}
 
156
 
 
157
/****** uti/prog/sge_get_default_cell() ***************************************
 
158
*  NAME
 
159
*     sge_get_default_cell() -- get cell name and remove trailing slash 
 
160
*
 
161
*  SYNOPSIS
 
162
*     const char* sge_get_default_cell(void) 
 
163
*
 
164
*  FUNCTION
 
165
*     This function returns the defined cell name of SGE/SGEEE.
 
166
*     This directory is defined by the SGE_CELL environment variable
 
167
*     of the calling process.
 
168
*     If the environment variable does not exist or is not set then
 
169
*     this function will return the 'DEFAULT_CELL'.
 
170
*
 
171
*  RESULT
 
172
*     const char* - Cell name of this SGE/SGEEE installation
 
173
*
 
174
*  NOTES
 
175
*     MT-NOTE: sge_get_default_cell() is MT safe
 
176
******************************************************************************/
 
177
const char *sge_get_default_cell(void)
 
178
{
 
179
   char *sge_cell;
 
180
   char *s;
 
181
 
 
182
   DENTER_(TOP_LAYER, "sge_get_default_cell");
 
183
   /*
 
184
    * Read some env variables
 
185
    */
 
186
   sge_cell = getenv("SGE_CELL");
 
187
 
 
188
   /*
 
189
    * Check the env variables
 
190
    */
 
191
   if (sge_cell) {
 
192
      s = sge_cell;
 
193
   } else {
 
194
      s = NULL;
 
195
   } 
 
196
 
 
197
   /*
 
198
    * Use default? 
 
199
    */     
 
200
   if (!s || strlen(s) == 0) {
 
201
      s = DEFAULT_CELL;
 
202
   } else {
 
203
      /*
 
204
       * Get rid of trailing slash
 
205
       */    
 
206
      if (s[strlen(s)-1] == '/') {
 
207
         s[strlen(s)-1] = '\0';
 
208
      }
 
209
   }
 
210
   DRETURN_(s);
 
211
}
 
212
 
 
213
/****** uti/prog/sge_get_alias_path() *****************************************
 
214
*  NAME
 
215
*     sge_get_alias_path() -- Return the path of the 'alias_file' 
 
216
*
 
217
*  SYNOPSIS
 
218
*     const char* sge_get_alias_path(void) 
 
219
*
 
220
*  FUNCTION
 
221
*     Return the path of the 'alias_file' 
 
222
*
 
223
*  NOTES
 
224
*     MT-NOTE: sge_get_alias_path() is MT safe
 
225
*
 
226
******************************************************************************/
 
227
const char *sge_get_alias_path(void) 
 
228
{
 
229
   const char *sge_root, *sge_cell;
 
230
   char *cp;
 
231
   int len;
 
232
   SGE_STRUCT_STAT sbuf;
 
233
 
 
234
   DENTER_(TOP_LAYER, "sge_get_alias_path");
 
235
 
 
236
   sge_root = sge_get_root_dir(1, NULL, 0, 1);
 
237
   sge_cell = sge_get_default_cell();
 
238
 
 
239
   if (SGE_STAT(sge_root, &sbuf)) {
 
240
      CRITICAL((SGE_EVENT, MSG_SGETEXT_SGEROOTNOTFOUND_S , sge_root));
 
241
      SGE_EXIT(NULL, 1);
 
242
   }
 
243
 
 
244
   len = strlen(sge_root) + strlen(sge_cell) + strlen(COMMON_DIR) + strlen(ALIAS_FILE) + 5;
 
245
   if (!(cp = malloc(len))) {
 
246
      CRITICAL((SGE_EVENT, MSG_MEMORY_MALLOCFAILEDFORPATHTOHOSTALIASFILE ));
 
247
      SGE_EXIT(NULL, 1);
 
248
   }
 
249
 
 
250
   sprintf(cp, "%s/%s/%s/%s", sge_root, sge_cell, COMMON_DIR, ALIAS_FILE);
 
251
   DRETURN_(cp);
 
252
}