~vanvugt/+junk/mediatomb

« back to all changes in this revision

Viewing changes to src/process_executor.cc

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2008-03-02 13:09:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080302130916-zlljdze3kt7vuq4b
Tags: 0.11.0-1
* New upstream release.
* Include message about which inotify headers will be used when enabling
  inotify runtime support.
* Fixed error with use of INTERFACE in init script. Also removed use of -m
  option.
* Including new config.xml options.
* Added more build dependencies for new upstream release.
* Removed build dependency of libid3-dev, taglib is now preferred.
* mediatomb.xpm and manpage.xml is now included in orig tarball.
* inotify patch is not needed anymore.
* md5 patch has been committed upstream and is no longer needed. Also removed
  README.Debian.
* TwinHelix PNG fix is now used. Removed from TODO.
* Adding dependency of iceweasel for mediatomb package.
* Updated copyright file.
* Updated watch file.
* Updated rules file for proper configure options.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*MT*
 
2
    
 
3
    MediaTomb - http://www.mediatomb.cc/
 
4
    
 
5
    process_executor.cc - this file is part of MediaTomb.
 
6
    
 
7
    Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
 
8
                       Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
 
9
    
 
10
    Copyright (C) 2006-2008 Gena Batyan <bgeradz@mediatomb.cc>,
 
11
                            Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
 
12
                            Leonhard Wimmer <leo@mediatomb.cc>
 
13
    
 
14
    MediaTomb is free software; you can redistribute it and/or modify
 
15
    it under the terms of the GNU General Public License version 2
 
16
    as published by the Free Software Foundation.
 
17
    
 
18
    MediaTomb is distributed in the hope that it will be useful,
 
19
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
    GNU General Public License for more details.
 
22
    
 
23
    You should have received a copy of the GNU General Public License
 
24
    version 2 along with MediaTomb; if not, write to the Free Software
 
25
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
26
    
 
27
    $Id: process_executor.cc 1698 2008-02-23 20:48:30Z lww $
 
28
*/
 
29
 
 
30
/// \file process_executor.cc
 
31
 
 
32
#ifdef HAVE_CONFIG_H
 
33
    #include "autoconfig.h"
 
34
#endif
 
35
 
 
36
#include "process_executor.h"
 
37
#include "process.h"
 
38
#include <pthread.h>
 
39
#include <signal.h>
 
40
 
 
41
using namespace zmm;
 
42
 
 
43
ProcessExecutor::ProcessExecutor(String command, Ref<Array<StringBase> > arglist)
 
44
{
 
45
#define MAX_ARGS 255
 
46
    char *argv[MAX_ARGS];
 
47
    
 
48
    argv[0] = command.c_str();
 
49
    int apos = 0;
 
50
 
 
51
    for (int i = 0; i < arglist->size(); i++)
 
52
    {
 
53
        argv[++apos] = arglist->get(i)->data;
 
54
        if (apos >= MAX_ARGS-1)
 
55
            break;
 
56
    }
 
57
    argv[++apos] = NULL;
 
58
 
 
59
    exit_status = 0;
 
60
 
 
61
    process_id = fork();
 
62
    
 
63
    switch (process_id)
 
64
    {
 
65
        case -1:
 
66
            throw _Exception(_("Failed to launch process ") + command);
 
67
        
 
68
        case 0:
 
69
            sigset_t mask_set;
 
70
            pthread_sigmask(SIG_SETMASK, &mask_set, NULL);
 
71
            log_debug("Launching process: %s\n", command.c_str());
 
72
            execvp(command.c_str(), argv);
 
73
        default:
 
74
            break;
 
75
    }
 
76
 
 
77
    log_debug("Launched process %s, pid: %d\n", command.c_str(), process_id);
 
78
}
 
79
 
 
80
bool ProcessExecutor::isAlive()
 
81
{
 
82
    return is_alive(process_id, &exit_status);
 
83
}
 
84
    
 
85
bool ProcessExecutor::kill()
 
86
{
 
87
    return kill_proc(process_id);
 
88
}
 
89
 
 
90
int ProcessExecutor::getStatus()
 
91
{
 
92
    is_alive(process_id, &exit_status);
 
93
    return exit_status;
 
94
}
 
95
 
 
96
ProcessExecutor::~ProcessExecutor()
 
97
{
 
98
    kill();
 
99
}
 
100