aboutsummaryrefslogtreecommitdiffstats
path: root/src/udev-kvm-check.c
diff options
context:
space:
mode:
authorLukas Nykryn <lnykryn@redhat.com>2013-11-18 12:27:22 +0100
committerLukas Nykryn <lnykryn@redhat.com>2013-11-18 12:47:51 +0100
commitbefa38a3a79feffb320e24e7e179ae42ed569914 (patch)
tree351f559212de392577322516ea77defe13cd1df9 /src/udev-kvm-check.c
parent91756279dab5d2f2fd58ac4c9e07d5c5d6f7c534 (diff)
downloadinitscripts-befa38a3a79feffb320e24e7e179ae42ed569914.tar
initscripts-befa38a3a79feffb320e24e7e179ae42ed569914.tar.gz
initscripts-befa38a3a79feffb320e24e7e179ae42ed569914.tar.bz2
initscripts-befa38a3a79feffb320e24e7e179ae42ed569914.tar.xz
initscripts-befa38a3a79feffb320e24e7e179ae42ed569914.zip
udev-kvm-check: simplify reading of threshold
Diffstat (limited to 'src/udev-kvm-check.c')
-rw-r--r--src/udev-kvm-check.c91
1 files changed, 17 insertions, 74 deletions
diff --git a/src/udev-kvm-check.c b/src/udev-kvm-check.c
index 43cb9d93..55595ee5 100644
--- a/src/udev-kvm-check.c
+++ b/src/udev-kvm-check.c
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "shvar.h"
#define DEFAULT 0
#define FACILITY "kvm"
@@ -19,85 +20,27 @@
" may review the Red Hat Enterprise subscription" \
" limits at http://www.redhat.com/rhel-virt-limits"
-int get_threshold_from_file(FILE *fp)
+
+int get_threshold()
{
- static const char key[] = "THRESHOLD=";
- int pos = 0;
- int thres;
- char ch;
-
-start:
- /* State START - at beginning of line, search for beginning of "THRESHOLD="
- * string.
- */
- ch = getc(fp);
- if (ch == EOF) {
- return DEFAULT;
- }
- if (isspace(ch)) {
- goto start;
- }
- if (ch == 'T') {
- pos = 1;
- goto key;
- }
- goto eol;
+ int val = 0;
+ char *cval = NULL;
-eol:
- /* State EOL - loop until end of line */
- ch = getc(fp);
- if (ch == EOF) {
- return DEFAULT;
- }
- if (ch == '\n') {
- goto start;
- }
- goto eol;
+ shvarFile *file = svNewFile(SYSCONFIG_KVM);
+ if (!file)
+ return 0;
-key:
- /* State KEY - match "THRESHOLD=" string, go to THRESHOLD if found */
- ch = getc(fp);
- if (ch == EOF) {
- return DEFAULT;
- }
- if (ch == key[pos]) {
- pos++;
- if (key[pos] == 0) {
- goto threshold;
- } else {
- goto key;
- }
- }
- goto eol;
-
-threshold:
- /* State THRESHOLD - parse number using fscanf, expect comment or space
- * or EOL.
- */
- ch = getc(fp);
- if (ch == EOF) {
- return DEFAULT;
- }
- if (!isdigit(ch)) {
- goto eol;
- }
- ungetc(ch, fp);
- if (fscanf(fp, "%d", &thres) != 1) {
- return DEFAULT;
- }
- ch = getc(fp);
- if (ch == '#' || ch == EOF || ch == '\n' || isspace(ch)) {
- return thres;
- }
- goto eol;
-}
+ cval = svGetValue(file, "THRESHOLD");
-int get_threshold()
-{
- FILE *fp = fopen(SYSCONFIG_KVM, "r");
- int val = get_threshold_from_file(fp);
+ svCloseFile(file);
+
+ if (cval == NULL)
+ return 0;
+
+ val = atoi(cval);
- fclose (fp);
+ free(cval);
+
return val;
}