[Initng-svn] r1907 - in initng: initfiles/daemon initfiles/system
plugins/bash_launcher plugins/dparser plugins/envparser
plugins/iparser plugins/ngc2 plugins/provide plugins/stcmd src
svn at initng.thinktux.net
svn at initng.thinktux.net
Tue Nov 1 12:22:07 CET 2005
Author: jimmy
Date: Tue Nov 1 12:22:05 2005
New Revision: 1907
Modified:
initng/initfiles/daemon/ifplugd.ii
initng/initfiles/system/alsasound.ii
initng/plugins/bash_launcher/initng_bash_launcher.c
initng/plugins/dparser/initng_d_parser.c
initng/plugins/envparser/initng_envparser.c
initng/plugins/iparser/initng_i_parser.c
initng/plugins/ngc2/initng_ngc2.c
initng/plugins/provide/initng_provide.c
initng/plugins/stcmd/initng_stcmd.c
initng/plugins/stcmd/print_service.c
initng/src/initng_active_db.c
initng/src/initng_global.c
initng/src/initng_service_data_types.h
initng/src/initng_string_tools.c
initng/src/initng_string_tools.h
initng/src/initng_struct_data.c
Log:
Big cleanup for the i_parser and fixes all over.
Modified: initng/initfiles/daemon/ifplugd.ii
==============================================================================
--- initng/initfiles/daemon/ifplugd.ii (original)
+++ initng/initfiles/daemon/ifplugd.ii Tue Nov 1 12:22:05 2005
@@ -1,4 +1,6 @@
+
+
daemon daemon/ifplugd/* {
#*/
need = system/mountfs system/modules
@@ -24,6 +26,4 @@
/sbin/ngc -d daemon/ifplugd/$IF &> /dev/null
done
}
-
-
}
Modified: initng/initfiles/system/alsasound.ii
==============================================================================
--- initng/initfiles/system/alsasound.ii (original)
+++ initng/initfiles/system/alsasound.ii Tue Nov 1 12:22:05 2005
@@ -15,18 +15,18 @@
# Copyright (c) by Jaroslav Kysela <perex at suse.cz>
#
#
-# This program is free software; you can redistribute it and/or modify
+# This program is free software you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# the Free Software Foundation either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# 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 General Public License
-# along with this program; if not, write to the Free Software
+# along with this program if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# ChangeLog:
Modified: initng/plugins/bash_launcher/initng_bash_launcher.c
==============================================================================
--- initng/plugins/bash_launcher/initng_bash_launcher.c (original)
+++ initng/plugins/bash_launcher/initng_bash_launcher.c Tue Nov 1 12:22:05 2005
@@ -51,10 +51,10 @@
#include "initng_bash_launcher.h"
-s_entry START_SCRIPT = { "start{", SCRIPT, 6, SERVICE_OPT };
-s_entry STOP_SCRIPT = { "stop{", SCRIPT, 5, SERVICE_OPT };
-s_entry DAEMON_SCRIPT = { "daemon{", SCRIPT, 7, DAEMON_OPT };
-s_entry KILL_SCRIPT = { "kill{", SCRIPT, 5, DAEMON_OPT };
+s_entry START_SCRIPT = { "start{", MULTILINE_STRING, 6, SERVICE_OPT };
+s_entry STOP_SCRIPT = { "stop{", MULTILINE_STRING, 5, SERVICE_OPT };
+s_entry DAEMON_SCRIPT = { "daemon{", MULTILINE_STRING, 7, DAEMON_OPT };
+s_entry KILL_SCRIPT = { "kill{", MULTILINE_STRING, 5, DAEMON_OPT };
static void bash_this(char *bash_code, active_h * s, char *args);
static int bash_exec(process_h * process_to_exec, active_h * s,
@@ -96,7 +96,7 @@
}
- /* WE ARE EXECUTING A START SCRIPT */
+ /* WE ARE EXECUTING A START MULTILINE_STRING */
if ((e = active_db_get_string(EXEC, service)))
{
char *args = NULL;
Modified: initng/plugins/dparser/initng_d_parser.c
==============================================================================
--- initng/plugins/dparser/initng_d_parser.c (original)
+++ initng/plugins/dparser/initng_d_parser.c Tue Nov 1 12:22:05 2005
@@ -191,7 +191,7 @@
case STRINGS:
strings_d_parser(current, tmp, serv);
return;
- case SCRIPT:
+ case MULTILINE_STRING:
script_d_parser(current, tmp, serv);
return;
case SET:
Modified: initng/plugins/envparser/initng_envparser.c
==============================================================================
--- initng/plugins/envparser/initng_envparser.c (original)
+++ initng/plugins/envparser/initng_envparser.c Tue Nov 1 12:22:05 2005
@@ -44,6 +44,8 @@
char *file = NULL;
char *file_content = NULL;
char *point = NULL;
+
+ assert(s);
/* go to last row on this array */
while (env[i])
Modified: initng/plugins/iparser/initng_i_parser.c
==============================================================================
--- initng/plugins/iparser/initng_i_parser.c (original)
+++ initng/plugins/iparser/initng_i_parser.c Tue Nov 1 12:22:05 2005
@@ -40,10 +40,11 @@
#include "initng_i_parser.h"
+static void print_line(char *from);
static service_h *parse_file(char *filename, char *watch_for);
-static service_h *parse_service_line(char **to_parse, char *watch_for,
+static int parse_service_line(char **to_parse, char *watch_for,
service_h * father, e_type type,
- char *filename);
+ char *filename, service_h **match, service_h **exact_match);
static int parse_opt(char **where, e_type type, service_h * srv);
static int set_parser(s_entry * type, char **value, service_h * from_service);
@@ -59,18 +60,16 @@
-
-
-/* Load a service from a process_name or process_path */
-service_h *initng_i_parser(char *process_name)
+/* Load a service from a service_to_find or process_path */
+service_h *initng_i_parser(char *service_to_find)
{
char filetoparse[200];
char *tmp = NULL;
service_h *got_serv = NULL;
- assert(process_name);
- D_("initng_i_parser(%s);\n", process_name);
- /* example INITNG_ROOT=/etc/initng process_name="deamon/sshd INITNG_EXT=".i" */
+ assert(service_to_find);
+ D_("initng_i_parser(%s);\n", service_to_find);
+ /* example INITNG_ROOT=/etc/initng service_to_find="deamon/sshd INITNG_EXT=".i" */
/* TRY NO 1, try load "/etc/initng/daemon/sshd.i" */
/* TRY NO 2, try load "/etc/initng/daemon/sshd/sshd.i" */
/* TRY NO 3, try load "/etc/initng/daemon/sshd/default.i" */
@@ -81,78 +80,84 @@
/* TRY NO 1, try load "/etc/initng/daemon/sshd/sshd.i" */
strcpy(filetoparse, INITNG_ROOT "/");
- strcat(filetoparse, process_name);
+ strcat(filetoparse, service_to_find);
strcat(filetoparse, "/");
- strcat(filetoparse, st_strip_path(process_name));
+ strcat(filetoparse, st_strip_path(service_to_find));
strcat(filetoparse, INITNG_EXT);
- if ((got_serv = parse_file(filetoparse, process_name)))
+ if ((got_serv = parse_file(filetoparse, service_to_find)))
return (got_serv);
/* TRY NO 2, try load "/etc/initng/daemon/sshd.i" */
strcpy(filetoparse, INITNG_ROOT "/");
- strcat(filetoparse, process_name);
+ strcat(filetoparse, service_to_find);
strcat(filetoparse, INITNG_EXT);
- if ((got_serv = parse_file(filetoparse, process_name)))
+ if ((got_serv = parse_file(filetoparse, service_to_find)))
return (got_serv);
/* TRY NO 3, try load "/etc/initng/daemon/sshd/default.i" */
strcpy(filetoparse, INITNG_ROOT "/");
- strcat(filetoparse, process_name);
+ strcat(filetoparse, service_to_find);
strcat(filetoparse, "/default" INITNG_EXT);
- if ((got_serv = parse_file(filetoparse, process_name)))
+ if ((got_serv = parse_file(filetoparse, service_to_find)))
return (got_serv);
/* TRY NO 4, try "/etc/initng/daemon/default.i" */
- tmp = st_get_path(process_name);
+ tmp = st_get_path(service_to_find);
strcpy(filetoparse, INITNG_ROOT "/");
strcat(filetoparse, tmp);
strcat(filetoparse, "/default" INITNG_EXT);
free(tmp);
- if ((got_serv = parse_file(filetoparse, process_name)))
+ if ((got_serv = parse_file(filetoparse, service_to_find)))
return (got_serv);
/* TRY NO 5, try "/etc/initng/daemon/daemon.i" */
- tmp = st_get_path(process_name);
+ tmp = st_get_path(service_to_find);
strcpy(filetoparse, INITNG_ROOT "/");
strcat(filetoparse, tmp);
strcat(filetoparse, "/");
strcat(filetoparse, tmp);
strcat(filetoparse, INITNG_EXT);
free(tmp);
- if ((got_serv = parse_file(filetoparse, process_name)))
+ if ((got_serv = parse_file(filetoparse, service_to_find)))
return (got_serv);
/* TRY NO 6, try "/etc/initng/sshd.i" */
strcpy(filetoparse, INITNG_ROOT "/");
- strcat(filetoparse, st_strip_path(process_name));
+ strcat(filetoparse, st_strip_path(service_to_find));
strcat(filetoparse, INITNG_EXT);
- if ((got_serv = parse_file(filetoparse, process_name)))
+ if ((got_serv = parse_file(filetoparse, service_to_find)))
return (got_serv);
/* TRY NO 7, try "/etc/initng/daemon.i" */
- tmp = st_get_path(process_name);
+ tmp = st_get_path(service_to_find);
strcpy(filetoparse, INITNG_ROOT "/");
strcat(filetoparse, tmp);
strcat(filetoparse, INITNG_EXT);
free(tmp);
- if ((got_serv = parse_file(filetoparse, process_name)))
+ if ((got_serv = parse_file(filetoparse, service_to_find)))
return (got_serv);
-
- D_("initng_load_process(%s): got \"NULL\"\n", process_name);
+ D_("Did not be able to parse: %s\n", service_to_find);
return (NULL);
}
-
+static void print_line(char *from)
+{
+ /* Complain a bit */
+ char *line = i_strndup(from, strcspn(from, "\n\0"));
+ D_("%s\n", line);
+ free(line);
+}
/* parse a file for services */
static service_h *parse_file(char *filename, char *watch_for)
{
char *file, *orig;
- service_h *service_to_return = NULL;
- service_h *tmp = NULL;
+ e_type t=TYPE_UNKNOWN;
+ service_h *match = NULL;
+ service_h *exact_match = NULL;
assert(filename);
assert(watch_for);
@@ -177,7 +182,7 @@
break;
/* skip lines starting with '#' */
- if (file[0] == '#')
+ if (file[0] == '#' || file[0] == '\n' || file[0] == ';')
{
JUMP_TO_NEXT_ROW(file);
continue;
@@ -185,79 +190,66 @@
/* if this row has keyword service */
if (st_cmp(&file, "service"))
- {
- if ((tmp =
- parse_service_line(&file, watch_for, NULL, TYPE_SERVICE,
- filename)))
- service_to_return = tmp;
- /* if this row has keyword class */
- }
+ t=TYPE_SERVICE;
else if (st_cmp(&file, "class"))
- {
- if ((tmp =
- parse_service_line(&file, watch_for, NULL, TYPE_CLASS,
- filename)))
- service_to_return = tmp;
- }
+ t=TYPE_CLASS;
else if (st_cmp(&file, "daemon"))
- {
- if ((tmp =
- parse_service_line(&file, watch_for, NULL, TYPE_DAEMON,
- filename)))
- service_to_return = tmp;
- }
+ t=TYPE_DAEMON;
else if (st_cmp(&file, "virtual"))
- {
- if ((tmp =
- parse_service_line(&file, watch_for, NULL, TYPE_VIRTUAL,
- filename)))
- service_to_return = tmp;
- }
+ t=TYPE_VIRTUAL;
+
- JUMP_TO_NEXT_ROW(file);
+ if(t!=TYPE_UNKNOWN)
+ {
+ if(parse_service_line(&file, watch_for, NULL, t,
+ filename, &match, &exact_match)==TRUE)
+ {
+ /* if we found RIGHT what we wanted */
+ if(exact_match)
+ {
+ free(orig);
+ return(exact_match);
+ }
+
+ JUMP_TO_NEXT_ROW(file);
+ continue;
+ }
+ }
+
+ /* else BAIL OUT */
+
+ F_("PARSE ERROR parse_file(%s): ", watch_for);
+ print_line(file);
+ F_("sleeping 2 seconds, then ABORT......\n");
+ sleep(2);
+ free(orig);
+ return(NULL);
} /* end while */
free(orig);
-#ifdef DEBUG_PRINT
- print_all();
-#endif
- /*exit_initng(1); */
-
- /*
- * Search the service chache again for an exeact match,
- * if this wasnt exactly what we where watching for.
- */
- if (!service_to_return
- || (service_to_return
- && strcmp(service_to_return->name, watch_for) != 0))
- if ((tmp = service_db_find_by_exact_name(watch_for)))
- return (tmp);
/* Return what we got, and hope for the best */
- if (service_to_return)
- return (service_to_return);
-
- return (NULL);
+ return (match);
}
-static service_h *parse_service_line(char **to_parse, char *watch_for,
+static int parse_service_line(char **to_parse, char *watch_for,
service_h * father, e_type type,
- char *filename)
+ char *filename, service_h **match, service_h **exact_match)
{
char *name = NULL;
char *father_name = NULL;
service_h *new_service = NULL;
- service_h *service_to_return = NULL;
service_h *duplicate = NULL;
assert(to_parse);
assert(*to_parse);
assert(watch_for);
- D_("parse_service_line(*s*,%s);\n", watch_for);
+ D_("parse_service_line(%s): ", watch_for);
+ print_line(*to_parse);
/* service test : class { */
/* | */
@@ -271,7 +263,7 @@
if (!(name = st_dup_next_word(to_parse)))
{
F_("Did not got name!\n");
- return (NULL);
+ return (FALSE);
}
/* service test : class { */
/* | */
@@ -313,7 +305,7 @@
{
/* something is wrong */
F_("error parsing, expected something else.\n");
- return (NULL);
+ return (FALSE);
}
/* jump to first char after start tag and begin from there. */
@@ -335,7 +327,7 @@
free(name);
if (father_name)
free(father_name);
- return (NULL);
+ return (FALSE);
}
/* set the father to the service */
@@ -378,8 +370,6 @@
/* carry on until segment stop or eof, this will handle all lines in current section */
while ((*to_parse)[0] != '\0' && (*to_parse)[0] != '}')
{
- service_h *tmp = NULL;
-
while (TRUE)
{
/* skip spaces and empty lines with them */
@@ -404,10 +394,9 @@
/* if this row has keyword service */
if (st_cmp(to_parse, "service") == TRUE)
{
- if ((tmp =
- parse_service_line(to_parse, watch_for, NULL, TYPE_SERVICE,
- filename)))
- service_to_return = tmp;
+ if(parse_service_line(to_parse, watch_for, NULL, TYPE_SERVICE,
+ filename, match, exact_match)==FALSE)
+ return(FALSE);
JUMP_TO_NEXT_ROW(*to_parse);
continue;
}
@@ -427,17 +416,19 @@
/* if this row has keyword class */
if (st_cmp(to_parse, "class") == TRUE)
{
- if ((tmp =
- parse_service_line(to_parse, watch_for, NULL, TYPE_CLASS,
- filename)))
- service_to_return = tmp;
+ if (parse_service_line(to_parse, watch_for, NULL, TYPE_CLASS,
+ filename, match, exact_match)==FALSE)
+ return(FALSE);
JUMP_TO_NEXT_ROW(*to_parse);
continue;
}
/* parse line - search for keywords in g.option_table */
- parse_opt(to_parse, type, new_service);
-
+ if(!parse_opt(to_parse, type, new_service)) {
+ if(new_service) service_db_free(new_service);
+ return(FALSE);
+ }
+
/* ok, this line is parsed, go to next */
JUMP_TO_NEXT_ROW(*to_parse);
}
@@ -454,19 +445,28 @@
service_db_remove_all(new_service);
if (new_service)
- free(new_service);
- return (NULL);
+ service_db_free(new_service);
+ return (FALSE);
}
-
+
+ if(strcmp(new_service->name, watch_for)==0)
+ {
+ D_("Found EXACT match: %s\n", new_service->name);
+ (*exact_match)=new_service;
+ return(TRUE);
+ }
+
/* check if this is the service we are looking for. */
- if (fnmatch(new_service->name, watch_for, FNM_CASEFOLD) == 0)
- return (new_service);
-
- /* if we got a service from a under service */
- if (service_to_return)
- return (service_to_return);
+ if (service_match(watch_for, new_service->name)==TRUE)
+ {
+ D_("Found :%s\n", new_service->name);
+ (*match)=new_service;
+ return(TRUE);
+ }
+
+ D_("No match\n");
/* return null if not */
- return (NULL);
+ return (TRUE);
}
@@ -474,8 +474,13 @@
static int parse_opt(char **where, e_type type, service_h * srv)
{
s_entry *current = NULL;
+ char *opt_name = NULL;
+ int opt_len=0;
int w_l = 0;
int result = FALSE;
+ int multiline = FALSE;
+ D_("parse_opt: ");
+ print_line(*where);
while (TRUE)
{
@@ -507,11 +512,54 @@
return (FALSE);
}
+ /* detect if it is a multi line option */
+ {
+ int i;
+ for(i=0; i<w_l; i++)
+ {
+ switch((*where)[i])
+ {
+ /* this idicates that it ends */
+ case '\n':
+ case ';':
+ case '\0':
+ multiline=FALSE;
+ i=w_l+1; /* stops the for loop */
+ break;
+ /* this indicates that option will be in more rows */
+ case '{':
+ multiline=TRUE;
+ i=w_l+1; /* stops the for loop */
+ break;
+ }
+ }
+ }
+
/* get option name and strip all blanks from it */
- char *opt_name = i_strndup(*where, w_l);
-
- st_strip(opt_name);
-
+ opt_name = initng_calloc(w_l+2, sizeof(char));
+ {
+ int i;
+ int j=0;
+ for(i=0; i<=w_l; i++)
+ {
+ switch((*where)[i])
+ {
+ case ' ':
+ case '\t':
+ continue;
+ case '\n':
+ case ';':
+ i=w_l+1;
+ continue;
+ }
+ opt_name[j++]=(*where)[i];
+ }
+ opt_name[j]='\0';
+ }
+ /* we save this, so we dont need to count this every while below */
+ opt_len=strlen(opt_name);
+
+ /* walk the option db */
while_option_db(current)
{
/* temporary pointer storage */
@@ -549,11 +597,11 @@
}
/* check string lenght of word, this is faster then strcasecmp */
- if ((int) strlen(opt_name) != current->str_len)
+ if (opt_len != current->str_len)
continue;
/* finaly, check if opt_name is what we are looking for */
- if (strcasecmp(current->opt_name, opt_name) != 0)
+ if (strncmp(current->opt_name, opt_name, opt_len) != 0)
continue;
D_("parse_opt(%s): option \"%s\" value at option.\n",
@@ -572,6 +620,15 @@
while (tmp->opt_type == ALIAS && tmp->alias)
tmp = tmp->alias;
+ if(multiline)
+ {
+ if(tmp->opt_type==MULTILINE_STRING) {
+ result = script_parser(current, where, srv);
+ } else {
+ D_("Option is contains a '{' but is not a MULTILINE_STRING!\n");
+ continue;
+ }
+ } else {
/* now switch the opt_type */
switch (tmp->opt_type)
{
@@ -581,7 +638,7 @@
case STRINGS:
result = strings_parser(current, where, srv);
break;
- case SCRIPT:
+ case MULTILINE_STRING:
result = script_parser(current, where, srv);
break;
case SET:
@@ -597,6 +654,7 @@
F_("Unknowun, or undefined type to parse!\n");
continue;
}
+ }
}
free(opt_name);
@@ -650,14 +708,16 @@
char *to;
assert(from_service);
- if (!(*value))
- return (FALSE);
+ assert(*value);
+ assert(value);
+
D_("string_parser(%s,s,%s);\n", type->opt_name, from_service->name);
if ((to = st_dup_line(value)))
{
service_db_set_string(type, from_service, to);
return (TRUE);
}
+ F_("Unable to parse line!\n");
return (FALSE);
}
@@ -666,17 +726,17 @@
char *to;
assert(from_service);
- if (!(*value))
- return (FALSE);
+ assert(*value);
+ assert(value);
+
D_("int_parser(%s,s,%s);\n", type->opt_name, from_service->name);
if ((to = st_dup_line(value)))
{
service_db_set_int(type, from_service, atoi(to));
if (to)
free(to);
- return (TRUE);
}
- return (FALSE);
+ return (TRUE);
}
static int strings_parser(s_entry * type, char **value,
@@ -685,8 +745,9 @@
char *to = NULL;
assert(from_service);
- if (!(*value))
- return (FALSE);
+ assert(*value);
+ assert(value);
+
D_("strings_parser(%s,s,%s);\n", type->opt_name, from_service->name);
while ((to = st_dup_next_word(value)))
@@ -695,7 +756,6 @@
JUMP_SPACES(*value);
}
return (TRUE);
- /*return(FALSE); */
}
static int script_parser(s_entry * type, char **value,
@@ -704,6 +764,9 @@
int stack_length = 0;
assert(from_service);
+ assert(*value);
+ assert(value);
+
D_("script_parser(%s,s,%s);\n", type->opt_name, from_service->name);
stack_length = chars_to_end_of_this_stack(*value);
Modified: initng/plugins/ngc2/initng_ngc2.c
==============================================================================
--- initng/plugins/ngc2/initng_ngc2.c (original)
+++ initng/plugins/ngc2/initng_ngc2.c Tue Nov 1 12:22:05 2005
@@ -605,7 +605,7 @@
if (!arg || strlen(arg) < 2)
return;
- serv = active_db_find_by_name(arg);
+ serv = active_db_find_in_name(arg);
if (!serv)
return;
@@ -627,7 +627,7 @@
if (arg && strlen(arg) > 1)
{
- if ((current = active_db_find_by_name(arg)))
+ if ((current = active_db_find_in_name(arg)))
{
row.s = current->a_status;
row.t = current->time_got_status;
Modified: initng/plugins/provide/initng_provide.c
==============================================================================
--- initng/plugins/provide/initng_provide.c (original)
+++ initng/plugins/provide/initng_provide.c Tue Nov 1 12:22:05 2005
@@ -123,7 +123,7 @@
assert(name);
/* check if an virtual exits - then set its status */
- if ((act = active_db_find_by_name(name)) && (act->type == TYPE_VIRTUAL))
+ if ((act = active_db_find_in_name(name)) && (act->type == TYPE_VIRTUAL))
{
mark_service(act, STOPPED);
active_db_del(act);
Modified: initng/plugins/stcmd/initng_stcmd.c
==============================================================================
--- initng/plugins/stcmd/initng_stcmd.c (original)
+++ initng/plugins/stcmd/initng_stcmd.c Tue Nov 1 12:22:05 2005
@@ -197,7 +197,7 @@
return (0);
- if (!(apt = active_db_find_by_name(arg)))
+ if (!(apt = active_db_find_in_name(arg)))
return (0);
/* browse all proceses */
@@ -231,7 +231,7 @@
if (!arg)
return (FALSE);
- if (!(apt = active_db_find_by_name(arg)))
+ if (!(apt = active_db_find_in_name(arg)))
return (FALSE);
active_db_del(apt);
@@ -246,7 +246,7 @@
if (!arg)
return (FALSE);
- apt = active_db_find_by_name(arg);
+ apt = active_db_find_in_name(arg);
if (!apt)
return (FALSE);
@@ -269,7 +269,7 @@
if (!arg)
return;
- apt = active_db_find_by_name(arg);
+ apt = active_db_find_in_name(arg);
if (!apt)
return;
@@ -283,7 +283,7 @@
{
service_h *s;
- s = service_db_find_by_name(arg);
+ s = service_db_find_in_name(arg);
if (!s)
{
D_("Clearing complete db.\n");
@@ -360,7 +360,7 @@
service_h *s;
D_("Print service \"%s\"\n", arg);
- if (arg && strlen(arg) > 1 && (s = service_db_find_by_name(arg)))
+ if (arg && strlen(arg) > 1 && (s = service_db_find_in_name(arg)))
{
service_db_print(s, fd);
}
@@ -381,7 +381,7 @@
{
active_h *s;
- if (arg && strlen(arg) > 1 && (s = active_db_find_by_name(arg)))
+ if (arg && strlen(arg) > 1 && (s = active_db_find_in_name(arg)))
{
active_db_print(s, fd);
}
@@ -410,7 +410,7 @@
{
service_h *s;
- s = service_db_find_by_name(arg);
+ s = service_db_find_in_name(arg);
if (!s)
{
F_("Did not find service: %s\n", arg);
@@ -432,7 +432,7 @@
active_h *current = NULL;
active_h *on = NULL;
- on = active_db_find_by_name(arg);
+ on = active_db_find_in_name(arg);
if (!on)
{
@@ -458,7 +458,7 @@
active_h *current = NULL;
active_h *on = NULL;
- on = active_db_find_by_name(arg);
+ on = active_db_find_in_name(arg);
if (!on)
{
Modified: initng/plugins/stcmd/print_service.c
==============================================================================
--- initng/plugins/stcmd/print_service.c (original)
+++ initng/plugins/stcmd/print_service.c Tue Nov 1 12:22:05 2005
@@ -101,7 +101,7 @@
{
if (tmp->type->opt_type == STRING ||
tmp->type->opt_type == STRINGS
- || tmp->type->opt_type == SCRIPT)
+ || tmp->type->opt_type == MULTILINE_STRING)
{
if (!tmp->t.s)
@@ -263,7 +263,7 @@
{
case STRING:
case STRINGS:
- case SCRIPT:
+ case MULTILINE_STRING:
if (!tmp->t.s)
break;
@@ -303,7 +303,7 @@
{
case STRING:
case STRINGS:
- case SCRIPT:
+ case MULTILINE_STRING:
if (!tmp->t.s)
break;
Modified: initng/src/initng_active_db.c
==============================================================================
--- initng/src/initng_active_db.c (original)
+++ initng/src/initng_active_db.c Tue Nov 1 12:22:05 2005
@@ -37,13 +37,17 @@
#include "initng_common.h"
#include "initng_static_data_id.h"
#include "initng_plugin_callers.h"
+#include "initng_string_tools.h"
/* ##### ACTIVE_DB_FIND_BY ######## */
-/* return index of service in active data structure or -1 if not found */
+/*
+ * This is an exact search "net/eth0" must be "net/eth0"
+ */
active_h *active_db_find_by_exact_name(const char *service)
{
active_h *current = NULL;
+ D_("(%s);", service);
assert(service);
@@ -60,81 +64,82 @@
return NULL;
}
+/*
+ * This is an less exact name, that will work with wildcards.
+ * Searching for "net/eth*" will give you "net/eth0"
+ */
active_h *active_db_find_by_name(const char *service)
{
assert(service);
+ active_h *current = NULL;
- active_h *current = active_db_find_by_exact_name(service);
-
- if (current)
- return (current);
-
- /* do pattern matching only if service name does not contain wildcards */
- if (strchr(service, '*') || strchr(service, '?'))
- return (NULL);
-
- /* create service name mask for pattern matching */
- char *service_mask = initng_calloc(strlen(service) + 3, sizeof(char));
+ D_("(%s);", service);
- strcpy(service_mask, "*/");
- strcat(service_mask, service);
+ /* first give the exact find a shot */
+ if((current = active_db_find_by_exact_name(service)))
+ return(current);
+ /* walk the active db and compere */
+ current=NULL;
while_active_db(current)
{
assert(current->name);
/* then try to find alike name */
+ if(service_match(current->name, service))
+ return(current);
- /* if existing service is a pattern */
- if (strchr(current->name, '*') || strchr(current->name, '?'))
- {
- if (fnmatch(current->name, service, FNM_CASEFOLD) == 0)
-
- {
- D_("active_db_find_by_name(%s): Found\n", current->name);
- free(service_mask);
- return (current);
- }
- }
- else if (fnmatch(service_mask, current->name, FNM_CASEFOLD) == 0)
- {
- D_("active_db_find_by_name(%s): Found\n", current->name);
- free(service_mask);
- return (current);
- }
}
+
/* did not find any */
- free(service_mask);
return NULL;
}
+/*
+ * This will search and find the best possible.
+ * Search for "eth" will get you "net/eth0"
+ */
active_h *active_db_find_in_name(const char *service)
{
active_h *current = NULL;
-
+ char *copy = NULL;
+ int i=0;
assert(service);
- /* first, search for an exact match */
- while_active_db(current)
+ D_("(%s);", service);
+
+ /* first search by name */
+ if ((current = active_db_find_by_name(service)))
+ return(current);
+
+ /* remove starting wildcards */
+ while(service[0]=='*' || service[0]=='?')
+ service++;
+
+ copy=i_strdup(service);
+ assert(copy);
+
+ /* remove last wildcards */
+ for(i=0; copy[i] ; i++)
{
- assert(current->name);
- /* check if this service name is like service */
- if (strcmp(current->name, service) == 0)
- return (current); /* return it */
+ if(copy[i]=='*' || copy[i]=='?')
+ copy[i]='\0';
}
-
+
/* then search for a word match */
current = NULL;
while_active_db(current)
{
assert(current->name);
/* check if this service name is like service */
- if (strstr(current->name, service))
+ if (strstr(current->name, copy))
{
D_("Warning, the return is not an exact match!\n");
+ free(copy);
return (current); /* return it */
}
}
-
+ free(copy);
+
/* did not find any */
return NULL;
}
@@ -268,9 +273,20 @@
/* remove every data entry */
d_remove_all(&pf->data.list);
+ /* remove file cache of entry if present, so we got a fresh read from file when this service is restarted */
+ if(pf->from_service)
+ {
+ /* remove from cache list */
+ list_del(&pf->from_service->list);
+ /* free entry */
+ service_db_free(pf->from_service);
+ }
+
+ /* free service name */
if (pf->name)
free(pf->name);
+ /* free service struct */
free(pf);
}
Modified: initng/src/initng_global.c
==============================================================================
--- initng/src/initng_global.c (original)
+++ initng/src/initng_global.c Tue Nov 1 12:22:05 2005
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "initng.h"
#include "initng_global.h"
#include "initng_load_module.h"
@@ -34,6 +35,9 @@
void initng_new(int argc, char *argv[], char *env[])
{
int i;
+
+ assert(argv);
+ assert(env);
/* we want to keep a copy of the arguments passed to us */
g.Argc = argc;
Modified: initng/src/initng_service_data_types.h
==============================================================================
--- initng/src/initng_service_data_types.h (original)
+++ initng/src/initng_service_data_types.h Tue Nov 1 12:22:05 2005
@@ -31,7 +31,7 @@
STRINGS = 2,
SET = 3,
UNSET = 4,
- SCRIPT = 5,
+ MULTILINE_STRING = 5,
INT = 6,
ALIAS = 7
} e_dt;
Modified: initng/src/initng_string_tools.c
==============================================================================
--- initng/src/initng_string_tools.c (original)
+++ initng/src/initng_string_tools.c Tue Nov 1 12:22:05 2005
@@ -26,6 +26,8 @@
#include <string.h>
#include <stdio.h>
#include <ctype.h>
+#include <assert.h>
+#include <stdlib.h>
#include "initng_string_tools.h"
#include "initng_toolbox.h"
@@ -49,6 +51,8 @@
/* step 1: count tokens */
char *s;
+ assert(buf);
+
for (s = buf; *s; s++)
if (*s == '\n' || *s == ',' || *s == ';' || *s == ' ')
n++;
@@ -79,10 +83,12 @@
* the string lent to the }, there can be many
* { and } in the middle.
*/
-int chars_to_end_of_this_stack(char *string)
+int chars_to_end_of_this_stack(const char *string)
{
int i = 0;
int stacks = 1;
+
+ assert(string);
while (string[i] != '\0')
{
@@ -106,8 +112,13 @@
*/
int st_cmp(char **string, const char *to_cmp)
{
- int chars = strlen(to_cmp);
+ int chars = 0;
+ assert(to_cmp);
+ assert(string);
+
+ chars = strlen(to_cmp);
+
/* skip beginning first spaces */
JUMP_SPACES(*string)
/* this might be an "comp pare" */
@@ -134,6 +145,8 @@
char *td = NULL;
int i = 0;
+ assert(string);
+
/* skip beginning first spaces */
JUMP_SPACES(*string);
@@ -176,6 +189,8 @@
char *td = NULL;
int i = 0;
+ assert(string);
+
/* count tokens */
if ((*string)[0] == '"')
{
@@ -210,6 +225,8 @@
{
int i = 0;
+ assert(string);
+
/* go to end */
while (string[i] != '\0')
i++;
@@ -228,6 +245,8 @@
{
int i = 0;
+ assert(string);
+
/* go to end */
while (string[i] != '\0')
i++;
@@ -246,6 +265,8 @@
{
int i = 0;
+ assert(string);
+
/* stand on last char */
while ((*string)[i] != '\0')
i++;
@@ -263,21 +284,50 @@
return (FALSE);
}
-/* function strips all blanks from string */
-int st_strip(char *string)
+/*
+ * This search for a pattern.
+ * If string is "net/eth0" then pattern "net/et*" and pattern "net/eth?"
+ * shoud return true.
+ */
+int service_match(const char *string, const char *pattern)
{
- int i = 0, j = 0;
+ char *service_mask = NULL;
- if (!string)
+ assert(string);
+ assert(pattern);
+
+ /* do pattern matching only if service name does not contain wildcards */
+ if (strchr(string, '*') || strchr(string, '?'))
+ {
+ F_("The string contains wildcards!\n");
return (FALSE);
+ }
- while (string[i] != '\0')
+ /* if existing service is a pattern */
+ if (strchr(pattern, '*') || strchr(pattern, '?'))
{
- if (string[j] != ' ' && string[j] != '\t')
- j++;
- i++;
- string[j] = string[i];
+ if (fnmatch(pattern, string, FNM_CASEFOLD) == 0)
+
+ {
+ /* found */
+ return (TRUE);
+ }
}
- return (TRUE);
+ /* create service name mask for pattern matching */
+ service_mask = initng_calloc(strlen(string) + 3, sizeof(char));
+ assert(service_mask);
+
+ strcpy(service_mask, "*/");
+ strcat(service_mask, string);
+
+ if (fnmatch(service_mask, pattern, FNM_CASEFOLD) == 0)
+ {
+ free(service_mask);
+ return (TRUE);
+ }
+
+ /* did not find any */
+ free(service_mask);
+ return (FALSE);
}
Modified: initng/src/initng_string_tools.h
==============================================================================
--- initng/src/initng_string_tools.h (original)
+++ initng/src/initng_string_tools.h Tue Nov 1 12:22:05 2005
@@ -40,13 +40,15 @@
char **split_n(char *buf, int *len, int plus, int ofs);
-int chars_to_end_of_this_stack(char *string);
+int chars_to_end_of_this_stack(const char *string);
int st_cmp(char **string, const char *to_cmp);
char *st_dup_next_word(char **string);
char *st_dup_line(char **string);
char *st_strip_path(char *string);
int st_strip_end(char **string);
char *st_get_path(char *string);
-int st_strip(char *string);
+
+/* pattern searching */
+int service_match(const char *string, const char *pattern);
#endif
Modified: initng/src/initng_struct_data.c
==============================================================================
--- initng/src/initng_struct_data.c (original)
+++ initng/src/initng_struct_data.c Tue Nov 1 12:22:05 2005
@@ -52,9 +52,9 @@
while (type->opt_type == ALIAS && type->alias)
type = type->alias;
- if (type->opt_type != STRING && type->opt_type != SCRIPT)
+ if (type->opt_type != STRING && type->opt_type != MULTILINE_STRING)
{
- F_("Cand only fetch a type, that is a STRING || SCRIPT!\n");
+ F_("Cand only fetch a type, that is a STRING || MULTILINE_STRING!\n");
return (NULL);
}
@@ -181,9 +181,9 @@
type = type->alias;
- if (type->opt_type != STRING && type->opt_type != SCRIPT)
+ if (type->opt_type != STRING && type->opt_type != MULTILINE_STRING)
{
- F_(" \"%s\" is not an STRING || SCRIPT type, sleeping 1 sek ..",
+ F_(" \"%s\" is not an STRING || MULTILINE_STRING type, sleeping 1 sek ..",
type->opt_name);
sleep(1);
return;
@@ -395,7 +395,7 @@
{
case STRING:
case STRINGS:
- case SCRIPT:
+ case MULTILINE_STRING:
if (current->t.s)
free(current->t.s);
break;
@@ -483,7 +483,7 @@
{
case STRING:
case STRINGS:
- case SCRIPT:
+ case MULTILINE_STRING:
if (current->t.s)
tmp->t.s = i_strdup(current->t.s);
break;
More information about the Initng-svn
mailing list