[Initng-svn] r2700 - initng/plugins/logfile
svn at initng.thinktux.net
svn at initng.thinktux.net
Wed Jan 4 12:13:04 CET 2006
Author: jimmy
Date: Wed Jan 4 12:13:03 2006
New Revision: 2700
Modified:
initng/plugins/logfile/initng_logfile.c
initng/plugins/logfile/initng_logfile.h
Log:
Fixed plugins/logfile, untested..
Modified: initng/plugins/logfile/initng_logfile.c
==============================================================================
--- initng/plugins/logfile/initng_logfile.c (original)
+++ initng/plugins/logfile/initng_logfile.c Wed Jan 4 12:13:03 2006
@@ -38,119 +38,55 @@
s_entry LOGFILE = { "logfile", STRING, NULL, "An extra output of service output." };
-#define MAX_P_ENTRY 200
-local_plugin_database_h **local_database;
-
-
-/* Returns pointer to old data if possible, and alloc's a new spot if needed.
- Note that this uses strdup on service->name, since service->name might be free'd without us knowing about it.
- */
-local_plugin_database_h *find_service(active_db_h * service)
-{
- /* Scans through our local database, returns a new one if we cant find an old one. */
- int i;
- int foundfree = 0;
-
- assert(service);
- assert(service->name);
-
- S_;
-
- D_("Scan for service %s\n", service->name);
- for (i = 0; i < MAX_P_ENTRY; i++)
- if (local_database[i])
- {
- if (strcmp(local_database[i]->servicename, service->name) == 0)
- return local_database[i];
- }
- else
- foundfree = i;
-
- /* No free service found */
- if (foundfree == 0)
- {
- F_("Service database full!\n");
- return (FALSE);
- }
- D_("Allocating new service\n");
- local_database[foundfree] = (local_plugin_database_h *) i_calloc(1,
- sizeof
- (local_plugin_database_h));
- local_database[foundfree]->servicename = i_strdup(service->name);
- local_database[foundfree]->fd = 0;
- local_database[foundfree]->append = FALSE;
- return local_database[foundfree];
-}
static int program_output(active_db_h * service, process_h * x)
{
- char *filename = NULL;
-
+ const char *filename = NULL;
+ char *filename_fixed = NULL;
+ int len=0;
+ int fd=-1;
+
assert(service);
assert(service->name);
assert(x);
- D_("service: \"%s\" have something to say.\n", service->name);
+ D_("%s process fd: # %i, %i, service %s, have something to say\n", x->pt->name, x->out_pipe[0], x->out_pipe[1], service->name);
-#ifdef DEBUG
- if (service->start_process == x)
- D_("start process fd: #%i\n", x->out_pipe[0]);
- else if (service->stop_process == x)
- D_("stop process fd: #%i\n", x->out_pipe[0]);
-
-#endif
- /* Check if this service has keyword LOGFILE */
- if (!initng_active_db_is(&LOGFILE, service))
+ /* get the filename */
+ filename = initng_active_db_get_string(&LOGFILE, service);
+ if(!filename)
{
- D_("LOGFILE not set.\n");
- return;
+ D_("Logfile not set\n");
+ return(FALSE);
}
- /* Get a new spot for entry of the data */
- local_plugin_database_h *entry = find_service(service);
-
- if (entry == NULL)
- return;
-
- if (datalen < 3)
- return;
-
- /* logfile file descriptor is 0, open it */
- if (entry->fd == 0)
+ /* Fix $variables in filename string */
+ filename_fixed = fix_variables(filename, service);
+
+ /* open the file */
+ fd = open(filename, O_WRONLY | O_CREAT | O_APPEND);
+ if (fd < 1)
{
- filename = fix_variables(initng_active_db_get_string
- (&LOGFILE, service), service);
- /* If entry->append then open with O_APPEND, else truncate */
- if (!entry->append)
- entry->fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC);
- else
- entry->fd = open(filename, O_WRONLY | O_CREAT | O_APPEND);
- if (entry->fd < 1)
- {
- entry->fd = 0;
- F_("Error opening %s, err : %s\n", filename, strerror(errno));
- }
+ F_("Error opening %s, err : %s\n", filename, strerror(errno));
+ return(FALSE);
}
+
/* Write data to logfile */
D_("Writing data...\n");
- if (write(entry->fd, &x->buffer[x->buffer_pos], datalen) != datalen)
+ len=strlen(&x->buffer[x->buffer_pos]);
+
+ if (write(fd, &x->buffer[x->buffer_pos], len)!=len)
F_("Error writing to %s's log, err : %s\n", service->name,
strerror(errno));
- free(filename);
- if (forceflush) /* If forceflush, this is probably the last this service is writing to logfile, close file (or buffer full) */
- {
- if (entry->fd > 0)
- close(entry->fd);
- /* Set append flag, in case buffer is full / in case we wanna log service->stop_process aswell, we don't want to truncate the log */
- entry->append = TRUE;
- entry->fd = 0;
- }
+ free(filename_fixed);
+ close(fd);
+
+ return(TRUE);
}
int module_init(const char *version)
{
- int i;
S_;
@@ -163,21 +99,12 @@
initng_service_data_types_add(&LOGFILE);
- /* This is quite bad and should be changed... */
- local_database = i_calloc(MAX_P_ENTRY + 1,
- sizeof(local_plugin_database_h));
- for (i = 0; i < MAX_P_ENTRY; i++)
- local_database[i] = NULL;
-
-
initng_plugin_hook_add(PIPEWATCHERS, 30, &program_output);
return (TRUE);
}
void module_unload(void)
{
- int i;
-
S_;
D_("module_unload();\n");
@@ -185,23 +112,4 @@
initng_service_data_types_del(&LOGFILE);
initng_plugin_hook_del(PIPEWATCHERS, &program_output);
-
- if (!local_database)
- return;
-
-
- for (i = 0; i < MAX_P_ENTRY; i++)
- if (local_database[i])
- {
- /* Remember to free servicename, as it's strdup'ed of service->name, not a pointer */
- if (local_database[i]->servicename)
- free(local_database[i]->servicename);
- if (local_database[i]->fd > 0)
- close(local_database[i]->fd);
- free(local_database[i]);
- }
-
- free(local_database);
- local_database = NULL;
-
}
Modified: initng/plugins/logfile/initng_logfile.h
==============================================================================
--- initng/plugins/logfile/initng_logfile.h (original)
+++ initng/plugins/logfile/initng_logfile.h Wed Jan 4 12:13:03 2006
@@ -19,19 +19,5 @@
extern s_entry STDOUT;
-
-typedef struct local_plugin_database local_plugin_database_h;
-struct local_plugin_database
-{
- char *servicename;
- /* active_h *service; */
- int fd;
- int append;
-};
-
int module_init(const char *version);
void module_unload(void);
-
-void program_output(active_db_h * service, int datalen, process_h * x,
- int forceflush);
-local_plugin_database_h *find_service(active_db_h * service);
More information about the Initng-svn
mailing list