CUBRID Engine  latest
broker_changer.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 /*
21  * broker_changer.c -
22  */
23 
24 #ident "$Id$"
25 
26 #include <stdio.h>
27 #include <string.h>
28 #include <stdlib.h>
29 #include <errno.h>
30 
31 #if defined(WINDOWS)
32 #include <process.h>
33 #include "porting.h"
34 #endif /* WINDOWS */
35 
36 #include "broker_admin_pub.h"
37 #include "broker_config.h"
38 #include "broker_util.h"
39 
40 #if defined(WINDOWS)
41 #include "broker_wsa_init.h"
42 #endif /* WINDOWS */
43 
44 int
45 main (int argc, char *argv[])
46 {
47  char *br_name;
48  char *conf_name;
49  char *conf_value;
51  int num_broker, master_shm_id;
52  int as_number = -1;
53 
54  if (argc == 2 && strcmp (argv[1], "--version") == 0)
55  {
56  printf ("VERSION %s\n", makestring (BUILD_NUMBER));
57  return 0;
58  }
59 
60 #if defined(WINDOWS)
61  wsa_initialize ();
62 #endif /* WINDOWS */
63 
64  if (argc < 4)
65  {
66  printf ("%s <broker-name> [<cas-number>] <conf-name> <conf-value>\n", argv[0]);
67  exit (0);
68  }
69 
70  if (broker_config_read (NULL, br_info, &num_broker, &master_shm_id, NULL, 0, NULL, NULL, NULL) < 0)
71  {
72  printf ("config file error\n");
73  exit (0);
74  }
75 
76  ut_cd_work_dir ();
77 
78  br_name = argv[1];
79 
80  if (argc == 5)
81  {
82  int result;
83 
84  result = parse_int (&as_number, argv[2], 10);
85 
86  if (result != 0 || as_number < 0)
87  {
88  printf ("Invalid cas number\n");
89  exit (0);
90  }
91 
92  conf_name = argv[3];
93  conf_value = argv[4];
94  }
95  else
96  {
97  conf_name = argv[2];
98  conf_value = argv[3];
99  }
100 
101  admin_err_msg[0] = '\0';
102 
103  if (admin_conf_change (master_shm_id, br_name, conf_name, conf_value, as_number) < 0)
104  {
105  printf ("%s\n", admin_err_msg);
106  exit (0);
107  }
108 
109  if (admin_err_msg[0] != '\0')
110  {
111  printf ("%s\n", admin_err_msg);
112  }
113 
114  printf ("OK\n");
115  return 0;
116 }
void ut_cd_work_dir(void)
Definition: broker_util.c:335
int main(int argc, char *argv[])
int argc
Definition: dynamic_load.c:951
int parse_int(int *ret_p, const char *str_p, int base)
Definition: porting.c:2290
int admin_conf_change(int master_shm_id, const char *br_name, const char *conf_name, const char *conf_value, int as_number)
int wsa_initialize()
int broker_config_read(const char *conf_file, T_BROKER_INFO *br_info, int *num_broker, int *br_shm_id, char *admin_log_file, char admin_flag, bool *acl_flag, char *acl_file, char *admin_err_msg)
#define MAX_BROKER_NUM
Definition: broker_config.h:50
#define NULL
Definition: freelistheap.h:34
char admin_err_msg[ADMIN_ERR_MSG_SIZE]
const char ** argv
Definition: dynamic_load.c:952
#define makestring(x)