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

« back to all changes in this revision

Viewing changes to source/daemons/shepherd/sge_shepconf.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
 
 
32
#include <string.h>
 
33
#include <signal.h>
 
34
 
 
35
#include "sge_shepconf.h"
 
36
#include "config_file.h"
 
37
#include "signal_queue.h"
 
38
#include "sge_signal.h"
 
39
#include "sge_string.h"
 
40
#include "err_trace.h"
 
41
 
 
42
/****** shepherd/shepconf/shepconf_has_userdef_method() ************************
 
43
*  NAME
 
44
*     shepconf_has_userdef_method() -- Do we have a user def. method?
 
45
*
 
46
*  SYNOPSIS
 
47
*     int shepconf_has_userdef_method(char *method_name, dstring *method) 
 
48
*
 
49
*  FUNCTION
 
50
*     Try to find the variable "method_name" in config-file. 
 
51
*     Return true and set "method" if it is an absolute path
 
52
*     otherwise return false.
 
53
*      
 
54
*
 
55
*  INPUTS
 
56
*     char *method_name - "starter_method", "suspend_method", 
 
57
*                         "resume_method" or "terminate_method"
 
58
*     dstring *method   - Absolut filename of the method 
 
59
*
 
60
*  RESULT
 
61
*     int - true or false 
 
62
*******************************************************************************/
 
63
int shepconf_has_userdef_method(const char *method_name, dstring *method)
 
64
{
 
65
   char *conf_val = search_nonone_conf_val(method_name);
 
66
   int ret = 0;
 
67
 
 
68
   if (conf_val != NULL && conf_val[0] == '/') {
 
69
      sge_dstring_copy_string(method, conf_val);
 
70
      ret = 1;
 
71
   }
 
72
   return ret;
 
73
}
 
74
 
 
75
/****** shepherd/shepconf/shepconf_has_userdef_signal() ***********************
 
76
*  NAME
 
77
*     shepconf_has_userdef_signal() -- Do we have a user def. signal? 
 
78
*
 
79
*  SYNOPSIS
 
80
*     int shepconf_has_userdef_signal(char *method_name, int *signal) 
 
81
*
 
82
*  FUNCTION
 
83
*     Try to find the variable "method_name" in config-file.
 
84
*     Return true and set "signal" if it is a signal name
 
85
*     otherwise return false. 
 
86
*
 
87
*  INPUTS
 
88
*     char *method_name - "starter_method", "suspend_method",
 
89
*                         "resume_method" or "terminate_method" 
 
90
*     int *signal       - signal id 
 
91
*
 
92
*  RESULT
 
93
*     int - true or false 
 
94
*******************************************************************************/
 
95
int shepconf_has_userdef_signal(const char *method_name, int *signal) 
 
96
{
 
97
   char *conf_val = search_nonone_conf_val(method_name);
 
98
   int ret = 0;
 
99
 
 
100
   if (conf_val != NULL && conf_val[0] != '/') {
 
101
      *signal = shepherd_sys_str2signal(conf_val);
 
102
      ret = 1;
 
103
   }
 
104
   return ret;
 
105
}
 
106
 
 
107
/****** shepherd/shepconf/shepconf_has_notify_signal() ************************
 
108
*  NAME
 
109
*     shepconf_has_notify_signal() -- Do we have a notification signal 
 
110
*
 
111
*  SYNOPSIS
 
112
*     int shepconf_has_notify_signal(char *notify_name, int *signal) 
 
113
*
 
114
*  FUNCTION
 
115
*     This function checks if the notification mechanism is enabled.
 
116
*     In this case the function will retuen 'true' and it will
 
117
*     return the default signal or the user defined signal for
 
118
*     the given "notify_name".
 
119
*
 
120
*  INPUTS
 
121
*     char *notify_name - "notify_susp" or "notify_kill" 
 
122
*     int *signal       - signal id 
 
123
*
 
124
*  RESULT
 
125
*     int - true or false
 
126
*******************************************************************************/
 
127
int shepconf_has_notify_signal(const char *notify_name, int *signal)
 
128
{
 
129
   const char *notify_array[] = {
 
130
      "notify_susp", "notify_kill", NULL
 
131
   };
 
132
   int signal_array[] = { 
 
133
      SIGUSR1, SIGUSR2, 0 
 
134
   };
 
135
   dstring param_name = DSTRING_INIT;
 
136
   char *conf_type = NULL;
 
137
   int conf_id;
 
138
   int ret = 0;
 
139
 
 
140
   /*
 
141
    * There are three possibilities:
 
142
    *    a) There is a user defined signal which should be used
 
143
    *    b) Default signal should be used
 
144
    *    c) Notification mechanism is disabled
 
145
    */
 
146
   sge_dstring_sprintf(&param_name, "%s%s", notify_name, "_type");
 
147
   conf_type = search_conf_val(sge_dstring_get_string(&param_name)); 
 
148
   if (conf_type != NULL) {
 
149
      conf_id = atol(conf_type);
 
150
   } else {
 
151
      conf_id = 1;   /* Default signal should be used */
 
152
   }
 
153
 
 
154
   if (conf_id == 0) {
 
155
      char *conf_signal = search_conf_val(notify_name);
 
156
 
 
157
      if (conf_signal != NULL) {
 
158
         *signal = sge_sys_str2signal(conf_signal);
 
159
         ret = 1;
 
160
      }
 
161
   } else if (conf_id == 1) {
 
162
      int i;
 
163
 
 
164
      for (i = 0; notify_array[i] != NULL; i++) {
 
165
         if (!strcmp(notify_array[i], notify_name)) {
 
166
            break;
 
167
         }
 
168
      }
 
169
      *signal = signal_array[i];
 
170
      ret = 1;
 
171
   } else {
 
172
      *signal = 0;
 
173
      ret = 0;
 
174
   }
 
175
   return ret;
 
176
}
 
177
 
 
178
/****** shepherd/shepconf/shepconf_has_to_notify_before_signal() **************
 
179
*  NAME
 
180
*     shepconf_has_to_notify_before_signal() -- Get notification time 
 
181
*
 
182
*  SYNOPSIS
 
183
*     int shepconf_has_to_notify_before_signal(int *seconds) 
 
184
*
 
185
*  FUNCTION
 
186
*     If the notification mechanism is enabled then this function
 
187
*     will return with "true" and "seconds" will be > 0. 
 
188
*
 
189
*  INPUTS
 
190
*     int *seconds - time to elapse between notification and final signal 
 
191
*
 
192
*  RESULT
 
193
*     int - true or false
 
194
*******************************************************************************/
 
195
int shepconf_has_to_notify_before_signal(int *seconds) 
 
196
{
 
197
   *seconds = atoi(get_conf_val("notify"));
 
198
 
 
199
   return (*seconds > 0);
 
200
 
201