[Initng-svn] r4412 - in initng/trunk/plugins: history
svn at initng.thinktux.net
svn at initng.thinktux.net
Thu Jun 8 13:56:10 CEST 2006
Author: jimmy
Date: Thu Jun 8 13:56:08 2006
New Revision: 4412
Modified:
initng/trunk/plugins/history/initng_history.c
initng/trunk/plugins/history/initng_history.h
initng/trunk/plugins/service_file/initng_service_file.c
Log:
Prettify ngc -l a lot!
Modified: initng/trunk/plugins/history/initng_history.c
==============================================================================
--- initng/trunk/plugins/history/initng_history.c (original)
+++ initng/trunk/plugins/history/initng_history.c Thu Jun 8 13:56:08 2006
@@ -87,6 +87,7 @@
memcpy(&row->time_set, ¤t->time, sizeof(struct timeval));
+
if (current->name)
strncpy(row->name, current->name, 100);
else if (current->service && current->service->name)
@@ -110,14 +111,16 @@
"Print out history_db."
};
+#define LOG_ROW_LEN 70
+#define NAME_SPACER "20"
+
static char *cmd_log(char *arg)
{
char *string = NULL;
char *name = NULL;
- char *latest = NULL;
- struct tm *ts;
int only_output = FALSE;
history_h *current = NULL;
+ time_t last;
/* reset arg, if strlen is short */
@@ -129,7 +132,7 @@
only_output = TRUE;
}
- mprintf(&string, " hh:mm:ss service : STATUS\n");
+ mprintf(&string, " %-" NAME_SPACER "s : STATUS\n", "SERVICE");
mprintf(&string,
" ------------------------------------------------------\n");
while_history_db_prev(current)
@@ -153,32 +156,69 @@
else
name = NULL;
- /* create an localtime struct form service->time */
- ts = localtime(¤t->time.tv_sec);
+ if (last != current->time.tv_sec)
+ {
+ /* print a nice service change status entry */
+ char *c = ctime(¤t->time.tv_sec);
+
+ mprintf(&string, "\n %s", c);
+ mprintf(&string,
+ " ------------------------------------------------------\n");
+
+ last = current->time.tv_sec;
+ }
+
+
/* if the log entry contains output data ... */
if (current->data)
{
- if (latest == name)
- mprintf(&string, "%s", current->data);
- else
- mprintf(&string, " %.2i:%.2i:%.2i %20s : *OUTPUT*\n%s",
- ts->tm_hour, ts->tm_min, ts->tm_sec, name,
- current->data);
- latest = name;
+ char *tmp = current->data;
+ char buf[LOG_ROW_LEN + 1];
+
+ while (tmp)
+ {
+ /* Variable that contains the no of chars to next newline */
+ int i = 0;
+
+ /* skip idention from data source */
+ while(tmp[0] == ' ' || tmp[0] == '\t' || tmp[0] == '\n')
+ tmp++;
+ /* if no more left, break */
+ if (!tmp[i])
+ break;
+
+ /* cont chars to newline */
+ while (tmp[i] && tmp[i] != '\n' && i < LOG_ROW_LEN)
+ i++;
+
+ /* fill with that row */
+ strncpy(buf, tmp, i);
+ buf[i] = '\0';
+
+ /* send that to client */
+ mprintf(&string, " %-" NAME_SPACER "s : %s\n", name, buf);
+
+ /* where to start next */
+ tmp = &tmp[i];
+ }
}
else
{
+
+ /* only print important state changes */
if (current->action->is == IS_UP || current->action->is == IS_DOWN
|| current->action->is == IS_FAILED)
{
- /* reset so that *OUTPUT* will be shown again */
- latest = NULL;
-
- /* print a nice service change status entry */
- mprintf(&string, " %.2i:%.2i:%.2i %20s : %s\n", ts->tm_hour,
- ts->tm_min, ts->tm_sec, name,
- current->action->state_name);
+ /* if there has gone some seconds sence last change, print that */
+ if (current->duration > 0)
+ mprintf(&string,
+ " %-" NAME_SPACER "s : %s (after %i seconds)\n",
+ name, current->action->state_name,
+ (int) current->duration);
+ else
+ mprintf(&string, " %-" NAME_SPACER "s : %s\n", name,
+ current->action->state_name);
}
}
@@ -324,6 +364,12 @@
sizeof(struct timeval));
tmp_e->action = service->current_state;
+ /* set duration if possible */
+ if (service->last_state && service->time_last_state.tv_sec > 1)
+ tmp_e->duration = difftime(service->time_current_state.tv_sec,
+ service->time_last_state.tv_sec);
+
+
/*D_("history_add_values() service : %s, name: %s, action: %s\n", service->name, NULL, service->current_state->state_name); */
add_hist(tmp_e);
Modified: initng/trunk/plugins/history/initng_history.h
==============================================================================
--- initng/trunk/plugins/history/initng_history.h (original)
+++ initng/trunk/plugins/history/initng_history.h Thu Jun 8 13:56:08 2006
@@ -33,6 +33,7 @@
{
active_db_h *service;
char *name;
+ double duration; /* The time in seconds the service stayed in this state */
struct timeval time;
char *data;
a_state_h *action;
Modified: initng/trunk/plugins/service_file/initng_service_file.c
==============================================================================
--- initng/trunk/plugins/service_file/initng_service_file.c (original)
+++ initng/trunk/plugins/service_file/initng_service_file.c Thu Jun 8 13:56:08 2006
@@ -58,11 +58,14 @@
INITNG_PLUGIN_MACRO;
+#ifdef GLOBAL_SOCKET
static void bp_incomming(f_module_h * from, e_fdw what);
-static void bp_closesock(void);
-static void bp_handle_client(int fd);
static int bp_open_socket(void);
static void bp_check_socket(int signal);
+static void bp_closesock(void);
+#endif
+
+static void bp_handle_client(int fd);
static void bp_new_active(bp_rep * rep, const char *type,
const char *service, const char *from_file);
static void bp_set_variable(bp_rep * rep, const char *service,
@@ -99,7 +102,9 @@
/* globals */
struct stat sock_stat;
+#ifdef GLOBAL_SOCKET
f_module_h bpf = { &bp_incomming, FDW_READ, -1 };
+#endif
#define RSCV() (TEMP_FAILURE_RETRY(recv(fd, &req, sizeof(bp_req), 0)))
#define SEND() send(fd, &rep, sizeof(bp_rep), 0)
@@ -499,7 +504,7 @@
return;
}
-
+#ifdef GLObAL_SOCKET
/* called by fd hook, when data is no socket */
void bp_incomming(f_module_h * from, e_fdw what)
{
@@ -544,8 +549,9 @@
bp_closesock();
return;
}
+#endif
-
+#ifdef GLOBAL_SOCKET
/* this will try to open a new socket */
static int bp_open_socket()
{
@@ -631,7 +637,9 @@
return (TRUE);
}
+#endif
+#ifdef GLOBAL_SOCKET
/* this will check socket, and reopen on failure */
static void bp_check_socket(int signal)
{
@@ -671,7 +679,9 @@
D_("Socket ok.\n");
return;
}
+#endif
+#ifdef GLOBAL_SOCKET
static void bp_closesock(void)
{
/* Check if we need to remove hooks */
@@ -683,6 +693,7 @@
close(bpf.fds);
bpf.fds = -1;
}
+#endif
static void handle_killed(active_db_h * service, process_h * process)
{
@@ -911,14 +922,18 @@
return (FALSE);
}
+#ifdef GLOBAL_SOCKET
/* zero globals */
bpf.fds = -1;
memset(&sock_stat, 0, sizeof(sock_stat));
+#endif
D_("adding hook, that will reopen socket, for every started service.\n");
initng_process_db_ptype_register(&parse);
- /*initng_plugin_hook_register(&g.FDWATCHERS, 30, &bpf); */
+#ifdef GLOBAL_SOCKET
+ initng_plugin_hook_register(&g.FDWATCHERS, 30, &bpf);
initng_plugin_hook_register(&g.SIGNAL, 50, &bp_check_socket);
+#endif
initng_plugin_hook_register(&g.NEW_ACTIVE, 50, &create_new_active);
initng_plugin_hook_register(&g.PIPE_WATCHER, 30, &get_pipe);
initng_active_state_register(&PARSING);
@@ -926,8 +941,11 @@
#ifdef USE_LOCALEXEC
initng_plugin_hook_register(&g.LAUNCH, 10, &initng_bash_run);
#endif
+
+#ifdef GLOBAL_SOCKET
/* do the first socket directly */
bp_open_socket();
+#endif
return (TRUE);
}
@@ -936,13 +954,17 @@
{
D_("module_unload(ngc2);\n");
+#ifdef GLOBAL_SOCKET
/* close open sockets */
bp_closesock();
+#endif
/* remove hooks */
initng_process_db_ptype_unregister(&parse);
- /* initng_plugin_hook_unregister(&g.FDWATCHERS, &bpf); */
+#ifdef GLOBAL_SOCKET
+ initng_plugin_hook_unregister(&g.FDWATCHERS, &bpf);
initng_plugin_hook_unregister(&g.SIGNAL, &bp_check_socket);
+#endif
initng_plugin_hook_unregister(&g.NEW_ACTIVE, &create_new_active);
initng_plugin_hook_unregister(&g.PIPE_WATCHER, &get_pipe);
initng_active_state_unregister(&PARSING);
More information about the Initng-svn
mailing list