Make brandelf explain itself a little better on error.

Also, at Boris' suggestion, add -l option to list known
ELF types.

PR:		bin/15285
Reviewed by:	bp
This commit is contained in:
wes 2000-01-04 02:33:54 +00:00
parent 6af7f84af3
commit 24d00c85e4
2 changed files with 46 additions and 12 deletions

View File

@ -36,6 +36,7 @@
.Sh SYNOPSIS
.Nm brandelf
.Op Fl f
.Op Fl l
.Op Fl v
.Op Fl t Ar string
.Ar file ...
@ -48,6 +49,8 @@ The options are as follows:
.It Fl f
forces branding even if the brand requested is unknown, and disables
warnings for unknown brands.
.It Fl l
lists all known ELF types on the standard error channel.
.It Fl v
turns on verbose reporting
.It Fl t Ar string
@ -78,7 +81,7 @@ command:
.Sh DIAGNOSTICS
Exit status is 0 on success, and 1 if the command
fails if a file doesn't exist, is too short, fails to brand properly,
or the brand requested is not 'Linux' or 'FreeBSD' and the
or the brand requested is not one of the known types and the
.Fl f
option is not set.
.Sh HISTORY

View File

@ -37,6 +37,7 @@
#include <err.h>
static int iselftype(const char *);
static void printelftypes(void);
static void usage __P((void));
int
@ -45,13 +46,17 @@ main(int argc, char **argv)
const char *type = "FreeBSD";
int retval = 0;
int ch, change = 0, verbose = 0, force = 0;
int ch, change = 0, verbose = 0, force = 0, listed = 0;
while ((ch = getopt(argc, argv, "ft:v")) != -1)
while ((ch = getopt(argc, argv, "flt:v")) != -1)
switch (ch) {
case 'f':
force = 1;
break;
case 'l':
printelftypes();
listed = 1;
break;
case 'v':
verbose = 1;
break;
@ -64,11 +69,20 @@ main(int argc, char **argv)
}
argc -= optind;
argv += optind;
if (!argc)
errx(1, "no file(s) specified");
if (!argc) {
if (listed)
exit(0);
else {
warnx("no file(s) specified");
usage();
}
}
if (!force && !iselftype(type))
errx(1, "invalid ELF type '%s'", type);
if (!force && !iselftype(type)) {
warnx("invalid ELF type '%s'", type);
printelftypes();
usage();
}
while (argc) {
int fd;
@ -98,9 +112,11 @@ main(int argc, char **argv)
fprintf(stdout,
"File '%s' is of brand '%s'.\n",
argv[0], string);
if (!force && !iselftype(string))
if (!force && !iselftype(string)) {
warnx("Brand '%s' is unknown",
string);
printelftypes();
}
}
else
fprintf(stdout, "File '%s' has no branding.\n",
@ -126,14 +142,16 @@ main(int argc, char **argv)
static void
usage()
{
fprintf(stderr, "usage: brandelf [-f] [-v] [-t string] file ...\n");
fprintf(stderr, "usage: brandelf [-f] [-v] [-l] [-t string] file ...\n");
exit(1);
}
/* XXX - any more types? */
static const char *elftypes[] = { "FreeBSD", "Linux", "SVR4" };
static int
iselftype(const char *elftype) {
/* XXX - any more types? */
const char *elftypes[] = { "FreeBSD", "Linux", "SVR4" };
iselftype(const char *elftype)
{
int elfwalk;
for (elfwalk = 0;
@ -143,3 +161,16 @@ iselftype(const char *elftype) {
return 1;
return 0;
}
static void
printelftypes()
{
int elfwalk;
fprintf(stderr, "known ELF types are: ");
for (elfwalk = 0;
elfwalk < sizeof(elftypes)/sizeof(elftypes[0]);
elfwalk++)
fprintf(stderr, "%s ", elftypes[elfwalk]);
fprintf(stderr, "\n");
}