diff options
| author | David M. Syzdek <david.syzdek@acsalaska.com> | 2020-02-10 12:50:03 -0900 |
|---|---|---|
| committer | David M. Syzdek <david.syzdek@acsalaska.com> | 2020-02-10 12:50:03 -0900 |
| commit | 8d9fe26f2fcdd70e2ec2f6ab74da3f8633b82873 (patch) | |
| tree | fd96159bad9f78ca44078ec5d4a92f8a45097732 /src/akcom-udpechod.c | |
| parent | 744814d80bf3d96b41de46a0e0796f99597983dd (diff) | |
| download | akcom-udpecho-8d9fe26f2fcdd70e2ec2f6ab74da3f8633b82873.tar.gz akcom-udpecho-8d9fe26f2fcdd70e2ec2f6ab74da3f8633b82873.tar.bz2 akcom-udpecho-8d9fe26f2fcdd70e2ec2f6ab74da3f8633b82873.tar.xz akcom-udpecho-8d9fe26f2fcdd70e2ec2f6ab74da3f8633b82873.zip | |
akcom-udpechod: replacing delay struct member with static variable
Diffstat (limited to '')
| -rw-r--r-- | src/akcom-udpechod.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/akcom-udpechod.c b/src/akcom-udpechod.c index a74aa78..8424efb 100644 --- a/src/akcom-udpechod.c +++ b/src/akcom-udpechod.c | |||
| @@ -148,7 +148,6 @@ static int should_stop = 0; | |||
| 148 | 148 | ||
| 149 | struct app_config | 149 | struct app_config |
| 150 | { | 150 | { |
| 151 | useconds_t delay; // Delay range in microseconds | ||
| 152 | int32_t verbose; // runtime verbosity | 151 | int32_t verbose; // runtime verbosity |
| 153 | int facility; // syslog facility | 152 | int facility; // syslog facility |
| 154 | int dont_fork; | 153 | int dont_fork; |
| @@ -158,7 +157,6 @@ struct app_config | |||
| 158 | }; | 157 | }; |
| 159 | static struct app_config cnf = | 158 | static struct app_config cnf = |
| 160 | { | 159 | { |
| 161 | .delay = 0, | ||
| 162 | .verbose = 0, | 160 | .verbose = 0, |
| 163 | .facility = LOG_DAEMON, | 161 | .facility = LOG_DAEMON, |
| 164 | .dont_fork = 0, | 162 | .dont_fork = 0, |
| @@ -171,6 +169,7 @@ static const char * cnf_pidfile = "/var/run/" PROGRAM_NAME ".pid"; | |||
| 171 | static uint16_t cnf_port = 30006; | 169 | static uint16_t cnf_port = 30006; |
| 172 | static int cnf_echoplus = 0; | 170 | static int cnf_echoplus = 0; |
| 173 | static int cnf_drop_perct = 0; | 171 | static int cnf_drop_perct = 0; |
| 172 | static useconds_t cnf_delay = 0; // Delay range in microseconds | ||
| 174 | 173 | ||
| 175 | 174 | ||
| 176 | ////////////////// | 175 | ////////////////// |
| @@ -276,7 +275,7 @@ int main(int argc, char * argv[]) | |||
| 276 | break; | 275 | break; |
| 277 | 276 | ||
| 278 | case 'D': | 277 | case 'D': |
| 279 | cnf.delay = (useconds_t)atoll(optarg); | 278 | cnf_delay = (useconds_t)atoll(optarg); |
| 280 | break; | 279 | break; |
| 281 | 280 | ||
| 282 | case 'e': | 281 | case 'e': |
| @@ -680,7 +679,7 @@ int my_daemonize(void) | |||
| 680 | openlog(prog_name, LOG_PID | (((cnf.dont_fork)) ? LOG_PERROR : 0), cnf.facility); | 679 | openlog(prog_name, LOG_PID | (((cnf.dont_fork)) ? LOG_PERROR : 0), cnf.facility); |
| 681 | syslog(LOG_NOTICE, "%s v%s", PROGRAM_NAME, PACKAGE_VERSION); | 680 | syslog(LOG_NOTICE, "%s v%s", PROGRAM_NAME, PACKAGE_VERSION); |
| 682 | syslog(LOG_NOTICE, "echo plus enabled: %s", ((cnf_echoplus)) ? "yes" : "no"); | 681 | syslog(LOG_NOTICE, "echo plus enabled: %s", ((cnf_echoplus)) ? "yes" : "no"); |
| 683 | syslog(LOG_NOTICE, "random delay: %u us", cnf.delay); | 682 | syslog(LOG_NOTICE, "random delay: %u us", cnf_delay); |
| 684 | syslog(LOG_NOTICE, "drop probability: %u%%", cnf_drop_perct); | 683 | syslog(LOG_NOTICE, "drop probability: %u%%", cnf_drop_perct); |
| 685 | syslog(LOG_NOTICE, "running as UID: %u", getuid()); | 684 | syslog(LOG_NOTICE, "running as UID: %u", getuid()); |
| 686 | syslog(LOG_NOTICE, "running as GID: %u", getgid()); | 685 | syslog(LOG_NOTICE, "running as GID: %u", getgid()); |
| @@ -867,9 +866,9 @@ int my_loop(int s, size_t * connp) | |||
| 867 | 866 | ||
| 868 | // insert random delay | 867 | // insert random delay |
| 869 | delay = 0; | 868 | delay = 0; |
| 870 | if (cnf.delay > 0) | 869 | if (cnf_delay > 0) |
| 871 | { | 870 | { |
| 872 | delay = (useconds_t)rand() % cnf.delay; | 871 | delay = (useconds_t)rand() % cnf_delay; |
| 873 | syslog(LOG_DEBUG, "conn %zu: delaying response for %i us", *connp, delay); | 872 | syslog(LOG_DEBUG, "conn %zu: delaying response for %i us", *connp, delay); |
| 874 | usleep(delay); | 873 | usleep(delay); |
| 875 | }; | 874 | }; |
| @@ -911,7 +910,7 @@ void my_usage(void) | |||
| 911 | printf("Usage: %s [options]\n", prog_name); | 910 | printf("Usage: %s [options]\n", prog_name); |
| 912 | printf("OPTIONS:\n"); | 911 | printf("OPTIONS:\n"); |
| 913 | printf(" -d num, --drop=num set packet drop probability [0-99] (default: %u)\n", cnf_drop_perct); | 912 | printf(" -d num, --drop=num set packet drop probability [0-99] (default: %u)\n", cnf_drop_perct); |
| 914 | printf(" -D usec, --delay=usec set echo delay range to microseconds (default: %u us)\n", cnf.delay); | 913 | printf(" -D usec, --delay=usec set echo delay range to microseconds (default: %u us)\n", cnf_delay); |
| 915 | printf(" -e, --echoplus enable echo plus, not RFC compliant%s\n", ((cnf_echoplus)) ? " (default)" : ""); | 914 | printf(" -e, --echoplus enable echo plus, not RFC compliant%s\n", ((cnf_echoplus)) ? " (default)" : ""); |
| 916 | printf(" -f str, --facility=str set syslog facility (default: daemon)\n"); | 915 | printf(" -f str, --facility=str set syslog facility (default: daemon)\n"); |
| 917 | printf(" -g gid, --group=gid setgid to gid (default: none)\n"); | 916 | printf(" -g gid, --group=gid setgid to gid (default: none)\n"); |
