#include <time.h>
#include <dlfcn.h>
#include <getopt.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/sysinfo.h>
#include <glib.h>
#include <glib-object.h>
+#include <dlog.h>
#include <tcore.h>
#include <plugin.h>
#include <server.h>
+#include <util.h>
+#include <log.h>
#include "monitor.h"
+#ifndef DAEMON_VERSION
+#define DAEMON_VERSION "unknown"
+#endif
+
static Server *_server;
+void tcore_log(enum tcore_log_type type, enum tcore_log_priority priority, const char *tag, const char *fmt, ...)
+{
+ va_list ap;
+ char buf[1024];
+
+ va_start(ap, fmt);
+ vsnprintf(buf, 1023, fmt, ap);
+ va_end(ap);
+
+ __dlog_print(type, priority, tag, buf);
+}
+
static gboolean load_plugins(Server *s, const char *path, int flag_test_load)
{
const gchar *file;
GDir *dir;
void *handle;
GSList *list;
+ struct stat stat_buf;
+ char file_date[27];
TcorePlugin *p;
struct tcore_plugin_define_desc *desc;
+ if (!path || !s)
+ return FALSE;
+
dir = g_dir_open(path, 0, NULL);
if (!dir)
return FALSE;
while ((file = g_dir_read_name(dir)) != NULL) {
- if (g_str_has_prefix(file, "lib") == TRUE || g_str_has_suffix(file, ".so") == FALSE)
+ if (g_str_has_prefix(file, "lib") == TRUE
+ || g_str_has_suffix(file, ".so") == FALSE)
continue;
filename = g_build_filename(path, file, NULL);
continue;
}
+ dbg("%s plugin", desc->name);
+ dbg(" - path = %s", filename);
+ dbg(" - version = %d", desc->version);
+ dbg(" - priority = %d", desc->priority);
+
+ memset(&stat_buf, 0, sizeof(struct stat));
+ if (stat(filename, &stat_buf) == 0) {
+ if (ctime_r(&stat_buf.st_mtime, file_date) != NULL) {
+ if (strlen(file_date) > 1)
+ file_date[strlen(file_date)-1] = '\0';
+
+ dbg(" - date = %s", file_date);
+ }
+ }
+
if (desc->load) {
if (desc->load() == FALSE) {
dbg("false return from load(). skip this plugin");
p = tcore_plugin_new(s, desc, filename, handle);
tcore_server_add_plugin(s, p);
- dbg("plugin(%s) added", filename);
+ dbg("%s added", desc->name);
g_free(filename);
}
g_dir_close(dir);
+ info("plugin load finished");
+
list = tcore_server_ref_plugins(s);
for (; list; list = list->next) {
p = list->data;
}
}
+ info("plugin init finished");
+
return TRUE;
}
{
struct sigaction sigact_usr1;
Server *s;
- int flag_test_load=0;
+ int flag_test_load = 0;
int opt;
int opt_index;
struct option options[] = {
{ 0, 0, 0, 0 }
};
char *plugin_path = "/usr/lib/telephony/plugins/";
+ char *tcore_ver;
+ struct sysinfo info;
+
+ if (sysinfo(&info) == 0) {
+ info("uptime: %ld secs", info.uptime);
+ }
+
+ info("daemon version: %s", DAEMON_VERSION);
+
+ tcore_ver = tcore_util_get_version();
+ info("libtcore version: %s", tcore_ver);
+ free(tcore_ver);
sigact_usr1.sa_handler = on_signal_usr1;
sigemptyset(&sigact_usr1.sa_mask);
warn("sigaction(SIGUSR1) failed.");
}
-
while (1) {
opt = getopt_long(argc, argv, "hT", options, &opt_index);
}
}
- if (optind < argc) {
+ if (optind < argc)
plugin_path = argv[optind];
- }
- dbg("plugin_path: [%s]", plugin_path);
- dbg("flag[test_load]: %d", flag_test_load);
+ info("plugin_path: [%s]", plugin_path);
g_type_init();
#if !GLIB_CHECK_VERSION (2, 31, 0)
}
_server = s;
- if (!load_plugins(s, plugin_path, flag_test_load)) {
+ if (!load_plugins(s, plugin_path, flag_test_load))
goto free_end;
- }
if (flag_test_load)
goto free_end;
+ info("server mainloop start");
+
if (tcore_server_run(s) == FALSE) {
err("server_run failed.");
- goto free_end;
}
/*
*/
free_end:
- dbg("exit!");
+ info("server end");
tcore_server_free(s);
end: