[Initng-svn] r1913 - in initng: plugins/reload plugins/stcmd src
svn at initng.thinktux.net
svn at initng.thinktux.net
Tue Nov 1 22:42:40 CET 2005
Author: jimmy
Date: Tue Nov 1 22:42:39 2005
New Revision: 1913
Modified:
initng/plugins/reload/initng_reload.c
initng/plugins/reload/initng_reload.h
initng/plugins/stcmd/initng_stcmd.c
initng/src/initng_fd.c
initng/src/initng_fork.c
initng/src/initng_process_db.h
Log:
Some cleanup, and commenting for code that was written orginally from neuron.
Modified: initng/plugins/reload/initng_reload.c
==============================================================================
--- initng/plugins/reload/initng_reload.c (original)
+++ initng/plugins/reload/initng_reload.c Tue Nov 1 22:42:39 2005
@@ -36,7 +36,7 @@
#include "initng_reload.h"
-#define SAVE_FILE "/tmp/active_db_save.v7"
+#define SAVE_FILE "/tmp/active_db_save.v8"
s_command FAST_RELOAD = { 'c', "hot_reload", TRUE_OR_FALSE_COMMAND, NO_OPT,
{(void *) &cmd_fast_reload},
@@ -52,6 +52,7 @@
data_save_struct entry;
s_data *d;
int i;
+ int pnr = 0;
process_h *process = NULL;
fil = fopen(SAVE_FILE, "r");
@@ -79,29 +80,31 @@
new_entry->type = entry.type;
new_entry->time_got_status = entry.time_got_status;
- if (entry.start_p_pid)
- {
- process = process_db_new(T_START);
- if (process)
- {
- process->pid = entry.start_p_pid;
- process->out_pipe[0] = entry.start_stdout1;
- process->out_pipe[1] = entry.start_stdout2;
- list_add(&process->list, &new_entry->processes.list);
- }
- }
-
- if (entry.stop_p_pid)
- {
- process = process_db_new(T_STOP);
- if (process)
- {
- process->pid = entry.stop_p_pid;
- process->out_pipe[0] = entry.stop_stdout1;
- process->out_pipe[1] = entry.stop_stdout2;
- list_add(&process->list, &new_entry->processes.list);
- }
- }
+ /* walk thru all processes */
+ pnr=0;
+ while(entry.process[pnr].ptype != T_UNKNOWN && pnr < MAX_PROCESSES)
+ {
+ /* allocate the process */
+ process = process_db_new(entry.process[pnr].ptype);
+ if(!process) continue;
+
+ /* fill the data */
+ process->pid = entry.process[pnr].pid;
+ process->out_pipe[0] = entry.process[pnr].stdout1;
+ process->out_pipe[1] = entry.process[pnr].stdout2;
+ process->r_code = entry.process[pnr].rcode;
+
+ /* allocate a new output buffer for this process */
+ process->buffer_pos=0;
+ process->buffer=NULL;
+
+ /* add this process to the list */
+ list_add(&process->list, &new_entry->processes.list);
+
+ printf("Added process type %i to %s\n", process->pt, new_entry->name);
+
+ pnr++;
+ }
i = 0;
while (entry.data[i].opt_type)
@@ -153,6 +156,7 @@
data_save_struct entry;
process_h *process = NULL;
int i;
+ int pnr=0;
s_data *c_d = NULL;
(void) arg;
@@ -172,34 +176,21 @@
entry.type = current->type;
entry.time_got_status = current->time_got_status;
- /* reset variables */
- entry.start_p_pid = -1;
- entry.start_stdout1 = -1;
- entry.start_stdout2 = -1;
- entry.stop_p_pid = -1;
- entry.stop_stdout1 = -1;
- entry.stop_stdout2 = -1;
-
/* collet some proceses */
process = NULL;
+ pnr=0;
while_processes(process, current)
{
- switch (process->pt)
- {
- case T_START:
- entry.start_p_pid = process->pid;
- entry.start_stdout1 = process->out_pipe[0];
- entry.start_stdout2 = process->out_pipe[1];
- break;
- case T_STOP:
- entry.stop_p_pid = process->pid;
- entry.stop_stdout1 = process->out_pipe[0];
- entry.stop_stdout2 = process->out_pipe[1];
- break;
- default:
- break;
- }
+ entry.process[pnr].ptype = process->pt;
+ entry.process[pnr].pid = process->pid;
+ entry.process[pnr].stdout1 = process->out_pipe[0];
+ entry.process[pnr].stdout2 = process->out_pipe[1];
+ entry.process[pnr].rcode = process->r_code;
+ pnr++;
+ if(pnr >= MAX_PROCESSES)
+ break;
}
+ entry.process[pnr].ptype = T_UNKNOWN;
/* reset data */
for (i = 0; i < MAX_ENTRYS_FOR_SERVICE; i++)
Modified: initng/plugins/reload/initng_reload.h
==============================================================================
--- initng/plugins/reload/initng_reload.h (original)
+++ initng/plugins/reload/initng_reload.h Tue Nov 1 22:42:39 2005
@@ -30,6 +30,7 @@
#define MAX_SERVICE_NAME_STRING_LEN 200
#define MAX_DATA_STRING_LEN 200
#define MAX_TYPE_STRING_LEN 100
+#define MAX_PROCESSES 6
#define MAX_ENTRYS_FOR_SERVICE 20
extern s_command FAST_RELOAD;
@@ -44,6 +45,15 @@
} t;
} r_d_e;
+typedef struct
+{
+ e_pt ptype;
+ int stdout1;
+ int stdout2;
+ int pid;
+ int rcode;
+} r_process;
+
/* this lines will the active contain */
typedef struct
{
@@ -52,14 +62,10 @@
e_a_status a_status;
time_t time_got_status;
- /* start process */
- pid_t start_p_pid;
- int start_stdout1;
- int start_stdout2;
- /* stop process */
- pid_t stop_p_pid;
- int stop_stdout1;
- int stop_stdout2;
+ /* struct with some processes */
+ r_process process[MAX_PROCESSES];
+
+ /* struct with some data */
r_d_e data[MAX_ENTRYS_FOR_SERVICE + 1];
} data_save_struct;
Modified: initng/plugins/stcmd/initng_stcmd.c
==============================================================================
--- initng/plugins/stcmd/initng_stcmd.c (original)
+++ initng/plugins/stcmd/initng_stcmd.c Tue Nov 1 22:42:39 2005
@@ -102,7 +102,7 @@
"Print uptime"
};
s_command SERVICE_RELOAD =
- { 'R', "reload_service", TRUE_OR_FALSE_COMMAND, REQUIRES_OPT,
+ { 'R', "reload_service", TRUE_OR_FALSE_COMMAND, USES_OPT,
{(void *) &cmd_reload}, "Service reload"
};
@@ -283,14 +283,21 @@
{
service_h *s;
- s = service_db_find_in_name(arg);
- if (!s)
+ /* if no arg, or empty arg set, remove all content */
+ if(!arg || strlen(arg) < 2)
{
D_("Clearing complete db.\n");
service_db_free_all();
return (TRUE);
}
+ s = service_db_find_in_name(arg);
+ if (!s)
+ {
+ F_("Did not find service %s to release cache for!\n", arg);
+ return (FALSE);
+ }
+
D_("removing service data for %s!\n", arg);
list_del(&s->list);
service_db_free(s);
Modified: initng/src/initng_fd.c
==============================================================================
--- initng/src/initng_fd.c (original)
+++ initng/src/initng_fd.c Tue Nov 1 22:42:39 2005
@@ -59,7 +59,7 @@
/* Calls plugins when data is ready in pipe */
void initng_plugin_readpipe(active_h * service, int datalen,
- process_h * process, int force_flush)
+ process_h * process, int flush_buffer)
{
s_call *current = NULL;
@@ -71,105 +71,130 @@
continue;
D_("Calling pipewatcher plugin.\n");
- (*current->c.pipewatcher) (service, datalen, process, force_flush);
+ (*current->c.pipewatcher) (service, datalen, process, flush_buffer);
}
}
-/* This does the actual read from pipe, all checks have been done here */
-/* This code has ben written by neuron, of course its bad commented */
-int initng_process_readpipe_read(active_h * service, process_h * x,
- int program_end)
+/*
+ * This does the actual read from pipe, all checks have been done here.
+ *
+ */
+int initng_process_readpipe_read(active_h * service, process_h * p,
+ int flush_buffer)
{
- int forceflush, maxread, len;
+ int len = 0; /* lenght of data read */
S_;
+
+ /* check if buffer exits, or have to be created */
+ if(!p->buffer)
+ {
+ /* allocate space for the buffer */
+ p->buffer=initng_calloc(MAX_BUFFER + 1, sizeof(char));
+ p->buffer_pos = 0;
+ }
- forceflush = program_end;
- maxread = MAX_BUFFER - x->buffer_pos;
-
+ /* read data from process, and continue again after a interrupt */
do
{
errno = 0;
- len = read(x->out_pipe[0], &x->buffer[x->buffer_pos], maxread);
+ /* can max read MAX_BUFFER (once allocated) - len (all currently read) - buffer_pos */
+ if((MAX_BUFFER - len - p->buffer_pos)<1)
+ {
+ F_("Cant read more, buffer is out!\n");
+ break;
+ }
+ len += read(p->out_pipe[0], &p->buffer[p->buffer_pos], (MAX_BUFFER - len - p->buffer_pos));
}
while (errno == EINTR);
- if (len > 0)
- {
- x->buffer[x->buffer_pos + len] = '\0';
-
- if (x->buffer_pos + len >= MAX_BUFFER)
- forceflush = TRUE;
+ /* make sure we got something */
+ if (len < 1) return(len);
- initng_plugin_readpipe(service, len, x, forceflush);
- x->buffer_pos = x->buffer_pos + len;
- if (forceflush)
- x->buffer_pos = 0;
- }
- return len;
+ /* if we got something. */
+
+ /* null the end to make sure */
+ p->buffer[p->buffer_pos + len] = '\0';
+
+ /* if max buffer is reached, make sure it flushes it */
+ if (p->buffer_pos + len >= MAX_BUFFER)
+ flush_buffer = TRUE;
+
+ /* let all plugin take part of data */
+ initng_plugin_readpipe(service, len, p, flush_buffer);
+
+ /* increase the buffer possision */
+ if (flush_buffer)
+ p->buffer_pos = 0;
+ else
+ p->buffer_pos = p->buffer_pos + len;
+
+ /* return lenght of data read */
+ return (len);
}
/* This does all the fancy pancy around the read */
-void initng_process_readpipe(active_h * service, process_h * x,
- int program_end)
+void initng_process_readpipe(active_h * service, process_h * p,
+ int flush_buffer)
{
- int i;
+ int len = 0;
S_;
- /* We've already ended */
- if ((!x->buffer))
- return;
-
-
/*
- * program_end is set, and radpipe is called just
+ * flush_buffer is set, and readpipe is called just
* before process are beeing freed, when the pocess
* is dead.
*/
-
- if (program_end)
+ if (flush_buffer)
{
int fd_flags;
- fd_flags = fcntl(x->out_pipe[0], F_GETFL, 0);
- fcntl(x->out_pipe[0], F_SETFL, fd_flags | O_NONBLOCK);
+ fd_flags = fcntl(p->out_pipe[0], F_GETFL, 0);
+ fcntl(p->out_pipe[0], F_SETFL, fd_flags | O_NONBLOCK);
}
- i = initng_process_readpipe_read(service, x, program_end);
-
- if (!program_end)
+ /* get data from process, it return lenght of data got */
+ len = initng_process_readpipe_read(service, p, flush_buffer);
+
+ if (!flush_buffer)
{
- /* We have an error other than EAGAIN, set program_end */
- if ((i == -1) && (errno != EAGAIN))
+ /* We have an error other than EAGAIN, set flush_buffer */
+ if ((len == -1) && (errno != EAGAIN))
{
- program_end = TRUE;
+ flush_buffer = TRUE;
F_("Error reading from pipe for %s (%s)\n", service->name,
strerror(errno));
}
+
+ /* Why flush buffer if we got nothing to read? */
/* End of file */
- if (i == 0)
- program_end = TRUE;
+ if (len == 0)
+ flush_buffer = TRUE;
}
/* If i < 1 we either have 0 (end of file) or -1 (error) */
- if (!program_end)
+ if (!flush_buffer)
return;
- /* Program is ending, close pipes */
- initng_plugin_readpipe(service, 0, x, TRUE);
+ /*
+ * Do this to tell plugin that buffer is flushing,
+ * and data is going to dissapere.
+ */
+ initng_plugin_readpipe(service, 0, p, TRUE);
+
/* free data, close and reset fds */
D_("Freeing buffer for %s\n", service->name);
- if (x->out_pipe[0] > 0)
- close(x->out_pipe[0]);
- if (x->out_pipe[1] > 0)
- close(x->out_pipe[1]);
- if (x->buffer)
- free(x->buffer);
- x->out_pipe[0] = -1;
- x->out_pipe[1] = -1;
- x->buffer = NULL;
+ if (p->out_pipe[0] > 0)
+ close(p->out_pipe[0]);
+ if (p->out_pipe[1] > 0)
+ close(p->out_pipe[1]);
+ if (p->buffer)
+ free(p->buffer);
+ p->out_pipe[0] = -1;
+ p->out_pipe[1] = -1;
+ p->buffer = NULL;
}
Modified: initng/src/initng_fork.c
==============================================================================
--- initng/src/initng_fork.c (original)
+++ initng/src/initng_fork.c Tue Nov 1 22:42:39 2005
@@ -63,10 +63,11 @@
}
/* alloc buffer */
- if (process->buffer)
+ if (process->buffer) {
free(process->buffer);
- process->buffer = initng_calloc(MAX_BUFFER + 1, 1);
- process->buffer_pos = 0;
+ process->buffer=NULL;
+ process->buffer_pos = 0;
+ }
/* Try to fork 30 times */
Modified: initng/src/initng_process_db.h
==============================================================================
--- initng/src/initng_process_db.h (original)
+++ initng/src/initng_process_db.h Tue Nov 1 22:42:39 2005
@@ -29,7 +29,7 @@
typedef enum
{
- T_UKNOWN = 0,
+ T_UNKNOWN = 0,
T_START = 1,
T_STOP = 2,
T_PRE = 3,
More information about the Initng-svn
mailing list