Skip to content

Commit 926b554

Browse files
authored
Merge pull request #126 from gao-yan/options-empty-string-default
Fix: sbd-inquisitor: take the defaults for the options set in sysconfig with empty strings
2 parents 57b84b5 + 8b823d1 commit 926b554

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

src/sbd-inquisitor.c

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,28 @@ bool sync_resource_startup = false;
3939

4040
int parse_device_line(const char *line);
4141

42+
static const char *
43+
get_env_option(const char *option)
44+
{
45+
const char *value = getenv(option);
46+
size_t max = 0;
47+
size_t lpc = 0;
48+
49+
if (value == NULL) {
50+
return NULL;
51+
}
52+
53+
max = strlen(value);
54+
55+
for (lpc = 0; lpc < max; lpc++) {
56+
if (!isspace(value[lpc])) {
57+
break;
58+
}
59+
}
60+
61+
return (strlen(value + lpc) > 0 ? (value + lpc) : NULL);
62+
}
63+
4264
static int
4365
recruit_servant(const char *devname, pid_t pid)
4466
{
@@ -894,14 +916,14 @@ int main(int argc, char **argv, char **envp)
894916

895917
sbd_get_uname();
896918

897-
value = getenv("SBD_PACEMAKER");
919+
value = get_env_option("SBD_PACEMAKER");
898920
if(value) {
899921
check_pcmk = crm_is_true(value);
900922
check_cluster = crm_is_true(value);
901923
}
902924
cl_log(LOG_INFO, "Enable pacemaker checks: %d (%s)", (int)check_pcmk, value?value:"default");
903925

904-
value = getenv("SBD_STARTMODE");
926+
value = get_env_option("SBD_STARTMODE");
905927
if(value == NULL) {
906928
} else if(strcmp(value, "clean") == 0) {
907929
start_mode = 1;
@@ -910,7 +932,7 @@ int main(int argc, char **argv, char **envp)
910932
}
911933
cl_log(LOG_INFO, "Start mode set to: %d (%s)", (int)start_mode, value?value:"default");
912934

913-
value = getenv("SBD_WATCHDOG_DEV");
935+
value = get_env_option("SBD_WATCHDOG_DEV");
914936
if(value) {
915937
free(watchdogdev);
916938
watchdogdev = strdup(value);
@@ -919,23 +941,23 @@ int main(int argc, char **argv, char **envp)
919941

920942
/* SBD_WATCHDOG has been dropped from sbd.sysconfig example.
921943
* This is for backward compatibility. */
922-
value = getenv("SBD_WATCHDOG");
944+
value = get_env_option("SBD_WATCHDOG");
923945
if(value) {
924946
watchdog_use = crm_is_true(value);
925947
}
926948

927-
value = getenv("SBD_WATCHDOG_TIMEOUT");
949+
value = get_env_option("SBD_WATCHDOG_TIMEOUT");
928950
if(value) {
929951
timeout_watchdog = crm_get_msec(value) / 1000;
930952
}
931953

932-
value = getenv("SBD_PIDFILE");
954+
value = get_env_option("SBD_PIDFILE");
933955
if(value) {
934956
pidfile = strdup(value);
935957
cl_log(LOG_INFO, "pidfile set to %s", pidfile);
936958
}
937959

938-
value = getenv("SBD_DELAY_START");
960+
value = get_env_option("SBD_DELAY_START");
939961
if(value) {
940962
delay_start = crm_is_true(value);
941963

@@ -951,12 +973,12 @@ int main(int argc, char **argv, char **envp)
951973
delay_start? (delay > 0 ? value: "msgwait") : "",
952974
delay_start? ")" : "");
953975

954-
value = getenv("SBD_TIMEOUT_ACTION");
976+
value = get_env_option("SBD_TIMEOUT_ACTION");
955977
if(value) {
956978
timeout_action = strdup(value);
957979
}
958980

959-
value = getenv("SBD_MOVE_TO_ROOT_CGROUP");
981+
value = get_env_option("SBD_MOVE_TO_ROOT_CGROUP");
960982
if(value) {
961983
move_to_root_cgroup = crm_is_true(value);
962984

@@ -1108,7 +1130,7 @@ int main(int argc, char **argv, char **envp)
11081130
then it is probably undesirable to add those
11091131
from environment (general rule cmdline has precedence)
11101132
*/
1111-
value = getenv("SBD_DEVICE");
1133+
value = get_env_option("SBD_DEVICE");
11121134
if ((value) && strlen(value)) {
11131135
#if SUPPORT_SHARED_DISK
11141136
int devices = parse_device_line(value);
@@ -1205,7 +1227,7 @@ int main(int argc, char **argv, char **envp)
12051227
}
12061228

12071229
if (strcmp(argv[optind], "watch") == 0) {
1208-
value = getenv("SBD_SYNC_RESOURCE_STARTUP");
1230+
value = get_env_option("SBD_SYNC_RESOURCE_STARTUP");
12091231
sync_resource_startup =
12101232
crm_is_true(value?value:SBD_SYNC_RESOURCE_STARTUP_DEFAULT);
12111233

0 commit comments

Comments
 (0)