diff options
author | Rob Austein <sra@hactrn.net> | 2016-07-07 12:27:37 -0400 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2016-07-07 12:27:37 -0400 |
commit | c5bbdc94037efa5050ad32454509bc1c366c288f (patch) | |
tree | 3fa6878d0574a6176dfead6651cdcfdaea23d002 | |
parent | 90835dcbe717824146e68cc686387546f0e45cfc (diff) |
Use environment variables rather than wired-in defaults in cryptech_rpcd.
This change allows the RPC MUX daemon to use the same environment
variable scheme to configure the RPC device and line speed as the
stand-alone RPC client code does, the only difference being that the
daemon, being an independent program, still allows one to override
these settings from the command line.
-rw-r--r-- | daemon.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -34,6 +34,7 @@ */ #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <sys/un.h> @@ -143,8 +144,15 @@ int main(int argc, char *argv[]) int lsock; int dsock; int opt; - const char *device = HAL_CLIENT_SERIAL_DEFAULT_DEVICE; - uint32_t speed = HAL_CLIENT_SERIAL_DEFAULT_SPEED; + const char *device = getenv(HAL_CLIENT_SERIAL_DEVICE_ENVVAR); + const char *speed_ = getenv(HAL_CLIENT_SERIAL_SPEED_ENVVAR); + uint32_t speed = HAL_CLIENT_SERIAL_DEFAULT_SPEED; + + if (device == NULL) + device = HAL_CLIENT_SERIAL_DEFAULT_DEVICE; + + if (speed_ != NULL) + speed = (uint32_t) strtoul(speed_, NULL, 10); while ((opt = getopt(argc, argv, "hn:d:s:")) != -1) { switch (opt) { @@ -158,7 +166,8 @@ int main(int argc, char *argv[]) device = optarg; break; case 's': - switch (atoi(optarg)) { + speed = (uint32_t) strtoul(optarg, NULL, 10); + switch (speed) { case 115200: case 921600: break; |