~ubuntu-branches/ubuntu/gutsy/ecasound2.2/gutsy

« back to all changes in this revision

Viewing changes to libecasound/audioio-forked-stream.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Junichi Uekawa
  • Date: 2007-04-22 01:25:44 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070422012544-lugfjb034udblalb
Tags: 2.4.5-1
* new upstream release
* build-depend on texlive
* pbuilder-test: error code changed from '-1' to '1', so update test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// ------------------------------------------------------------------------
2
2
// audioio-forked-streams.cpp: Helper class providing routines for
3
3
//                             forking for piped input/output.
4
 
// Copyright (C) 2000-2004 Kai Vehmanen
 
4
// Copyright (C) 2000-2004,2006 Kai Vehmanen
5
5
//
6
6
// Attributes:
7
7
//     eca-style-version: 3
39
39
#include <signal.h>
40
40
#include <unistd.h>
41
41
 
 
42
#include <kvu_dbc.h>
42
43
#include <kvu_numtostr.h>
43
44
#include <kvu_utils.h>
44
45
 
319
320
 * function must be called from the same thread as 
320
321
 * fork_child_for_read/write() was called.
321
322
 */
322
 
void AUDIO_IO_FORKED_STREAM::clean_child(void)
 
323
void AUDIO_IO_FORKED_STREAM::clean_child(bool force)
323
324
{
324
 
  if (fd_rep > 0) ::close(fd_rep);
 
325
  if (fd_rep > 0) {
 
326
    /* close the pipe between this process and the forked child
 
327
     * process, should terminate the forked application -> see
 
328
     * waitpid() below */
 
329
    ::close(fd_rep);
 
330
    fd_rep = -1;
 
331
  }
325
332
 
326
333
  if (pid_of_child_rep > 0) {
 
334
    int flags = 0;
 
335
#ifdef __WALL
 
336
    /* Linux-specific flag to waitpid() for to wait for
 
337
     * childs created by other threads */
 
338
    flags += __WALL;
 
339
#endif
 
340
    /* wait until child process has exited */
 
341
    int status = 0;
 
342
    int res = waitpid(pid_of_child_rep, &status, flags);
 
343
    if (res == pid_of_child_rep && WIFEXITED(status)) {
 
344
      ECA_LOG_MSG(ECA_LOGGER::system_objects, "Child process exit ok");
 
345
      pid_of_child_rep = 0;
 
346
    }
 
347
    else {
 
348
      if (res < 0)
 
349
        perror("waitpid");
 
350
    }
 
351
  }
 
352
 
 
353
  /* if 'killing you softly' didn't work, next try with SIGTERM */
 
354
  if (force == true && pid_of_child_rep > 0) {
 
355
    ECA_LOG_MSG(ECA_LOGGER::system_objects, "sending SIGTERM to child process");
 
356
    /* close did not trigger exit, send SIGTERM */
327
357
    kill(pid_of_child_rep, SIGTERM);
328
 
    if (::getpid() == pid_of_parent_rep) {
329
 
      waitpid(pid_of_child_rep, 0, 0);
330
 
      pid_of_child_rep = 0;
331
 
    }
332
 
    else {
333
 
      ECA_LOG_MSG(ECA_LOGGER::system_objects, "WARNING: Parent-pid changed!");
334
 
    }
 
358
    pid_of_child_rep = 0;
335
359
  }
 
360
  
336
361
  if (tmp_file_created_rep == true) {
337
362
    ::remove(tmpfile_repp.c_str());
 
363
    tmp_file_created_rep = false;
338
364
  }
339
365
}
340
366