[Initng-svn] r3760 - in initng/trunk/plugins: ngcs
svn at initng.thinktux.net
svn at initng.thinktux.net
Tue Apr 11 14:42:29 CEST 2006
Author: makomk
Date: Tue Apr 11 14:42:28 2006
New Revision: 3760
Modified:
initng/trunk/plugins/Makefile.am
initng/trunk/plugins/ngcs/Makefile.am
initng/trunk/plugins/ngcs/ngcs.c
Log:
Makefile fixes and some minor changes to ngcs
Modified: initng/trunk/plugins/Makefile.am
==============================================================================
--- initng/trunk/plugins/Makefile.am (original)
+++ initng/trunk/plugins/Makefile.am Tue Apr 11 14:42:28 2006
@@ -9,9 +9,9 @@
SUBDIRS+=bash_launcher
endif
-if BUILD_BDBPARSER
- SUBDIRS+=bdbparser
-endif
+# if BUILD_BDBPARSER
+# SUBDIRS+=bdbparser
+# endif
if BUILD_CHDIR
SUBDIRS+=chdir
Modified: initng/trunk/plugins/ngcs/Makefile.am
==============================================================================
--- initng/trunk/plugins/ngcs/Makefile.am (original)
+++ initng/trunk/plugins/ngcs/Makefile.am Tue Apr 11 14:42:28 2006
@@ -3,7 +3,7 @@
plugin_LTLIBRARIES = libngcs.la
lib_LTLIBRARIES = libngcs_common.la libngcs_client.la
sbin_SCRIPTS = ngcs.py
-# sbin_PROGRAMS = ngcs ngdcs
+sbin_PROGRAMS = ngcs
libngcs_la_SOURCES = \
initng_ngcs.c \
@@ -24,12 +24,22 @@
libngcs_la_LDFLAGS = @PLUGIN_LDFLAGS@
libngcs_la_LIBADD = @PLUGIN_LIBS@ libngcs_common.la
+nodist_libngcs_client_la_SOURCES = \
+ ngcs_marshal.c \
+ ngcs_marshal.h
+
libngcs_client_la_SOURCES = \
ngcs_client.c \
- ngcs_client.h
+ ngcs_client.h \
+ ngcs_common.h \
+ ngcs_paths.h
libngcs_client_la_LIBADD = libngcs_common.la
+ngcs_SOURCES = ngcs.c ansi_colors.h ngcs_client.h
+ngcs_LDADD = libngcs_client.la
+
+
BUILT_SOURCES = ngcs_marshal.h
EXTRA_DIST = ngcs_marshal.ngci idef.py ngcs.py
Modified: initng/trunk/plugins/ngcs/ngcs.c
==============================================================================
--- initng/trunk/plugins/ngcs/ngcs.c (original)
+++ initng/trunk/plugins/ngcs/ngcs.c Tue Apr 11 14:42:28 2006
@@ -35,7 +35,8 @@
#define C_ERROR "\n "C_FG_RED" [ERROR] -->> "C_OFF
-#define maybe_printf(...); { if(quiet==FALSE) printf(__VA_ARGS__ ); }
+#define maybe_printf(...) { if(quiet==FALSE) printf(__VA_ARGS__ ); }
+#define maybe_grab_out(me) ( quiet ? 0 : grab_out(me))
typedef enum {
@@ -63,6 +64,42 @@
void resp_handler (ngcs_cli_conn *cconn, void *userdata, ngcs_data *ret);
void docmd(char* cmd, char* arg);
void svc_watch_cb (ngcs_svc_evt_hook *hook, void *userdata, ngcs_svc_evt *event);
+const char *state_color(int rough_state);
+int grab_out(void *me) ;
+
+void *last_out; int need_nl = 0;
+
+int grab_out(void *me) {
+ int n;
+
+ if(me == NULL || last_out != me) {
+ for(n = 0; n < need_nl; n++)
+ putchar('\n');
+ last_out = me; return 1;
+ }
+ else return 0;
+}
+
+const char *state_color(int rough_state) {
+ switch (rough_state)
+ {
+ case IS_UP:
+ return C_FG_NEON_GREEN;
+ case IS_DOWN:
+ return C_FG_LIGHT_BLUE;
+ case IS_FAILED:
+ return C_FG_LIGHT_RED;
+ case IS_STARTING:
+ return C_FG_YELLOW;
+ case IS_STOPPING:
+ return C_FG_CYAN;
+ case IS_WAITING:
+ return C_FG_MAGENTA;
+ case IS_UNKNOWN:
+ default:
+ return C_FG_DEFAULT;
+ }
+}
void svc_watch_cb (ngcs_svc_evt_hook *hook, void *userdata, ngcs_svc_evt *event)
{
@@ -72,8 +109,9 @@
switch(event->type) {
case NGCS_SVC_EVT_BEGIN:
- if(res->d.svc_watch.mode == WATCH_STATUS)
+ if(res->d.svc_watch.mode == WATCH_STATUS)
{
+ grab_out(NULL);
printf( C_FG_LIGHT_RED "hh:mm:ss" C_OFF C_FG_CYAN " T "
C_OFF "service : "
C_FG_NEON_GREEN "status\n" C_OFF);
@@ -90,8 +128,12 @@
case NGCS_SVC_EVT_OUTPUT:
if(res->d.svc_watch.mode == WATCH_STATUS)
break;
- printf(C_FG_BLUE "%s output:" C_OFF "\n%s\n",
- event->svc_name, event->r.output);
+ if(maybe_grab_out(res))
+ {
+ maybe_printf(C_FG_BLUE "\n%s output:" C_OFF "\n", event->svc_name);
+ need_nl = 1;
+ }
+ maybe_printf("%s", event->r.output);
break;
case NGCS_SVC_EVT_STATE:
switch(res->d.svc_watch.mode)
@@ -99,6 +141,7 @@
case WATCH_START:
if(event->r.adb.current_state->is == IS_UP)
{
+ grab_out(NULL);
printf("%s is started (%s)\n", event->svc_name,
event->r.adb.current_state->state_name);
ngcs_client_free_svc_watch(hook); return;
@@ -109,6 +152,7 @@
event->r.adb.current_state->is != IS_STARTING)
{
+ grab_out(NULL);
printf("%s failed to start (%s)\n",
event->svc_name,
event->r.adb.current_state->state_name);
@@ -119,7 +163,8 @@
case WATCH_STOP:
if(event->r.adb.current_state->is == IS_DOWN)
{
- printf("%s is stopped (%s)\n", event->svc_name,
+ grab_out(NULL);
+ printf("Service \"%s\" is stopped (%s)\n", event->svc_name,
event->r.adb.current_state->state_name);
ngcs_client_free_svc_watch(hook); return;
@@ -129,7 +174,8 @@
event->r.adb.current_state->is != IS_STOPPING)
{
- printf("%s failed to stop (%s)\n",
+ grab_out(NULL);
+ printf("Service \"%s\" failed to stop (%s)\n",
event->svc_name,
event->r.adb.current_state->state_name);
failed = 1;
@@ -139,53 +185,32 @@
case WATCH_STATUS:
{
struct tm *ts = localtime(&event->r.adb.time_current_state.tv_sec);
+ grab_out(NULL);
printf(
C_FG_LIGHT_RED "%.2i:%.2i:%.2i" C_OFF C_FG_CYAN " %c"
- C_OFF " %-35s : ", ts->tm_hour, ts->tm_min, ts->tm_sec,
- (char) toupper((int) event->r.adb.type.name[0]), event->svc_name);
-
-
- switch (event->r.adb.current_state->is)
- {
- case IS_UP:
- printf(C_FG_NEON_GREEN "%s" C_OFF "\n",
- event->r.adb.current_state->state_name);
- break;
- case IS_DOWN:
- printf(C_FG_LIGHT_BLUE "%s" C_OFF "\n",
+ C_OFF " %-35s : %s%s"C_OFF "\n", ts->tm_hour, ts->tm_min, ts->tm_sec,
+ (char) toupper((int) event->r.adb.type.name[0]),
+ event->svc_name,
+ state_color(event->r.adb.current_state->is),
event->r.adb.current_state->state_name);
- break;
- case IS_FAILED:
- printf(C_FG_LIGHT_RED "%s" C_OFF "\n",
- event->r.adb.current_state->state_name);
- break;
- case IS_STARTING:
- printf(C_FG_YELLOW "%s" C_OFF "\n", event->r.adb.current_state->state_name);
- break;
- case IS_STOPPING:
- printf(C_FG_CYAN "%s" C_OFF "\n", event->r.adb.current_state->state_name);
- break;
- case IS_WAITING:
- printf(C_FG_MAGENTA "%s" C_OFF "\n",
- event->r.adb.current_state->state_name);
- break;
- case IS_UNKNOWN:
- printf("%s\n", event->r.adb.current_state->state_name);
- break;
- }
-
-
- /* TODO */
return;
}
default:
break;
}
- printf("%s is now %s\n", event->svc_name,
- event->r.adb.current_state->state_name);
+ if(res->d.svc_watch.in_present && (res->d.svc_watch.mode == WATCH_NORMAL ||
+ !quiet))
+ {
+ maybe_grab_out(NULL);
+ maybe_printf("Service \"%s\" is now in state %s%s" C_OFF "\n", event->svc_name,
+ state_color(event->r.adb.current_state->is),
+ event->r.adb.current_state->state_name);
+ }
break;
case NGCS_SVC_EVT_END:
/* FIXME - need to detect failure here */
+ if(last_out == res)
+ last_out = NULL;
list_del(&res->list); free(res);
break;
default:
@@ -213,6 +238,7 @@
if(ngcs_watch_service(cconn, arg, NGCS_WATCH_OUTPUT |
NGCS_WATCH_STATUS, svc_watch_cb,
res) == NULL) {
+ grab_out(NULL);
printf(C_ERROR "Couldn't send command %s %s\n" C_OFF,
cmd, (arg == NULL ? "" : arg));
failed = 1; free(res); return;
@@ -226,6 +252,7 @@
res->d.svc_watch.mode = WATCH_STATUS;
if(ngcs_watch_service(cconn, arg, NGCS_CURRENT_STATUS,
svc_watch_cb, res) == NULL) {
+ grab_out(NULL);
printf(C_ERROR "Couldn't send command %s %s\n" C_OFF,
cmd, (arg == NULL ? "" : arg));
failed = 1; free(res); return;
@@ -239,6 +266,7 @@
res->d.svc_watch.mode = WATCH_START;
if(ngcs_start_stop(cconn, "start", arg, svc_watch_cb,
res) == NULL) {
+ grab_out(NULL);
printf(C_ERROR "Couldn't send command %s %s\n" C_OFF,
cmd, (arg == NULL ? "" : arg));
failed = 1; free(res); return;
@@ -252,6 +280,7 @@
res->d.svc_watch.mode = WATCH_STOP;
if(ngcs_start_stop(cconn, "stop", arg, svc_watch_cb,
res) == NULL) {
+ grab_out(NULL);
printf(C_ERROR "Couldn't send command %s %s\n" C_OFF,
cmd, (arg == NULL ? "" : arg));
failed = 1; free(res); return;
@@ -271,6 +300,7 @@
if(ngcs_cmd_async(cconn, (arg == NULL ? 1 : 2), dat,
resp_handler, res))
{
+ grab_out(NULL);
printf(C_ERROR "Couldn't send command %s %s\n" C_OFF,
cmd, (arg == NULL ? "" : arg));
failed = 1; free(res); return;
@@ -287,6 +317,7 @@
if(ret == NULL || ret->len < 0)
{
+ grab_out(NULL);
printf(C_ERROR "Didn't get response for command %s %s\n" C_OFF,
res->cmd, (res->arg == NULL ? "" : res->arg));
failed = 1;
@@ -294,20 +325,24 @@
else switch(ret->type)
{
case NGCS_TYPE_NULL:
+ maybe_grab_out(NULL);
maybe_printf("%s %s returned " C_FG_BLUE "nothing" C_OFF "\n",
res->cmd, (res->arg == NULL ? "" : res->arg));
break;
case NGCS_TYPE_INT:
+ maybe_grab_out(NULL);
maybe_printf("%s %s returned %i\n",
res->cmd, (res->arg == NULL ? "" : res->arg),
ret->d.i);
break;
case NGCS_TYPE_LONG:
+ maybe_grab_out(NULL);
maybe_printf("%s %s returned %li\n",
res->cmd, (res->arg == NULL ? "" : res->arg),
ret->d.l);
break;
case NGCS_TYPE_BOOL:
+ maybe_grab_out(NULL);
maybe_printf("%s %s returned %s\n",
res->cmd, (res->arg == NULL ? "" : res->arg),
(ret->d.i ? "TRUE" : "FALSE"));
@@ -315,13 +350,14 @@
break;
case NGCS_TYPE_ERROR:
{
-
+ grab_out(NULL);
printf(C_ERROR "%s %s failed: %s\n" C_OFF,
res->cmd, (res->arg == NULL ? "" : res->arg),
ret->d.s);
failed = 1; break;
}
default:
+ grab_out(NULL);
printf(C_ERROR "%s %s returned unknown type %i\n" C_OFF,
res->cmd, (res->arg == NULL ? "" : res->arg),
ret->type);
@@ -342,6 +378,8 @@
assert(argv[0]);
INIT_LIST_HEAD(&pending.list);
+ last_out = NULL; need_nl = 0;
+
/*
* Skip path in Argv.
* example argv[0] == "/sbin/ngc" then Argv == "ngc"
@@ -453,6 +491,7 @@
ngcs_client_dispatch(cconn);
}
+ grab_out(NULL);
ngcs_client_free(cconn);
return failed;
}
More information about the Initng-svn
mailing list