#include <sys/wait.h>
#include <Ecore.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
#include "tts_main.h"
#include "tts_setting.h"
static bool g_is_daemon_started = false;
-static int __check_tts_daemon();
+static int __check_setting_tts_daemon();
static tts_setting_state_e g_state = TTS_SETTING_STATE_NONE;
if (0 != tts_setting_dbus_request_hello()) {
if (false == g_is_daemon_started) {
g_is_daemon_started = true;
- __check_tts_daemon();
+ __check_setting_tts_daemon();
}
return EINA_TRUE;
}
/* Send hello */
if (0 != tts_setting_dbus_request_hello()) {
- __check_tts_daemon();
+ __check_setting_tts_daemon();
}
/* do request */
return ret;
}
+int __setting_get_cmd_line(char *file, char *buf)
+{
+ FILE *fp = NULL;
+ int i;
+
+ fp = fopen(file, "r");
+ if (fp == NULL) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get command line");
+ return -1;
+ }
+ memset(buf, 0, sizeof(buf));
+ fgets(buf, 256, fp);
+ fclose(fp);
+
+ return 0;
+}
/* Functions for tts-daemon fork */
-static bool __tts_is_alive()
+static bool __tts_setting_is_alive()
{
- FILE *fp = NULL;
- char buff[256];
- char cmd[256];
+ DIR *dir;
+ struct dirent *entry;
+ struct stat filestat;
+
+ int pid;
+ char cmdLine[256];
+ char tempPath[256];
- memset(buff, '\0', sizeof(char) * 256);
- memset(cmd, '\0', sizeof(char) * 256);
+ dir = opendir("/proc");
- fp = popen("ps", "r");
- if (NULL == fp) {
- SLOG(LOG_DEBUG, TAG_TTSC, "[TTS SETTING ERROR] popen error");
- return FALSE;
- }
+ while ((entry = readdir(dir)) != NULL) {
+ lstat(entry->d_name, &filestat);
- while (fgets(buff, 255, fp)) {
- strcpy(cmd, buff + 26);
+ if (!S_ISDIR(filestat.st_mode))
+ continue;
- if( 0 == strncmp(cmd, "[tts-daemon]", strlen("[tts-daemon]")) ||
- 0 == strncmp(cmd, "tts-daemon", strlen("tts-daemon")) ||
- 0 == strncmp(cmd, "/usr/bin/tts-daemon", strlen("/usr/bin/tts-daemon"))
- ) {
- SLOG(LOG_DEBUG, TAG_TTSC, "tts-daemon is ALIVE !!");
- fclose(fp);
- return TRUE;
+ pid = atoi(entry->d_name);
+ if (pid <= 0) continue;
+
+ sprintf(tempPath, "/proc/%d/cmdline", pid);
+ if (0 != __setting_get_cmd_line(tempPath, cmdLine)) {
+ break;
}
+ if (0 == strncmp(cmdLine, "[tts-daemon]", strlen("[tts-daemon]")) ||
+ 0 == strncmp(cmdLine, "tts-daemon", strlen("tts-daemon")) ||
+ 0 == strncmp(cmdLine, "/usr/bin/tts-daemon", strlen("/usr/bin/tts-daemon"))) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "tts-daemon is ALIVE !! \n");
+ return TRUE;
+ }
}
- fclose(fp);
-
SLOG(LOG_DEBUG, TAG_TTSC, "THERE IS NO tts-daemon !! \n");
+ closedir(dir);
return FALSE;
+
}
-static void __my_sig_child(int signo, siginfo_t *info, void *data)
+static void __setting_my_sig_child(int signo, siginfo_t *info, void *data)
{
int status;
pid_t child_pid, child_pgid;
return;
}
-static int __check_tts_daemon()
+static int __check_setting_tts_daemon()
{
- if( TRUE == __tts_is_alive() )
+ if( TRUE == __tts_setting_is_alive() )
return 0;
/* fork-exec tts-daemom */
struct sigaction act, dummy;
act.sa_handler = NULL;
- act.sa_sigaction = __my_sig_child;
+ act.sa_sigaction = __setting_my_sig_child;
sigemptyset(&act.sa_mask);
act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;