~y-maris/libmemcached/libmemcached

« back to all changes in this revision

Viewing changes to libtest/killpid.cc

  • Committer: Continuous Integration
  • Date: 2012-11-26 10:58:31 UTC
  • mfrom: (1080.1.6 libmemcached-1.2)
  • Revision ID: ci@tangent.org-20121126105831-4bnsokmlh631slsx
Merge lp:~tangent-org/libmemcached/1.2-build Build: jenkins-Libmemcached-1.2-4

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 *
35
35
 */
36
36
 
37
 
#include <config.h>
 
37
#include "mem_config.h"
38
38
#include <libtest/common.h>
39
39
 
40
40
#include <cstdlib>
80
80
    }
81
81
  }
82
82
 
83
 
  int status= 0;
84
 
  if (waitpid(pid_arg, &status, 0) == -1)
85
83
  {
86
 
    switch (errno)
 
84
    uint32_t this_wait= 0;
 
85
    uint32_t timeout= 20; // This number should be high enough for valgrind startup (which is slow)
 
86
    uint32_t waited;
 
87
    uint32_t retry;
 
88
 
 
89
    for (waited= 0, retry= 4; ; retry++, waited+= this_wait)
87
90
    {
88
 
      // Just means that the server has already gone away
89
 
    case ECHILD:
90
 
      {
91
 
        return true;
92
 
      }
 
91
      int status= 0;
 
92
      if (waitpid(pid_arg, &status, WNOHANG) == 0)
 
93
      {
 
94
        break;
 
95
      }
 
96
      else if (errno == ECHILD)
 
97
      {
 
98
        // Server has already gone away
 
99
        break;
 
100
      }
 
101
      else if (waited >= timeout)
 
102
      {
 
103
        // Timeout failed
 
104
        kill(pid_arg, SIGKILL);
 
105
        break;
 
106
      }
 
107
 
 
108
      this_wait= retry * retry / 3 + 1;
 
109
      libtest::dream(this_wait, 0);
93
110
    }
94
 
 
95
 
    Error << "Error occured while waitpid(" << strerror(errno) << ") on pid " << int(pid_arg);
96
 
 
97
 
    return false;
98
111
  }
99
112
 
100
113
  return true;