From 4d86011a91b7fe05fd5f4d84fa88c19d8c031110 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 26 Oct 2016 20:59:32 +0200 Subject: [PATCH] Various: Simplify code using composite literals. --- src/daemon/common.c | 8 +++----- src/log_logstash.c | 4 +--- src/logfile.c | 5 ++--- src/notify_email.c | 4 +--- src/openldap.c | 2 +- 5 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/daemon/common.c b/src/daemon/common.c index 3d1420d6..208e16dd 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -1620,10 +1620,8 @@ void set_sock_opts (int sockfd) /* {{{ */ int status; int socktype; - socklen_t socklen = sizeof (socklen_t); - int so_keepalive = 1; - - status = getsockopt (sockfd, SOL_SOCKET, SO_TYPE, &socktype, &socklen); + status = getsockopt (sockfd, SOL_SOCKET, SO_TYPE, + &socktype, &(socklen_t) { sizeof (socktype) }); if (status != 0) { WARNING ("set_sock_opts: failed to determine socket type"); @@ -1633,7 +1631,7 @@ void set_sock_opts (int sockfd) /* {{{ */ if (socktype == SOCK_STREAM) { status = setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, - &so_keepalive, sizeof (so_keepalive)); + &(int) {1}, sizeof (int)); if (status != 0) WARNING ("set_sock_opts: failed to set socket keepalive flag"); diff --git a/src/log_logstash.c b/src/log_logstash.c index 08868409..24083a50 100644 --- a/src/log_logstash.c +++ b/src/log_logstash.c @@ -90,7 +90,6 @@ static void log_logstash_print (yajl_gen g, int severity, struct tm timestamp_tm; char timestamp_str[64]; const unsigned char *buf; - time_t tt; #if HAVE_YAJL_V2 size_t len; #else @@ -140,8 +139,7 @@ static void log_logstash_print (yajl_gen g, int severity, yajl_gen_status_ok) goto err; - tt = CDTIME_T_TO_TIME_T (timestamp_time); - gmtime_r (&tt, ×tamp_tm); + gmtime_r (&CDTIME_T_TO_TIME_T (timestamp_time), ×tamp_tm); /* * format time as a UTC ISO 8601 compliant string diff --git a/src/logfile.c b/src/logfile.c index d18a5365..6d555842 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -90,7 +90,6 @@ static void logfile_print (const char *msg, int severity, { FILE *fh; _Bool do_close = 0; - struct tm timestamp_tm; char timestamp_str[64]; char level_str[16] = ""; @@ -120,8 +119,8 @@ static void logfile_print (const char *msg, int severity, if (print_timestamp) { - time_t tt = CDTIME_T_TO_TIME_T (timestamp_time); - localtime_r (&tt, ×tamp_tm); + struct tm timestamp_tm; + localtime_r (&CDTIME_T_TO_TIME_T (timestamp_time), ×tamp_tm); strftime (timestamp_str, sizeof (timestamp_str), "%Y-%m-%d %H:%M:%S", ×tamp_tm); diff --git a/src/notify_email.c b/src/notify_email.c index cefeb22f..dc20cbbe 100644 --- a/src/notify_email.c +++ b/src/notify_email.c @@ -228,7 +228,6 @@ static int notify_email_notification (const notification_t *n, user_data_t __attribute__((unused)) *user_data) { - time_t tt; struct tm timestamp_tm; char timestamp_str[64]; @@ -248,8 +247,7 @@ static int notify_email_notification (const notification_t *n, (email_subject == NULL) ? DEFAULT_SMTP_SUBJECT : email_subject, severity, n->host); - tt = CDTIME_T_TO_TIME_T (n->time); - localtime_r (&tt, ×tamp_tm); + localtime_r (&CDTIME_T_TO_TIME_T (n->time), ×tamp_tm); strftime (timestamp_str, sizeof (timestamp_str), "%Y-%m-%d %H:%M:%S", ×tamp_tm); timestamp_str[sizeof (timestamp_str) - 1] = '\0'; diff --git a/src/openldap.c b/src/openldap.c index d5e58b1a..e100aeed 100644 --- a/src/openldap.c +++ b/src/openldap.c @@ -567,7 +567,7 @@ static int cldap_config_add (oconfig_item_t *ci) /* {{{ */ } st->starttls = 0; - st->timeout = (long) (CDTIME_T_TO_MS(plugin_get_interval()) / 1000); + st->timeout = (long) CDTIME_T_TO_TIME_T(plugin_get_interval()); st->verifyhost = 1; st->version = LDAP_VERSION3; -- 2.30.2