1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
*
* The Contents of this file are made available subject to the terms of
* the Sun Industry Standards Source License Version 1.2
*
* Sun Microsystems Inc., March, 2001
*
*
* Sun Industry Standards Source License Version 1.2
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.2 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2001 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
************************************************************************/
/*___INFO__MARK_END__*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "comm/commd.h"
#include "uti/sge_rmon.h"
#include "uti/sge_stdio.h"
#include "uti/sge_log.h"
#include "uti/setup_path.h"
#include "uti/sge_string.h"
#include "gdi/qm_name.h"
#include "gdi/sge_gdiP.h"
#include "basis_types.h"
#include "msg_gdilib.h"
/*-----------------------------------------------------------------------
* Read name of qmaster from master_file
* -> master_file
* <- return -1 error in err_str
* 0 host name of master in master_host
* don't copy error to err_str if err_str = NULL
* master_file name of file which should point to act_qmaster file
* copy name of qmaster host to master_host
*
* NOTES
* MT-NOTE: get_qm_name() is MT safe
*-----------------------------------------------------------------------*/
int get_qm_name(
char *master_host,
const char *master_file,
char *err_str,
size_t elen
) {
FILE *fp;
char buf[CL_MAXHOSTLEN*3+1], *cp, *first;
int len;
DENTER(TOP_LAYER, "get_qm_name");
if (!master_host || !master_file) {
if (err_str) {
if (master_host) {
snprintf(err_str, elen, SFNMAX, MSG_GDI_NULLPOINTERPASSED);
}
}
DRETURN(-1);
}
if (!(fp=fopen(master_file,"r"))) {
ERROR((SGE_EVENT, MSG_GDI_FOPEN_FAILED, master_file, strerror(errno)));
if (err_str) {
snprintf(err_str, elen, MSG_GDI_OPENMASTERFILEFAILED_S, master_file);
}
DRETURN(-1);
}
/* read file in one sweep and append O Byte to the end */
if (!(len = fread(buf, 1, CL_MAXHOSTLEN*3, fp))) {
if (err_str) {
snprintf(err_str, elen, MSG_GDI_READMASTERHOSTNAMEFAILED_S, master_file);
}
}
buf[len] = '\0';
/* Skip white space including newlines */
cp = buf;
while (*cp && (*cp == ' ' || *cp == '\t' || *cp == '\n'))
cp++;
first = cp;
/* read all non white space characters */
while (*cp && !(*cp == ' ' || *cp == '\t' || *cp == '\n')) {
cp++;
}
*cp = '\0';
len = cp - first;
if (len == 0) {
if (err_str) {
snprintf(err_str, elen, MSG_GDI_MASTERHOSTNAMEHASZEROLENGTH_S, master_file);
}
FCLOSE(fp);
DRETURN(-1);
}
if (len > CL_MAXHOSTLEN - 1) {
if (err_str) {
snprintf(err_str, elen, MSG_GDI_MASTERHOSTNAMEEXCEEDSCHARS_SI,
master_file, (int) CL_MAXHOSTLEN);
snprintf(err_str, elen, "\n");
}
FCLOSE(fp);
DRETURN(-1);
}
FCLOSE(fp);
sge_strlcpy(master_host, first, CL_MAXHOSTLEN);
DRETURN(0);
FCLOSE_ERROR:
DRETURN(-1);
}
/*********************************************************************
Write the actual qmaster into the master_file
-> master_file and master_host
<- return -1 error in err_str
0 means OK
NOTES
MT-NOTE: write_qm_name() is MT safe
*********************************************************************/
int write_qm_name(
const char *master_host,
const char *master_file,
char *err_str,
size_t elen
) {
FILE *fp;
if (!(fp = fopen(master_file, "w"))) {
if (err_str)
snprintf(err_str, elen, MSG_GDI_OPENWRITEMASTERHOSTNAMEFAILED_SS,
master_file, strerror(errno));
return -1;
}
if (fprintf(fp, "%s\n", master_host) == EOF) {
if (err_str)
snprintf(err_str, elen, MSG_GDI_WRITEMASTERHOSTNAMEFAILED_S,
master_file);
FCLOSE(fp);
return -1;
}
FCLOSE(fp);
return 0;
FCLOSE_ERROR:
return -1;
}
|