aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/Makefile8
-rw-r--r--src/udev-kvm-check.c91
2 files changed, 23 insertions, 76 deletions
diff --git a/src/Makefile b/src/Makefile
index f2842152..e1265694 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -7,6 +7,7 @@ PPPWATCH_OBJS=ppp-watch.o shvar.o
BRANDBOT_OBJS=brandbot.o shvar.o
CONSOLE_INIT_OBJS=console_init.o shvar.o
USLEEP_OBJS=usleep.o
+UDEV_KVM_CHECK_OBJS=udev-kvm-check.o shvar.o
mandir=/usr/share/man
@@ -54,6 +55,9 @@ ppp-watch: $(PPPWATCH_OBJS)
brandbot: $(BRANDBOT_OBJS)
$(CC) $(LDFLAGS) -o $@ $(BRANDBOT_OBJS) `pkg-config glib-2.0 --libs`
+udev-kvm-check: $(UDEV_KVM_CHECK_OBJS)
+ $(CC) $(LDFLAGS) -o $@ $(UDEV_KVM_CHECK_OBJS) `pkg-config glib-2.0 --libs`
+
usernetctl.o: usernetctl.c
$(CC) $(CFLAGS) -fPIE -c usernetctl.c -o usernetctl.o
@@ -78,6 +82,6 @@ ppp-watch.o: ppp-watch.c
rename_device: rename_device.c
$(CC) $(CFLAGS) `pkg-config glib-2.0 --cflags` -o $@ $< `pkg-config glib-2.0 --libs`
-udev-kvm-check: udev-kvm-check.c
- $(CC) $(CFLAGS) -o $@ $<
+udev-kvm-check.o: udev-kvm-check.c
+ $(CC) $(CFLAGS) `pkg-config glib-2.0 --cflags` -c udev-kvm-check.c -o udev-kvm-check.o
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;
}