args.repeat_interval = 1000000;
args.repeat_counter = 0;
+ program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
flags |= FREE_REPEAT;
args.repeat_interval = (1000000 * strtof(optarg, &endptr));
if (errno || optarg == endptr || (endptr && *endptr))
- errx(EXIT_FAILURE, _("seconds argument `%s' failed"), optarg);
+ xerrx(EXIT_FAILURE, _("seconds argument `%s' failed"), optarg);
if (args.repeat_interval < 1)
- errx(EXIT_FAILURE,
+ xerrx(EXIT_FAILURE,
_("seconds argument `%s' is not positive number"), optarg);
break;
case 'c':
flags |= FREE_REPEATCOUNT;
args.repeat_counter = strtoul(optarg, &endptr, 10);
if (errno || optarg == endptr || (endptr && *endptr))
- errx(EXIT_FAILURE, _("count argument `%s' failed"), optarg);
+ xerrx(EXIT_FAILURE, _("count argument `%s' failed"), optarg);
break;
case HELP_OPTION:
#include <string.h>
#include <errno.h>
-#ifdef HAVE_ERR_H
-# include <err.h>
-#endif
-
/*
* Compiler specific stuff
*/
/*
* Error printing.
*/
-#ifndef HAVE_ERR_H
-static inline void
-errmsg(char doexit, int excode, char adderr, const char *fmt, ...)
-{
- fprintf(stderr, "%s: ", program_invocation_short_name);
- if (fmt != NULL) {
- va_list argp;
- va_start(argp, fmt);
- vfprintf(stderr, fmt, argp);
- va_end(argp);
- if (adderr)
- fprintf(stderr, ": ");
- }
- if (adderr)
- fprintf(stderr, "%m");
- fprintf(stderr, "\n");
- if (doexit)
- exit(excode);
-}
-
-# ifndef HAVE_ERR
-# define err(E, FMT...) errmsg(1, E, 1, FMT)
-# endif
-
-# ifndef HAVE_ERRX
-# define errx(E, FMT...) errmsg(1, E, 0, FMT)
-# endif
-
-# ifndef HAVE_WARN
-# define warn(FMT...) errmsg(0, 0, 1, FMT)
-# endif
-
-# ifndef HAVE_WARNX
-# define warnx(FMT...) errmsg(0, 0, 0, FMT)
-# endif
-#endif /* !HAVE_ERR_H */
-
+#define xwarn(FMT...) error(0, errno, FMT)
+#define xwarnx(FMT...) error(0, 0, FMT)
+#define xerr(STATUS, FMT...) error(STATUS, errno, FMT)
+#define xerrx(STATUS, FMT...) error(STATUS, 0, FMT)
/*
* Constant strings for usage() functions.
long num;
char *end = NULL;
- if (str == NULL || *str == '\0')
- goto err;
- errno = 0;
- num = strtol(str, &end, 10);
- if (errno || str == end || (end && *end))
- goto err;
-
- return num;
- err:
- if (errno)
- err(EXIT_FAILURE, "%s: '%s'", errmesg, str);
- else
- errx(EXIT_FAILURE, "%s: '%s'", errmesg, str);
+ if (str != NULL && *str != '\0') {
+ errno = 0;
+ num = strtol(str, &end, 10);
+ if (errno == 0 && str != end && end != NULL && *end == '\0')
+ return num;
+ }
+ error(EXIT_FAILURE, errno, "%s: '%s'", errmesg, str);
+ return 0;
}
/*
* same as strtod(3) but exit on failure instead of returning crap
double num;
char *end = NULL;
- if (str == NULL || *str == '\0')
- goto err;
- errno = 0;
- num = strtod(str, &end);
-
- if (errno || str == end || (end && *end))
- goto err;
-
- return num;
- err:
- if (errno)
- err(EXIT_FAILURE, "%s: '%s'", errmesg, str);
- else
- errx(EXIT_FAILURE, "%s: '%s'", errmesg, str);
+ if (str != NULL && *str != '\0') {
+ errno = 0;
+ num = strtod(str, &end);
+ if (errno == 0 && str != end && end != NULL && *end == '\0')
+ return num;
+ }
+ error(EXIT_FAILURE, errno, "%s: '%s'", errmesg, str);
return 0;
}
pwd = getpwnam (name);
if (pwd == NULL) {
- warnx(_("invalid user name: %s"), name);
+ xwarnx(_("invalid user name: %s"), name);
return 0;
}
e->num = pwd->pw_uid;
grp = getgrnam (name);
if (grp == NULL) {
- warnx(_("invalid group name: %s"), name);
+ xwarnx(_("invalid group name: %s"), name);
return 0;
}
e->num = grp->gr_gid;
static int conv_pgrp (const char *restrict name, union el *restrict e)
{
if (! strict_atol (name, &e->num)) {
- warnx(_("invalid process group: %s"), name);
+ xwarnx(_("invalid process group: %s"), name);
return 0;
}
if (e->num == 0)
static int conv_sid (const char *restrict name, union el *restrict e)
{
if (! strict_atol (name, &e->num)) {
- warnx(_("invalid session id: %s"), name);
+ xwarnx(_("invalid session id: %s"), name);
return 0;
}
if (e->num == 0)
static int conv_num (const char *restrict name, union el *restrict e)
{
if (! strict_atol (name, &e->num)) {
- warnx(_("not a number: %s"), name);
+ xwarnx(_("not a number: %s"), name);
return 0;
}
return 1;
}
if(opt_lock && !opt_pidfile)
- errx(EXIT_FAILURE, _("-L without -F makes no sense\n"
+ xerrx(EXIT_FAILURE, _("-L without -F makes no sense\n"
"Try `%s --help' for more information."),
program_invocation_short_name);
if(opt_pidfile){
opt_pid = read_pidfile();
if(!opt_pid)
- errx(EXIT_FAILURE, _("pidfile not valid\n"
+ xerrx(EXIT_FAILURE, _("pidfile not valid\n"
"Try `%s --help' for more information."),
program_invocation_short_name);
}
if (argc - optind == 1)
opt_pattern = argv[optind];
else if (argc - optind > 1)
- errx(EXIT_FAILURE, _("only one pattern can be provided\n"
+ xerrx(EXIT_FAILURE, _("only one pattern can be provided\n"
"Try `%s --help' for more information."),
program_invocation_short_name);
else if (criteria_count == 0)
- errx(EXIT_FAILURE, _("no matching criteria specified\n"
+ xerrx(EXIT_FAILURE, _("no matching criteria specified\n"
"Try `%s --help' for more information."),
program_invocation_short_name);
}
union el *procs;
int num;
+ program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
if (errno==ESRCH)
// gone now, which is OK
continue;
- warn(_("killing pid %ld failed"));
+ xwarn(_("killing pid %ld failed"));
}
} else {
if (opt_count) {
*/
#include <ctype.h>
-#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
{NULL, 0, NULL, 0}
};
+ program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
x_option = 1;
break;
case 'r':
- warnx(_("option -r is ignored as SunOS compatibility"));
+ xwarnx(_("option -r is ignored as SunOS compatibility"));
break;
case 'd':
d_option = 1;
argv += optind;
if (argc < 1)
- errx(EXIT_FAILURE, _("argument missing"));
+ xerrx(EXIT_FAILURE, _("argument missing"));
if (d_option && x_option)
- errx(EXIT_FAILURE, _("options -d and -x cannot coexist"));
+ xerrx(EXIT_FAILURE, _("options -d and -x cannot coexist"));
pidlist = xmalloc(sizeof(unsigned) * argc);
#define NORETURN __attribute__((__noreturn__))
#define FUNCTION __attribute__((__const__)) // no access to global mem, even via ptr, and no side effect
-#if !defined(restrict) && __STDC_VERSION__ < 199901
-#if __GNUC__ > 2 || __GNUC_MINOR__ >= 92
-#define restrict __restrict__
-#else
-#warning No restrict keyword?
-#define restrict
-#endif
-#endif
-
#if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
// won't alias anything, and aligned enough for anything
#define MALLOC __attribute__ ((__malloc__))
{NULL, 0, 0, 0}
};
+ program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
#endif
d = opendir("/proc");
if (!d)
- err(EXIT_FAILURE, "/proc");
+ xerr(EXIT_FAILURE, "/proc");
while ((de = readdir(d))) {
if (de->d_name[0] > '9')
continue;
if (s)
printf("%s\n", s);
else
- warnx(_("unknown signal name %s"),
+ xwarnx(_("unknown signal name %s"),
optarg);
free(s);
} else {
prio = strtol_or_err(argv[i],
_("failed to parse argument"));
if (prio < INT_MIN || INT_MAX < prio)
- errx(EXIT_FAILURE,
+ xerrx(EXIT_FAILURE,
_("priority %lu out of range"), prio);
nargs--;
if (nargs - i)
/* No more arguments to process. Must sanity check. */
if (!tty_count && !uid_count && !cmd_count && !pid_count)
- errx(EXIT_FAILURE, _("no process selection criteria"));
+ xerrx(EXIT_FAILURE, _("no process selection criteria"));
if ((run_time->fast | run_time->interactive | run_time->
verbose | run_time->warnings | run_time->noaction) & ~1)
- errx(EXIT_FAILURE, _("general flags may not be repeated"));
+ xerrx(EXIT_FAILURE, _("general flags may not be repeated"));
if (run_time->interactive
&& (run_time->verbose | run_time->fast | run_time->noaction))
- errx(EXIT_FAILURE, _("-i makes no sense with -v, -f, and -n"));
+ xerrx(EXIT_FAILURE, _("-i makes no sense with -v, -f, and -n"));
if (run_time->verbose && (run_time->interactive | run_time->fast))
- errx(EXIT_FAILURE, _("-v makes no sense with -i and -f"));
+ xerrx(EXIT_FAILURE, _("-v makes no sense with -i and -f"));
if (run_time->noaction) {
program = PROG_SKILL;
/* harmless */
/* main body */
int main(int argc, char ** argv)
{
+ program_invocation_name = program_invocation_short_name;
struct run_time_conf_t run_time;
memset(&run_time, 0, sizeof(struct run_time_conf_t));
my_pid = getpid();
int o;
unsigned short old_rows;
struct slab_info *slab_list = NULL;
- int run_once=0;
+ int run_once=0;
static const struct option longopts[] = {
{ "delay", required_argument, NULL, 'd' },
{ NULL, 0, NULL, 0 }
};
+ program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
errno = 0;
delay = strtol_or_err(optarg, _("illegal delay"));
if (delay < 1)
- errx(EXIT_FAILURE,
+ xerrx(EXIT_FAILURE,
_("delay must be positive integer"));
break;
case 's':
}
if (tcgetattr(STDIN_FILENO, &saved_tty) == -1)
- warn(_("terminal setting retrieval"));
+ xwarn(_("terminal setting retrieval"));
old_rows = rows;
term_size(0);
while(p){
char c = *p;
if((*(p+1) == '/' || *(p+1) == '.') && warned) {
- warnx(_("separators should not be repeated: %s"), p);
+ xwarnx(_("separators should not be repeated: %s"), p);
warned = 0;
}
if(c==old) *p=new;
struct stat ts;
if (!name || !*name) {
- warnx(_("\"%s\" is an unknown key"), name);
+ xwarnx(_("\"%s\" is an unknown key"), name);
return -1;
}
if (stat(tmpname, &ts) < 0) {
if (!IgnoreError) {
- warn(_("cannot stat %s"), tmpname);
+ xwarn(_("cannot stat %s"), tmpname);
rc = -1;
}
goto out;
switch(errno) {
case ENOENT:
if (!IgnoreError) {
- warnx(_("\"%s\" is an unknown key"), outname);
+ xwarnx(_("\"%s\" is an unknown key"), outname);
rc = -1;
}
break;
case EACCES:
- warnx(_("permission denied on key '%s'"), outname);
+ xwarnx(_("permission denied on key '%s'"), outname);
rc = -1;
break;
default:
- warn(_("reading key \"%s\""), outname);
+ xwarn(_("reading key \"%s\""), outname);
rc = -1;
break;
}
} else {
switch(errno) {
case EACCES:
- warnx(_("permission denied on key '%s'"), outname);
+ xwarnx(_("permission denied on key '%s'"), outname);
rc = -1;
break;
case EISDIR:{
goto out;
}
default:
- warnx(_("reading key \"%s\""), outname);
+ xwarnx(_("reading key \"%s\""), outname);
rc = -1;
case 0:
break;
dp = opendir(path);
if (!dp) {
- warnx(_("unable to open directory \"%s\""), path);
+ xwarnx(_("unable to open directory \"%s\""), path);
rc = -1;
} else {
readdir(dp); // skip .
sprintf(tmpdir, "%s%s", path, de->d_name);
rc2 = stat(tmpdir, &ts);
if (rc2 != 0) {
- warn(_("cannot stat %s"), tmpdir);
+ xwarn(_("cannot stat %s"), tmpdir);
} else {
if (S_ISDIR(ts.st_mode)) {
strcat(tmpdir, "/");
equals = strchr(setting, '=');
if (!equals) {
- warnx(_("\"%s\" must be of the form name=value"), setting);
+ xwarnx(_("\"%s\" must be of the form name=value"), setting);
return -1;
}
value = equals + 1; /* point to the value in name=value */
if (!*name || !*value || name == equals) {
- warnx(_("Malformed setting \"%s\""), setting);
+ xwarnx(_("Malformed setting \"%s\""), setting);
return -2;
}
if (stat(tmpname, &ts) < 0) {
if (!IgnoreError) {
- warn(_("cannot stat %s"), tmpname);
+ xwarn(_("cannot stat %s"), tmpname);
rc = -1;
}
goto out;
}
if ((ts.st_mode & S_IWUSR) == 0) {
- warn(_("setting key \"%s\""), outname);
+ xwarn(_("setting key \"%s\""), outname);
goto out;
}
if (S_ISDIR(ts.st_mode)) {
- warn(_("setting key \"%s\""), outname);
+ xwarn(_("setting key \"%s\""), outname);
goto out;
}
switch(errno) {
case ENOENT:
if (!IgnoreError) {
- warnx(_("\"%s\" is an unknown key"), outname);
+ xwarnx(_("\"%s\" is an unknown key"), outname);
rc = -1;
}
break;
case EACCES:
- warnx(_("permission denied on key '%s'"), outname);
+ xwarnx(_("permission denied on key '%s'"), outname);
rc = -1;
break;
default:
- warn(_("setting key \"%s\""), outname);
+ xwarn(_("setting key \"%s\""), outname);
rc = -1;
break;
}
} else {
rc = fprintf(fp, "%s\n", value);
if (rc < 0) {
- warn(_("setting key \"%s\""), outname);
+ xwarn(_("setting key \"%s\""), outname);
fclose(fp);
} else {
rc=fclose(fp);
if (rc != 0)
- warn(_("setting key \"%s\""), outname);
+ xwarn(_("setting key \"%s\""), outname);
}
if (rc==0 && !Quiet) {
if (NameOnly) {
;
if (!fp) {
- warn(_("cannot open \"%s\""), filename);
+ xwarn(_("cannot open \"%s\""), filename);
return -1;
}
name = strtok(t, "=");
if (!name || !*name) {
- warnx(_("%s(%d): invalid syntax, continuing..."), filename, n);
+ xwarnx(_("%s(%d): invalid syntax, continuing..."), filename, n);
continue;
}
value = strtok(NULL, "\n\r");
if (!value || !*value) {
- warnx(_("%s(%d): invalid syntax, continuing..."), filename, n);
+ xwarnx(_("%s(%d): invalid syntax, continuing..."), filename, n);
continue;
}
{NULL, 0, NULL, 0}
};
- setlocale (LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
+ program_invocation_name = program_invocation_short_name;
+ setlocale (LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
PrintName = true;
PrintNewline = true;
argv += optind;
if (argc < 1)
- errx(EXIT_FAILURE, _("no variables specified\n"
+ xerrx(EXIT_FAILURE, _("no variables specified\n"
"Try `%s --help' for more information."),
program_invocation_short_name);
if (NameOnly && Quiet)
- errx(EXIT_FAILURE, _("options -N and -q cannot coexist\n"
+ xerrx(EXIT_FAILURE, _("options -N and -q cannot coexist\n"
"Try `%s --help' for more information."),
program_invocation_short_name);
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0}
};
-
+
+ program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
case 's':
max_scale = strtod_or_err(optarg, _("failed to parse argument"));
if (max_scale < 0)
- errx(EXIT_FAILURE, _("scale cannot be negative"));
+ xerrx(EXIT_FAILURE, _("scale cannot be negative"));
break;
case 'd':
tmpdly = strtol_or_err(optarg, _("failed to parse argument"));
if (tmpdly < 1)
- errx(EXIT_FAILURE, _("delay must be positive integer"));
+ xerrx(EXIT_FAILURE, _("delay must be positive integer"));
else if (UINT_MAX < tmpdly)
- errx(EXIT_FAILURE, _("too large delay value"));
+ xerrx(EXIT_FAILURE, _("too large delay value"));
dly = tmpdly;
break;
case 'V':
if (argc > optind)
if ((fd = open(argv[optind], 1)) == -1)
- err(EXIT_FAILURE, _("can not open tty"));
+ xerr(EXIT_FAILURE, _("can not open tty"));
setsize(0);
{NULL, 0, NULL, 0}
};
+ program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
fDiskstat = fopen("/proc/diskstats", "rb");
if (!fDiskstat)
- errx(EXIT_FAILURE,
+ xerrx(EXIT_FAILURE,
_("Your kernel doesn't support diskstat. (2.5.70 or above required)"));
fclose(fDiskstat);
free(partitions);
}
} else
- errx(EXIT_FAILURE,
+ xerrx(EXIT_FAILURE,
_("Your kernel doesn't support diskstat (2.5.70 or above required)"));
}
fSlab = fopen("/proc/slabinfo", "rb");
if (!fSlab) {
- warnx(_("Your kernel doesn't support slabinfo or your permissions are insufficient."));
+ xwarnx(_("Your kernel doesn't support slabinfo or your permissions are insufficient."));
return;
}
{NULL, 0, NULL, 0}
};
+ program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
dataUnit = UNIT_M;
break;
default:
- errx(EXIT_FAILURE,
+ xerrx(EXIT_FAILURE,
/* Translation Hint: do not change argument characters */
_("-S requires k, K, m or M (default is kb)"));
}
if (optind < argc) {
tmp = strtol_or_err(argv[optind++], _("failed to parse argument"));
if (tmp < 1)
- errx(EXIT_FAILURE, _("delay must be positive integer"));
+ xerrx(EXIT_FAILURE, _("delay must be positive integer"));
else if (UINT_MAX < tmp)
- errx(EXIT_FAILURE, _("too large delay value"));
+ xerrx(EXIT_FAILURE, _("too large delay value"));
sleep_time = tmp;
infinite_updates = 1;
}
{NULL, 0, NULL, 0}
};
+ program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
if ((env_var = getenv("PROCPS_USERLEN")) != NULL) {
userlen = atoi(env_var);
if (userlen < 8 || userlen > USERSZ) {
- warnx
+ xwarnx
(_("User length environment PROCPS_USERLEN must be between 8 and %d, ignoring.\n"),
USERSZ);
userlen = 8;
if ((env_var = getenv("PROCPS_FROMLEN")) != NULL) {
fromlen = atoi(env_var);
if (fromlen < 8 || fromlen > HOSTSZ) {
- warnx
+ xwarnx
(_("From length environment PROCPS_FROMLEN must be between 8 and %d, ignoring.\n"),
HOSTSZ);
fromlen = 16;
else
maxcmd = 80;
if (maxcmd < 71)
- errx(EXIT_FAILURE, _("%d column window is too narrow"), maxcmd);
+ xerrx(EXIT_FAILURE, _("%d column window is too narrow"), maxcmd);
maxcmd -= 21 + userlen + (from ? fromlen : 0) + (longform ? 20 : 0);
if (maxcmd < 3)
- warnx(_("warning: screen width %d suboptimal"), win.ws_col);
+ xwarnx(_("warning: screen width %d suboptimal"), win.ws_col);
procs = readproctab(PROC_FILLCOM | PROC_FILLUSR | PROC_FILLSTAT);
{0, 0, 0, 0}
};
+ program_invocation_name = program_invocation_short_name;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);