~ubuntu-branches/ubuntu/wily/trafficserver/wily

« back to all changes in this revision

Viewing changes to lib/ts/lockfile.cc

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-04-29 11:47:57 UTC
  • mfrom: (5.2.1 sid)
  • Revision ID: package-import@ubuntu.com-20130429114757-bbeb5eacidfuj2qg
Tags: 3.2.4-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Revert FreeBSD strerror_r() fixes that give errors with glibc 2.16.
* Drop markos's ARM barrier definition patch, now integrated upstream.
* Brute-force upstream's suboptimal C/C++ with: -Wno-unused-result
  -Wno-sizeof-pointer-memaccess -Wno-unused-local-typedefs flags.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "ink_platform.h"
25
25
#include "ink_lockfile.h"
26
26
 
27
 
#if defined(linux)
28
 
#include "ink_killall.h"
29
 
#endif
30
 
 
31
27
#define LOCKFILE_BUF_LEN 16     // 16 bytes should be enought for a pid
32
28
 
33
29
int
195
191
// killed): Unfortunately, it's possible on Linux that the main PID of
196
192
// the process has been successfully killed (and is waiting to be
197
193
// reaped while in a defunct state), while some of the other threads
198
 
// of the process just don't want to go away.  Integrate ink_killall
199
 
// into Kill() and KillAll() just to make sure we really kill
200
 
// everything and so that we don't spin hard while trying to kill a
201
 
// defunct process.
 
194
// of the process just don't want to go away.
202
195
//-------------------------------------------------------------------------
203
196
 
204
197
static void
205
198
lockfile_kill_internal(pid_t init_pid, int init_sig, pid_t pid, const char *pname, int sig)
206
199
{
207
200
  int err;
208
 
 
209
 
#if defined(linux)
210
 
 
211
 
  pid_t *pidv;
212
 
  int pidvcnt;
213
 
 
214
 
  // Need to grab pname's pid vector before we issue any kill signals.
215
 
  // Specifically, this prevents the race-condition in which
216
 
  // traffic_manager spawns a new traffic_server while we still think
217
 
  // we're killall'ing the old traffic_server.
218
 
  if (pname) {
219
 
    ink_killall_get_pidv_xmalloc(pname, &pidv, &pidvcnt);
220
 
  }
221
 
 
222
 
  if (init_sig > 0) {
223
 
    kill(init_pid, init_sig);
224
 
    // sleep for a bit and give time for the first signal to be
225
 
    // delivered
226
 
    sleep(1);
227
 
  }
228
 
 
229
 
  do {
230
 
    if ((err = kill(pid, sig)) == 0) {
231
 
      sleep(1);
232
 
    }
233
 
    if (pname && (pidvcnt > 0)) {
234
 
      ink_killall_kill_pidv(pidv, pidvcnt, sig);
235
 
      sleep(1);
236
 
    }
237
 
  } while ((err == 0) || ((err < 0) && (errno == EINTR)));
238
 
 
239
 
  ats_free(pidv);
240
 
 
241
 
#else
242
 
 
243
 
  if (init_sig > 0) {
244
 
    kill(init_pid, init_sig);
245
 
    // sleep for a bit and give time for the first signal to be
246
 
    // delivered
247
 
    sleep(1);
 
201
  int status;
 
202
 
 
203
  if (init_sig > 0) {
 
204
    kill(init_pid, init_sig);
 
205
    // Wait for children to exit
 
206
    do {
 
207
      err = waitpid(-1, &status, WNOHANG);
 
208
      if (err == -1) break;
 
209
    } while(!WIFEXITED(status) && !WIFSIGNALED(status));
248
210
  }
249
211
 
250
212
  do {
251
213
    err = kill(pid, sig);
252
214
  } while ((err == 0) || ((err < 0) && (errno == EINTR)));
253
215
 
254
 
#endif  // linux check
255
 
 
256
216
}
257
217
 
258
218
void
294
254
 
295
255
    if ((pid < 0) || (pid == getpid()))
296
256
      pid = holding_pid;
297
 
    else
 
257
 
 
258
    if (pid != 0) {
 
259
      // This way, we kill the process_group:
298
260
      pid = -pid;
299
 
 
300
 
    if (pid != 0) {
301
 
      // We kill the holding_pid instead of the process_group
302
 
      // initially since there is no point trying to get core files
303
 
      // from a group since the core file of one overwrites the core
304
 
      // file of another one
 
261
      // In order to get core files from each process, please
 
262
      // set your core_pattern appropriately.
305
263
      lockfile_kill_internal(holding_pid, initial_sig, pid, pname, sig);
306
264
    }
307
265
  }