Blame SOURCES/bltk-1.0.9-conf.patch

983249
diff -up /dev/null bltk/include/parseconf.h
983249
--- /dev/null	2009-07-29 07:53:51.640007938 +0200
983249
+++ bltk/include/parseconf.h	2009-07-29 11:14:00.913495946 +0200
983249
@@ -0,0 +1,61 @@
983249
+/*
983249
+ *  Copyright (c) 2009 Red Hat Inc.
983249
+ *  Copyright (c) 2009 Jiri Skala <jskala@redhat.com>
983249
+ *  All rights reserved.
983249
+ *
983249
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
983249
+ *
983249
+ *  Redistribution and use in source and binary forms, with or without
983249
+ *  modification, are permitted provided that the following conditions
983249
+ *  are met:
983249
+ *
983249
+ *    Redistributions of source code must retain the above copyright notice,
983249
+ *    this list of conditions and the following disclaimer.
983249
+ *
983249
+ *    Redistributions in binary form must reproduce the above copyright
983249
+ *    notice, this list of conditions and the following disclaimer in the
983249
+ *    documentation and/or other materials provided with the distribution.
983249
+ *
983249
+ *    Neither the name of Intel Corporation nor the names of its contributors
983249
+ *    may be used to endorse or promote products derived from this software
983249
+ *    without specific prior written permission.
983249
+ *
983249
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
983249
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
983249
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
983249
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
983249
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
983249
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
983249
+ *  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
983249
+ *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
983249
+ *  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
983249
+ *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
983249
+ *  THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
983249
+ *  DAMAGE.
983249
+ *
983249
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
983249
+ */
983249
+
983249
+#ifndef __PARSECONF_H__
983249
+#define __PARSECONF_H__
983249
+
983249
+extern char *bltk_home;
983249
+extern char *soffice_prog;
983249
+extern char *wl_office_working_dir;
983249
+extern char *bltk_player_prog;
983249
+extern char *bltk_player_file;
983249
+extern char *bltk_reader_prog;
983249
+
983249
+extern int wl_developer_enabled;
983249
+extern int wl_developer_extern;
983249
+extern int wl_game_enabled;
983249
+extern int wl_game_extern;
983249
+extern int wl_office_enabled;
983249
+extern int wl_office_extern;
983249
+extern int wl_player_enabled;
983249
+extern int wl_player_extern;
983249
+extern int wl_reader_enabled;
983249
+extern int wl_reader_extern;
983249
+
983249
+#endif
983249
+
983249
diff -up bltk/tools/bltk/main.c.conf bltk/tools/bltk/main.c
983249
--- bltk/tools/bltk/main.c.conf	2009-04-10 09:14:20.000000000 +0200
983249
+++ bltk/tools/bltk/main.c	2009-07-29 11:15:27.694746739 +0200
983249
@@ -57,6 +57,7 @@
983249
 #include <ctype.h>
983249
 
983249
 #include "bltk.h"
983249
+#include "parseconf.h"
983249
 
983249
 #define	OUTPUT_CONSOLE		10
983249
 #define	OUTPUT_FILE		20
983249
@@ -960,12 +961,13 @@ static int environment_init(int argc, ch
983249
 	char str[STR_LEN];
983249
 	int ret, i;
983249
 
983249
-	(void)unlink(LAST_RESULTS);
983249
-	ret = symlink(results, LAST_RESULTS);
983249
+	sprintf(str, "%s/%s", bltk_home, LAST_RESULTS);
983249
+	(void)unlink(str);
983249
+	ret = symlink(results, str);
983249
 	if (ret != 0) {
983249
 		(void)sprintf(prt_str, "symlink(%s, %s) failed, "
983249
 			      "errno %d (%s)\n",
983249
-			      results, LAST_RESULTS, errno, strerror(errno));
983249
+			      results, str, errno, strerror(errno));
983249
 		write_to_err_log(prt_str);
983249
 		prog_exit(1);
983249
 	}
983249
@@ -987,6 +989,7 @@ static int environment_init(int argc, ch
983249
 	(void)sprintf(fail_fname, "%s/fail", results);
983249
 	(void)sprintf(pass_fname, "%s/pass", results);
983249
 	prog_putenv("BLTK_FAIL_FNAME", fail_fname);
983249
+	prog_putenv("BLTK_STOP_FNAME", stop_fname);
983249
 	prog_putenv("BLTK_PASS_FNAME", pass_fname);
983249
 
983249
 	(void)sprintf(err_log_fname, "%s/err.log", results);
983249
@@ -1041,10 +1044,12 @@ static int environment_init(int argc, ch
983249
 	}
983249
 	(void)strcat(cmdline, "'");
983249
 
983249
-	(void)sprintf(cmd, "%s >>history", cmdline);
983249
+	sprintf(str, "%s/%s", bltk_home, HISTORY);
983249
+	(void)sprintf(cmd, "%s >>%s", cmdline, str);
983249
 	(void)prog_system(cmd);
983249
 
983249
-	(void)sprintf(cmd, "%s >last_cmd", cmdline);
983249
+	sprintf(str, "%s/%s", bltk_home, LAST_CMD);
983249
+	(void)sprintf(cmd, "%s >%s", cmdline, str);
983249
 	(void)prog_system(cmd);
983249
 
983249
 	(void)sprintf(cmd, "%s >%s/cmd", cmdline, results);
983249
@@ -1078,7 +1083,7 @@ static int environment_init(int argc, ch
983249
 	set_signal(SIGUSR2);
983249
 	set_signal(SIGHUP);
983249
 
983249
-	(void)sprintf(cmd, "mkdir -p -m 0777 %s/tmp", bltk_root);
983249
+	(void)sprintf(cmd, "mkdir -p -m 0777 %s/tmp", bltk_home);
983249
 	ret = prog_system(cmd);
983249
 	if (ret != 0) {
983249
 		(void)sprintf(prt_str, "%s failed\n", cmd);
983249
@@ -1608,6 +1613,28 @@ static char *get_bltk_root_by_argv0(char
983249
 	return (wp1);
983249
 }
983249
 
983249
+static char *get_bltk_root_by_proc()
983249
+{
983249
+	char str[256], *path, *ret=NULL;
983249
+
983249
+	snprintf(str, sizeof str, "/proc/%d/exe", getpid());
983249
+	if (readlink(str, str, sizeof str) > -1)
983249
+	{
983249
+		if ((path = dirname(str)))
983249
+		{
983249
+			// take one folder higher
983249
+			ret = strrchr(path, '/');
983249
+			if (ret != NULL)
983249
+			{
983249
+				*ret = 0;
983249
+				ret = path;
983249
+			}
983249
+		}
983249
+	}
983249
+
983249
+	return ret ? strdup(ret) : ret;
983249
+}
983249
+
983249
 static char *get_bltk_root_by_path(char *argv0)
983249
 {
983249
 	char *path, *dpath, *res;
983249
@@ -1648,7 +1675,7 @@ static void set_bltk_root(char *argv0)
983249
 	int ret;
983249
 	char cwd[STR_LEN];
983249
 
983249
-	wp1 = check_bltk_root(".");
983249
+	wp1 = get_bltk_root_by_proc();
983249
 	if (wp1 == NULL) {
983249
 		wp1 = get_bltk_root_by_argv0(argv0);
983249
 	}
983249
@@ -1792,6 +1819,12 @@ int main(int argc, char **argv)
983249
 	(void)umask(0);
983249
 	(void)set_path(0);
983249
 
983249
+	param_init();
983249
+
983249
+	prog_putenv("BLTK_HOME", bltk_home);
983249
+	prog_putenv("WL_OFFICE_WORKING_DIR", wl_office_working_dir);
983249
+	prog_putenv("WL_READER_WORKING_DIR", wl_office_working_dir);
983249
+
983249
 	time_start = time_prev = prog_time();
983249
 
983249
 	(void)prog_system("xset dpms 0 0 0 >/dev/null 2>&1");
983249
@@ -2125,7 +2158,7 @@ int main(int argc, char **argv)
983249
 			    ("getcwd() failed, cannot continue the test\n");
983249
 			prog_exit(1);
983249
 		}
983249
-		(void)sprintf(results_str, "%s/%s", results_parent, results);
983249
+		(void)sprintf(results_str, "%s/%s", bltk_home, results);
983249
 		results = results_str;
983249
 	}
983249
 
983249
diff -up bltk/tools/bltk/Makefile.conf bltk/tools/bltk/Makefile
983249
--- bltk/tools/bltk/Makefile.conf	2009-04-10 09:14:20.000000000 +0200
983249
+++ bltk/tools/bltk/Makefile	2009-07-29 11:14:00.917495009 +0200
983249
@@ -4,12 +4,12 @@ CFLAGS		= -Wall -pedantic -std=c99 -g -O
983249
 
983249
 BIN		= ../../bin
983249
 
983249
-FILES		= main init file stat
983249
+FILES		= main init file stat parseconf
983249
 
983249
 OFILES		= ${FILES:=.o}
983249
 CFILES		= ${FILES:=.c}
983249
 
983249
-HIDERS		= ../../include/bltk.h
983249
+HIDERS		= ../../include/bltk.h ../../include/parseconf.h
983249
 
983249
 TARGETS		= $(BIN)/bltk
983249
 
983249
@@ -38,6 +38,7 @@ main.o : $(HIDERS) main.c
983249
 init.o : $(HIDERS) init.c
983249
 file.o : $(HIDERS) file.c
983249
 stat.o : $(HIDERS) stat.c
983249
+parseconf.o : $(HIDERS) parseconf.c
983249
 
983249
 $(SHTARGETS) : $(SHFILES_SH)
983249
 	cp $(@:$(BIN)/%=%.sh) $@
983249
diff -up /dev/null bltk/tools/bltk/parseconf.c
983249
--- /dev/null	2009-07-29 07:53:51.640007938 +0200
983249
+++ bltk/tools/bltk/parseconf.c	2009-07-29 11:14:00.921494700 +0200
983249
@@ -0,0 +1,299 @@
983249
+/*
983249
+ *  Copyright (c) 2009 Red Hat Inc.
983249
+ *  Copyright (c) 2009 Jiri Skala <jskala@redhat.com>
983249
+ *  All rights reserved.
983249
+ *
983249
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
983249
+ *
983249
+ *  Redistribution and use in source and binary forms, with or without
983249
+ *  modification, are permitted provided that the following conditions
983249
+ *  are met:
983249
+ *
983249
+ *    Redistributions of source code must retain the above copyright notice,
983249
+ *    this list of conditions and the following disclaimer.
983249
+ *
983249
+ *    Redistributions in binary form must reproduce the above copyright
983249
+ *    notice, this list of conditions and the following disclaimer in the
983249
+ *    documentation and/or other materials provided with the distribution.
983249
+ *
983249
+ *    Neither the name of Intel Corporation nor the names of its contributors
983249
+ *    may be used to endorse or promote products derived from this software
983249
+ *    without specific prior written permission.
983249
+ *
983249
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
983249
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
983249
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
983249
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
983249
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
983249
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
983249
+ *  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
983249
+ *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
983249
+ *  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
983249
+ *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
983249
+ *  THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
983249
+ *  DAMAGE.
983249
+ *
983249
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
983249
+ */
983249
+
983249
+#include <stdio.h>
983249
+#include <string.h>
983249
+#include <unistd.h>
983249
+#include <stdlib.h>
983249
+#include <errno.h>
983249
+#include <ctype.h>
983249
+#include <sys/stat.h>
983249
+#include <sys/types.h>
983249
+
983249
+#include "bltk.h"
983249
+
983249
+#define BLTK_CONF                   "/etc/bltk.conf"
983249
+
983249
+typedef struct para_item_str_t
983249
+{
983249
+	const char *name;
983249
+	char **val;
983249
+	size_t len;
983249
+} para_item_str;
983249
+
983249
+typedef struct para_item_int_t
983249
+{
983249
+	const char *name;
983249
+	int *val;
983249
+} para_item_int;
983249
+
983249
+typedef struct para_item_bool_t
983249
+{
983249
+	const char *name;
983249
+	int *val;
983249
+} para_item_bool;
983249
+
983249
+char *bltk_home;
983249
+char *soffice_prog;
983249
+char *wl_office_working_dir;
983249
+char *bltk_player_prog;
983249
+char *bltk_player_file;
983249
+char *bltk_reader_prog;
983249
+char *bltk_reader_file;
983249
+
983249
+int wl_developer_enabled;
983249
+int wl_developer_extern;
983249
+int wl_game_enabled;
983249
+int wl_game_extern;
983249
+int wl_office_enabled;
983249
+int wl_office_extern;
983249
+int wl_player_enabled;
983249
+int wl_player_extern;
983249
+int wl_reader_enabled;
983249
+int wl_reader_extern;
983249
+
983249
+static para_item_str params_str[] =
983249
+{
983249
+	{ "BLTK_HOME", &bltk_home, 0 },
983249
+	{ "SOFFICE_PROG", &soffice_prog, 0 },
983249
+	{ "WL_OFFICE_WORKING_DIR", &wl_office_working_dir, 0 },
983249
+	{ "BLTK_PLAYER_PROG", &bltk_player_prog, 0 },
983249
+	{ "BLTK_PLAYER_FILE", &bltk_player_file, 0 },
983249
+	{ "BLTK_READER_PROG", &bltk_reader_prog, 0 },
983249
+	{ "BLTK_READER_FILE", &bltk_reader_file, 0 },
983249
+  { NULL, NULL, 0 }
983249
+};
983249
+
983249
+static para_item_int params_int[] =
983249
+{
983249
+  { NULL, 0 }
983249
+};
983249
+
983249
+static para_item_bool params_bool[] =
983249
+{
983249
+	{ "WL_DEVELOPER_ENABLED", &wl_developer_enabled },
983249
+	{ "WL_DEVELOPER_EXTERN", &wl_developer_extern },
983249
+	{ "WL_GAME_ENABLED", &wl_game_enabled },
983249
+	{ "WL_GAME_EXTERN", &wl_game_extern },
983249
+	{ "WL_OFFICE_ENABLED", &wl_office_enabled },
983249
+	{ "WL_OFFICE_EXTERN", &wl_office_extern },
983249
+	{ "WL_PLAYER_ENABLED", &wl_player_enabled },
983249
+	{ "WL_PLAYER_EXTERN", &wl_player_extern },
983249
+	{ "WL_READER_ENABLED", &wl_reader_enabled },
983249
+	{ "WL_READER_EXTERN", &wl_reader_extern },
983249
+  { NULL, 0 }
983249
+};
983249
+
983249
+
983249
+char *
983249
+strupper(char *str)
983249
+{
983249
+  int i;
983249
+  for (i=0; i < strlen(str); i++)
983249
+    str[i] = (char)toupper(str[i]);
983249
+  return str;
983249
+}
983249
+
983249
+int
983249
+param_find_str(const char *name)
983249
+{
983249
+  int i;
983249
+  for (i=0;
983249
+    params_str[i].name != NULL && strcmp(name, params_str[i].name) != 0;
983249
+    i++) ;
983249
+  return params_str[i].name == NULL ? -1 : i;
983249
+}
983249
+
983249
+int
983249
+param_find_int(const char *name)
983249
+{
983249
+  int i;
983249
+  for (i=0;
983249
+    params_int[i].name != NULL && strcmp(name, params_int[i].name) != 0;
983249
+    i++) ;
983249
+  return params_int[i].name == NULL ? -1 : i;
983249
+}
983249
+
983249
+int
983249
+param_find_bool(const char *name)
983249
+{
983249
+  int i;
983249
+  for (i=0;
983249
+    params_bool[i].name != NULL && strcmp(name, params_bool[i].name) != 0;
983249
+    i++) ;
983249
+  return params_bool[i].name == NULL ? -1 : i;
983249
+}
983249
+
983249
+int
983249
+line_empty_or_spaces(const char *line)
983249
+{
983249
+  int i;
983249
+  for (i=0; line[i] > 0 && line[i] <= ' ' && i < strlen(line); i++) ;
983249
+  return line[i] == 0;
983249
+}
983249
+
983249
+int
983249
+line_commented(const char *line)
983249
+{
983249
+  int i;
983249
+  for (i=0; line[i] > 0 && line[i] <= ' ' && i < strlen(line); i++) ;
983249
+  return line[i] == '#';
983249
+}
983249
+
983249
+int
983249
+param_parse_line(const char *line, char *name, char *val)
983249
+{
983249
+  char *str, *str1;
983249
+  int ret=-1;
983249
+
983249
+  str = strdup(line);
983249
+  if ((str1 = strchr(str, '=')) != NULL)
983249
+  {
983249
+    *str1 = 0;
983249
+    str1++;
983249
+    strcpy(val, str1);
983249
+    strcpy(name, str);
983249
+    ret = 0;
983249
+  }
983249
+  else
983249
+  {
983249
+    fprintf(stderr, "Incorrect line in the %s\n", BLTK_CONF);
983249
+  } 
983249
+  free (str);
983249
+  return ret;
983249
+}
983249
+
983249
+void
983249
+param_export_value(const char *name)
983249
+{
983249
+	char expval[STR_LEN];
983249
+  int index;
983249
+
983249
+  if ((index = param_find_str(name)) > -1)
983249
+	  snprintf(expval, STR_LEN, "%s=%s", name, *(params_str[index].val));
983249
+  else if ((index = param_find_int(name)) > -1)
983249
+	  snprintf(expval, STR_LEN, "%s=%d", name, *(params_int[index].val));
983249
+  else if ((index = param_find_bool(name)) > -1)
983249
+	  snprintf(expval, STR_LEN, "%s=%s", name, *(params_bool[index].val) ? "YES": "NO");
983249
+
983249
+  if (index > -1)
983249
+    putenv(strdup(expval));
983249
+  else
983249
+    fprintf(stderr, "Undefined parameter (%s)\n", name);
983249
+}
983249
+
983249
+void
983249
+param_load_conf()
983249
+{
983249
+  char str[STR_LEN];
983249
+  char name[STR_LEN], val[STR_LEN];
983249
+  int index, len;
983249
+	FILE *f;
983249
+
983249
+  if ((f = fopen(BLTK_CONF, "rt")) != NULL)
983249
+  {
983249
+    while (fgets(str, STR_LEN, f) != NULL)
983249
+    {
983249
+      if ((len = strlen(str)) > 0 && str[len-1] == '\n')
983249
+        str[len-1] = 0;
983249
+      if (line_empty_or_spaces(str) || line_commented(str))
983249
+        continue;
983249
+
983249
+      param_parse_line(str, name, val);
983249
+
983249
+      if ((index = param_find_str(name)) > -1)
983249
+        *(params_str[index].val) = strdup(val);
983249
+      else if ((index = param_find_int(name)) > -1)
983249
+        *(params_int[index].val) = atoi(val);
983249
+      else if ((index = param_find_bool(name)) > -1)
983249
+      {
983249
+        if (!strcmp(strupper(val), "YES") ||
983249
+            !strcmp(strupper(val), "TRUE") ||
983249
+            val[0] == '1')
983249
+          *(params_bool[index].val) = 1;
983249
+        else if (!strcmp(strupper(val), "NO") ||
983249
+            !strcmp(strupper(val), "FALSE") ||
983249
+            val[0] == '0')
983249
+          *(params_bool[index].val) = 0;
983249
+      }
983249
+    }
983249
+
983249
+    fclose(f);
983249
+  }
983249
+}
983249
+
983249
+void
983249
+param_load_defaults()
983249
+{
983249
+  char str[STR_LEN];
983249
+
983249
+  if (bltk_home == NULL)
983249
+  {
983249
+    sprintf(str, "%s/.bltk", getenv("HOME"));
983249
+    bltk_home = strdup(str);
983249
+  } else if (bltk_home[0] == '~') {
983249
+    sprintf(str, "%s%s", getenv("HOME"), bltk_home+1);
983249
+    free(bltk_home);
983249
+    bltk_home = strdup(str);
983249
+  }
983249
+
983249
+  if (access(bltk_home, 0) != 0)
983249
+    mkdir(bltk_home, 0700);
983249
+
983249
+  if (wl_office_working_dir == NULL)
983249
+    wl_office_working_dir = strdup(bltk_home);
983249
+
983249
+  if (access(wl_office_working_dir, 0) != 0)
983249
+  {
983249
+    if (wl_office_working_dir[0] == '~')
983249
+    {
983249
+      sprintf(str, "%s%s", getenv("HOME"), wl_office_working_dir+1);
983249
+      free(wl_office_working_dir);
983249
+      wl_office_working_dir = strdup(str);
983249
+    }
983249
+    mkdir(wl_office_working_dir, 0700);
983249
+  }
983249
+}
983249
+
983249
+void
983249
+param_init()
983249
+{
983249
+  param_load_conf();
983249
+  param_load_defaults();
983249
+}
983249
+