diff options
author | Bang Kwang min <justine.bang@samsung.com> | 2012-09-04 17:02:55 +0900 |
---|---|---|
committer | Bang Kwang min <justine.bang@samsung.com> | 2012-09-05 14:43:36 +0900 |
commit | d840a7f98949b64578122a657f97a78c7f1be92b (patch) | |
tree | 32c85c4456d2c60cc8aa8ee7368f799128d821ae | |
parent | a0687e821c375a4efe4db67b655bc8b26b09e1c8 (diff) | |
download | download-provider-d840a7f98949b64578122a657f97a78c7f1be92b.tar.gz download-provider-d840a7f98949b64578122a657f97a78c7f1be92b.tar.bz2 download-provider-d840a7f98949b64578122a657f97a78c7f1be92b.zip |
change thread style
[Title] change thread style as detached
[Issue#] S1-8296
[Problem] tkill SIGABRT when turn off phone
[Cause] pthread_cancel bug
[Solution] detach the thread to free by itself.
[SCMRequest] N/A
Change-Id: I139b5a770fde2ffa01f5622a1755604635a709fa
-rw-r--r-- | src/download-provider-main.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/download-provider-main.c b/src/download-provider-main.c index 46a0334..4751fba 100644 --- a/src/download-provider-main.c +++ b/src/download-provider-main.c @@ -9,7 +9,6 @@ #include "download-provider-log.h" GMainLoop *gMainLoop = 0; // need for libsoup, decided the life-time by mainloop. -pthread_t gRequestThreadPid; int lock_download_provider_pid(char *path); void *run_manage_download_server(void *args); @@ -23,21 +22,26 @@ void TerminateDaemon(int signo) static gboolean CreateThreadFunc(void *data) { + pthread_t thread_pid; pthread_attr_t thread_attr; if (pthread_attr_init(&thread_attr) != 0) { TRACE_DEBUG_MSG("failed to init pthread attr"); - if (g_main_loop_is_running(gMainLoop)) - g_main_loop_quit(gMainLoop); + TerminateDaemon(SIGTERM); return FALSE; } + if (pthread_attr_setdetachstate(&thread_attr, + PTHREAD_CREATE_DETACHED) != 0) { + TRACE_DEBUG_MSG("failed to set detach option"); + TerminateDaemon(SIGTERM); + return 0; + } // create thread for receiving the client request. if (pthread_create - (&gRequestThreadPid, &thread_attr, run_manage_download_server, + (&thread_pid, &thread_attr, run_manage_download_server, data) != 0) { TRACE_DEBUG_MSG ("failed to create pthread for run_manage_download_server"); - if (g_main_loop_is_running(gMainLoop)) - g_main_loop_quit(gMainLoop); + TerminateDaemon(SIGTERM); } return FALSE; } @@ -83,9 +87,6 @@ int main() TRACE_DEBUG_INFO_MSG("Download-Provider will be terminated."); - pthread_cancel(gRequestThreadPid); - pthread_join(gRequestThreadPid, NULL); - // if exit socket file, delete it if (access(DOWNLOAD_PROVIDER_IPC, F_OK) == 0) { unlink(DOWNLOAD_PROVIDER_IPC); |