Permalink
Browse files

Merge pull request #1606 from kgaillot/fixes

Miscellaneous bug fixes
  • Loading branch information...
kgaillot committed Oct 17, 2018
2 parents af56173 + f67b36f commit 406c4c76c447dcfb83fb1f60c8e9880ac0849411
View
@@ -146,7 +146,6 @@ $(PACKAGE)-suse.spec: $(PACKAGE).spec.in GNUmakefile
sed -i \
-e 's:%{_docdir}/%{name}:%{_docdir}/%{name}-%{version}:g' \
-e 's:%{name}-libs:lib%{name}3:g' \
-e 's@Requires:\( *\)%{python_pkg}\(-devel\)\? @Requires:\1python-curses python-xml %{python_pkg}\2 @' \
-e 's: libtool-ltdl-devel\(%{?_isa}\)\?::g' \
-e 's:bzip2-devel:libbz2-devel:g' \
-e 's:docbook-style-xsl:docbook-xsl-stylesheets:g' \
@@ -734,42 +734,42 @@ OCF_RESKEY_CRM_meta_notify_start_uname="sles-1 sles-3 sles-2"
[width="95%",cols="5,<3",options="header",align="center"]
|=========================================================
|_OCF_RESKEY_CRM_meta_notify_master_resource_
|OCF_RESKEY_CRM_meta_notify_master_resource
|Resources that are running in +Master+ mode
indexterm:[Environment Variable,OCF_RESKEY_CRM_meta_notify_,master_resource]
indexterm:[master_resource,Notification Environment Variable]
|_OCF_RESKEY_CRM_meta_notify_slave_resource_
|OCF_RESKEY_CRM_meta_notify_slave_resource
|Resources that are running in +Slave+ mode
indexterm:[Environment Variable,OCF_RESKEY_CRM_meta_notify_,slave_resource]
indexterm:[slave_resource,Notification Environment Variable]
|_OCF_RESKEY_CRM_meta_notify_promote_resource_
|OCF_RESKEY_CRM_meta_notify_promote_resource
|Resources to be promoted
indexterm:[Environment Variable,OCF_RESKEY_CRM_meta_notify_,promote_resource]
indexterm:[promote_resource,Notification Environment Variable]
|_OCF_RESKEY_CRM_meta_notify_demote_resource_
|OCF_RESKEY_CRM_meta_notify_demote_resource
|Resources to be demoted
indexterm:[Environment Variable,OCF_RESKEY_CRM_meta_notify_,demote_resource]
indexterm:[demote_resource,Notification Environment Variable]
|_OCF_RESKEY_CRM_meta_notify_promote_uname_
|OCF_RESKEY_CRM_meta_notify_promote_uname
|Nodes on which resources will be promoted
indexterm:[Environment Variable,OCF_RESKEY_CRM_meta_notify_,promote_uname]
indexterm:[promote_uname,Notification Environment Variable]
|_OCF_RESKEY_CRM_meta_notify_demote_uname_
|OCF_RESKEY_CRM_meta_notify_demote_uname
|Nodes on which resources will be demoted
indexterm:[Environment Variable,OCF_RESKEY_CRM_meta_notify_,demote_uname]
indexterm:[demote_uname,Notification Environment Variable]
|_OCF_RESKEY_CRM_meta_notify_master_uname_
|OCF_RESKEY_CRM_meta_notify_master_uname
|Nodes on which resources are running in +Master+ mode
indexterm:[Environment Variable,OCF_RESKEY_CRM_meta_notify_,master_uname]
indexterm:[master_uname,Notification Environment Variable]
|_OCF_RESKEY_CRM_meta_notify_slave_uname_
|OCF_RESKEY_CRM_meta_notify_slave_uname
|Nodes on which resources are running in +Slave+ mode
indexterm:[Environment Variable,OCF_RESKEY_CRM_meta_notify_,slave_uname]
indexterm:[slave_uname,Notification Environment Variable]
@@ -41,6 +41,7 @@ int crm_default_remote_port(void);
char *crm_itoa_stack(int an_int, char *buf, size_t len);
gboolean crm_is_true(const char *s);
int crm_str_to_boolean(const char *s, int *ret);
long long crm_parse_ll(const char *text, const char *default_text);
int crm_parse_int(const char *text, const char *default_text);
char * crm_strip_trailing_newline(char *str);
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case);
View
@@ -1,20 +1,10 @@
/*
* Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net>
* Copyright 2004-2018 Andrew Beekhof <andrew@beekhof.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/
#ifndef CRM_COMMON_XML__H
# define CRM_COMMON_XML__H
@@ -198,6 +188,8 @@ int find_xml_children(xmlNode ** children, xmlNode * root,
int crm_element_value_int(const xmlNode *data, const char *name, int *dest);
int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest);
int crm_element_value_timeval(const xmlNode *data, const char *name_sec,
const char *name_usec, struct timeval *dest);
char *crm_element_value_copy(const xmlNode *data, const char *name);
xmlNode *get_xpath_object(const char *xpath, xmlNode * xml_obj, int error_level);
xmlNode *get_xpath_object_relative(const char *xpath, xmlNode * xml_obj, int error_level);
View
@@ -438,20 +438,13 @@ parse_election_message(election_t *e, xmlNode *message, struct vote *vote)
if (crm_str_eq(vote->op, CRM_OP_VOTE, TRUE)) {
// Only vote ops have uptime
int age_s = -1;
int age_us = -1;
// @TODO add functions to parse time_t / suseconds_t directly from XML
crm_element_value_int(message, F_CRM_ELECTION_AGE_S, &age_s);
crm_element_value_int(message, F_CRM_ELECTION_AGE_US, &age_us);
if ((age_s < 0) || (age_us < 0)) {
crm_element_value_timeval(message, F_CRM_ELECTION_AGE_S,
F_CRM_ELECTION_AGE_US, &(vote->age));
if ((vote->age.tv_sec < 0) || (vote->age.tv_usec < 0)) {
crm_warn("Cannot count %s %s from %s because it is missing uptime",
(e? e->name : "election"), vote->op, vote->from);
return FALSE;
}
vote->age.tv_sec = age_s;
vote->age.tv_usec = age_us;
} else if (!crm_str_eq(vote->op, CRM_OP_NOVOTE, TRUE)) {
crm_info("Cannot process %s message from %s because %s is not a known election op",
View
@@ -14,6 +14,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <bzlib.h>
#include <sys/types.h>
@@ -72,29 +73,46 @@ crm_int_helper(const char *text, char **end_text)
return result;
}
int
crm_parse_int(const char *text, const char *default_text)
/*!
* \brief Parse a long long integer value from a string
*
* \param[in] text The string to parse
* \param[in] default_text Default string to parse if text is NULL
*
* \return Parsed value on success, -1 (and set errno) on error
*/
long long
crm_parse_ll(const char *text, const char *default_text)
{
int atoi_result = -1;
if (text != NULL) {
atoi_result = crm_int_helper(text, NULL);
if (errno == 0) {
return atoi_result;
if (text == NULL) {
text = default_text;
if (text == NULL) {
crm_err("No default conversion value supplied");
errno = EINVAL;
return -1;
}
}
return crm_int_helper(text, NULL);
}
if (default_text != NULL) {
atoi_result = crm_int_helper(default_text, NULL);
if (errno == 0) {
return atoi_result;
}
/*!
* \brief Parse an integer value from a string
*
* \param[in] text The string to parse
* \param[in] default_text Default string to parse if text is NULL
*
* \return Parsed value on success, -1 (and set errno) on error
*/
int
crm_parse_int(const char *text, const char *default_text)
{
long long result = crm_parse_ll(text, default_text);
} else {
crm_err("No default conversion value supplied");
if ((result < INT_MIN) || (result > INT_MAX)) {
errno = ERANGE;
return -1;
}
return -1;
return (int) result;
}
/*!
View
@@ -3309,9 +3309,10 @@ xml_has_children(const xmlNode * xml_root)
int
crm_element_value_int(const xmlNode *data, const char *name, int *dest)
{
const char *value = crm_element_value(data, name);
const char *value = NULL;
CRM_CHECK(dest != NULL, return -1);
value = crm_element_value(data, name);
if (value) {
*dest = crm_int_helper(value, NULL);
return 0;
@@ -3322,13 +3323,62 @@ crm_element_value_int(const xmlNode *data, const char *name, int *dest)
int
crm_element_value_ms(const xmlNode *data, const char *name, guint *dest)
{
const char *value = crm_element_value(data, name);
const char *value = NULL;
CRM_CHECK(dest != NULL, return -1);
value = crm_element_value(data, name);
*dest = crm_parse_ms(value);
return errno? -1 : 0;
}
/*!
* \brief Parse a time value from XML
*
* \param[in] xml XML to parse
* \param[in] name_sec Name of XML attribute for seconds
* \param[in] name_usec Name of XML attribute for microseconds
* \param[out] dest Where to store result
*
* \return 0 on success, -errno on error
* \note Values default to 0 if XML or XML attribute does not exist
*/
int
crm_element_value_timeval(const xmlNode *xml, const char *name_sec,
const char *name_usec, struct timeval *dest)
{
const char *value_s = NULL;
long long value_i = 0;
CRM_CHECK(dest != NULL, return -EINVAL);
dest->tv_sec = 0;
dest->tv_usec = 0;
if (xml == NULL) {
return 0;
}
// Parse seconds
value_s = crm_element_value(xml, name_sec);
if (value_s) {
value_i = crm_parse_ll(value_s, NULL);
if (errno) {
return -errno;
}
dest->tv_sec = (time_t) value_i;
}
// Parse microseconds
value_s = crm_element_value(xml, name_usec);
if (value_s) {
value_i = crm_parse_ll(value_s, NULL);
if (errno) {
return -errno;
}
dest->tv_usec = (suseconds_t) value_i;
}
return 0;
}
char *
crm_element_value_copy(const xmlNode *data, const char *name)
{
Oops, something went wrong.

0 comments on commit 406c4c7

Please sign in to comment.