Switch to unified view

a b/src/utils/rclionice.cpp
1
/* Copyright (C) 2004 J.F.Dockes
2
 *   This program is free software; you can redistribute it and/or modify
3
 *   it under the terms of the GNU General Public License as published by
4
 *   the Free Software Foundation; either version 2 of the License, or
5
 *   (at your option) any later version.
6
 *
7
 *   This program is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *   GNU General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program; if not, write to the
14
 *   Free Software Foundation, Inc.,
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
 */
17
#include <stdio.h>
18
19
#include "rclionice.h"
20
#include "execmd.h"
21
#include "debuglog.h"
22
23
bool rclionice(const string& clss, const string& cdata)
24
{
25
    string ionicexe;
26
    if (!ExecCmd::which("ionice", ionicexe)) {
27
  // ionice not found, bail out
28
  LOGDEB(("rclionice: ionice not found\n"));
29
  return false;
30
    }
31
    list<string> args;
32
    args.push_back("-c");
33
    args.push_back(clss);
34
35
    if (!cdata.empty()) {
36
  args.push_back("-n");
37
  args.push_back(cdata);
38
    }
39
    
40
    char cpid[100];
41
    sprintf(cpid, "%d", getpid());
42
    args.push_back("-p");
43
    args.push_back(cpid);
44
45
    ExecCmd cmd;
46
    int status = cmd.doexec(ionicexe, args);
47
48
    if (status) {
49
  LOGERR(("rclionice: failed, status 0x%x\n", status));
50
  return false;
51
    }
52
    return true;
53
}