[Initng-svn] r2382 - in initng: plugins/find plugins/stcmd src
svn at initng.thinktux.net
svn at initng.thinktux.net
Mon Dec 12 02:33:09 CET 2005
Author: jimmy
Date: Mon Dec 12 02:33:08 2005
New Revision: 2382
Modified:
initng/plugins/find/initng_find.c
initng/plugins/stcmd/initng_stcmd.c
initng/src/initng_global.c
initng/src/initng_global.h
initng/src/initng_main.c
initng/src/initng_main.h
initng/src/initng_open_read_close.c
initng/src/initng_open_read_close.h
Log:
initng_global.c is not a got place for functions called by plugins.
Modified: initng/plugins/find/initng_find.c
==============================================================================
--- initng/plugins/find/initng_find.c (original)
+++ initng/plugins/find/initng_find.c Mon Dec 12 02:33:08 2005
@@ -42,6 +42,40 @@
#include "initng_find.h"
+static char *get_find_alias(const char *from);
+
+static service_h *search_dir(const char *from, const char *dir)
+{
+ service_h *tmp = NULL;
+ DIR *path;
+ struct dirent *dir_e;
+ char t[100];
+ char d[30];
+
+ sprintf(d, "%s/%s", INITNG_ROOT, dir);
+
+ path = opendir(d);
+ if (!path)
+ return(NULL);
+
+ while ((dir_e = readdir(path)))
+ {
+ if(!strstr(dir_e->d_name, from))
+ continue;
+
+ strncpy(t, dir, 40);
+ strcpy(t, "/");
+ strncat(t, from, 40);
+ W_("Service shud be %s/%s\n", dir, from);
+ if ((tmp = parse_service(t)))
+ {
+ closedir(path);
+ return (tmp);
+ }
+ }
+ closedir(path);
+ return(NULL);
+}
/* Load a service from a process_name or process_path */
service_h *initng_find(char *service)
@@ -49,13 +83,10 @@
/* means that it may not be a direct service request, then we start looking in subfolders */
service_h *tmp = NULL;
- DIR *path;
- struct dirent *dir_e;
- char t[20];
+ char *tmp_serv = NULL;
assert(service);
-
/* Never try to find a service with a '/' in the name, it alredy have a path */
{
int i = 0;
@@ -68,46 +99,87 @@
}
}
- path = opendir(INITNG_ROOT "/system");
- if (path)
- {
- while ((dir_e = readdir(path)))
- {
- if (strstr(dir_e->d_name, service))
- {
- strcpy(t, "system/");
- strcat(t, service);
- W_("Service shud be system/%s\n", service);
- if ((tmp = parse_service(t)))
- return (tmp);
-
- }
+ if((tmp=search_dir(service, "system")))
+ return(tmp);
+
+ if((tmp=search_dir(service, "daemon")))
+ return(tmp);
+
+ tmp_serv=get_find_alias(service);
+ if((!tmp_serv))
+ return(NULL);
+
+ if((tmp=search_dir(tmp_serv, "system")))
+ return(tmp);
+
+ if((tmp=search_dir(tmp_serv, "daemon")))
+ return(tmp);
+
+ return (NULL);
+}
- }
- closedir(path);
- }
+#define ALIAS_FILE "/etc/initng/service_alias"
+static char *get_find_alias(const char *from)
+{
+ int from_len=0;
+ int i=0;
- path = opendir(INITNG_ROOT "/daemon");
- if (path)
+ char *file_content = NULL;
+ char *point = NULL;
+ char *ret = NULL;
+
+ /* open that file */
+ if (!open_read_close(ALIAS_FILE, &file_content))
+ return (NULL);
+
+ /* get lengt of what we are searching */
+ from_len=strlen(from);
+
+ /* Start Parsing */
+ point = file_content;
+ while (point[0])
{
- while ((dir_e = readdir(path)))
+ /* skip initzial spaces */
+ JUMP_SPACES(point);
+ if (!point[0])
+ break;
+
+ /* skip rows, starting with '#' */
+ if (point[0] == '#')
+ {
+ JUMP_TO_NEXT_ROW(point);
+ continue;
+ }
+
+ /* chek if first word is a match */
+ if(strncmp(point, from, from_len)!=0)
+ {
+ JUMP_TO_NEXT_ROW(point);
+ continue;
+ }
+
+ /* check so there is an '=' after */
+ if (!point[from_len] || !point[from_len+1] || point[from_len+1] != '=')
{
- if (strstr(dir_e->d_name, service))
- {
- strcpy(t, "daemon/");
- strcat(t, service);
- W_("Service shud be daemon/%s\n", service);
-
- if ((tmp = parse_service(t)))
- return (tmp);
- }
+ JUMP_TO_NEXT_ROW(point);
+ continue;
}
- closedir(path);
+
+ while(point[from_len+2+i] && point[from_len+2+i]!='\n')
+ i++;
+
+ /* copy the rest of line */
+ ret=i_strndup(&point[from_len+2], i);
+
+ free(file_content);
+ return(ret);
}
-
+ free(file_content);
return (NULL);
}
+
+
int module_init(const char *version)
{
Modified: initng/plugins/stcmd/initng_stcmd.c
==============================================================================
--- initng/plugins/stcmd/initng_stcmd.c (original)
+++ initng/plugins/stcmd/initng_stcmd.c Mon Dec 12 02:33:08 2005
@@ -49,6 +49,7 @@
#include "../../src/initng_string_tools.h"
#include "../../src/initng_static_states.h"
#include "../../src/initng_static_process_types.h"
+#include "../../src/initng_main.h"
#include "initng_stcmd.h"
#include "print_service.h"
Modified: initng/src/initng_global.c
==============================================================================
--- initng/src/initng_global.c (original)
+++ initng/src/initng_global.c Mon Dec 12 02:33:08 2005
@@ -35,25 +35,6 @@
/* HERE IS THE GLOBAL DEFINED STRUCT, WE OFTHEN RELATE TO */
s_global g;
-void initng_set_runlevel(const char *runlevel)
-{
- /* first free the old_runlevel */
- if (g.old_runlevel)
- {
- free(g.old_runlevel);
- g.old_runlevel = NULL;
- }
-
- /* then move the last new, to the old */
- if (g.runlevel)
- {
- g.old_runlevel = g.runlevel;
- g.runlevel = NULL;
- }
-
- /* and set the new */
- g.runlevel = i_strdup(runlevel);
-}
void initng_new(int argc, char *argv[], char *env[])
{
Modified: initng/src/initng_global.h
==============================================================================
--- initng/src/initng_global.h (original)
+++ initng/src/initng_global.h Mon Dec 12 02:33:08 2005
@@ -103,7 +103,6 @@
void initng_new(int argc, char *argv[], char *env[]);
void initng_free(void);
void initng_parse_argv(char **argv);
-void initng_set_runlevel(const char *runlevel);
#define initng_set_sleep(sec) { D_("Sleep set: %i seconds.\n", sec); if(sec<g.sleep_seconds) g.sleep_seconds=sec; }
#define initng_set_interrupt() { D_("Interrupt set!\n"); g.interrupt = TRUE; }
Modified: initng/src/initng_main.c
==============================================================================
--- initng/src/initng_main.c (original)
+++ initng/src/initng_main.c Mon Dec 12 02:33:08 2005
@@ -342,3 +342,23 @@
}
_exit(99);
}
+
+void initng_set_runlevel(const char *runlevel)
+{
+ /* first free the old_runlevel */
+ if (g.old_runlevel)
+ {
+ free(g.old_runlevel);
+ g.old_runlevel = NULL;
+ }
+
+ /* then move the last new, to the old */
+ if (g.runlevel)
+ {
+ g.old_runlevel = g.runlevel;
+ g.runlevel = NULL;
+ }
+
+ /* and set the new */
+ g.runlevel = i_strdup(runlevel);
+}
Modified: initng/src/initng_main.h
==============================================================================
--- initng/src/initng_main.h (original)
+++ initng/src/initng_main.h Mon Dec 12 02:33:08 2005
@@ -40,4 +40,7 @@
int blacklist_add(const char *sname);
void initng_segfault(void);
+
+void initng_set_runlevel(const char *runlevel);
+
#endif
Modified: initng/src/initng_open_read_close.c
==============================================================================
--- initng/src/initng_open_read_close.c (original)
+++ initng/src/initng_open_read_close.c Mon Dec 12 02:33:08 2005
@@ -37,7 +37,7 @@
static void bailout(int *, char **buffer);
-int open_read_close(char *filename, char **buffer)
+int open_read_close(const char *filename, char **buffer)
{
int conf_file; /* File descriptor for configfile */
struct stat stat_buf;
Modified: initng/src/initng_open_read_close.h
==============================================================================
--- initng/src/initng_open_read_close.h (original)
+++ initng/src/initng_open_read_close.h Mon Dec 12 02:33:08 2005
@@ -21,6 +21,6 @@
#ifndef OPEN_READ_CLOSE_H
#define OPEN_READ_CLOSE_H
-int open_read_close(char *filename, char **buffer);
+int open_read_close(const char *filename, char **buffer);
#endif
More information about the Initng-svn
mailing list