bin_SCRIPTS += corosync-xmlproc
endif
+noinst_HEADERS = util.h
+
AM_CFLAGS = $(knet_CFLAGS)
EXTRA_DIST = corosync-xmlproc.sh \
corosync-notifyd.sysconfig.example \
corosync-blackbox.sh
+corosync_cfgtool_SOURCES = corosync-cfgtool.c util.c
+
+corosync_quorumtool_SOURCES = corosync-quorumtool.c util.c
+
corosync-xmlproc: corosync-xmlproc.sh
$(SED) -e 's#@''DATADIR@#${datadir}#g' \
-e 's#@''BASHPATH@#${BASHPATH}#g' \
#include <sys/un.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <limits.h>
#include <corosync/corotypes.h>
#include <corosync/totem/totem.h>
#include <corosync/cfg.h>
#include <corosync/cmap.h>
+#include "util.h"
#define cs_repeat(result, max, code) \
do { \
int rc = EXIT_SUCCESS;
enum user_action action = ACTION_NOOP;
int brief = 0;
+ long long int l;
while ( (opt = getopt(argc, argv, options)) != -1 ) {
switch (opt) {
action = ACTION_REOPEN_LOG_FILES;
break;
case 'k':
- nodeid = atoi (optarg);
+ if (util_strtonum(optarg, 1, UINT_MAX, &l) == -1) {
+ fprintf(stderr, "The nodeid was not valid, try a positive number\n");
+ exit(EXIT_FAILURE);
+ }
+ nodeid = l;
action = ACTION_KILL_NODE;
break;
case 'H':
action = ACTION_SHUTDOW;
break;
case 'a':
- nodeid = atoi (optarg);
+ if (util_strtonum(optarg, 1, UINT_MAX, &l) == -1) {
+ fprintf(stderr, "The nodeid was not valid, try a positive number\n");
+ exit(EXIT_FAILURE);
+ }
+ nodeid = l;
action = ACTION_SHOWADDR;
break;
case '?':
#include <corosync/cmap.h>
#include <corosync/quorum.h>
#include <corosync/votequorum.h>
+#include "util.h"
typedef enum {
NODEID_FORMAT_DECIMAL,
int main (int argc, char *argv[]) {
const char *options = "VHaslpmfe:v:hin:o:";
- char *endptr;
int opt;
int votes = 0;
int ret = 0;
command_t command_opt = CMD_SHOWSTATUS;
sorttype_t sort_opt = SORT_ADDR;
char sortchar;
- long int l;
+ long long int l;
if (init_all()) {
close_all();
break;
case 'e':
if (using_votequorum() > 0) {
- votes = strtol(optarg, &endptr, 0);
- if ((votes == 0 && endptr == optarg) || votes <= 0) {
+ if (util_strtonum(optarg, 1, INT_MAX, &l) == -1) {
fprintf(stderr, "New expected votes value was not valid, try a positive number\n");
exit(EXIT_FAILURE);
} else {
+ votes = l;
command_opt = CMD_SETEXPECTED;
}
} else {
}
break;
case 'n':
- l = strtol(optarg, &endptr, 0);
- if ((l == 0 && endptr == optarg) || l < 0) {
+ if (util_strtonum(optarg, 1, UINT_MAX, &l) == -1) {
fprintf(stderr, "The nodeid was not valid, try a positive number\n");
exit(EXIT_FAILURE);
}
break;
case 'v':
if (using_votequorum() > 0) {
- votes = strtol(optarg, &endptr, 0);
- if ((votes == 0 && endptr == optarg) || votes < 0) {
+ if (util_strtonum(optarg, 0, INT_MAX, &l) == -1) {
fprintf(stderr, "New votes value was not valid, try a positive number or zero\n");
exit(EXIT_FAILURE);
} else {
+ votes = l;
command_opt = CMD_SETVOTES;
}
}
--- /dev/null
+#include <stdlib.h>
+#include <errno.h>
+
+#include "util.h"
+
+/*
+ * Safer wrapper of strtoll. Return 0 on success, otherwise -1.
+ * Idea from corosync-qdevice project
+ */
+int
+util_strtonum(const char *str, long long int min_val, long long int max_val,
+ long long int *res)
+{
+ long long int tmp_ll;
+ char *ep;
+
+ if (min_val > max_val) {
+ return (-1);
+ }
+
+ errno = 0;
+
+ tmp_ll = strtoll(str, &ep, 10);
+ if (ep == str || *ep != '\0' || errno != 0) {
+ return (-1);
+ }
+
+ if (tmp_ll < min_val || tmp_ll > max_val) {
+ return (-1);
+ }
+
+ *res = tmp_ll;
+
+ return (0);
+}
--- /dev/null
+#ifndef COROSYNC_TOOLS_UTIL_H_DEFINED
+#define COROSYNC_TOOLS_UTIL_H_DEFINED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int util_strtonum(const char *str, long long int min_val,
+ long long int max_val, long long int *res);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* COROSYNC_TOOLS_UTIL_H_DEFINED */