static void _ms_lock_state(void);
static void _ms_unlock_state(void);
static gboolean _ms_connection_handler(GIOChannel *source, GIOCondition condition, gpointer data);
-#ifdef MUSE_USE_LWIPC
-static void _ms_wait_event(void);
static void _ms_diag_init(void);
static void _ms_diag_deinit(void);
static gboolean _ms_idle_cb(gpointer data);
static int _ms_open_lockfile(void);
+static void _ms_process_init(void);
+static void _ms_launch_foreground(void);
+static void _ms_daemonize(void);
+
+#ifdef MUSE_USE_LWIPC
+static void _ms_wait_event(void);
static void _ms_wait_event(void)
{
static int _ms_new(muse_channel_e channel)
{
int fd, errsv;
+ mode_t m = 0;
struct sockaddr_un addr_un;
socklen_t address_len;
char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
strncpy(addr_un.sun_path, UDS_files[channel], sizeof(addr_un.sun_path) - 1);
address_len = (socklen_t)sizeof(addr_un);
+ if (!muse_server->daemonize)
+ m = umask(0);
+
/* Bind to filename */
if (bind(fd, (struct sockaddr *)&addr_un, address_len) < 0) {
errsv = errno;
if (muse_core_set_nonblocking(fd, false) < 0) /* blocking */
LOGE("failed to set server socket to blocking");
+ if (!muse_server->daemonize)
+ umask(m);
+
return fd;
}
return MM_ERROR_NONE;
}
+static void _ms_process_init(void)
+{
+ if (g_mkdir_with_parents(tzplatform_mkpath(TZ_SYS_RUN, "mused"), S_IRWXU | S_IRWXG | S_IRWXO) != 0)
+ exit(EXIT_FAILURE);
+
+ if (muse_server->daemonize) {
+ if (ms_pidfile_create(MUSE_DEFAULT_PIDFILE, muse_server->pid) != MM_ERROR_NONE)
+ exit(EXIT_FAILURE);
+ else
+ LOGW("MUSE_DEFAULT_PIDFILE(%s) file was created", MUSE_DEFAULT_PIDFILE);
+ }
+
+ _ms_init();
+
+ muse_return_if_fail(_ms_open_lockfile() == MM_ERROR_NONE);
+
+ ms_new();
+}
+
+static void _ms_launch_foreground(void)
+{
+ muse_server->pid = (int)getpid();
+
+ _ms_process_init();
+}
+
+static void _ms_daemonize(void)
+{
+ int notify_fd;
+
+ muse_server->pid = ms_daemonize(¬ify_fd);
+
+ _ms_process_init();
+
+ ms_daemonize_complete(notify_fd);
+}
+
void ms_setup_syslog(void)
{
int flags = LOG_CONS|LOG_NDELAY|LOG_PID;
muse_return_if_fail(muse_core_fd_is_valid(notify_fd));
-#ifdef MUSE_REGISTER_VIP
- proc_stat_set_vip_process();
-#endif
-
write(notify_fd, MSG_DONE, strlen(MSG_DONE) + 1);
LOGW("[%d] Notify parent process that child initialization is done", notify_fd);
close(notify_fd);
void ms_init(char **argv)
{
int idx;
- int notify_fd;
+
muse_module_cmd_dispatchfunc *cmd_dispatcher = NULL;
LOGW("Enter");
muse_server = g_new0(muse_server_t, 1);
- ms_setup_syslog();
-
- muse_server->pid = ms_daemonize(¬ify_fd);
+ for (idx = 1; argv[idx] != NULL; idx++) {
+ if (strcmp(argv[idx], "-D") == 0) {
+ LOGI("enable daemonize");
+ muse_server->daemonize = TRUE;
+ }
+ }
- if (g_mkdir_with_parents(tzplatform_mkpath(TZ_SYS_RUN, "mused"), S_IRWXU | S_IRWXG | S_IRWXO) != 0)
- exit(EXIT_FAILURE);
+ ms_setup_syslog();
- if (ms_pidfile_create(MUSE_DEFAULT_PIDFILE, muse_server->pid) != MM_ERROR_NONE)
- exit(EXIT_FAILURE);
+ if (muse_server->daemonize)
+ _ms_daemonize();
else
- LOGW("MUSE_DEFAULT_PIDFILE(%s) file was created", MUSE_DEFAULT_PIDFILE);
-
- _ms_init();
+ _ms_launch_foreground();
- muse_return_if_fail(_ms_open_lockfile() == MM_ERROR_NONE);
-
- ms_new();
-
- ms_daemonize_complete(notify_fd);
+#ifdef MUSE_REGISTER_VIP
+ proc_stat_set_vip_process();
+#endif
#ifdef MUSE_TTRACE_LOG
trace_end();