~ubuntu-branches/ubuntu/precise/util-linux/precise-proposed

« back to all changes in this revision

Viewing changes to schedutils/ionice.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-06-20 22:31:50 UTC
  • mfrom: (1.6.3 upstream) (4.5.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110620223150-lz8wrv0946ihcz3z
Tags: 2.19.1-2ubuntu1
* Merge from Debian unstable, remaining changes:
  - Build for multiarch.
  - Add pre-depends on multiarch-support.
  - configure.ac: don't try to be clever about extracting a path name from
    $libdir to append to /usr in a way that's not overridable; instead,
    reuse the built-in configurable libexecdir.
  - Fix up the .pc.in files to know about libexecdir, so our substitutions
    don't leave us with unusable pkg-config files.
  - Install custom blkid.conf to use /dev/.blkid.tab since we don't
    expect device names to survive a reboot
  - Mention mountall(8) in fstab(5) manpages, along with its special
    options.
  - Since upstart is required in Ubuntu, the hwclock.sh init script is not
    called on startup and the hwclockfirst.sh init script is removed.
  - Drop depends on initscripts for the above.
  - Replace hwclock udev rule with an Upstart job.
  - For the case where mount is called with a directory to mount, look
    that directory up in mountall's /lib/init/fstab if we couldn't find
    it mentioned anywhere else.  This means "mount /proc", "mount /sys",
    etc. work.
  - mount.8 points to the cifs-utils package, not the obsolete smbfs one. 
* Dropped changes:
  - mount.preinst: lsb_release has been fixed in lucid and above to be
    usable without configuration, so we don't have to diverge from Debian
    here anymore.
* Changes merged upstream:
  - sfdisk support for '+' with '-N'
  - mount/umount.c: fix a segfault on umount with empty mtab entry
  - Fix arbitrary unmount with fuse security issue

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
#include <errno.h>
12
12
#include <getopt.h>
13
13
#include <unistd.h>
14
 
#include <sys/ptrace.h>
15
14
#include <sys/syscall.h>
16
 
#include <asm/unistd.h>
17
15
#include <err.h>
18
16
 
19
17
#include "nls.h"
20
18
 
 
19
#include "strutils.h"
 
20
 
21
21
static int tolerant;
22
22
 
23
23
static inline int ioprio_set(int which, int who, int ioprio)
91
91
        exit(rc);
92
92
}
93
93
 
94
 
static long getnum(const char *str)
95
 
{
96
 
        long num;
97
 
        char *end = NULL;
98
 
 
99
 
        if (str == NULL || *str == '\0')
100
 
                goto err;
101
 
        errno = 0;
102
 
        num = strtol(str, &end, 10);
103
 
 
104
 
        if (errno || (end && *end))
105
 
                goto err;
106
 
 
107
 
        return num;
108
 
err:
109
 
        if (errno)
110
 
                err(EXIT_SUCCESS, _("cannot parse number '%s'"), str);
111
 
        else
112
 
                errx(EXIT_SUCCESS, _("cannot parse number '%s'"), str);
113
 
        return 0;
114
 
}
115
 
 
116
94
int main(int argc, char *argv[])
117
95
{
118
96
        int ioprio = 4, set = 0, ioclass = IOPRIO_CLASS_BE, c;
125
103
        while ((c = getopt(argc, argv, "+n:c:p:th")) != EOF) {
126
104
                switch (c) {
127
105
                case 'n':
128
 
                        ioprio = getnum(optarg);
 
106
                        ioprio = strtol_or_err(optarg, _("failed to parse class data"));
129
107
                        set |= 1;
130
108
                        break;
131
109
                case 'c':
132
 
                        ioclass = getnum(optarg);
 
110
                        ioclass = strtol_or_err(optarg, _("failed to parse class"));
133
111
                        set |= 2;
134
112
                        break;
135
113
                case 'p':
136
 
                        pid = getnum(optarg);
 
114
                        pid = strtol_or_err(optarg, _("failed to parse pid"));
137
115
                        break;
138
116
                case 't':
139
117
                        tolerant = 1;
167
145
                ioprio_print(pid);
168
146
 
169
147
                for(; argv[optind]; ++optind) {
170
 
                        pid = getnum(argv[optind]);
 
148
                        pid = strtol_or_err(argv[optind], _("failed to parse pid"));
171
149
                        ioprio_print(pid);
172
150
                }
173
151
        } else {
176
154
 
177
155
                        for(; argv[optind]; ++optind)
178
156
                        {
179
 
                                pid = getnum(argv[optind]);
 
157
                                pid = strtol_or_err(argv[optind], _("failed to parse pid"));
180
158
                                ioprio_setpid(pid, ioprio, ioclass);
181
159
                        }
182
160
                }
184
162
                        ioprio_setpid(0, ioprio, ioclass);
185
163
                        execvp(argv[optind], &argv[optind]);
186
164
                        /* execvp should never return */
187
 
                        err(EXIT_FAILURE, _("execvp failed"));
 
165
                        err(EXIT_FAILURE, _("executing %s failed"), argv[optind]);
188
166
                }
189
167
        }
190
168