Skip to content

Commit

Permalink
Clean up usage and error reporting output
Browse files Browse the repository at this point in the history
- Shorten/clean up some error messages
- Usage syntax should go to stderr like most BSD programs
- Make usage syntax use a single fprintf() call
- Use warnx() instead of warn() where applicable
- Use warnx() instead of printf() in some scenarios; these messages
  will now go to stderr instead of stdout
- Reflect the above changes in the man page
  • Loading branch information
koitsu committed Dec 21, 2017
1 parent 813b283 commit 64fac5c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions bsdhwmon.8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.Dd January 21, 2016
.Dd December 21, 2017
.Dt BSDHWMON 8
.Os
.Sh NAME
Expand All @@ -14,7 +14,7 @@ is a user-land application which communicates via SMBus with hardware
monitoring ICs on motherboards. Many different pieces of information
can be returned, but the most common are fan RPMs, processor and system
temperatures, and motherboard voltages. All data is sent to standard
output.
output. Usage syntax and all errors are sent to standard error.
.Pp
At this time,
.Nm
Expand Down
4 changes: 2 additions & 2 deletions bsdhwmon.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DESCRIPTION
hardware monitoring ICs on motherboards. Many different pieces of infor-
mation can be returned, but the most common are fan RPMs, processor and
system temperatures, and motherboard voltages. All data is sent to stan-
dard output.
dard output. Usage syntax and all errors are sent to standard error.

At this time, bsdhwmon supports a multitude of Winbond hardware monitor-
ing ICs, predominantly on Supermicro motherboards.
Expand Down Expand Up @@ -149,4 +149,4 @@ CONTRIBUTORS
lm_sensors project, for providing an unofficial secondary source of IC
documentation and details of chip quirks.

FreeBSD 9.3 January 21, 2016 FreeBSD 9.3
FreeBSD 9.3 December 21, 2017 FreeBSD 9.3
41 changes: 21 additions & 20 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,20 @@ VERBOSE(const char *fmt, ...)
static void
USAGE(void)
{
printf("Usage: bsdhwmon [options]\n");
printf("\n");
printf("Options:\n");
printf(" -J JSON-formatted output\n");
printf(" -c comma-delimited output\n");
printf(" -f DEVICE use DEVICE as smb(4) device (default: " DEFAULT_SMBDEV ")\n");
printf(" -l list supported motherboard ID strings\n");
printf(" -h print this message\n");
printf(" -v be verbose (show debugging output)\n");
printf("\n");
printf("https://github.com/koitsu/bsdhwmon\n");
printf("Report bugs at https://github.com/koitsu/bsdhwmon/issues\n");
fprintf(stderr,
"Usage: bsdhwmon [options]\n"
"\n"
"Options:\n"
" -J JSON-formatted output\n"
" -c comma-delimited output\n"
" -f DEVICE use DEVICE as smb(4) device (default: " DEFAULT_SMBDEV ")\n"
" -l list supported motherboard ID strings\n"
" -h print this message\n"
" -v be verbose (show debugging output)\n"
"\n"
"https://github.com/koitsu/bsdhwmon\n"
"Report bugs at https://github.com/koitsu/bsdhwmon/issues\n"
);
exit(EX_USAGE);
}

Expand Down Expand Up @@ -129,7 +131,7 @@ main(int argc, char *argv[])
break;
case 'f':
if (strlcpy(smbdev, optarg, MAXPATHLEN) >= MAXPATHLEN) {
warn("Device pathname exceeds %u bytes in length", MAXPATHLEN);
warnx("Device pathname exceeds %u bytes in length", MAXPATHLEN);
exitcode = EX_SOFTWARE;
goto finish;
}
Expand All @@ -154,7 +156,7 @@ main(int argc, char *argv[])
* bsdhwmon requires root access due to opening /dev/smbX
*/
if (geteuid() != 0) {
warn("Must be run as root, or setuid root");
warnx("Must be run as root, or setuid root");
exitcode = EX_NOPERM;
goto finish;
}
Expand All @@ -163,7 +165,7 @@ main(int argc, char *argv[])
* Do some basic argument conflict checking
*/
if (comma_output && json_output) {
warn("Please choose only one output format");
warnx("Please choose only one output format");
exitcode = EX_USAGE;
goto finish;
}
Expand Down Expand Up @@ -202,7 +204,7 @@ main(int argc, char *argv[])
}

if ((mb = board_lookup(maker, product)) == NULL) {
printf("Your motherboard does not appear to be supported. Please visit\n"
warnx("Your motherboard does not appear to be supported. Please visit\n"
"https://github.com/koitsu/bsdhwmon to see if support for your motherboard\n"
"and/or system is under development.\n");
exitcode = EX_DATAERR;
Expand Down Expand Up @@ -244,8 +246,7 @@ main(int argc, char *argv[])
ret = w83793g_main(smbfd, mb->slave, sdata);
break;
default:
printf("Internal bsdhwmon coding error. Please report this bug\n"
"to the bsdhwmon author.\n");
warnx("Internal error. Please report this bug to the author.");
exitcode = EX_SOFTWARE;
goto finish;
}
Expand All @@ -255,9 +256,9 @@ main(int argc, char *argv[])
* validation passed, etc.).
*/
if (ret != 0) {
printf("Your motherboard is supported, but H/W chip verification failed.\n"
warnx("Your motherboard is supported, but H/W chip verification failed.\n"
"Please re-run bsdhwmon with the -v flag and send full output + bug\n"
"report to the bsdhwmon author.\n");
"report to the author.");
exitcode = EX_SOFTWARE;
goto finish;
}
Expand Down

0 comments on commit 64fac5c

Please sign in to comment.