/*
-* Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
#include <sys/wait.h>
#include <Ecore.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
#include "tts_main.h"
#include "tts_client.h"
ret = tts_dbus_request_finalize(client->uid);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request finalize");
- }
+ }
+ g_is_daemon_started = false;
case TTS_STATE_CREATED:
/* Free resources */
tts_client_destroy(tts);
if (0 != ret) {
SLOG(LOG_WARN, TAG_TTSC, "[ERROR] Fail to request finalize");
}
+ g_is_daemon_started = false;
client->before_state = client->current_state;
client->current_state = TTS_STATE_CREATED;
int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, void* user_data)
{
if (NULL == tts || NULL == callback) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt started cb : Input parameter is null");
return TTS_ERROR_INVALID_PARAMETER;
}
tts_client_s* client = tts_client_get(tts);
if (NULL == client) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt started cb : A handle is not valid");
return TTS_ERROR_INVALID_PARAMETER;
}
return 0;
}
-static bool _tts_is_alive()
+int __get_cmd_line(char *file, char *buf)
{
FILE *fp = NULL;
- char buff[256];
- char cmd[256];
+ int i;
- memset(buff, '\0', sizeof(char) * 256);
- memset(cmd, '\0', sizeof(char) * 256);
-
- if ((fp = popen("ps -eo \"cmd\"", "r")) == NULL) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] popen error");
- return FALSE;
+ fp = fopen(file, "r");
+ if (fp == NULL) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get command line");
+ return -1;
}
- while(fgets(buff, 255, fp)) {
- sscanf(buff, "%s", cmd);
+ memset(buf, 0, 256);
+ fgets(buf, 256, fp);
+ fclose(fp);
- 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;
- }
- }
+ return 0;
+}
- fclose(fp);
+static bool _tts_is_alive()
+{
+ DIR *dir;
+ struct dirent *entry;
+ struct stat filestat;
+
+ int pid;
+ char cmdLine[256];
+ char tempPath[256];
- SLOG(LOG_DEBUG, TAG_TTSC, "THERE IS NO tts-daemon !!");
+ dir = opendir("/proc");
+ if (NULL == dir) {
+ SLOG(LOG_ERROR, TAG_TTSC, "process checking is FAILED");
+ return FALSE;
+ }
- return FALSE;
-}
+ while ((entry = readdir(dir)) != NULL) {
+ if (0 != lstat(entry->d_name, &filestat))
+ continue;
+ if (!S_ISDIR(filestat.st_mode))
+ continue;
-static void __my_sig_child(int signo, siginfo_t *info, void *data)
-{
- int status;
- pid_t child_pid, child_pgid;
+ pid = atoi(entry->d_name);
+ if (pid <= 0) continue;
- child_pgid = getpgid(info->si_pid);
- SLOG(LOG_DEBUG, TAG_TTSC, "Signal handler: dead pid = %d, pgid = %d", info->si_pid, child_pgid);
+ sprintf(tempPath, "/proc/%d/cmdline", pid);
+ if (0 != __get_cmd_line(tempPath, cmdLine)) {
+ continue;
+ }
- while (0 < (child_pid = waitpid(-1, &status, WNOHANG))) {
- if(child_pid == child_pgid)
- killpg(child_pgid, SIGKILL);
+ 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 !!");
+ closedir(dir);
+ return TRUE;
+ }
}
- return;
+ SLOG(LOG_DEBUG, TAG_TTSC, "THERE IS NO tts-daemon !!");
+
+ closedir(dir);
+ return FALSE;
}
static int __tts_check_tts_daemon()
{
- if (TRUE == _tts_is_alive())
+ if (TRUE == _tts_is_alive()) {
return 0;
+ }
/* fork-exec tts-daemom */
int pid, i;
- struct sigaction act, dummy;
-
- act.sa_handler = NULL;
- act.sa_sigaction = __my_sig_child;
- sigemptyset(&act.sa_mask);
- act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
-
- if (sigaction(SIGCHLD, &act, &dummy) < 0) {
- SLOG(LOG_ERROR, TAG_TTSC, "Cannot make a signal handler");
- return -1;
- }
pid = fork();