[This diff is very similar to one I sent previously off-list to a few.]
Just some style(9) and simple cleanup:
- order getopt string and switch cases
- add space between "if" and "("
- wrap a long line
- return rather than exit() from main()
- move chngdir == NULL test to where it belongs
Questions:
- is there any reason
404 /* Jail: sandbox, file-system, user. */
405
406 if (pledge("stdio", NULL) == -1) {
407 warn("pledge");
408 exit(EXIT_FAILURE);
409 }
410
shouldn't just use err() ?
If so, then the exit() should still be return, shouldn't it?
- should the exit() calls from the various forked child processes
be _exit()?
Index: main.c
===================================================================
RCS file: /cvs/src/usr.sbin/acme-client/main.c,v
retrieving revision 1.36
diff -u -p -r1.36 main.c
--- main.c 27 Nov 2017 01:58:52 -0000 1.36
+++ main.c 30 Jul 2018 01:12:45 -0000
@@ -56,21 +56,24 @@ main(int argc, char *argv[])
struct domain_c *domain = NULL;
struct altname_c *ac;
- while ((c = getopt(argc, argv, "FADrvnf:")) != -1)
+ while ((c = getopt(argc, argv, "ADFf:nrv")) != -1)
switch (c) {
- case 'f':
- if ((conffile = strdup(optarg)) == NULL)
- err(EXIT_FAILURE, "strdup");
- break;
- case 'F':
- force = 1;
- break;
case 'A':
popts |= ACME_OPT_NEWACCT;
break;
case 'D':
popts |= ACME_OPT_NEWDKEY;
break;
+ case 'F':
+ force = 1;
+ break;
+ case 'f':
+ if ((conffile = strdup(optarg)) == NULL)
+ err(EXIT_FAILURE, "strdup");
+ break;
+ case 'n':
+ popts |= ACME_OPT_CHECK;
+ break;
case 'r':
revocate = 1;
break;
@@ -78,9 +81,6 @@ main(int argc, char *argv[])
verbose = verbose ? 2 : 1;
popts |= ACME_OPT_VERBOSE;
break;
- case 'n':
- popts |= ACME_OPT_CHECK;
- break;
default:
goto usage;
}
@@ -90,7 +90,7 @@ main(int argc, char *argv[])
/* parse config file */
if ((conf = parse_config(conffile, popts)) == NULL)
- exit(EXIT_FAILURE);
+ return EXIT_FAILURE;
argc -= optind;
argv += optind;
@@ -127,7 +127,7 @@ main(int argc, char *argv[])
err(EXIT_FAILURE, "basename");
}
- if(domain->chain != NULL) {
+ if (domain->chain != NULL) {
if ((chainfile = basename(domain->chain)) != NULL) {
if ((chainfile = strdup(chainfile)) == NULL)
err(EXIT_FAILURE, "strdup");
@@ -135,7 +135,7 @@ main(int argc, char *argv[])
err(EXIT_FAILURE, "basename");
}
- if(domain->fullchain != NULL) {
+ if (domain->fullchain != NULL) {
if ((fullchainfile = basename(domain->fullchain)) != NULL) {
if ((fullchainfile = strdup(fullchainfile)) == NULL)
err(EXIT_FAILURE, "strdup");
@@ -160,14 +160,12 @@ main(int argc, char *argv[])
/* XXX replace with existance check in parse.y */
err(EXIT_FAILURE, "no account key in config?");
}
- if (domain->challengedir == NULL)
- chngdir = strdup(WWW_DIR);
- else
+ if (domain->challengedir == NULL) {
+ if ((chngdir = strdup(WWW_DIR)) == NULL)
+ err(EXIT_FAILURE, "strdup");
+ } else
chngdir = domain->challengedir;
- if (chngdir == NULL)
- err(EXIT_FAILURE, "strdup");
-
/*
* Do some quick checks to see if our paths exist.
* This will be done in the children, but we might as well check
@@ -185,7 +183,8 @@ main(int argc, char *argv[])
if (!(popts & ACME_OPT_NEWDKEY) && access(domain->key, R_OK) == -1) {
warnx("%s: domain key file must exist", domain->key);
ne++;
- } else if ((popts & ACME_OPT_NEWDKEY) && access(domain->key, R_OK) !=
-1) {
+ } else if ((popts & ACME_OPT_NEWDKEY) && access(domain->key, R_OK)
+ != -1) {
dodbg("%s: domain key exists (not creating)", domain->key);
popts &= ~ACME_OPT_NEWDKEY;
}
@@ -204,10 +203,10 @@ main(int argc, char *argv[])
}
if (ne > 0)
- exit(EXIT_FAILURE);
+ return EXIT_FAILURE;
if (popts & ACME_OPT_CHECK)
- exit(EXIT_SUCCESS);
+ return EXIT_SUCCESS;
/* Set the zeroth altname as our domain. */
altsz = domain->altname_count + 1;