Hi Anders Widell,

ACK ,  Tested TCP /TIPC

-AVM


On 12/6/2016 8:05 PM, Anders Widell wrote:
>   osaf/services/infrastructure/dtms/transport/main.cc |  33 
> +++++++++++++++++---
>   1 files changed, 27 insertions(+), 6 deletions(-)
>
>
> There were error handling paths where the LogServer object went out of scope 
> and
> was destroyed while the log server thread was still running and using the
> LogServer object. This has been fixed by terminating the log server thread
> before destroying the object it operates on.
>
> diff --git a/osaf/services/infrastructure/dtms/transport/main.cc 
> b/osaf/services/infrastructure/dtms/transport/main.cc
> --- a/osaf/services/infrastructure/dtms/transport/main.cc
> +++ b/osaf/services/infrastructure/dtms/transport/main.cc
> @@ -17,6 +17,7 @@
>   
>   #include <pthread.h>
>   #include <sched.h>
> +#include <signal.h>
>   #include <syslog.h>
>   #include <cerrno>
>   #include <cstdlib>
> @@ -47,6 +48,15 @@ static void* LogServerStartFunction(void
>     return nullptr;
>   }
>   
> +static void StopLogServerThread() {
> +  if (raise(SIGTERM) != 0) syslog(LOG_ERR, "raise(SIGTERM) failed: %d", 
> errno);
> +}
> +
> +static void JoinLogServerThread(pthread_t thread_id) {
> +  int result = pthread_join(thread_id, nullptr);
> +  if (result != 0) syslog(LOG_ERR, "pthread_join() failed: %d", result);
> +}
> +
>   Result MainFunction(int term_fd) {
>     pthread_attr_t attr;
>     int result = pthread_attr_init(&attr);
> @@ -86,17 +96,28 @@ Result MainFunction(int term_fd) {
>       return Result{kExit, "pthread_create() failed", result};
>     }
>     result = pthread_attr_destroy(&attr);
> -  if (result != 0) return Result{kExit, "pthread_attr_destroy() failed", 
> result};
> +  if (result != 0) {
> +    StopLogServerThread();
> +    JoinLogServerThread(thread_id);
> +    return Result{kExit, "pthread_attr_destroy() failed", result};
> +  }
>     TransportMonitor monitor{term_fd};
>     if (!monitor.use_tipc()) {
>       pid_t pid = monitor.WaitForDaemon("osafdtmd", 
> kDaemonStartWaitTimeInSeconds);
> -    if (pid == pid_t{-1}) return Result{kReboot, "osafdtmd failed to start", 
> 0};
> +    if (pid == pid_t{-1}) {
> +      StopLogServerThread();
> +      JoinLogServerThread(thread_id);
> +      return Result{kReboot, "osafdtmd failed to start", 0};
> +    }
>       monitor.SuperviseDaemon(pid);
> -    if (!monitor.Sleep(0)) return Result{kReboot,
> -                                 "osafdtmd Process down, Rebooting the 
> node", 0};
> +    if (!monitor.Sleep(0)) {
> +      StopLogServerThread();
> +      JoinLogServerThread(thread_id);
> +      return Result{kReboot,
> +            "osafdtmd Process down, Rebooting the node", 0};
> +    }
>     }
> -  result = pthread_join(thread_id, nullptr);
> -  if (result != 0) syslog(LOG_ERR, "pthread_join() failed: %d", result);
> +  JoinLogServerThread(thread_id);
>     return Result{kDaemonExit, "SIGTERM received, exiting", 0};
>   }
>   


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to