CUBRID Engine  latest
master_util.c
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * master_util.c - common module for commdb and master
21  */
22 
23 #ident "$Id$"
24 
25 #include "config.h"
26 
27 #include <sys/types.h>
28 #include <signal.h>
29 #include <stdio.h>
30 
31 #include "system_parameter.h"
32 #include "master_util.h"
33 
34 /*
35  * master_util_config_startup() - get port id and service name from parameters
36  * return: true if port id and service name are valid,
37  * otherwise false
38  * db_name(in)
39  * port_id(out)
40  */
41 bool
42 master_util_config_startup (const char *db_name, int *port_id)
43 {
45  {
46  return false;
47  }
48  *port_id = prm_get_master_port_id ();
49 
50  /*
51  * Must give either port_id or service_name
52  * if port == 0, nothing special use port number of service
53  * port < 0, bind a local reserved port
54  * port > 0, it is the port number of service
55  */
56  if (*port_id <= 0)
57  {
58  return false;
59  }
60  else
61  {
62  return true;
63  }
64 }
65 
66 /*
67  * master_util_wait_proc_terminate()
68  * return: none
69  * pid(in)
70  */
71 void
73 {
74 #if defined(WINDOWS)
75  HANDLE h;
76  h = OpenProcess (SYNCHRONIZE, FALSE, pid);
77  if (h)
78  {
79  WaitForSingleObject (h, INFINITE);
80  CloseHandle (h);
81  }
82 #else /* ! WINDOWS */
83  while (1)
84  {
85  if (kill (pid, 0) < 0)
86  break;
87  sleep (1);
88  }
89 #endif /* ! WINDOWS */
90 }
#define NO_ERROR
Definition: error_code.h:46
void master_util_wait_proc_terminate(int pid)
Definition: master_util.c:72
int sysprm_load_and_init(const char *db_name, const char *conf_file, const int load_flags)
int prm_get_master_port_id(void)
#define NULL
Definition: freelistheap.h:34
bool master_util_config_startup(const char *db_name, int *port_id)
Definition: master_util.c:42
pid_t pid
Definition: dynamic_load.c:955
char * db_name
#define FALSE
Definition: broker_admin.c:50