#include <ul_log.h>
#include <ul_logreg.h>
#include <unistd.h>
+#include "discovery.h"
#ifdef CONFIG_FORB_PROTO_UNIX
#include <forb/proto_unix.h>
#endif
#include <fcb.h>
#include <fcb_contact_info.h>
#endif
+#include <fcntl.h>
#ifdef DEBUG
#define UL_LOGL_DEF UL_LOGL_DEB
#include "log_domains.inc"
extern UL_LOG_CUST(ulogd_forb);
+static int init_ul_log(void);
UL_LOGREG_DOMAINS_INIT_FUNCTION(forb_logreg_domains, forb_logreg_domains_array);
+#if 0
static void
destroy_forb_on_exit(int exitcode, void *arg)
{
forb_orb orb = arg;
forb_destroy(orb);
}
+#endif
static void
forb_is_alive(forb_orb _obj, CORBA_Environment *ev)
memset(forb, 0, sizeof(*forb));
/* Initialize ULUT logging facility */
+ init_ul_log();
forb_logreg_domains();
if (attr) {
if (fosa_mutex_init(&forb->request_mutex, 0) != 0) goto err2;
forb_request_nolock_init_root_field(forb);
-
- if (fosa_mutex_init(&forb->peer_mutex, 0) != 0) goto err2;
- forb_peer_nolock_init_root_field(forb);
- if (fosa_mutex_init(&forb->objkey_mutex, 0) != 0) goto err2;
- forb_objects_nolock_init_root_field(forb);
+ if (forb_discovery_init(forb) != 0) goto err2;
if (fosa_mutex_init(&forb->regref_mutex, 0) != 0) goto err2;
forb_regref_nolock_init_root_field(forb);
forb_execution_thread, orb);
if (ret != 0)
goto err2;
-
- on_exit(destroy_forb_on_exit, orb);
+
+ /* FIXME: I do not know how to deregister the exit handler if
+ * forb_destroy() is called manually. */
+ /* on_exit(destroy_forb_on_exit, orb); */
#ifdef CONFIG_FORB_PROTO_UNIX
{
*maximum_ptr = *buf_pptr ? num_elements : 0;
return (*buf_pptr != NULL) || (num_elements == 0);
}
+
+static FILE *forb_ul_log_file;
+static char progname[64] = "";
+
+void
+forb_ul_log_fnc(ul_log_domain_t *domain, int level,
+ const char *format, va_list ap)
+{
+ if(!(level&UL_LOGL_CONT)) {
+ level&=UL_LOGL_MASK;
+ if (progname[0])
+ fprintf(forb_ul_log_file,"%s: ", progname);
+ if(domain && domain->name)
+ fprintf(forb_ul_log_file,"%s: ",domain->name);
+ }
+ vfprintf(forb_ul_log_file, format, ap);
+ fflush(forb_ul_log_file);
+}
+
+static int init_ul_log(void)
+{
+ char *s;
+ char *log_fname;
+ int fd;
+ int flg = 0;
+ char path[128];
+
+/* if(ul_log_output != NULL) */
+/* return 0; */
+
+ fd = open("/proc/self/cmdline", O_RDONLY);
+ if (fd >= 0) {
+ int ret;
+ ret = read(fd, path, sizeof(path)-1);
+ if (ret > 0) {
+ path[ret]=0;
+ s = strrchr(path, '/');
+ if (s) s++;
+ else s = path;
+ strncpy(progname, s, sizeof(progname)-1);
+ }
+ close(fd);
+ }
+
+ if((log_fname=getenv("UL_LOG_FILENAME"))!=NULL){
+ forb_ul_log_file=fopen(log_fname,"a");
+ }
+ if(forb_ul_log_file==NULL)
+ forb_ul_log_file=stderr;
+
+ if((s=getenv("UL_DEBUG_FLG")) != NULL){
+ flg=atoi(s);
+ }
+
+ ul_log_redir(forb_ul_log_fnc, flg);
+
+ return 0;
+}