[Initng-svn] r3849 - in initng/trunk: devtool plugins/bash_launcher plugins/cpout plugins/daemon plugins/debug_commands plugins/history plugins/iparser plugins/ngcs plugins/nge plugins/reload plugins/service src tools
svn at initng.thinktux.net
svn at initng.thinktux.net
Thu Apr 20 01:18:20 CEST 2006
Author: jimmy
Date: Thu Apr 20 01:18:18 2006
New Revision: 3849
Modified:
initng/trunk/devtool/test_parser.c
initng/trunk/plugins/bash_launcher/initng_bash_launcher.c
initng/trunk/plugins/cpout/initng_colorprint_out.c
initng/trunk/plugins/daemon/initng_daemon.c
initng/trunk/plugins/debug_commands/print_service.c
initng/trunk/plugins/history/initng_history.c
initng/trunk/plugins/iparser/initng_i_parser.c
initng/trunk/plugins/ngc4/initng_ngc4.c
initng/trunk/plugins/ngc4/libngcclient.c
initng/trunk/plugins/ngc4/ngc4.c
initng/trunk/plugins/ngcs/initng_ngcs.c
initng/trunk/plugins/ngcs/ngcs.c
initng/trunk/plugins/ngcs/ngcs_client.c
initng/trunk/plugins/ngcs/ngcs_client.h
initng/trunk/plugins/ngcs/ngcs_common.c
initng/trunk/plugins/ngcs/ngcs_common.h
initng/trunk/plugins/nge/initng_nge.c
initng/trunk/plugins/nge/libngeclient.c
initng/trunk/plugins/reload/initng_reload.c
initng/trunk/plugins/service/initng_service.c
initng/trunk/src/initng_active_db.c
initng/trunk/src/initng_common.c
initng/trunk/src/initng_fd.c
initng/trunk/src/initng_fork.c
initng/trunk/src/initng_global.c
initng/trunk/src/initng_list.h
initng/trunk/src/initng_load_module.c
initng/trunk/src/initng_main.c
initng/trunk/src/initng_process_db.c
initng/trunk/src/initng_process_db.h
initng/trunk/src/initng_service_cache.c
initng/trunk/src/initng_signal.c
initng/trunk/src/main.c
initng/trunk/tools/itype.c
Log:
Indenting files, and itype work.
Modified: initng/trunk/devtool/test_parser.c
==============================================================================
--- initng/trunk/devtool/test_parser.c (original)
+++ initng/trunk/devtool/test_parser.c Thu Apr 20 01:18:18 2006
@@ -228,14 +228,15 @@
}
}
-
+
#ifdef PRINT_ALL
{
- char *all=service_db_print_all();
+ char *all = service_db_print_all();
+
printf("%s\n", all);
}
#endif
-
+
exit:
/* unload all modules */
Modified: initng/trunk/plugins/bash_launcher/initng_bash_launcher.c
==============================================================================
--- initng/trunk/plugins/bash_launcher/initng_bash_launcher.c (original)
+++ initng/trunk/plugins/bash_launcher/initng_bash_launcher.c Thu Apr 20 01:18:18 2006
@@ -119,32 +119,41 @@
const char *selinux_context = get_string(&SELINUX_CONTEXT, s);
char *sestr = NULL;
context_t seref = NULL;
- int rc=0;
+ int rc = 0;
char *sedomain;
- if(selinux_context) {
- sedomain=(char*)malloc((sizeof(char) * strlen(selinux_context) + 1));
- strcpy(sedomain, selinux_context);
+
+ if (selinux_context)
+ {
+ sedomain = (char *) malloc((sizeof(char) * strlen(selinux_context) +
+ 1));
+ strcpy(sedomain, selinux_context);
}
- else {
- sedomain=(char*)malloc((sizeof(char) * 9));
- strcpy(sedomain, "initrc_t");
+ else
+ {
+ sedomain = (char *) malloc((sizeof(char) * 9));
+ strcpy(sedomain, "initrc_t");
}
rc = getcon(&sestr);
- if (rc < 0) goto fail;
+ if (rc < 0)
+ goto fail;
seref = context_new(sestr);
- if (!seref) goto fail;
- if (context_type_set(seref, sedomain)) goto fail;
+ if (!seref)
+ goto fail;
+ if (context_type_set(seref, sedomain))
+ goto fail;
freecon(sestr);
sestr = context_str(seref);
- if (!sestr) goto fail;
+ if (!sestr)
+ goto fail;
rc = setexeccon(sestr);
- if (rc < 0) goto fail;
+ if (rc < 0)
+ goto fail;
#endif
/* execute */
execve("/bin/sh", argtmp, new_environ(s));
#ifdef SELINUX
-fail:
+ fail:
F_("bash_this(): could not change selinux context!\n ERROR!\n");
#endif
/* free them all */
Modified: initng/trunk/plugins/cpout/initng_colorprint_out.c
==============================================================================
--- initng/trunk/plugins/cpout/initng_colorprint_out.c (original)
+++ initng/trunk/plugins/cpout/initng_colorprint_out.c Thu Apr 20 01:18:18 2006
@@ -404,12 +404,12 @@
F_("This module is compiled for api_version %i version and initng is compiled on %i version, won't load this module!\n", API_VERSION, api_version);
return (FALSE);
}
-
+
/* only add this module if this is a real init */
- if(g.i_am != I_AM_INIT && g.i_am != I_AM_FAKE_INIT)
- return(TRUE);
-
-
+ if (g.i_am != I_AM_INIT && g.i_am != I_AM_FAKE_INIT)
+ return (TRUE);
+
+
for (i = 0; g.Argv[i]; i++)
{
if (strstr(g.Argv[i], "quiet_when_up"))
@@ -434,7 +434,7 @@
void module_unload(void)
{
D_("color_out: module_unload();\n");
- if(g.i_am != I_AM_INIT && g.i_am != I_AM_FAKE_INIT)
+ if (g.i_am != I_AM_INIT && g.i_am != I_AM_FAKE_INIT)
return;
Modified: initng/trunk/plugins/daemon/initng_daemon.c
==============================================================================
--- initng/trunk/plugins/daemon/initng_daemon.c (original)
+++ initng/trunk/plugins/daemon/initng_daemon.c Thu Apr 20 01:18:18 2006
@@ -893,17 +893,17 @@
initng_process_db_free(process);
return;
}
-
+
/* Set local rcode, and free process */
- rcode=process->r_code;
- initng_process_db_free(process);
+ rcode = process->r_code;
+ initng_process_db_free(process);
/*
* Make sure r_code don't signal error (can be override by UP_ON_FAILURE.
*/
/* If daemon stoped by a SEGFAULT (SIGSEGV==11) this is always bad */
- if(WTERMSIG(rcode)==11)
+ if (WTERMSIG(rcode) == 11)
{
initng_common_mark_service(daemon, &DAEMON_FAIL_START_SIGNAL);
return;
@@ -911,23 +911,24 @@
/* if exit with sucess */
- if(WEXITSTATUS(rcode)==0)
+ if (WEXITSTATUS(rcode) == 0)
{
/* OK! now daemon is STOPPED! */
initng_common_mark_service(daemon, &DAEMON_STOPPED);
return;
}
-
+
/* else exitstatus is abouw 0 */
- if(is(&DAEMON_FAIL_OK, daemon))
+ if (is(&DAEMON_FAIL_OK, daemon))
{
/* It might be ok anyway */
initng_common_mark_service(daemon, &DAEMON_STOPPED);
return;
- }
-
+ }
+
/* This is also ok */
- if(daemon->current_state->is == IS_STOPPING && is(&DAEMON_STOPS_BADLY, daemon))
+ if (daemon->current_state->is == IS_STOPPING
+ && is(&DAEMON_STOPS_BADLY, daemon))
{
/* It might be ok anyway */
initng_common_mark_service(daemon, &DAEMON_STOPPED);
Modified: initng/trunk/plugins/debug_commands/print_service.c
==============================================================================
--- initng/trunk/plugins/debug_commands/print_service.c (original)
+++ initng/trunk/plugins/debug_commands/print_service.c Thu Apr 20 01:18:18 2006
@@ -145,7 +145,8 @@
assert(s);
assert(s->name);
- mprintf(string, "\n# service_cache_entry: %s \"%s", s->type->name, s->name);
+ mprintf(string, "\n# service_cache_entry: %s \"%s", s->type->name,
+ s->name);
if (s->father_name)
mprintf(string, " : %s", s->father_name);
@@ -192,44 +193,42 @@
static void active_db_print_process(process_h * p, char **string)
{
assert(p);
- if(p->pst == P_FREE)
+ if (p->pst == P_FREE)
mprintf(string, "\tOLD Process: type %s\n", p->pt->name);
- if(p->pst == P_ACTIVE)
+ if (p->pst == P_ACTIVE)
mprintf(string, "\tACTIVE Process: type %s\n", p->pt->name);
-
- if(p->pid>0)
+
+ if (p->pid > 0)
mprintf(string, "\t\tPid: %i\n", p->pid);
-
- if(p->r_code>0)
+
+ if (p->r_code > 0)
mprintf(string, "\t\tSIGNALS:\n"
- "\t\tWEXITSTATUS %i\n"
- "\t\tWIFEXITED %i\n"
- "\t\tWIFSIGNALED %i\n"
- "\t\tWTERMSIG %i\n"
+ "\t\tWEXITSTATUS %i\n"
+ "\t\tWIFEXITED %i\n"
+ "\t\tWIFSIGNALED %i\n" "\t\tWTERMSIG %i\n"
#ifdef WCOREDUMP
- "\t\tWCOREDUMP %i\n"
+ "\t\tWCOREDUMP %i\n"
#endif
- "\t\tWIFSTOPPED %i\n"
- "\t\tWSTOPSIG %i\n"
- "\n",
- WEXITSTATUS(p->r_code),
- WIFEXITED(p->r_code),
- WIFSIGNALED(p->r_code),
- WTERMSIG(p->r_code),
+ "\t\tWIFSTOPPED %i\n"
+ "\t\tWSTOPSIG %i\n"
+ "\n",
+ WEXITSTATUS(p->r_code),
+ WIFEXITED(p->r_code),
+ WIFSIGNALED(p->r_code), WTERMSIG(p->r_code),
#ifdef WCOREDUMP
- WCOREDUMP(p->r_code),
+ WCOREDUMP(p->r_code),
#endif
- WIFSTOPPED(p->r_code),
- WSTOPSIG(p->r_code));
-
- if(p->out_pipe[0]>0 || p->out_pipe[1]>0)
+ WIFSTOPPED(p->r_code), WSTOPSIG(p->r_code));
+
+ if (p->out_pipe[0] > 0 || p->out_pipe[1] > 0)
mprintf(string, "\t\tFds read: %i, write: %i\n", p->out_pipe[0],
- p->out_pipe[1]);
-
- if (p->buffer && p->buffer_allocated>0)
+ p->out_pipe[1]);
+
+ if (p->buffer && p->buffer_allocated > 0)
{
- mprintf(string, "\t\tBuffer (%i): \n########## BUFFER ##########\n%s\n##############################\n", p->buffer_allocated,
- p->buffer);
+ mprintf(string,
+ "\t\tBuffer (%i): \n########## BUFFER ##########\n%s\n##############################\n",
+ p->buffer_allocated, p->buffer);
}
}
@@ -252,7 +251,7 @@
if (s->from_service)
{
mprintf(string, " :: %s", s->from_service->name);
- if(s->from_service->father_name)
+ if (s->from_service->father_name)
{
mprintf(string, " : %s", s->from_service->father_name);
}
Modified: initng/trunk/plugins/history/initng_history.c
==============================================================================
--- initng/trunk/plugins/history/initng_history.c (original)
+++ initng/trunk/plugins/history/initng_history.c Thu Apr 20 01:18:18 2006
@@ -232,7 +232,7 @@
/* free history entry */
free(current);
- current=NULL;
+ current = NULL;
}
}
@@ -271,7 +271,7 @@
/* free the struct */
free(entry);
- entry=NULL;
+ entry = NULL;
/* count down the number of records */
history_records--;
Modified: initng/trunk/plugins/iparser/initng_i_parser.c
==============================================================================
--- initng/trunk/plugins/iparser/initng_i_parser.c (original)
+++ initng/trunk/plugins/iparser/initng_i_parser.c Thu Apr 20 01:18:18 2006
@@ -43,7 +43,7 @@
#define ENDED(x) (!(x)[0] || (x)[0]=='\n')
const char *g_filename = NULL;
-const char *g_pointer = NULL; /* a pointer to the first char we can back step to when printing line copies */
+const char *g_pointer = NULL; /* a pointer to the first char we can back step to when printing line copies */
/* set this to have a really verbose walking output */
@@ -55,7 +55,8 @@
static void err_print_line2t(char *point, const char *message, e_mt err,
const char *file, const char *func,
int codeline);
-static service_cache_h *parse_file(const char *filename, const char *watch_for);
+static service_cache_h *parse_file(const char *filename,
+ const char *watch_for);
static int parse_service_line(char **to_parse, const char *watch_for,
service_cache_h * father, stype_h * type,
const char *filename, service_cache_h ** match,
@@ -162,10 +163,10 @@
* when searching on a full .i filename, the service
* returned is the first entry found in the i.file
*/
- if(service_to_find[0]=='/')
+ if (service_to_find[0] == '/')
{
/* sending null returns the first found */
- return(parse_file(service_to_find, NULL));
+ return (parse_file(service_to_find, NULL));
}
/*
@@ -278,7 +279,8 @@
}
/* parse a file for services */
-static service_cache_h *parse_file(const char *filename, const char *watch_for)
+static service_cache_h *parse_file(const char *filename,
+ const char *watch_for)
{
/* Pointer to content read, and pointer to where we are reading */
char *file_content = NULL;
@@ -351,7 +353,8 @@
if (parse_service_line(&file, watch_for, NULL, stype,
filename, &match, &exact_match) == TRUE)
{
- D_("parse_service_line(%s, %s)\n", match ? match->name : NULL, exact_match ? exact_match->name : NULL);
+ D_("parse_service_line(%s, %s)\n", match ? match->name : NULL,
+ exact_match ? exact_match->name : NULL);
/* ok, jump the ending '}' stack */
if (file[0] == '}')
@@ -367,8 +370,8 @@
}
/* Return what we got, and hope for the best */
- if(exact_match)
- return(exact_match);
+ if (exact_match)
+ return (exact_match);
return (match);
}
@@ -597,17 +600,17 @@
initng_service_cache_add(new_service);
/* if not watching for anything special */
- if(!watch_for)
+ if (!watch_for)
{
D_("Nothing to wait for\n");
/* set matach to the first found, and user may walk the services from that point added */
- if(!(*match))
+ if (!(*match))
{
(*match) = new_service;
}
- return (TRUE);
+ return (TRUE);
}
-
+
if (strcmp(new_service->name, watch_for) == 0)
{
Modified: initng/trunk/plugins/ngc4/initng_ngc4.c
==============================================================================
--- initng/trunk/plugins/ngc4/initng_ngc4.c (original)
+++ initng/trunk/plugins/ngc4/initng_ngc4.c Thu Apr 20 01:18:18 2006
@@ -1204,8 +1204,8 @@
else if (g.i_am == I_AM_FAKE_INIT)
socket_filename = SOCKET_4_FILENAME_TEST;
else
- return(TRUE);
-
+ return (TRUE);
+
D_("Socket is: %s\n", socket_filename);
D_("adding hook, that will reopen socket, for every started service.\n");
Modified: initng/trunk/plugins/ngc4/libngcclient.c
==============================================================================
--- initng/trunk/plugins/ngc4/libngcclient.c (original)
+++ initng/trunk/plugins/ngc4/libngcclient.c Thu Apr 20 01:18:18 2006
@@ -435,8 +435,8 @@
{
/* simplest create an int pointer */
int *p = rep->payload;
-
- string = malloc(20);
+
+ string = malloc(20);
sprintf(string, "%i", *p);
break;
Modified: initng/trunk/plugins/ngc4/ngc4.c
==============================================================================
--- initng/trunk/plugins/ngc4/ngc4.c (original)
+++ initng/trunk/plugins/ngc4/ngc4.c Thu Apr 20 01:18:18 2006
@@ -225,14 +225,13 @@
if (header_printed == FALSE && quiet == FALSE)
{
/* print banner - only on terminal */
- if(ansi)
+ if (ansi)
{
- print_out(C_FG_LIGHT_BLUE " Next Generation init Control. version ( "
- C_FG_MAGENTA "%s"
- C_FG_LIGHT_BLUE " )" C_OFF
- C_FG_LIGHT_RED "\n (c) Jimmy Wennlund, " C_OFF
- C_FG_NEON_GREEN "http://www.initng.org/" C_OFF "\n",
- VERSION);
+ print_out(C_FG_LIGHT_BLUE
+ " Next Generation init Control. version ( " C_FG_MAGENTA
+ "%s" C_FG_LIGHT_BLUE " )" C_OFF C_FG_LIGHT_RED
+ "\n (c) Jimmy Wennlund, " C_OFF C_FG_NEON_GREEN
+ "http://www.initng.org/" C_OFF "\n", VERSION);
}
header_printed = TRUE;
}
@@ -285,8 +284,8 @@
/*
* If output to a terminal, turn on ansi colors.
*/
- if(isatty(1))
- ansi=TRUE;
+ if (isatty(1))
+ ansi = TRUE;
/*
@@ -330,7 +329,7 @@
/* check if cmd-line contains "ngdc", if set debug */
if (strncasecmp(Argv, "ngd", 3) == 0)
{
- if(ansi)
+ if (ansi)
print_out(C_FG_YELLOW "Warning. This is ngdc!" C_OFF "\n");
debug = TRUE;
}
@@ -338,9 +337,10 @@
if (debug == FALSE && getuid() != 0)
{
- if(ansi)
- print_out(C_ERROR "You need root access to communicate with initng."
- C_OFF "\n");
+ if (ansi)
+ print_out(C_ERROR
+ "You need root access to communicate with initng." C_OFF
+ "\n");
exit(2);
}
Modified: initng/trunk/plugins/ngcs/initng_ngcs.c
==============================================================================
--- initng/trunk/plugins/ngcs/initng_ngcs.c (original)
+++ initng/trunk/plugins/ngcs/initng_ngcs.c Thu Apr 20 01:18:18 2006
@@ -70,7 +70,7 @@
static void handle_chan0(ngcs_chan * chan, int type, int len, char *data);
static void handle_close(ngcs_conn * conn);
static void ngcs_cmd_compat(ngcs_request * req);
-static void pollmode_hook(ngcs_conn *conn, int have_pending_writes);
+static void pollmode_hook(ngcs_conn * conn, int have_pending_writes);
ngcs_cmd ngcs_compat_cmds = {
NULL,
@@ -151,7 +151,8 @@
return;
}
- conn->conn = ngcs_conn_from_fd(newsock, conn, handle_close, pollmode_hook);
+ conn->conn = ngcs_conn_from_fd(newsock, conn, handle_close,
+ pollmode_hook);
if (conn->conn == NULL)
{
F_("Couldn't allocate ngcs_conn!");
@@ -160,7 +161,8 @@
return;
}
- chan0 = ngcs_chan_reg(conn->conn, 0, &handle_chan0, &ngcs_chan_del, NULL);
+ chan0 = ngcs_chan_reg(conn->conn, 0, &handle_chan0, &ngcs_chan_del,
+ NULL);
if (chan0 == NULL)
{
F_("Couldn't register channel 0!");
@@ -206,14 +208,14 @@
{
ngcs_svr_conn *conn = (ngcs_svr_conn *) from;
- if(what & FDW_READ)
+ if (what & FDW_READ)
ngcs_conn_data_ready(conn->conn);
- if(what & FDW_WRITE)
+ if (what & FDW_WRITE)
ngcs_conn_write_ready(conn->conn);
clean_dead_conns();
}
-static void pollmode_hook(ngcs_conn *conn, int have_pending_writes)
+static void pollmode_hook(ngcs_conn * conn, int have_pending_writes)
{
ngcs_svr_conn *sconn = (ngcs_svr_conn *) conn->userdata;
@@ -421,7 +423,8 @@
ngcs_svr_conn *sconn = (ngcs_svr_conn *) conn->userdata;
/* FIXME - if nextid wraps around to 0, this breaks */
- return ngcs_chan_reg(conn, sconn->nextid++, gotdata, ngcs_chan_del, chanfree);
+ return ngcs_chan_reg(conn, sconn->nextid++, gotdata, ngcs_chan_del,
+ chanfree);
}
void ngcs_close_channel(ngcs_chan * chan)
Modified: initng/trunk/plugins/ngcs/ngcs.c
==============================================================================
--- initng/trunk/plugins/ngcs/ngcs.c (original)
+++ initng/trunk/plugins/ngcs/ngcs.c Thu Apr 20 01:18:18 2006
@@ -39,18 +39,22 @@
#define maybe_grab_out(me) ( quiet ? 0 : grab_out(me))
-typedef enum {
+typedef enum
+{
WATCH_NORMAL = 0,
- WATCH_START = 1,
+ WATCH_START = 1,
WATCH_STOP = 2,
WATCH_STATUS = 3
} e_watch_mode;
-typedef struct cmd_res_s {
- char* cmd;
- char* arg;
- union {
- struct {
+typedef struct cmd_res_s
+{
+ char *cmd;
+ char *arg;
+ union
+ {
+ struct
+ {
int in_present;
int mode;
} svc_watch;
@@ -58,235 +62,275 @@
struct list_head list;
} cmd_res;
-cmd_res pending; int quiet = 0;
-ngcs_cli_conn *cconn; int debug = 0; int failed = 0;
-
-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);
+cmd_res pending;
+int quiet = 0;
+ngcs_cli_conn *cconn;
+int debug = 0;
+int failed = 0;
+
+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) ;
+int grab_out(void *me);
-void *last_out; int need_nl = 0;
+void *last_out;
+int need_nl = 0;
-int grab_out(void *me) {
+int grab_out(void *me)
+{
int n;
- if(me == NULL || last_out != me) {
- for(n = 0; n < need_nl; n++)
+ if (me == NULL || last_out != me)
+ {
+ for (n = 0; n < need_nl; n++)
putchar('\n');
- last_out = me; return 1;
- }
- else return 0;
+ last_out = me;
+ return 1;
+ }
+ else
+ return 0;
}
-const char *state_color(int rough_state) {
+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;
+ 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)
+void svc_watch_cb(ngcs_svc_evt_hook * hook, void *userdata,
+ ngcs_svc_evt * event)
{
cmd_res *res = userdata;
- assert(event); assert(res);
- switch(event->type) {
-
- case NGCS_SVC_EVT_BEGIN:
- 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);
- printf("----------------------------------------------------------------\n");
- }
- break;
- case NGCS_SVC_EVT_NOW:
- res->d.svc_watch.in_present = 1;
- if(res->d.svc_watch.mode == WATCH_STATUS)
- {
- ngcs_client_free_svc_watch(hook); return;
- }
- break;
- case NGCS_SVC_EVT_OUTPUT:
- if(res->d.svc_watch.mode == WATCH_STATUS)
- break;
- 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)
- {
- case WATCH_START:
- if(event->r.adb.current_state->is == IS_UP)
+ assert(event);
+ assert(res);
+
+ switch (event->type)
+ {
+
+ case NGCS_SVC_EVT_BEGIN:
+ if (res->d.svc_watch.mode == WATCH_STATUS)
{
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;
-
- }
- else if( ( res->d.svc_watch.in_present ||
- event->r.adb.current_state->is != IS_DOWN) &&
- event->r.adb.current_state->is != IS_STARTING)
-
+ 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);
+ printf("----------------------------------------------------------------\n");
+ }
+ break;
+ case NGCS_SVC_EVT_NOW:
+ res->d.svc_watch.in_present = 1;
+ if (res->d.svc_watch.mode == WATCH_STATUS)
{
- grab_out(NULL);
- printf("%s failed to start (%s)\n",
- event->svc_name,
- event->r.adb.current_state->state_name);
- failed = 1;
- ngcs_client_free_svc_watch(hook); return;
+ ngcs_client_free_svc_watch(hook);
+ return;
}
break;
- case WATCH_STOP:
- if(event->r.adb.current_state->is == IS_DOWN)
+ case NGCS_SVC_EVT_OUTPUT:
+ if (res->d.svc_watch.mode == WATCH_STATUS)
+ break;
+ if (maybe_grab_out(res))
{
- 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;
-
- }
- else if( ( res->d.svc_watch.in_present ||
- event->r.adb.current_state->is != IS_UP ) &&
- event->r.adb.current_state->is != IS_STOPPING)
-
+ 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)
{
- grab_out(NULL);
- printf("Service \"%s\" failed to stop (%s)\n",
- event->svc_name,
- event->r.adb.current_state->state_name);
- failed = 1;
- ngcs_client_free_svc_watch(hook); return;
+ 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;
+
+ }
+ else if ((res->d.svc_watch.in_present ||
+ event->r.adb.current_state->is != IS_DOWN) &&
+ 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);
+ failed = 1;
+ ngcs_client_free_svc_watch(hook);
+ return;
+ }
+ break;
+ case WATCH_STOP:
+ if (event->r.adb.current_state->is == IS_DOWN)
+ {
+ 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;
+
+ }
+ else if ((res->d.svc_watch.in_present ||
+ event->r.adb.current_state->is != IS_UP) &&
+ event->r.adb.current_state->is != IS_STOPPING)
+
+ {
+ grab_out(NULL);
+ printf("Service \"%s\" failed to stop (%s)\n",
+ event->svc_name,
+ event->r.adb.current_state->state_name);
+ failed = 1;
+ ngcs_client_free_svc_watch(hook);
+ return;
+ }
+ break;
+ 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 : %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);
+ return;
+ }
+ default:
+ break;
+ }
+ 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 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 : %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);
- return;
- }
+ 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:
break;
- }
- 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:
- break;
}
}
-void docmd(char* cmd, char* arg)
+void docmd(char *cmd, char *arg)
{
ngcs_data dat[2];
cmd_res *res = malloc(sizeof(cmd_res));
- if(res == NULL)
+
+ if (res == NULL)
{
printf(C_ERROR "Malloc failed\n" C_OFF);
exit(2);
}
- res->cmd = cmd; res->arg = arg;
- res->list.prev = 0; res->list.next = 0;
+ res->cmd = cmd;
+ res->arg = arg;
+ res->list.prev = 0;
+ res->list.next = 0;
- if(strcmp(cmd, "--watch") == 0)
+ if (strcmp(cmd, "--watch") == 0)
{
res->d.svc_watch.in_present = 0;
res->d.svc_watch.mode = WATCH_NORMAL;
- if(ngcs_watch_service(cconn, arg, NGCS_WATCH_OUTPUT |
- NGCS_WATCH_STATUS, svc_watch_cb,
- res) == NULL) {
+ 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;
+ cmd, (arg == NULL ? "" : arg));
+ failed = 1;
+ free(res);
+ return;
}
- list_add(&res->list, &pending.list); return;
+ list_add(&res->list, &pending.list);
+ return;
}
- else if(strcmp(cmd, "--status") == 0 || strcmp(cmd, "-s") == 0)
+ else if (strcmp(cmd, "--status") == 0 || strcmp(cmd, "-s") == 0)
{
res->d.svc_watch.in_present = 0;
res->d.svc_watch.mode = WATCH_STATUS;
- if(ngcs_watch_service(cconn, arg, NGCS_CURRENT_STATUS,
- svc_watch_cb, res) == NULL) {
+ 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;
+ cmd, (arg == NULL ? "" : arg));
+ failed = 1;
+ free(res);
+ return;
}
- list_add(&res->list, &pending.list); return;
+ list_add(&res->list, &pending.list);
+ return;
}
- else if(strcmp(cmd, "--start") == 0 || strcmp(cmd, "-u") == 0)
+ else if (strcmp(cmd, "--start") == 0 || strcmp(cmd, "-u") == 0)
{
res->d.svc_watch.in_present = 0;
res->d.svc_watch.mode = WATCH_START;
- if(ngcs_start_stop(cconn, "start", arg, svc_watch_cb,
- res) == NULL) {
+ 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;
+ cmd, (arg == NULL ? "" : arg));
+ failed = 1;
+ free(res);
+ return;
}
- list_add(&res->list, &pending.list); return;
+ list_add(&res->list, &pending.list);
+ return;
}
- else if(strcmp(cmd, "--stop") == 0 || strcmp(cmd, "-d") == 0)
+ else if (strcmp(cmd, "--stop") == 0 || strcmp(cmd, "-d") == 0)
{
res->d.svc_watch.in_present = 0;
res->d.svc_watch.mode = WATCH_STOP;
- if(ngcs_start_stop(cconn, "stop", arg, svc_watch_cb,
- res) == NULL) {
+ 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;
+ cmd, (arg == NULL ? "" : arg));
+ failed = 1;
+ free(res);
+ return;
}
- list_add(&res->list, &pending.list); return;
+ list_add(&res->list, &pending.list);
+ return;
}
dat[0].type = NGCS_TYPE_STRING;
@@ -297,75 +341,82 @@
dat[1].len = -1;
dat[1].d.s = arg;
- if(ngcs_cmd_async(cconn, (arg == NULL ? 1 : 2), dat,
- resp_handler, res))
+ 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;
+ cmd, (arg == NULL ? "" : arg));
+ failed = 1;
+ free(res);
+ return;
}
list_add(&res->list, &pending.list);
}
-void resp_handler (ngcs_cli_conn *cconn, void *userdata, ngcs_data *ret)
+void resp_handler(ngcs_cli_conn * cconn, void *userdata, ngcs_data * ret)
{
cmd_res *res = userdata;
+
assert(res);
- if(ret == NULL || ret->len < 0)
+ 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));
+ res->cmd, (res->arg == NULL ? "" : res->arg));
failed = 1;
- }
- 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"));
- if(!ret->d.i) failed = 1;
- 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);
- failed = 1; break;
-
}
+ 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"));
+ if (!ret->d.i)
+ failed = 1;
+ 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);
+ failed = 1;
+ break;
- list_del(&res->list); free(res);
+ }
+
+ list_del(&res->list);
+ free(res);
}
/* THIS IS MAIN */
@@ -378,7 +429,8 @@
assert(argv[0]);
INIT_LIST_HEAD(&pending.list);
- last_out = NULL; need_nl = 0;
+ last_out = NULL;
+ need_nl = 0;
/*
* Skip path in Argv.
@@ -429,12 +481,12 @@
if (debug == FALSE && getuid() != 0)
{
printf(C_ERROR "You need root access to communicate with initng."
- C_OFF "\n");
+ C_OFF "\n");
exit(2);
}
-
+
cconn = ngcs_client_connect((debug ? NGCS_CLIENT_CONN_TEST : 0),
- NULL, NULL, NULL);
+ NULL, NULL, NULL);
if (cconn == NULL)
{
@@ -442,50 +494,55 @@
exit(2);
}
- for(cc = 1; cc < argc; cc++)
+ for (cc = 1; cc < argc; cc++)
{
- if(argv[cc][0] == '-')
+ if (argv[cc][0] == '-')
{
- if(last_sw >= 0 && last_sw == cc - 1)
+ if (last_sw >= 0 && last_sw == cc - 1)
docmd(argv[last_sw], NULL);
last_sw = cc;
}
else
{
- if(last_sw < 0)
+ if (last_sw < 0)
{
printf(C_FG_RED "Bad usage" C_OFF "\n");
- ngcs_client_free(cconn); exit(2);
+ ngcs_client_free(cconn);
+ exit(2);
}
docmd(argv[last_sw], argv[cc]);
}
}
- if(last_sw >= 0 && last_sw == cc - 1)
+ if (last_sw >= 0 && last_sw == cc - 1)
docmd(argv[last_sw], NULL);
- while(!list_empty(&pending.list) && !ngcs_client_conn_is_closed(cconn)) {
+ while (!list_empty(&pending.list) && !ngcs_client_conn_is_closed(cconn))
+ {
fd_set readset, writeset;
- int fd = ngcs_client_get_fd(cconn); int retval;
+ int fd = ngcs_client_get_fd(cconn);
+ int retval;
- FD_ZERO(&readset); FD_ZERO(&writeset);
+ FD_ZERO(&readset);
+ FD_ZERO(&writeset);
FD_SET(fd, &readset);
- if(ngcs_client_conn_has_pending_writes(cconn))
+ if (ngcs_client_conn_has_pending_writes(cconn))
FD_SET(fd, &writeset);
retval = select(fd + 1, &readset, &writeset, NULL, NULL);
- if(retval < 0 && errno != EINTR)
+ if (retval < 0 && errno != EINTR)
{
printf(C_ERROR "select() failed!\n" C_OFF "\n");
- ngcs_client_free(cconn); exit(2);
+ ngcs_client_free(cconn);
+ exit(2);
}
- if(retval > 0 && FD_ISSET(fd, &readset))
+ if (retval > 0 && FD_ISSET(fd, &readset))
ngcs_client_data_ready(cconn);
- if(retval > 0 && FD_ISSET(fd, &writeset))
+ if (retval > 0 && FD_ISSET(fd, &writeset))
ngcs_client_write_ready(cconn);
ngcs_client_dispatch(cconn);
Modified: initng/trunk/plugins/ngcs/ngcs_client.c
==============================================================================
--- initng/trunk/plugins/ngcs/ngcs_client.c (original)
+++ initng/trunk/plugins/ngcs/ngcs_client.c Thu Apr 20 01:18:18 2006
@@ -25,10 +25,12 @@
#include <unistd.h>
#include <assert.h>
-struct ngcs_svc_evt_hook_s {
- void* userdata;
- ngcs_chan* chan;
- void (*hook) (ngcs_svc_evt_hook *hook, void *userdata, ngcs_svc_evt *event);
+struct ngcs_svc_evt_hook_s
+{
+ void *userdata;
+ ngcs_chan *chan;
+ void (*hook) (ngcs_svc_evt_hook * hook, void *userdata,
+ ngcs_svc_evt * event);
};
typedef struct ngcs_cli_req_s
@@ -46,42 +48,48 @@
ngcs_chan *chan0;
ngcs_cli_req pending_reqs;
ngcs_cli_req resps;
- void (*onclose) (ngcs_cli_conn *conn);
- void (*pollmode_hook) (ngcs_cli_conn *cconn, int have_pending_writes);
- void* userdata;
+ void (*onclose) (ngcs_cli_conn * conn);
+ void (*pollmode_hook) (ngcs_cli_conn * cconn, int have_pending_writes);
+ void *userdata;
};
static void ngcs_client_close_hook(ngcs_conn * conn);
-static void pollmode_hook_fixup(ngcs_conn* conn, int have_pending_writes);
+static void pollmode_hook_fixup(ngcs_conn * conn, int have_pending_writes);
static void chan0_gotdata(ngcs_chan * chan, int type, int len, char *data);
-static void chan0_close (ngcs_chan * chan);
-static void handle_svc_event_req(ngcs_cli_conn *cconn, void *userdata, ngcs_data *ret);
-static void svc_status_gotdata (ngcs_chan *chan, int type, int len, char *data);
-static void svc_status_end (ngcs_chan *chan);
+static void chan0_close(ngcs_chan * chan);
+static void handle_svc_event_req(ngcs_cli_conn * cconn, void *userdata,
+ ngcs_data * ret);
+static void svc_status_gotdata(ngcs_chan * chan, int type, int len,
+ char *data);
+static void svc_status_end(ngcs_chan * chan);
-void ngcs_client_free_svc_watch(ngcs_svc_evt_hook *hook)
+void ngcs_client_free_svc_watch(ngcs_svc_evt_hook * hook)
{
ngcs_svc_evt event;
assert(hook);
- if(hook->chan != NULL)
+ if (hook->chan != NULL)
{
ngcs_chan_del(hook->chan);
}
else
{
- event.type = NGCS_SVC_EVT_END; event.svc_name = NULL;
+ event.type = NGCS_SVC_EVT_END;
+ event.svc_name = NULL;
hook->hook(hook, hook->userdata, &event);
free(hook);
}
}
-static void handle_svc_event_req(ngcs_cli_conn *cconn, void *userdata, ngcs_data *ret)
+static void handle_svc_event_req(ngcs_cli_conn * cconn, void *userdata,
+ ngcs_data * ret)
{
- ngcs_svc_evt_hook *hook = userdata; ngcs_svc_evt event;
+ ngcs_svc_evt_hook *hook = userdata;
+ ngcs_svc_evt event;
+
assert(hook != NULL);
- if(ret == NULL || ret->len < 0 || ret->type != NGCS_TYPE_INT)
+ if (ret == NULL || ret->len < 0 || ret->type != NGCS_TYPE_INT)
{
/* FIXME - better error handling? */
ngcs_client_free_svc_watch(hook);
@@ -89,8 +97,8 @@
}
hook->chan = ngcs_chan_reg(cconn->conn, ret->d.i, svc_status_gotdata,
- ngcs_chan_del, svc_status_end);
- if(hook->chan == NULL)
+ ngcs_chan_del, svc_status_end);
+ if (hook->chan == NULL)
{
ngcs_client_free_svc_watch(hook);
return;
@@ -102,16 +110,20 @@
hook->hook(hook, hook->userdata, &event);
}
-static void svc_status_gotdata (ngcs_chan *chan, int type, int len, char *data)
+static void svc_status_gotdata(ngcs_chan * chan, int type, int len,
+ char *data)
{
- ngcs_svc_evt_hook *hook = chan->userdata; ngcs_svc_evt event;
- ngcs_data *s; int cnt;
+ ngcs_svc_evt_hook *hook = chan->userdata;
+ ngcs_svc_evt event;
+ ngcs_data *s;
+ int cnt;
+
assert(hook != NULL);
- if(len < 0)
+ if (len < 0)
return;
- if(type == NGCS_TYPE_NULL)
+ if (type == NGCS_TYPE_NULL)
{
event.type = NGCS_SVC_EVT_NOW;
event.svc_name = NULL;
@@ -119,15 +131,15 @@
return;
}
- if(type != NGCS_TYPE_STRUCT)
- return; /* FIXME - report error */
+ if (type != NGCS_TYPE_STRUCT)
+ return; /* FIXME - report error */
cnt = ngcs_unpack(data, len, &s);
- if(cnt < 0)
- return;
+ if (cnt < 0)
+ return;
- if(cnt == 2 && s[0].type == NGCS_TYPE_STRING
- && s[1].type == NGCS_TYPE_STRING)
+ if (cnt == 2 && s[0].type == NGCS_TYPE_STRING
+ && s[1].type == NGCS_TYPE_STRING)
{
event.type = NGCS_SVC_EVT_OUTPUT;
event.svc_name = s[0].d.s;
@@ -139,27 +151,28 @@
{
ngcs_free_unpack(cnt, s);
- if(ngcs_unmarshal_ngcs_active_db_h(&event.r.adb, len, data))
+ if (ngcs_unmarshal_ngcs_active_db_h(&event.r.adb, len, data))
{
printf("DEBUG: unmarshal active_db error\n");
- return; /* FIXME - should report error too */
+ return; /* FIXME - should report error too */
}
event.type = NGCS_SVC_EVT_STATE;
event.svc_name = event.r.adb.name;
-
+
hook->hook(hook, hook->userdata, &event);
ngcs_free_ngcs_active_db_h(&event.r.adb);
-
-
+
+
/* TODO */
}
}
-static void svc_status_end (ngcs_chan *chan)
+static void svc_status_end(ngcs_chan * chan)
{
ngcs_svc_evt_hook *hook = chan->userdata;
+
assert(hook != NULL);
hook->chan = NULL;
@@ -167,55 +180,66 @@
}
-ngcs_cli_conn* ngcs_client_connect(e_ngcs_cli_connflags flags, void* userdata,
- void (*pollmode_hook) (ngcs_cli_conn *cconn, int have_pending_writes),
- void (*onclose) (ngcs_cli_conn *conn))
-{
- int len; int sock; ngcs_cli_conn* cconn;
+ngcs_cli_conn *ngcs_client_connect(e_ngcs_cli_connflags flags, void *userdata,
+ void (*pollmode_hook) (ngcs_cli_conn *
+ cconn,
+ int
+ have_pending_writes),
+ void (*onclose) (ngcs_cli_conn * conn))
+{
+ int len;
+ int sock;
+ ngcs_cli_conn *cconn;
struct sockaddr_un sockname;
sock = socket(PF_UNIX, SOCK_STREAM, 0);
if (sock < 0)
return NULL;
-
+
sockname.sun_family = AF_UNIX;
- strcpy(sockname.sun_path, (flags & NGCS_CLIENT_CONN_TEST ?
- SOCKET_FILENAME_TEST : SOCKET_FILENAME_REAL));
+ strcpy(sockname.sun_path, (flags & NGCS_CLIENT_CONN_TEST ?
+ SOCKET_FILENAME_TEST : SOCKET_FILENAME_REAL));
len = strlen(sockname.sun_path) + sizeof(sockname.sun_family);
-
+
if (connect(sock, (struct sockaddr *) &sockname, len))
{
- close(sock); return NULL;
+ close(sock);
+ return NULL;
}
-
+
cconn = malloc(sizeof(ngcs_cli_conn));
- if(cconn == NULL)
+ if (cconn == NULL)
{
- close(sock); return NULL;
+ close(sock);
+ return NULL;
}
cconn->conn = ngcs_conn_from_fd(sock, cconn, ngcs_client_close_hook,
- pollmode_hook_fixup);
+ pollmode_hook_fixup);
- if(cconn->conn == NULL)
+ if (cconn->conn == NULL)
{
- free(cconn); close(sock); return NULL;
+ free(cconn);
+ close(sock);
+ return NULL;
}
INIT_LIST_HEAD(&cconn->pending_reqs.list);
INIT_LIST_HEAD(&cconn->resps.list);
- cconn->onclose = NULL; cconn->pollmode_hook = NULL;
+ cconn->onclose = NULL;
+ cconn->pollmode_hook = NULL;
cconn->userdata = userdata;
-
+
/* Command channel; we don't need notification of it being freed */
- cconn->chan0 = ngcs_chan_reg(cconn->conn, 0, chan0_gotdata,
- chan0_close, NULL);
+ cconn->chan0 = ngcs_chan_reg(cconn->conn, 0, chan0_gotdata,
+ chan0_close, NULL);
- if(cconn->chan0 == NULL)
+ if (cconn->chan0 == NULL)
{
- ngcs_conn_close(cconn->conn); return NULL;
+ ngcs_conn_close(cconn->conn);
+ return NULL;
}
cconn->onclose = onclose;
@@ -224,9 +248,9 @@
return cconn;
}
-void ngcs_client_free(ngcs_cli_conn *cconn)
+void ngcs_client_free(ngcs_cli_conn * cconn)
{
- if(cconn->conn != NULL)
+ if (cconn->conn != NULL)
{
ngcs_conn_free(cconn->conn);
}
@@ -236,31 +260,31 @@
free(cconn);
}
-int ngcs_client_conn_is_closed(ngcs_cli_conn *cconn)
+int ngcs_client_conn_is_closed(ngcs_cli_conn * cconn)
{
return cconn->conn == NULL;
}
-int ngcs_client_conn_has_pending_writes(ngcs_cli_conn *cconn)
+int ngcs_client_conn_has_pending_writes(ngcs_cli_conn * cconn)
{
- return cconn->conn != NULL &&
- ngcs_conn_has_pending_writes(cconn->conn);
+ return cconn->conn != NULL && ngcs_conn_has_pending_writes(cconn->conn);
}
-static void pollmode_hook_fixup(ngcs_conn* conn, int have_pending_writes)
+static void pollmode_hook_fixup(ngcs_conn * conn, int have_pending_writes)
{
ngcs_cli_conn *cconn = conn->userdata;
- if(cconn->pollmode_hook)
+
+ if (cconn->pollmode_hook)
cconn->pollmode_hook(cconn, have_pending_writes);
}
-void* ngcs_client_conn_get_userdata(ngcs_cli_conn *cconn)
+void *ngcs_client_conn_get_userdata(ngcs_cli_conn * cconn)
{
return cconn->userdata;
}
-void ngcs_client_conn_set_userdata(ngcs_cli_conn *cconn, void *userdata)
+void ngcs_client_conn_set_userdata(ngcs_cli_conn * cconn, void *userdata)
{
cconn->userdata = userdata;
}
@@ -269,7 +293,7 @@
{
ngcs_cli_conn *cconn = conn->userdata;
- if(cconn->onclose != NULL)
+ if (cconn->onclose != NULL)
cconn->onclose(cconn);
cconn->conn = NULL;
@@ -277,30 +301,34 @@
/* TODO */
}
-static void chan0_gotdata(ngcs_chan * chan, int type, int len, char *data) {
+static void chan0_gotdata(ngcs_chan * chan, int type, int len, char *data)
+{
ngcs_cli_conn *cconn = chan->conn->userdata;
ngcs_cli_req *req;
- if(list_empty(&cconn->pending_reqs.list))
+ if (list_empty(&cconn->pending_reqs.list))
{
/* FIXME - should display some sort of error */
- ngcs_chan_close(chan); return;
+ ngcs_chan_close(chan);
+ return;
}
req = list_entry(cconn->pending_reqs.list.next, ngcs_cli_req, list);
- if(ngcs_unpack_one(type, len, data, &req->resp))
+ if (ngcs_unpack_one(type, len, data, &req->resp))
{
/* FIXME - should also display an error */
req->resp.type = NGCS_TYPE_NULL;
- req->resp.len = -1; req->resp.d.p = NULL;
+ req->resp.len = -1;
+ req->resp.d.p = NULL;
}
list_move_tail(&req->list, &cconn->resps.list);
}
/* Cancels all requests awaiting a response */
-static void chan0_close (ngcs_chan * chan) {
+static void chan0_close(ngcs_chan * chan)
+{
ngcs_cli_conn *cconn = chan->conn->userdata;
ngcs_cli_req *req, *next;
@@ -315,56 +343,57 @@
cconn->chan0 = NULL;
}
-void ngcs_client_dispatch(ngcs_cli_conn *cconn)
+void ngcs_client_dispatch(ngcs_cli_conn * cconn)
{
ngcs_cli_req *req, *next;
ngcs_conn_dispatch(cconn->conn);
-
+
list_for_each_entry_safe(req, next, &cconn->resps.list, list)
{
- if(req->handler)
+ if (req->handler)
req->handler(cconn, req->cookie, &req->resp);
-
+
list_del(&req->list);
ngcs_free_unpack_one(&req->resp);
free(req);
}
}
-int ngcs_client_get_fd(ngcs_cli_conn *cconn)
+int ngcs_client_get_fd(ngcs_cli_conn * cconn)
{
assert(cconn->conn != NULL);
return cconn->conn->fd;
}
-void ngcs_client_data_ready(ngcs_cli_conn *cconn)
+void ngcs_client_data_ready(ngcs_cli_conn * cconn)
{
ngcs_client_dispatch(cconn);
- if(cconn->conn != NULL)
+ if (cconn->conn != NULL)
ngcs_conn_data_ready(cconn->conn);
- ngcs_client_dispatch(cconn);
+ ngcs_client_dispatch(cconn);
}
-void ngcs_client_write_ready(ngcs_cli_conn *cconn)
+void ngcs_client_write_ready(ngcs_cli_conn * cconn)
{
- if(cconn->conn != NULL)
+ if (cconn->conn != NULL)
ngcs_conn_write_ready(cconn->conn);
}
-int ngcs_cmd_async(ngcs_cli_conn *cconn, int argc, ngcs_data* argv,
- void (*handler) (ngcs_cli_conn *cconn, void *userdata,
- ngcs_data *ret),
- void* userdata)
+int ngcs_cmd_async(ngcs_cli_conn * cconn, int argc, ngcs_data * argv,
+ void (*handler) (ngcs_cli_conn * cconn, void *userdata,
+ ngcs_data * ret), void *userdata)
{
- int len, ret; char *buf; ngcs_cli_req *req;
+ int len, ret;
+ char *buf;
+ ngcs_cli_req *req;
assert(cconn);
- if(cconn->chan0 == NULL)
+ if (cconn->chan0 == NULL)
return 1;
len = ngcs_pack(argv, argc, NULL);
- if(len < 0)
+ if (len < 0)
return -1;
buf = malloc(len);
@@ -379,90 +408,103 @@
}
req = malloc(sizeof(ngcs_cli_req));
- if(req == NULL)
+ if (req == NULL)
{
free(buf);
return 1;
}
ret = ngcs_chan_send(cconn->chan0, NGCS_TYPE_STRUCT, len, buf);
- free(buf);
- if(ret)
+ free(buf);
+ if (ret)
{
- free(req); return 1;
+ free(req);
+ return 1;
}
- req->cookie = userdata; req->handler = handler;
- req->list.prev = 0; req->list.next = 0;
+ req->cookie = userdata;
+ req->handler = handler;
+ req->list.prev = 0;
+ req->list.next = 0;
list_add_tail(&req->list, &cconn->pending_reqs.list);
return 0;
}
-ngcs_svc_evt_hook* ngcs_svc_event_cmd(ngcs_cli_conn *cconn,
- int argc, ngcs_data* argv,
- void (*handler) (ngcs_svc_evt_hook *hook, void *userdata, ngcs_svc_evt *event),
- void* userdata)
+ngcs_svc_evt_hook *ngcs_svc_event_cmd(ngcs_cli_conn * cconn,
+ int argc, ngcs_data * argv,
+ void (*handler) (ngcs_svc_evt_hook *
+ hook, void *userdata,
+ ngcs_svc_evt * event),
+ void *userdata)
{
ngcs_svc_evt_hook *hook = malloc(sizeof(ngcs_svc_evt_hook));
-
- assert(cconn); assert(handler);
- if(hook == NULL)
+ assert(cconn);
+ assert(handler);
+
+ if (hook == NULL)
return NULL;
-
+
hook->chan = NULL;
hook->hook = handler;
hook->userdata = userdata;
- if(ngcs_cmd_async(cconn, argc, argv, handle_svc_event_req, hook))
+ if (ngcs_cmd_async(cconn, argc, argv, handle_svc_event_req, hook))
{
- free(hook); return NULL;
+ free(hook);
+ return NULL;
}
return hook;
}
-ngcs_svc_evt_hook* ngcs_watch_service(ngcs_cli_conn *cconn, char* svc,
- int flags,
- void (*handler) (ngcs_svc_evt_hook
- *hook, void *userdata,
- ngcs_svc_evt *event),
- void* userdata)
+ngcs_svc_evt_hook *ngcs_watch_service(ngcs_cli_conn * cconn, char *svc,
+ int flags,
+ void (*handler) (ngcs_svc_evt_hook
+ * hook, void *userdata,
+ ngcs_svc_evt * event),
+ void *userdata)
{
ngcs_data args[3];
- args[0].type = NGCS_TYPE_STRING; args[0].len = -1;
- args[0].d.s = (char*)"watch";
- args[1].type = NGCS_TYPE_INT; args[1].d.i = flags;
-
- if(svc == NULL)
+ args[0].type = NGCS_TYPE_STRING;
+ args[0].len = -1;
+ args[0].d.s = (char *) "watch";
+ args[1].type = NGCS_TYPE_INT;
+ args[1].d.i = flags;
+
+ if (svc == NULL)
{
- args[2].type = NGCS_TYPE_NULL; args[2].len = 0;
+ args[2].type = NGCS_TYPE_NULL;
+ args[2].len = 0;
}
else
{
- args[2].type = NGCS_TYPE_STRING; args[2].len = -1;
+ args[2].type = NGCS_TYPE_STRING;
+ args[2].len = -1;
args[2].d.s = svc;
}
return ngcs_svc_event_cmd(cconn, 3, args, handler, userdata);
}
-ngcs_svc_evt_hook* ngcs_start_stop(ngcs_cli_conn *cconn, const char* cmd,
- const char* svc,
- void (*handler) (ngcs_svc_evt_hook *hook,
- void *userdata,
- ngcs_svc_evt *event),
- void* userdata)
+ngcs_svc_evt_hook *ngcs_start_stop(ngcs_cli_conn * cconn, const char *cmd,
+ const char *svc,
+ void (*handler) (ngcs_svc_evt_hook * hook,
+ void *userdata,
+ ngcs_svc_evt * event),
+ void *userdata)
{
ngcs_data args[3];
- args[0].type = NGCS_TYPE_STRING; args[0].len = -1;
- args[0].d.s = (char*) cmd;
-
- args[1].type = NGCS_TYPE_STRING; args[1].len = -1;
- args[1].d.s = (char*) svc;
+ args[0].type = NGCS_TYPE_STRING;
+ args[0].len = -1;
+ args[0].d.s = (char *) cmd;
+
+ args[1].type = NGCS_TYPE_STRING;
+ args[1].len = -1;
+ args[1].d.s = (char *) svc;
return ngcs_svc_event_cmd(cconn, 2, args, handler, userdata);
}
Modified: initng/trunk/plugins/ngcs/ngcs_client.h
==============================================================================
--- initng/trunk/plugins/ngcs/ngcs_client.h (original)
+++ initng/trunk/plugins/ngcs/ngcs_client.h Thu Apr 20 01:18:18 2006
@@ -22,78 +22,86 @@
#include "ngcs_common.h"
#include "ngcs_marshal.h"
-typedef enum {
+typedef enum
+{
NGCS_CLIENT_CONN_TEST = 1
} e_ngcs_cli_connflags;
-typedef struct ngcs_svc_evt_hook_s ngcs_svc_evt_hook;
+typedef struct ngcs_svc_evt_hook_s ngcs_svc_evt_hook;
typedef struct ngcs_cli_conn_s ngcs_cli_conn;
-typedef enum {
- NGCS_SVC_EVT_BEGIN = 0, /* start getting service events */
- NGCS_SVC_EVT_STATE = 1, /* state change */
- NGCS_SVC_EVT_OUTPUT = 2, /* service output */
- NGCS_SVC_EVT_NOW = 3, /* end of current state information, start
- of state change information */
- NGCS_SVC_EVT_END = 4 /* end of service events */
+typedef enum
+{
+ NGCS_SVC_EVT_BEGIN = 0, /* start getting service events */
+ NGCS_SVC_EVT_STATE = 1, /* state change */
+ NGCS_SVC_EVT_OUTPUT = 2, /* service output */
+ NGCS_SVC_EVT_NOW = 3, /* end of current state information, start
+ of state change information */
+ NGCS_SVC_EVT_END = 4 /* end of service events */
} e_ngcs_svc_evt_type;
-typedef struct ngcs_svc_evt_s {
+typedef struct ngcs_svc_evt_s
+{
e_ngcs_svc_evt_type type;
- char* svc_name;
- union {
- char* output;
+ char *svc_name;
+ union
+ {
+ char *output;
ngcs_active_db_h adb;
} r;
} ngcs_svc_evt;
-ngcs_cli_conn* ngcs_client_connect(e_ngcs_cli_connflags flags, void* userdata,
- void (*pollmode_hook) (ngcs_cli_conn *conn, int have_pending_writes),
- void (*onclose) (ngcs_cli_conn *conn));
+ngcs_cli_conn *ngcs_client_connect(e_ngcs_cli_connflags flags, void *userdata,
+ void (*pollmode_hook) (ngcs_cli_conn *
+ conn,
+ int
+ have_pending_writes),
+ void (*onclose) (ngcs_cli_conn * conn));
-void ngcs_client_free(ngcs_cli_conn *cconn);
+void ngcs_client_free(ngcs_cli_conn * cconn);
-void ngcs_client_dispatch(ngcs_cli_conn *cconn);
+void ngcs_client_dispatch(ngcs_cli_conn * cconn);
-void ngcs_client_data_ready(ngcs_cli_conn *cconn);
+void ngcs_client_data_ready(ngcs_cli_conn * cconn);
-void ngcs_client_write_ready(ngcs_cli_conn *cconn);
+void ngcs_client_write_ready(ngcs_cli_conn * cconn);
-int ngcs_client_conn_has_pending_writes(ngcs_cli_conn *cconn);
+int ngcs_client_conn_has_pending_writes(ngcs_cli_conn * cconn);
-int ngcs_client_get_fd(ngcs_cli_conn *cconn);
+int ngcs_client_get_fd(ngcs_cli_conn * cconn);
-int ngcs_cmd_async(ngcs_cli_conn *cconn, int argc, ngcs_data* argv,
- void (*handler) (ngcs_cli_conn *cconn, void *userdata,
- ngcs_data *ret),
- void* userdata);
+int ngcs_cmd_async(ngcs_cli_conn * cconn, int argc, ngcs_data * argv,
+ void (*handler) (ngcs_cli_conn * cconn, void *userdata,
+ ngcs_data * ret), void *userdata);
-void* ngcs_client_conn_get_userdata(ngcs_cli_conn *cconn);
-
-void ngcs_client_conn_set_userdata(ngcs_cli_conn *cconn, void *userdata);
+void *ngcs_client_conn_get_userdata(ngcs_cli_conn * cconn);
-int ngcs_client_conn_is_closed(ngcs_cli_conn *cconn);
+void ngcs_client_conn_set_userdata(ngcs_cli_conn * cconn, void *userdata);
-void ngcs_client_free_svc_watch(ngcs_svc_evt_hook *hook);
+int ngcs_client_conn_is_closed(ngcs_cli_conn * cconn);
-ngcs_svc_evt_hook* ngcs_svc_event_cmd(ngcs_cli_conn *cconn,
- int argc, ngcs_data* argv,
- void (*handler) (ngcs_svc_evt_hook *hook, void *userdata, ngcs_svc_evt *event),
- void* userdata);
+void ngcs_client_free_svc_watch(ngcs_svc_evt_hook * hook);
-ngcs_svc_evt_hook* ngcs_watch_service(ngcs_cli_conn *cconn, char* svc,
- int flags,
- void (*handler) (ngcs_svc_evt_hook *hook,
- void *userdata,
- ngcs_svc_evt *event),
- void* userdata);
+ngcs_svc_evt_hook *ngcs_svc_event_cmd(ngcs_cli_conn * cconn,
+ int argc, ngcs_data * argv,
+ void (*handler) (ngcs_svc_evt_hook *
+ hook, void *userdata,
+ ngcs_svc_evt * event),
+ void *userdata);
-ngcs_svc_evt_hook* ngcs_start_stop(ngcs_cli_conn *cconn, const char* cmd,
- const char* svc,
- void (*handler) (ngcs_svc_evt_hook *hook,
- void *userdata,
- ngcs_svc_evt *event),
- void* userdata);
+ngcs_svc_evt_hook *ngcs_watch_service(ngcs_cli_conn * cconn, char *svc,
+ int flags,
+ void (*handler) (ngcs_svc_evt_hook *
+ hook, void *userdata,
+ ngcs_svc_evt * event),
+ void *userdata);
+
+ngcs_svc_evt_hook *ngcs_start_stop(ngcs_cli_conn * cconn, const char *cmd,
+ const char *svc,
+ void (*handler) (ngcs_svc_evt_hook * hook,
+ void *userdata,
+ ngcs_svc_evt * event),
+ void *userdata);
#if 0
/* Note that these should only be used on connections returned
Modified: initng/trunk/plugins/ngcs/ngcs_common.c
==============================================================================
--- initng/trunk/plugins/ngcs/ngcs_common.c (original)
+++ initng/trunk/plugins/ngcs/ngcs_common.c Thu Apr 20 01:18:18 2006
@@ -34,7 +34,7 @@
struct list_head list;
} ngcs_incoming;
-static void ngcs_chan_closed(ngcs_chan *chan);
+static void ngcs_chan_closed(ngcs_chan * chan);
#if 0
int ngcs_sendmsg(int sock, int chan, int type, int len, const char *data)
@@ -150,41 +150,43 @@
return outcnt;
}
-int ngcs_unpack_one(int type, int len, const char* data, ngcs_data *res)
+int ngcs_unpack_one(int type, int len, const char *data, ngcs_data * res)
{
- res->type = type; res->len = len;
- if(len < 0)
+ res->type = type;
+ res->len = len;
+ if (len < 0)
{
- res->d.p = NULL; return 0;
+ res->d.p = NULL;
+ return 0;
}
switch (type)
{
- case NGCS_TYPE_INT:
- case NGCS_TYPE_BOOL:
- if (len != sizeof(int))
- return 1;
- res->d.i = *(const int *) data;
- break;
- case NGCS_TYPE_LONG:
- if (len != sizeof(long))
- return 1;
- res->d.i = *(const long *) data;
- break;
- case NGCS_TYPE_ERROR:
- case NGCS_TYPE_STRING:
- res->d.s = malloc(len + 1);
- if (!res->d.s)
- return 1;
- memcpy(res->d.s, data, len);
- res->d.s[len] = 0;
- break;
- default:
- res->d.p = malloc(len);
- if (!res->d.p)
- return 1;
- memcpy(res->d.p, data, len);
- break;
+ case NGCS_TYPE_INT:
+ case NGCS_TYPE_BOOL:
+ if (len != sizeof(int))
+ return 1;
+ res->d.i = *(const int *) data;
+ break;
+ case NGCS_TYPE_LONG:
+ if (len != sizeof(long))
+ return 1;
+ res->d.i = *(const long *) data;
+ break;
+ case NGCS_TYPE_ERROR:
+ case NGCS_TYPE_STRING:
+ res->d.s = malloc(len + 1);
+ if (!res->d.s)
+ return 1;
+ memcpy(res->d.s, data, len);
+ res->d.s[len] = 0;
+ break;
+ default:
+ res->d.p = malloc(len);
+ if (!res->d.p)
+ return 1;
+ memcpy(res->d.p, data, len);
+ break;
}
return 0;
}
@@ -214,7 +216,8 @@
{
int head[2];
memcpy(head, d, 2 * sizeof(int));
- rtype = head[0]; rlen = head[1];
+ rtype = head[0];
+ rlen = head[1];
if (head[1] < 0)
{
free(*res);
@@ -230,14 +233,15 @@
return -1;
}
- if(ngcs_unpack_one(rtype, rlen, d, (*res)+cnt))
+ if (ngcs_unpack_one(rtype, rlen, d, (*res) + cnt))
{
free(*res);
*res = NULL;
return -1;
}
- d += rlen; l -= rlen;
+ d += rlen;
+ l -= rlen;
cnt++;
}
return cnt;
@@ -247,19 +251,19 @@
{
switch (res->type)
{
- case NGCS_TYPE_INT:
- case NGCS_TYPE_BOOL:
- case NGCS_TYPE_LONG:
- break;
- case NGCS_TYPE_ERROR:
- case NGCS_TYPE_STRING:
- if (res->d.s)
- free(res->d.s);
- break;
- default:
- if (res->d.p)
- free(res->d.p);
- break;
+ case NGCS_TYPE_INT:
+ case NGCS_TYPE_BOOL:
+ case NGCS_TYPE_LONG:
+ break;
+ case NGCS_TYPE_ERROR:
+ case NGCS_TYPE_STRING:
+ if (res->d.s)
+ free(res->d.s);
+ break;
+ default:
+ if (res->d.p)
+ free(res->d.p);
+ break;
}
}
@@ -276,8 +280,9 @@
}
ngcs_conn *ngcs_conn_from_fd(int fd, void *userdata,
- void (*close_hook) (ngcs_conn * conn),
- void (*pollmode_hook) (ngcs_conn *conn, int have_pending_writes))
+ void (*close_hook) (ngcs_conn * conn),
+ void (*pollmode_hook) (ngcs_conn * conn,
+ int have_pending_writes))
{
ngcs_conn *conn;
struct timeval tv;
@@ -293,7 +298,8 @@
setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)))
{
/* FIXME - shoupd print error? */
- free(conn); return NULL;
+ free(conn);
+ return NULL;
}
@@ -307,17 +313,19 @@
conn->wrbuflen = 1024;
conn->wrbuf = malloc(conn->wrbuflen);
- if(conn->wrbuf == NULL)
+ if (conn->wrbuf == NULL)
{
- free(conn); return NULL;
+ free(conn);
+ return NULL;
}
return conn;
}
-static int ngcs_conn_send(ngcs_conn* conn, int chan, int type, int len, const char *data)
+static int ngcs_conn_send(ngcs_conn * conn, int chan, int type, int len,
+ const char *data)
{
- int total_len = 3*sizeof(int) + (len < 0 ? 0 : len);
+ int total_len = 3 * sizeof(int) + (len < 0 ? 0 : len);
int head[3];
if (len > 0)
@@ -326,41 +334,42 @@
head[1] = type;
head[2] = len;
- if(conn->fd < 0)
+ if (conn->fd < 0)
return 1;
/* Resize buffer if neccesary */
- if(conn->wrbuflen - conn->towrite < total_len)
+ if (conn->wrbuflen - conn->towrite < total_len)
{
/* FIXME - there are better allocation strategies */
- char* newbuf = realloc(conn->wrbuf, conn->towrite + total_len);
+ char *newbuf = realloc(conn->wrbuf, conn->towrite + total_len);
- if(newbuf == NULL)
+ if (newbuf == NULL)
return 1;
-
- conn->wrbuf = newbuf; conn->wrbuflen = conn->towrite + total_len;
+
+ conn->wrbuf = newbuf;
+ conn->wrbuflen = conn->towrite + total_len;
}
/* Copy message to write buffer */
- memcpy(conn->wrbuf + conn->towrite, head, 3*sizeof(int));
- if(len > 0)
- memcpy(conn->wrbuf + conn->towrite + 3*sizeof(int), data, len);
+ memcpy(conn->wrbuf + conn->towrite, head, 3 * sizeof(int));
+ if (len > 0)
+ memcpy(conn->wrbuf + conn->towrite + 3 * sizeof(int), data, len);
conn->towrite += total_len;
/* Try to send as much of the data as we can */
ngcs_conn_write_ready(conn);
-
+
/* FIXME - only need to call this if it's changed */
- if(conn->towrite > 0 && conn->pollmode_hook)
+ if (conn->towrite > 0 && conn->pollmode_hook)
conn->pollmode_hook(conn, 1);
return (conn->fd < 0);
}
ngcs_chan *ngcs_chan_reg(ngcs_conn * conn, int chanid,
- void (*gotdata) (ngcs_chan *, int, int, char *),
- void (*chanclose) (ngcs_chan*),
- void (*chanfree) (ngcs_chan *))
+ void (*gotdata) (ngcs_chan *, int, int, char *),
+ void (*chanclose) (ngcs_chan *),
+ void (*chanfree) (ngcs_chan *))
{
ngcs_chan *chan = malloc(sizeof(ngcs_chan));
@@ -373,7 +382,8 @@
chan->gotdata = gotdata;
chan->onclose = chanclose;
chan->onfree = chanfree;
- chan->close_state = NGCS_CHAN_OPEN; chan->is_freed = 0;
+ chan->close_state = NGCS_CHAN_OPEN;
+ chan->is_freed = 0;
chan->is_freeing = 0;
chan->list.next = 0;
chan->list.prev = 0;
@@ -383,23 +393,24 @@
void ngcs_chan_close(ngcs_chan * chan)
{
- if(chan->close_state != NGCS_CHAN_OPEN) return;
- chan->close_state = NGCS_CHAN_CLOSING; /* do this early, safer */
-
- if(chan->conn->fd >= 0)
+ if (chan->close_state != NGCS_CHAN_OPEN)
+ return;
+ chan->close_state = NGCS_CHAN_CLOSING; /* do this early, safer */
+
+ if (chan->conn->fd >= 0)
{
ngcs_conn_send(chan->conn, chan->id, NGCS_TYPE_NULL, -1, NULL);
}
- else
+ else
{
chan->close_state = NGCS_CHAN_CLOSED;
- if(chan->onclose)
+ if (chan->onclose)
chan->onclose(chan);
}
}
/* Called when the other side closes a channel */
-static void ngcs_chan_closed(ngcs_chan *chan)
+static void ngcs_chan_closed(ngcs_chan * chan)
{
assert(chan->close_state != NGCS_CHAN_CLOSED);
@@ -407,14 +418,14 @@
/* chan->onclose may free the channel. It should be NULL anyway if
chan->is_freed is true, but best to be safe */
- if(chan->is_freed)
- {
+ if (chan->is_freed)
+ {
list_del(&chan->list);
free(chan);
return;
}
- if(chan->onclose)
+ if (chan->onclose)
chan->onclose(chan);
}
@@ -422,24 +433,27 @@
{
void (*onclose) (ngcs_chan *);
- if(chan->close_state != NGCS_CHAN_OPEN) return;
+ if (chan->close_state != NGCS_CHAN_OPEN)
+ return;
ngcs_chan_close(chan);
- chan->gotdata = NULL; onclose = chan->onclose; chan->onclose = NULL;
+ chan->gotdata = NULL;
+ onclose = chan->onclose;
+ chan->onclose = NULL;
- if(chan->close_state == NGCS_CHAN_CLOSING && onclose)
+ if (chan->close_state == NGCS_CHAN_CLOSING && onclose)
onclose(chan);
-
+
}
void ngcs_chan_del(ngcs_chan * chan)
{
- if(chan->is_freeing)
+ if (chan->is_freeing)
return;
chan->is_freeing = 1;
- if(!chan->is_freed)
+ if (!chan->is_freed)
{
ngcs_chan_close_now(chan);
chan->is_freed = 1;
@@ -447,7 +461,7 @@
chan->onfree(chan);
}
- if(chan->close_state == NGCS_CHAN_CLOSED)
+ if (chan->close_state == NGCS_CHAN_CLOSED)
{
list_del(&chan->list);
free(chan);
@@ -457,23 +471,23 @@
}
/* called to dispatch a single message in various places */
-static void ngcs_conn_dispatch_one(ngcs_conn *conn, ngcs_incoming *it)
+static void ngcs_conn_dispatch_one(ngcs_conn * conn, ngcs_incoming * it)
{
int done = 0;
ngcs_chan *chan;
-
+
/* Dispatch to handler for this channel */
- while_ngcs_chans(chan, conn) if (chan->id == it->chan &&
- chan->close_state != NGCS_CHAN_CLOSED)
+ while_ngcs_chans(chan, conn) if (chan->id == it->chan &&
+ chan->close_state != NGCS_CHAN_CLOSED)
{
- if(it->len < 0)
- ngcs_chan_closed(chan);
+ if (it->len < 0)
+ ngcs_chan_closed(chan);
else if (chan->gotdata)
chan->gotdata(chan, it->type, it->len, it->data);
done = 1;
break;
}
-
+
if (!done && it->len >= 0)
{
/* Unknown channel - close it */
@@ -516,18 +530,19 @@
free(in.data);
}
-void ngcs_conn_write_ready(ngcs_conn* conn)
+void ngcs_conn_write_ready(ngcs_conn * conn)
{
int retval;
-
- if(conn->fd < 0 || conn->towrite <= 0)
+
+ if (conn->fd < 0 || conn->towrite <= 0)
return;
retval = send(conn->fd, conn->wrbuf, conn->towrite, 0);
- if(retval < 0)
+ if (retval < 0)
{
- if(errno != EAGAIN && errno != EINTR) {
+ if (errno != EAGAIN && errno != EINTR)
+ {
ngcs_conn_close(conn);
}
@@ -537,16 +552,16 @@
memmove(conn->wrbuf, conn->wrbuf + retval, conn->towrite - retval);
conn->towrite -= retval;
- if(conn->towrite <= 0 && conn->pollmode_hook)
+ if (conn->towrite <= 0 && conn->pollmode_hook)
conn->pollmode_hook(conn, 0);
}
-int ngcs_conn_has_pending_writes(ngcs_conn *conn)
+int ngcs_conn_has_pending_writes(ngcs_conn * conn)
{
return (conn->fd >= 0 && conn->towrite > 0);
}
-#if 0 /* FIXME - needs complete rewrite/rethink */
+#if 0 /* FIXME - needs complete rewrite/rethink */
int ngcs_chan_read_msg(ngcs_chan * chan, int *type, int *len, char **data)
{
fd_set fds;
@@ -566,9 +581,11 @@
}
}
- if(chan->close_state == NGCS_CHAN_CLOSED)
+ if (chan->close_state == NGCS_CHAN_CLOSED)
{
- *type = NGCS_TYPE_NULL; *len = -1; *data = NULL;
+ *type = NGCS_TYPE_NULL;
+ *len = -1;
+ *data = NULL;
return 0;
}
@@ -596,11 +613,11 @@
{
/* got the message */
- if(*len < 0)
+ if (*len < 0)
ngcs_chan_close(chan);
return 0;
- }
+ }
it = malloc(sizeof(ngcs_incoming));
if (it == NULL)
@@ -632,7 +649,7 @@
close(conn->fd);
conn->fd = -1;
- if(conn->towrite > 0 && conn->pollmode_hook)
+ if (conn->towrite > 0 && conn->pollmode_hook)
conn->pollmode_hook(conn, 0);
while_ngcs_chans_safe(chan, tmp, conn)
@@ -662,7 +679,8 @@
list_del(&chan->list);
free(chan);
}
- free(conn->wrbuf); free(conn);
+ free(conn->wrbuf);
+ free(conn);
/* TODO */
}
@@ -708,5 +726,5 @@
int ngcs_chan_send(ngcs_chan * chan, int type, int len, const char *data)
{
- return ngcs_conn_send(chan->conn, chan->id, type, len, data);
+ return ngcs_conn_send(chan->conn, chan->id, type, len, data);
}
Modified: initng/trunk/plugins/ngcs/ngcs_common.h
==============================================================================
--- initng/trunk/plugins/ngcs/ngcs_common.h (original)
+++ initng/trunk/plugins/ngcs/ngcs_common.h Thu Apr 20 01:18:18 2006
@@ -76,7 +76,7 @@
#define NGCS_TYPE_ERROR 8
-typedef enum
+typedef enum
{
NGCS_CHAN_OPEN = 0,
@@ -158,11 +158,11 @@
/*! \brief A function called when the connection is closed */
void (*close_hook) (ngcs_conn * conn);
- void (*pollmode_hook) (ngcs_conn *conn, int have_pending_writes);
+ void (*pollmode_hook) (ngcs_conn * conn, int have_pending_writes);
- char* wrbuf; /* write buffer */
- int wrbuflen; /* write buffer length */
- int towrite; /* length of data in write buffer */
+ char *wrbuf; /* write buffer */
+ int wrbuflen; /* write buffer length */
+ int towrite; /* length of data in write buffer */
struct list_head inqueue;
};
@@ -233,7 +233,7 @@
*/
int ngcs_pack(ngcs_data * data, int cnt, char *buf);
-int ngcs_unpack_one(int type, int len, const char* data, ngcs_data *res);
+int ngcs_unpack_one(int type, int len, const char *data, ngcs_data * res);
/*! \brief Unpack a received structure
*
@@ -280,8 +280,9 @@
* careful what you put in it.
*/
ngcs_conn *ngcs_conn_from_fd(int fd, void *userdata,
- void (*close_hook) (ngcs_conn * conn),
- void (*pollmode_hook) (ngcs_conn *conn, int have_pending_writes));
+ void (*close_hook) (ngcs_conn * conn),
+ void (*pollmode_hook) (ngcs_conn * conn,
+ int have_pending_writes));
/*! \brief Registers a channel handler on the specified connection
*
@@ -303,9 +304,9 @@
* free it), or NULL on failure
*/
ngcs_chan *ngcs_chan_reg(ngcs_conn * conn, int chanid,
- void (*gotdata) (ngcs_chan *, int, int, char *),
- void (*chanclose) (ngcs_chan*),
- void (*chanfree) (ngcs_chan *));
+ void (*gotdata) (ngcs_chan *, int, int, char *),
+ void (*chanclose) (ngcs_chan *),
+ void (*chanfree) (ngcs_chan *));
/*! \brief Closes a channel
*
@@ -330,9 +331,9 @@
*/
void ngcs_conn_data_ready(ngcs_conn * conn);
-void ngcs_conn_write_ready(ngcs_conn* conn);
+void ngcs_conn_write_ready(ngcs_conn * conn);
-int ngcs_conn_has_pending_writes(ngcs_conn *conn);
+int ngcs_conn_has_pending_writes(ngcs_conn * conn);
/*! \brief Closes a connection
*
Modified: initng/trunk/plugins/nge/initng_nge.c
==============================================================================
--- initng/trunk/plugins/nge/initng_nge.c (original)
+++ initng/trunk/plugins/nge/initng_nge.c Thu Apr 20 01:18:18 2006
@@ -533,16 +533,16 @@
* Decide witch path to socket to use.
* set socket_filename to right path
*/
-
- /* decide which socket to use */
- if (g.i_am == I_AM_INIT)
- socket_filename = NGE_REAL;
- else if (g.i_am == I_AM_FAKE_INIT)
- socket_filename = NGE_TEST;
- else
- return(FALSE);
- D_("Socket is: %s\n", socket_filename);
-
+
+ /* decide which socket to use */
+ if (g.i_am == I_AM_INIT)
+ socket_filename = NGE_REAL;
+ else if (g.i_am == I_AM_FAKE_INIT)
+ socket_filename = NGE_TEST;
+ else
+ return (FALSE);
+ D_("Socket is: %s\n", socket_filename);
+
/*
* Giving initng a SIGHUP, will make initng check that all sockets are open,
Modified: initng/trunk/plugins/nge/libngeclient.c
==============================================================================
--- initng/trunk/plugins/nge/libngeclient.c (original)
+++ initng/trunk/plugins/nge/libngeclient.c Thu Apr 20 01:18:18 2006
@@ -464,7 +464,7 @@
/* called on a <event type="initial_state_finished" */
static void ngeclient_handle_initial_state_finished(nge_event * event,
- char *tag, int chars)
+ char *tag, int chars)
{
if (event->initial_state_finished)
(*event->initial_state_finished) (event);
Modified: initng/trunk/plugins/reload/initng_reload.c
==============================================================================
--- initng/trunk/plugins/reload/initng_reload.c (original)
+++ initng/trunk/plugins/reload/initng_reload.c Thu Apr 20 01:18:18 2006
@@ -399,43 +399,45 @@
static int dump_state(void)
{
- const char * file = NULL;
+ const char *file = NULL;
/* set the correct filename */
- if(g.i_am == I_AM_INIT)
+ if (g.i_am == I_AM_INIT)
file = SAVE_FILE;
- else if(g.i_am == I_AM_FAKE_INIT)
+ else if (g.i_am == I_AM_FAKE_INIT)
file = SAVE_FILE_FAKE;
-
+
/* if there is a file */
- if(!file) return(TRUE);
+ if (!file)
+ return (TRUE);
- return(write_file(file));
+ return (write_file(file));
}
static int reload_state(void)
{
struct stat st;
- const char * file = NULL;
+ const char *file = NULL;
/* set the correct filename */
- if(g.i_am == I_AM_INIT)
+ if (g.i_am == I_AM_INIT)
file = SAVE_FILE;
- else if(g.i_am == I_AM_FAKE_INIT)
+ else if (g.i_am == I_AM_FAKE_INIT)
file = SAVE_FILE_FAKE;
-
+
/* if there is a file */
- if(!file) return(TRUE);
-
+ if (!file)
+ return (TRUE);
+
/* check that file exits */
- if (stat(file, &st)!=0)
+ if (stat(file, &st) != 0)
{
D_("No state file found, passing on reload_state request\n");
- return(FALSE);
+ return (FALSE);
}
- /* return with file */
- return(read_file(file));
+ /* return with file */
+ return (read_file(file));
}
/* Save a reload file for backup if initng segfaults */
Modified: initng/trunk/plugins/service/initng_service.c
==============================================================================
--- initng/trunk/plugins/service/initng_service.c (original)
+++ initng/trunk/plugins/service/initng_service.c Thu Apr 20 01:18:18 2006
@@ -637,7 +637,7 @@
/* free this process what ever happends */
- rcode=process->r_code; /* save rcode */
+ rcode = process->r_code; /* save rcode */
initng_process_db_free(process);
/*
@@ -657,19 +657,19 @@
/* check so it did not segfault */
- if(WTERMSIG(process->r_code)==11)
+ if (WTERMSIG(process->r_code) == 11)
{
F_("Service %s process start SETGFAUTED!\n");
initng_common_mark_service(service, &SERVICE_FAIL_START_SIGNAL);
return;
- }
+ }
/*
* Make sure r_code don't signal error (can be override by UP_ON_FAILURE.
*/
/* if rcode > 0 */
- if (WEXITSTATUS(rcode)>0 && !is(&START_FAIL_OK, service))
+ if (WEXITSTATUS(rcode) > 0 && !is(&START_FAIL_OK, service))
{
F_(" start %s, Returned with TERMSIG %i rcode %i.\n", service->name,
WTERMSIG(rcode), WEXITSTATUS(rcode));
@@ -704,9 +704,9 @@
D_("(%s);\n", service->name);
/* Free the process what ever happens below */
- rcode=process->r_code;
+ rcode = process->r_code;
initng_process_db_free(process);
-
+
/*
* If this exited after a timeout, stay failed
@@ -722,7 +722,7 @@
}
/* check with SIGSEGV (11) */
- if(WTERMSIG(process->r_code)==11)
+ if (WTERMSIG(process->r_code) == 11)
{
F_(" service %s stop process SEGFAUTED!\n", service->name);
Modified: initng/trunk/src/initng_active_db.c
==============================================================================
--- initng/trunk/src/initng_active_db.c (original)
+++ initng/trunk/src/initng_active_db.c Thu Apr 20 01:18:18 2006
@@ -174,22 +174,23 @@
current = NULL;
while_active_db(current)
{
- char * see = current->name;
+ char *see = current->name;
+
assert(current->name);
/* go to end of string */
- while(see[0])
+ while (see[0])
see++;
-
+
/* go back to the first '/' */
- while(see!=current->name && see[0]!='/')
+ while (see != current->name && see[0] != '/')
see--;
-
+
/* and skip that '/' char */
- if(see[0]=='/')
+ if (see[0] == '/')
see++;
-
-
+
+
/* check if this service name is like service */
if (strstr(see, copy))
{
@@ -581,7 +582,7 @@
if (g.now.tv_sec > current->time_current_state.tv_sec + CLEAN_DELAY)
{
initng_process_db_clear_freed(current);
-
+
/* count stopped services */
if (!IS_DOWN(current))
continue;
Modified: initng/trunk/src/initng_common.c
==============================================================================
--- initng/trunk/src/initng_common.c (original)
+++ initng/trunk/src/initng_common.c Thu Apr 20 01:18:18 2006
@@ -212,7 +212,7 @@
/* if the name of service is starting on a / chars, its a full filename
* and the service name cant be that name
*/
- if(service->name[0]=='/')
+ if (service->name[0] == '/')
{
/*
* <jimmy.wennlund at gmail.com>
@@ -230,7 +230,7 @@
/* Right now youst rip the from_service name right off */
free(service->name);
- service->name=strdup(service->from_service->name);
+ service->name = strdup(service->from_service->name);
}
/*
@@ -338,13 +338,14 @@
{
s_call *current, *safe = NULL;
service_cache_h *service = NULL;
+
D_("initng_common_parse_service(%s);\n", name);
/* first check service cache */
service = initng_service_cache_find_by_name(name);
if (service)
return (service);
-
+
/* try parse with dynamic loaded parsers */
while_list_safe(current, &g.PARSERS, safe)
{
Modified: initng/trunk/src/initng_fd.c
==============================================================================
--- initng/trunk/src/initng_fd.c (original)
+++ initng/trunk/src/initng_fd.c Thu Apr 20 01:18:18 2006
@@ -45,7 +45,7 @@
while_list_safe(current, &g.FDWATCHERS, safe)
{
- if(current->c.fdh->fds > 0)
+ if (current->c.fdh->fds > 0)
close(current->c.fdh->fds);
list_del(¤t->list);
@@ -129,16 +129,14 @@
/* OBSERVE, i_realloc may change the path to the data, so dont set buffer_pos to early */
/* Make sure there is room for 100 more chars */
- D_("left: %i > %i\n", p->buffer_len + 100,
- p->buffer_allocated);
+ D_("left: %i > %i\n", p->buffer_len + 100, p->buffer_allocated);
if (p->buffer_len + 100 >= p->buffer_allocated)
{
/* do a realloc */
D_("Changing size of buffer %p to: %i\n", p->buffer,
p->buffer_allocated + 100 + 1);
tmp = i_realloc(p->buffer,
- (p->buffer_allocated + 100 +
- 1) * sizeof(char));
+ (p->buffer_allocated + 100 + 1) * sizeof(char));
/* make sure realloc suceeded */
if (tmp)
@@ -146,12 +144,12 @@
D_("p->buffer changes from %p to %p.\n", p->buffer, tmp);
p->buffer = tmp;
p->buffer_allocated += 100;
-
+
/*
* make sure it nulls, specially when i_realloc is run for the verry first time
* and maby there is nothing to get by read
*/
- p->buffer[p->buffer_len]='\0';
+ p->buffer[p->buffer_len] = '\0';
}
else
{
@@ -163,7 +161,7 @@
/* read the data */
D_("Reading 100 chars.\n");
read_ret = read(p->out_pipe[0], &p->buffer[p->buffer_len], 100);
- /*printf("read_ret = %i : \"%.100s\"\n", read_ret, read_pos);*/
+ /*printf("read_ret = %i : \"%.100s\"\n", read_ret, read_pos); */
/* make sure read does not return -1 */
if (read_ret <= 0)
@@ -171,9 +169,9 @@
/* increase buffer_len */
p->buffer_len += read_ret;
-
- /* make sure its nulled at end */
- p->buffer[p->buffer_len]='\0';
+
+ /* make sure its nulled at end */
+ p->buffer[p->buffer_len] = '\0';
}
/* if read_ret == 100, it migit be more to read, or it got interrupted. */
while (read_ret >= 100 || errno == EINTR);
@@ -188,13 +186,13 @@
}
/*if empty, dont waist memory */
- if(p->buffer_len==0 && p->buffer)
+ if (p->buffer_len == 0 && p->buffer)
{
free(p->buffer);
- p->buffer=NULL;
- p->buffer_allocated=0;
- p->buffer_len=0;
- }
+ p->buffer = NULL;
+ p->buffer_allocated = 0;
+ p->buffer_len = 0;
+ }
/*
@@ -210,15 +208,15 @@
close(p->out_pipe[1]);
p->out_pipe[0] = -1;
p->out_pipe[1] = -1;
-
+
/* else, realloc to exact size */
- if(p->buffer && p->buffer_allocated>(p->buffer_len + 1))
+ if (p->buffer && p->buffer_allocated > (p->buffer_len + 1))
{
tmp = i_realloc(p->buffer, (p->buffer_len + 1) * sizeof(char));
- if(tmp)
+ if (tmp)
{
- p->buffer=tmp;
- p->buffer_allocated=p->buffer_len;
+ p->buffer = tmp;
+ p->buffer_allocated = p->buffer_len;
}
}
return;
@@ -236,14 +234,14 @@
if (tmp)
{
p->buffer = tmp;
- p->buffer_allocated = 9000; /* shorted by 1000 chars */
- p->buffer_len-=1000; /* shorted by 1000 chars */
- p->buffer[9000] = '\0'; /* shorted by 1000 chars */
+ p->buffer_allocated = 9000; /* shorted by 1000 chars */
+ p->buffer_len -= 1000; /* shorted by 1000 chars */
+ p->buffer[9000] = '\0'; /* shorted by 1000 chars */
}
else
{
/* make the best for the current situation */
- if(p->buffer)
+ if (p->buffer)
free(p->buffer);
p->buffer[0] = '\0';
F_("realloc failed, possibly out of memory!\n");
Modified: initng/trunk/src/initng_fork.c
==============================================================================
--- initng/trunk/src/initng_fork.c (original)
+++ initng/trunk/src/initng_fork.c Thu Apr 20 01:18:18 2006
@@ -127,7 +127,7 @@
fcntl(STDERR_FILENO, F_SETFD, 0);
/* Close the sides of the pipes we don't need, as we're in fork we won't need this part. */
- if(process->out_pipe[0]>0)
+ if (process->out_pipe[0] > 0)
close(process->out_pipe[0]);
process->out_pipe[0] = -1;
@@ -165,7 +165,7 @@
{
/* close the receiving end on pipe, on parent */
- if(process->out_pipe[1]>0)
+ if (process->out_pipe[1] > 0)
close(process->out_pipe[1]);
process->out_pipe[1] = -1;
if (pid_fork > 0)
Modified: initng/trunk/src/initng_global.c
==============================================================================
--- initng/trunk/src/initng_global.c (original)
+++ initng/trunk/src/initng_global.c Thu Apr 20 01:18:18 2006
@@ -49,7 +49,7 @@
/* zero the complete s_global */
memset(&g, 0, sizeof(s_global));
-
+
/* Set the i_am */
g.i_am = i_am;
Modified: initng/trunk/src/initng_list.h
==============================================================================
--- initng/trunk/src/initng_list.h (original)
+++ initng/trunk/src/initng_list.h Thu Apr 20 01:18:18 2006
@@ -127,7 +127,8 @@
static inline void list_move(struct list_head *list, struct list_head *head)
{
__list_del(list->prev, list->next);
- list->prev = 0; list->next = 0;
+ list->prev = 0;
+ list->next = 0;
list_add(list, head);
}
@@ -140,7 +141,8 @@
struct list_head *head)
{
__list_del(list->prev, list->next);
- list->prev = 0; list->next = 0;
+ list->prev = 0;
+ list->next = 0;
list_add_tail(list, head);
}
Modified: initng/trunk/src/initng_load_module.c
==============================================================================
--- initng/trunk/src/initng_load_module.c (original)
+++ initng/trunk/src/initng_load_module.c Thu Apr 20 01:18:18 2006
@@ -228,7 +228,7 @@
/* free module name */
if (m->module_name)
{
- /*printf("Free: %s\n", m->module_name);*/
+ /*printf("Free: %s\n", m->module_name); */
free(m->module_name);
m->module_name = NULL;
}
@@ -437,7 +437,7 @@
/* open the module */
current = initng_load_module_open(module_path, module_name);
- free(module_name); /* initng_load_module_open strdups this itself */
+ free(module_name); /* initng_load_module_open strdups this itself */
module_name = NULL;
/* add this to the list of loaded modules */
@@ -483,7 +483,7 @@
/* check if it was initialized correctly */
if (current->initziated != TRUE)
{
- if(g.i_am == I_AM_INIT || g.i_am == I_AM_FAKE_INIT)
+ if (g.i_am == I_AM_INIT || g.i_am == I_AM_FAKE_INIT)
F_("Module %s did not load correctly (module_init() returned %i)\n", current->module_name, current->initziated);
initng_load_module_close_and_free(current);
}
@@ -491,7 +491,7 @@
}
/* initng_load_static_modules(); */
- return(TRUE);
+ return (TRUE);
}
Modified: initng/trunk/src/initng_main.c
==============================================================================
--- initng/trunk/src/initng_main.c (original)
+++ initng/trunk/src/initng_main.c Thu Apr 20 01:18:18 2006
@@ -477,7 +477,8 @@
emergency_output = open("/dev/console", O_WRONLY);
if (emergency_output > 0)
{
- (void)write(emergency_output, LMESSAGE, sizeof(char) * strlen(LMESSAGE));
+ (void) write(emergency_output, LMESSAGE,
+ sizeof(char) * strlen(LMESSAGE));
close(emergency_output);
}
Modified: initng/trunk/src/initng_process_db.c
==============================================================================
--- initng/trunk/src/initng_process_db.c (original)
+++ initng/trunk/src/initng_process_db.c Thu Apr 20 01:18:18 2006
@@ -56,8 +56,8 @@
new_p->r_code = 0;
/* Set this to active, so it wont get freed */
- new_p->pst = P_ACTIVE;
-
+ new_p->pst = P_ACTIVE;
+
/* return new process_h pointer */
return (new_p);
}
@@ -126,7 +126,7 @@
{
if (current->pst != P_FREE)
continue;
-
+
initng_process_db_real_free(current);
}
}
Modified: initng/trunk/src/initng_process_db.h
==============================================================================
--- initng/trunk/src/initng_process_db.h (original)
+++ initng/trunk/src/initng_process_db.h Thu Apr 20 01:18:18 2006
@@ -49,16 +49,16 @@
{
ptype_h *pt;
pid_t pid; /* pid of process */
-
+
/*
* r_code is the return code, this is not the process exit(1) no
* instead see man waitpid for how to use it.
* example exit_code = WEXITSTATUS(process->r_code);
- */
+ */
int r_code;
int out_pipe[2]; /* pipes of process */
char *buffer; /* stdout buffer ## THE BEGINNING ## */
- int buffer_allocated; /* chars right now allocated for this buffer */
+ int buffer_allocated; /* chars right now allocated for this buffer */
int buffer_len; /* the count of chars from the beginning in buffer right now */
e_pst pst;
Modified: initng/trunk/src/initng_service_cache.c
==============================================================================
--- initng/trunk/src/initng_service_cache.c (original)
+++ initng/trunk/src/initng_service_cache.c Thu Apr 20 01:18:18 2006
@@ -46,16 +46,18 @@
*/
int initng_service_cache_add(service_cache_h * s)
{
- service_cache_h * found = NULL;
+ service_cache_h *found = NULL;
+
assert(s->name);
assert(s);
/* Check that we are unique */
- found=initng_service_cache_find_by_exact_name(s->name);
+ found = initng_service_cache_find_by_exact_name(s->name);
if (found)
{
- W_("Service %s alredy in db, please look there before parsing\n", s->name);
- return(TRUE);
+ W_("Service %s alredy in db, please look there before parsing\n",
+ s->name);
+ return (TRUE);
}
/* if not found, add this one on the list */
@@ -201,7 +203,7 @@
}
}
- return(NULL);
+ return (NULL);
}
/*
Modified: initng/trunk/src/initng_signal.c
==============================================================================
--- initng/trunk/src/initng_signal.c (original)
+++ initng/trunk/src/initng_signal.c Thu Apr 20 01:18:18 2006
@@ -94,9 +94,9 @@
WCOREDUMP(status), WIFSTOPPED(status), WSTOPSIG(status));
/*if(WTERMSIG(status))
- {
- printf("Service segfaulted!\n");
- }*/
+ {
+ printf("Service segfaulted!\n");
+ } */
/*
* call handle_killed_by_pid(), and will walk the active_db
Modified: initng/trunk/src/main.c
==============================================================================
--- initng/trunk/src/main.c (original)
+++ initng/trunk/src/main.c Thu Apr 20 01:18:18 2006
@@ -21,10 +21,10 @@
#include "initng.h"
#include <unistd.h>
-#include <time.h> /* time() */
-#include <fcntl.h> /* fcntl() */
-#include <linux/kd.h> /* KDSIGACCEPT */
-#include <stdlib.h> /* free() exit() */
+#include <time.h> /* time() */
+#include <fcntl.h> /* fcntl() */
+#include <linux/kd.h> /* KDSIGACCEPT */
+#include <stdlib.h> /* free() exit() */
#include <termios.h>
#include <stdio.h>
#include <dirent.h>
@@ -34,14 +34,14 @@
#include <sys/stat.h>
#include <sys/klog.h>
-#include <sys/reboot.h> /* reboot() RB_DISABLE_CAD */
-#include <sys/ioctl.h> /* ioctl() */
+#include <sys/reboot.h> /* reboot() RB_DISABLE_CAD */
+#include <sys/ioctl.h> /* ioctl() */
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/mman.h>
#include <sys/types.h>
-#include <sys/un.h> /* memmove() strcmp() */
-#include <sys/wait.h> /* waitpid() sa */
+#include <sys/un.h> /* memmove() strcmp() */
+#include <sys/wait.h> /* waitpid() sa */
#include <sys/mount.h>
#ifdef SELINUX
#include <selinux/selinux.h>
@@ -51,7 +51,7 @@
#include "initng_global.h"
#include "initng_signal.h"
#include "initng_handler.h"
-#include "initng_execute.h" /* new_environ() */
+#include "initng_execute.h" /* new_environ() */
#include "initng_active_db.h"
#include "initng_load_module.h"
#include "initng_plugin_callers.h"
@@ -415,20 +415,27 @@
#ifndef OLDSELINUX
int enforce = 0;
char *envstr;
- if (getenv("SELINUX_INIT") == NULL) {
- envstr=malloc(sizeof("SELINUX_INIT=YES"));
- strcpy(envstr,"SELINUX_INIT=YES");
- putenv(envstr);
- if (selinux_init_load_policy(&enforce) == 0 ) {
- execv(argv[0], argv);
- } else {
- if (enforce > 0) {
- /* SELinux in enforcing mode but load_policy failed */
- /* At this point, we probably can't open /dev/console, so log() won't work */
- fprintf(stderr,"Unable to load SELinux Policy. Machine is in enforcing mode. Halting now.");
- exit(1);
- }
- }
+
+ if (getenv("SELINUX_INIT") == NULL)
+ {
+ envstr = malloc(sizeof("SELINUX_INIT=YES"));
+ strcpy(envstr, "SELINUX_INIT=YES");
+ putenv(envstr);
+ if (selinux_init_load_policy(&enforce) == 0)
+ {
+ execv(argv[0], argv);
+ }
+ else
+ {
+ if (enforce > 0)
+ {
+ /* SELinux in enforcing mode but load_policy failed */
+ /* At this point, we probably can't open /dev/console, so log() won't work */
+ fprintf(stderr,
+ "Unable to load SELinux Policy. Machine is in enforcing mode. Halting now.");
+ exit(1);
+ }
+ }
}
#endif
#endif
@@ -451,7 +458,9 @@
if (getpid() == 1)
{
initng_global_new(argc, argv, env, I_AM_INIT);
- } else {
+ }
+ else
+ {
initng_global_new(argc, argv, env, I_AM_FAKE_INIT);
}
@@ -505,7 +514,7 @@
/* if the hot reload failed, we're probably in big trouble */
initng_main_su_login();
}
-
+
/* Hopefully no-one will try a hot reload when the system isn't up... */
initng_main_set_sys_state(STATE_UP);
}
Modified: initng/trunk/tools/itype.c
==============================================================================
--- initng/trunk/tools/itype.c (original)
+++ initng/trunk/tools/itype.c Thu Apr 20 01:18:18 2006
@@ -61,42 +61,45 @@
#define MAX_PATH_LEN 40
-static void parse_path(char *ipath)
+static service_cache_h *parse_path(char *ipath)
{
char *path = NULL;
+
/* if path is specified with CWD */
- if(ipath[0]=='.')
+ if (ipath[0] == '.')
+ {
+ path = malloc(sizeof(char) * (strlen(ipath) + MAX_PATH_LEN + 1));
+ path = getcwd(path, MAX_PATH_LEN);
+ path = strcat(path, &ipath[1]);
+ }
+ else
{
- path=malloc(sizeof(char) * (strlen(ipath) + MAX_PATH_LEN + 1));
- path=getcwd(path, MAX_PATH_LEN);
- path=strcat(path, &ipath[1]);
- } else {
- path=strdup(ipath);
+ path = strdup(ipath);
}
-
+
/* Start parsing file. */
- initng_common_parse_service(path);
+ return (initng_common_parse_service(path));
}
int main(int argc, char *argv[], char *env[])
{
- /*printf("argc: %i argv[0]: %s\n", argc, argv[0]);*/
+ /*printf("argc: %i argv[0]: %s argv[1]: %s argv[2]: %s\n", argc, argv[0], argv[1], argv[2]); */
/* initialise global variables */
initng_global_new(argc, argv, env, I_AM_UTILITY);
+ /* Load all plugins */
if (!initng_load_module_load_all())
{
printf("could not load all modules\n");
exit(1);
}
-
-
/* se what we want do be done */
- if(argc==3 && strcmp(argv[1], "--list_services")==0)
+ if (argc == 3 && strcmp(argv[1], "--list_services") == 0)
{
service_cache_h *service = NULL;
+
parse_path(argv[2]);
while_service_cache(service)
{
@@ -107,9 +110,37 @@
}
/* fallback */
- if(argv[1])
+ if (argc == 3)
+ {
+ service_cache_h *serv = NULL;
+
+ serv = parse_path(argv[1]);
+ if (serv)
+ {
+ if (strcmp(argv[2], "start") == 0)
+ {
+ printf("ngc -u %s\n", serv->name);
+ goto end;
+ }
+
+ if (strcmp(argv[2], "stop") == 0)
+ {
+ printf("ngc -d %s\n", serv->name);
+ goto end;
+ }
+
+ if (strcmp(argv[2], "status") == 0)
+ {
+ printf("ngc -s %s\n", serv->name);
+ goto end;
+ }
+ }
+ }
+
+ if (argc == 1 && argv[1])
{
service_cache_h *service = NULL;
+
printf("%s file content these services:\n", argv[1]);
parse_path(argv[1]);
while_service_cache(service)
@@ -122,7 +153,7 @@
{
printf("Usage: itype --list_services i_file.i\n");
}
-end:
+ end:
/* unload all modules */
initng_unload_module_unload_all();
initng_service_cache_free_all();
More information about the Initng-svn
mailing list