~vanvugt/ubuntu/oneiric/mediatomb/fix-770964-784431

« back to all changes in this revision

Viewing changes to src/process.cc

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2009-04-22 21:39:19 UTC
  • mto: (4.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20090422213919-52m015y6gcpv1m1g
Tags: upstream-0.12.0~svn2018
ImportĀ upstreamĀ versionĀ 0.12.0~svn2018

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
    Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
8
8
                       Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
9
9
    
10
 
    Copyright (C) 2006-2008 Gena Batyan <bgeradz@mediatomb.cc>,
 
10
    Copyright (C) 2006-2009 Gena Batyan <bgeradz@mediatomb.cc>,
11
11
                            Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
12
12
                            Leonhard Wimmer <leo@mediatomb.cc>
13
13
    
24
24
    version 2 along with MediaTomb; if not, write to the Free Software
25
25
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
26
26
    
27
 
    $Id: process.cc 1698 2008-02-23 20:48:30Z lww $
 
27
    $Id: process.cc 2010 2009-01-11 19:10:43Z lww $
28
28
*/
29
29
 
30
30
/// \file process.cc
63
63
        
64
64
    Ref<ConfigManager> cfg = ConfigManager::getInstance();
65
65
    String input_file = tempName(cfg->getOption(CFG_SERVER_TMPDIR), temp_in);
66
 
    fd = open(input_file.c_str(), O_RDWR);
67
 
    int ret = write(fd, input.c_str(), input.length());
 
66
    fd = open(input_file.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
 
67
    if (fd == -1)
 
68
    {
 
69
        log_debug("Failed to open input file %s: %s\n", input_file.c_str(),
 
70
                  strerror(errno));
 
71
        throw _Exception(_("Failed to open input file ") + input_file +_(" ") + 
 
72
                         strerror(errno));
 
73
    }
 
74
    ssize_t ret = write(fd, input.c_str(), input.length());
68
75
    close(fd);
 
76
    if (ret < input.length())
 
77
    {
 
78
 
 
79
        log_debug("Failed to write to %s: %s\n", input.c_str(), 
 
80
                   strerror(errno));
 
81
        throw _Exception(_("Failed to write to ") + input + ": " + 
 
82
                         strerror(errno));
 
83
    }
69
84
    
70
85
    /* touching output file */
71
86
    String output_file = tempName(cfg->getOption(CFG_SERVER_TMPDIR), temp_out);
72
 
    fd = open(output_file.c_str(), O_RDWR);
 
87
    fd = open(output_file.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
 
88
    if (fd == -1)
 
89
    {
 
90
        log_debug("Failed to open output file %s: %s\n", output_file.c_str(),
 
91
                  strerror(errno));
 
92
        throw _Exception(_("Failed to open output file ")+ input_file +_(" ") + 
 
93
                         strerror(errno));
 
94
    }
73
95
    close(fd);
74
 
   
 
96
 
75
97
    /* executing script */
76
 
    String command = prog + " " + param + " < " + input_file +
77
 
        " > " + output_file;
 
98
    String command = prog + " " + param + " < " + input_file + 
 
99
                                          " > " + output_file;
78
100
    log_debug("running %s\n", command.c_str());
79
 
    ret = system(command.c_str());
 
101
    int sysret = system(command.c_str());
 
102
    if (sysret == -1)
 
103
    {
 
104
        log_debug("Failed to execute: %s\n", command.c_str());
 
105
        throw _Exception(_("Failed to execute: ") + command);
 
106
    }
80
107
 
81
108
    /* reading output file */
82
109
    file = fopen(output_file.c_str(), "r");
 
110
    if (!file)
 
111
    {
 
112
        log_debug("Could not open output file %s: %s\n", output_file.c_str(),
 
113
                strerror(errno));
 
114
        throw _Exception(_("Failed to open output file ")+output_file +_(" ") + 
 
115
                strerror(errno));
 
116
    }
83
117
    Ref<StringBuffer> output(new StringBuffer());
84
118
 
85
119
    int bytesRead;