From 8b71cd46f337b493dc3eea0d80e1f47298a07f61 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Tue, 3 May 2016 14:31:50 +0000 Subject: [PATCH] Rework control_open to be cleaner for static analysis. --- control.c | 17 ++++++++--------- control.h | 4 ++-- dhcpcd.c | 18 +++++------------- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/control.c b/control.c index 4c0e3beb..2b1ccc3e 100644 --- a/control.c +++ b/control.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2015 Roy Marples + * Copyright (c) 2006-2016 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -311,22 +311,21 @@ freeit: } int -control_open(struct dhcpcd_ctx *ctx, const char *ifname) +control_open(const char *ifname) { struct sockaddr_un sa; + int fd; - if ((ctx->control_fd = make_sock(&sa, ifname, 0)) != -1) { + if ((fd = make_sock(&sa, ifname, 0)) != -1) { socklen_t len; - int r; len = (socklen_t)SUN_LEN(&sa); - r = connect(ctx->control_fd, (struct sockaddr *)&sa, len); - if (r == -1) { - close(ctx->control_fd); - ctx->control_fd = -1; + if (connect(fd, (struct sockaddr *)&sa, len) == -1) { + close(fd); + fd = -1; } } - return ctx->control_fd; + return fd; } ssize_t diff --git a/control.h b/control.h index 1b5a6197..d3dd85fa 100644 --- a/control.h +++ b/control.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2015 Roy Marples + * Copyright (c) 2006-2016 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -56,7 +56,7 @@ TAILQ_HEAD(fd_list_head, fd_list); int control_start(struct dhcpcd_ctx *, const char *); int control_stop(struct dhcpcd_ctx *); -int control_open(struct dhcpcd_ctx *, const char *); +int control_open(const char *); ssize_t control_send(struct dhcpcd_ctx *, int, char * const *); int control_queue(struct fd_list *fd, char *data, size_t data_len, uint8_t fit); void control_close(struct dhcpcd_ctx *ctx); diff --git a/dhcpcd.c b/dhcpcd.c index 09a5dd03..0e207430 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -1455,12 +1455,6 @@ main(int argc, char **argv) const char *siga = NULL; #endif - int seq; - seq = INT_MAX; - printf ("%d\n", seq); - seq++; - printf ("%u\n", (uint32_t)seq); - /* Test for --help and --version */ if (argc > 1) { if (strcmp(argv[1], "--help") == 0) { @@ -1732,13 +1726,11 @@ printpidfile: !(ctx.options & DHCPCD_TEST)) { #endif - if (ctx.options & DHCPCD_MASTER) - i = -1; - else - i = control_open(&ctx, argv[optind]); - if (i == -1) - i = control_open(&ctx, NULL); - if (i != -1) { + if (!(ctx.options & DHCPCD_MASTER)) + ctx.control_fd = control_open(argv[optind]); + if (ctx.control_fd == -1) + ctx.control_fd = control_open(NULL); + if (ctx.control_fd != -1) { logger(&ctx, LOG_INFO, "sending commands to master dhcpcd process"); len = control_send(&ctx, argc, argv); -- 2.47.3