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

« back to all changes in this revision

Viewing changes to sys-utils/renice.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:
44
44
#include <stdlib.h>
45
45
#include <string.h>
46
46
#include <errno.h>
 
47
#include <err.h>
47
48
#include "nls.h"
48
49
 
49
 
int donice(int,int,int);
 
50
static int donice(int,int,int);
50
51
 
51
 
void usage(int rc)
 
52
static void __attribute__((__noreturn__)) usage(FILE *out)
52
53
{
53
 
        printf( _("\nUsage:\n"
54
 
                " renice [-n] priority [-p|--pid] pid  [... pid]\n"
55
 
                " renice [-n] priority  -g|--pgrp pgrp [... pgrp]\n"
56
 
                " renice [-n] priority  -u|--user user [... user]\n"
57
 
                " renice -h | --help\n"
58
 
                " renice -v | --version\n\n"));
59
 
 
60
 
        exit(rc);
 
54
        fprintf(out, _(
 
55
                "\nUsage:\n"
 
56
                " %1$s [-n] <priority> [-p] <pid> [<pid>  ...]\n"
 
57
                " %1$s [-n] <priority>  -g <pgrp> [<pgrp> ...]\n"
 
58
                " %1$s [-n] <priority>  -u <user> [<user> ...]\n"),
 
59
                program_invocation_short_name);
 
60
 
 
61
        fprintf(out, _(
 
62
                "\nOptions:\n"
 
63
                " -g, --pgrp <id>        interpret as process group ID\n"
 
64
                " -h, --help             print help\n"
 
65
                " -n, --priority <num>   set the nice increment value\n"
 
66
                " -p, --pid <id>         force to be interpreted as process ID\n"
 
67
                " -u, --user <name|id>   interpret as username or user ID\n"
 
68
                " -v, --version          print version\n"));
 
69
 
 
70
        fprintf(out, _("\nFor more information see renice(1).\n"));
 
71
 
 
72
        exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
61
73
}
62
74
 
63
75
/*
82
94
        if (argc == 1) {
83
95
                if (strcmp(*argv, "-h") == 0 ||
84
96
                    strcmp(*argv, "--help") == 0)
85
 
                        usage(EXIT_SUCCESS);
 
97
                        usage(stdout);
86
98
 
87
99
                if (strcmp(*argv, "-v") == 0 ||
88
100
                    strcmp(*argv, "--version") == 0) {
92
104
        }
93
105
 
94
106
        if (argc < 2)
95
 
                usage(EXIT_FAILURE);
 
107
                usage(stderr);
96
108
 
97
109
        if (strcmp(*argv, "-n") == 0 || strcmp(*argv, "--priority") == 0) {
98
110
                argc--;
101
113
 
102
114
        prio = strtol(*argv, &endptr, 10);
103
115
        if (*endptr)
104
 
                usage(EXIT_FAILURE);
 
116
                usage(stderr);
105
117
 
106
118
        argc--;
107
119
        argv++;
123
135
                        register struct passwd *pwd = getpwnam(*argv);
124
136
 
125
137
                        if (pwd == NULL) {
126
 
                                fprintf(stderr, _("renice: %s: unknown user\n"),
127
 
                                        *argv);
 
138
                                warnx(_("unknown user %s"), *argv);
128
139
                                continue;
129
140
                        }
130
141
                        who = pwd->pw_uid;
131
142
                } else {
132
143
                        who = strtol(*argv, &endptr, 10);
133
144
                        if (who < 0 || *endptr) {
134
 
                                fprintf(stderr, _("renice: %s: bad value\n"),
135
 
                                        *argv);
 
145
                                warnx(_("bad value %s"), *argv);
136
146
                                continue;
137
147
                        }
138
148
                }
141
151
        return errs != 0 ? EXIT_FAILURE : EXIT_SUCCESS;
142
152
}
143
153
 
144
 
int
 
154
static int
145
155
donice(int which, int who, int prio) {
146
156
        int oldprio, newprio;
 
157
        const char *idtype = _("process ID");
 
158
 
 
159
        if (which == PRIO_USER)
 
160
                idtype = _("user ID");
 
161
        else if (which == PRIO_PGRP)
 
162
                idtype = _("process group ID");
147
163
 
148
164
        errno = 0;
149
165
        oldprio = getpriority(which, who);
150
166
        if (oldprio == -1 && errno) {
151
 
                fprintf(stderr, "renice: %d: ", who);
152
 
                perror(_("getpriority"));
 
167
                warn(_("failed to get priority for %d (%s)"), who, idtype);
153
168
                return 1;
154
169
        }
155
170
        if (setpriority(which, who, prio) < 0) {
156
 
                fprintf(stderr, "renice: %d: ", who);
157
 
                perror(_("setpriority"));
 
171
                warn(_("failed to set priority for %d (%s)"), who, idtype);
158
172
                return 1;
159
173
        }
160
174
        errno = 0;
161
175
        newprio = getpriority(which, who);
162
176
        if (newprio == -1 && errno) {
163
 
                fprintf(stderr, "renice: %d: ", who);
164
 
                perror(_("getpriority"));
 
177
                warn(_("failed to get priority for %d (%s)"), who, idtype);
165
178
                return 1;
166
179
        }
167
180
 
168
 
        printf(_("%d: old priority %d, new priority %d\n"),
169
 
               who, oldprio, newprio);
 
181
        printf(_("%d (%s) old priority %d, new priority %d\n"),
 
182
               who, idtype, oldprio, newprio);
170
183
        return 0;
171
184
}