view toys/posix/renice.c @ 1189:95ae2805622f draft

Add Szabolcs Nagy's deflate/inflate code from git://git.suckless.org/flate Confirmed with him on IRC it's ok to use under toybox license, glued the files together and hammered square peg into round hole, no other changes yet.
author Rob Landley <rob@landley.net>
date Fri, 31 Jan 2014 06:01:30 -0600
parents 53a9bcb938f0
children 57f2a26fa92c
line wrap: on
line source

/* renice.c - renice process
 *
 * Copyright 2013 CE Strake <strake888 at gmail.com>
 *
 * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/renice.html

USE_RENICE(NEWTOY(renice, "<1gpun#|", TOYFLAG_BIN))

config RENICE
  bool "renice"
  default y
  help
    usage: renice [-gpu] -n increment ID ...
*/

#define FOR_renice
#include "toys.h"

GLOBALS(
  long nArgu;
)

void renice_main(void) {
  int which = (toys.optflags & FLAG_g) ? PRIO_PGRP :
              ((toys.optflags & FLAG_u) ? PRIO_USER : PRIO_PROCESS);
  char **arg;

  for (arg = toys.optargs; *arg; arg++) {
    char *s = *arg;
    int id = -1;

    if (toys.optflags & FLAG_u) {
      struct passwd *p = getpwnam(s);
      if (p) id = p->pw_uid;
    } else {
      id = strtol(s, &s, 10);
      if (*s) id = -1;
    }

    if (id < 0) {
      error_msg("bad '%s'", *arg);
      continue;
    }

    if (setpriority(which, id, getpriority(which, id)+TT.nArgu) < 0)
      perror_msg("setpriority %d", id);
  }
}