controlelf: clean up warnings

- use explicit ELF note name when not found
- no trailing . on warnings
- no \n

Sponsored by:	The FreeBSD Foundation
This commit is contained in:
emaste 2019-09-27 16:35:08 +00:00
parent 6c59a42e18
commit fcd405d5ab

View File

@ -132,9 +132,9 @@ main(int argc, char **argv)
if ((kind = elf_kind(elf)) != ELF_K_ELF) { if ((kind = elf_kind(elf)) != ELF_K_ELF) {
if (kind == ELF_K_AR) if (kind == ELF_K_AR)
warnx("file '%s' is an archive.", argv[0]); warnx("file '%s' is an archive", argv[0]);
else else
warnx("file '%s' is not an ELF file.", warnx("file '%s' is not an ELF file",
argv[0]); argv[0]);
retval = 1; retval = 1;
goto fail; goto fail;
@ -201,7 +201,7 @@ convert_to_feature_val(char* feature_str, u_int32_t* feature_val)
else if (feature_str[0] == '=') else if (feature_str[0] == '=')
set = true; set = true;
else if (feature_str[0] != '-') { else if (feature_str[0] != '-') {
warnx("'%c' is not an operator. Use instead '+', '-', '='.", warnx("'%c' not an operator - use '+', '-', '='",
feature_str[0]); feature_str[0]);
return (false); return (false);
} }
@ -216,7 +216,7 @@ convert_to_feature_val(char* feature_str, u_int32_t* feature_val)
} }
} }
if (i == len) { if (i == len) {
warnx("%s is not a valid feature.", feature); warnx("%s is not a valid feature", feature);
return (false); return (false);
} }
} }
@ -238,7 +238,7 @@ edit_file_features(Elf *elf, int phcount, int fd, char *val)
u_int64_t off; u_int64_t off;
if (!get_file_features(elf, phcount, fd, &features, &off)) { if (!get_file_features(elf, phcount, fd, &features, &off)) {
warnx("No control features note on the file.\n"); warnx("NT_FREEBSD_FEATURE_CTL note not found");
return (false); return (false);
} }
@ -327,7 +327,7 @@ get_file_features(Elf *elf, int phcount, int fd, u_int32_t *features, u_int64_t
namesz = roundup2(note.n_namesz, 4); namesz = roundup2(note.n_namesz, 4);
name = malloc(namesz); name = malloc(namesz);
if (name == NULL) { if (name == NULL) {
warn("malloc() failed.\n"); warn("malloc() failed.");
return (false); return (false);
} }
descsz = roundup2(note.n_descsz, 4); descsz = roundup2(note.n_descsz, 4);
@ -339,7 +339,7 @@ get_file_features(Elf *elf, int phcount, int fd, u_int32_t *features, u_int64_t
note.n_type != NT_FREEBSD_FEATURE_CTL) { note.n_type != NT_FREEBSD_FEATURE_CTL) {
/* Not the right note. Skip the description */ /* Not the right note. Skip the description */
if (lseek(fd, descsz, SEEK_CUR) < 0) { if (lseek(fd, descsz, SEEK_CUR) < 0) {
warn("lseek() failed.\n"); warn("lseek() failed.");
free(name); free(name);
return (false); return (false);
} }
@ -360,7 +360,7 @@ get_file_features(Elf *elf, int phcount, int fd, u_int32_t *features, u_int64_t
* descriptor. This should respect descsz. * descriptor. This should respect descsz.
*/ */
if (note.n_descsz > sizeof(u_int32_t)) if (note.n_descsz > sizeof(u_int32_t))
warnx("Feature note is bigger than expected."); warnx("Feature note is bigger than expected");
read(fd, features, sizeof(u_int32_t)); read(fd, features, sizeof(u_int32_t));
if (off != NULL) if (off != NULL)
*off = phdr.p_offset + read_total; *off = phdr.p_offset + read_total;
@ -369,6 +369,6 @@ get_file_features(Elf *elf, int phcount, int fd, u_int32_t *features, u_int64_t
} }
} }
warnx("Couldn't find a note header with control feature note."); warnx("NT_FREEBSD_FEATURE_CTL note not found");
return (false); return (false);
} }