1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
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
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.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
37
#include "sge_stdlib.h"
42
#include "msg_utilib.h"
43
#include "msg_common.h"
44
#include "sge_unistd.h"
46
#include "sge_string.h"
48
/****** uti/prog/sge_get_arch() ************************************************
50
* sge_get_arch() -- SGE/EE architecture string
53
* const char* sge_get_arch(void)
56
* This function returns the SGE/EE architecture string of that
57
* host where the application is running which called this
61
* MT-NOTE: sge_get_arch() is MT safe
64
* const char* - architecture string
65
******************************************************************************/
66
const char *sge_get_arch(void)
68
#ifndef SGE_ARCH_STRING
69
# pragma "Define an architecture for SGE"
72
#define xstr(s) str(s)
75
return xstr(SGE_ARCH_STRING);
78
/****** uti/prog/sge_get_root_dir() *******************************************
80
* sge_get_root_dir() -- SGE/SGEEE installation directory
83
* const char* sge_get_root_dir(int do_exit,
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.
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
104
* const char* - Root directory of the SGE/SGEEE installation
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)
114
DENTER_(TOP_LAYER, "sge_get_root_dir");
117
* Read some env variables
119
sge_root = getenv("SGE_ROOT");
122
* Check the env variables
129
if (!s || strlen(s)==0) {
133
* Get rid of trailing slash
135
if (s[strlen(s)-1] == '/') {
136
s[strlen(s)-1] = '\0';
143
if (buffer != NULL) {
144
sge_strlcpy(buffer, MSG_SGEROOTNOTSET, size);
146
CRITICAL((SGE_EVENT, MSG_SGEROOTNOTSET));
157
/****** uti/prog/sge_get_default_cell() ***************************************
159
* sge_get_default_cell() -- get cell name and remove trailing slash
162
* const char* sge_get_default_cell(void)
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'.
172
* const char* - Cell name of this SGE/SGEEE installation
175
* MT-NOTE: sge_get_default_cell() is MT safe
176
******************************************************************************/
177
const char *sge_get_default_cell(void)
182
DENTER_(TOP_LAYER, "sge_get_default_cell");
184
* Read some env variables
186
sge_cell = getenv("SGE_CELL");
189
* Check the env variables
200
if (!s || strlen(s) == 0) {
204
* Get rid of trailing slash
206
if (s[strlen(s)-1] == '/') {
207
s[strlen(s)-1] = '\0';
213
/****** uti/prog/sge_get_alias_path() *****************************************
215
* sge_get_alias_path() -- Return the path of the 'alias_file'
218
* const char* sge_get_alias_path(void)
221
* Return the path of the 'alias_file'
224
* MT-NOTE: sge_get_alias_path() is MT safe
226
******************************************************************************/
227
const char *sge_get_alias_path(void)
229
const char *sge_root, *sge_cell;
232
SGE_STRUCT_STAT sbuf;
234
DENTER_(TOP_LAYER, "sge_get_alias_path");
236
sge_root = sge_get_root_dir(1, NULL, 0, 1);
237
sge_cell = sge_get_default_cell();
239
if (SGE_STAT(sge_root, &sbuf)) {
240
CRITICAL((SGE_EVENT, MSG_SGETEXT_SGEROOTNOTFOUND_S , sge_root));
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 ));
250
sprintf(cp, "%s/%s/%s/%s", sge_root, sge_cell, COMMON_DIR, ALIAS_FILE);