]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Rework control_open to be cleaner for static analysis.
authorRoy Marples <roy@marples.name>
Tue, 3 May 2016 14:31:50 +0000 (14:31 +0000)
committerRoy Marples <roy@marples.name>
Tue, 3 May 2016 14:31:50 +0000 (14:31 +0000)
control.c
control.h
dhcpcd.c

index 4c0e3beb0f6ef4130a5c0ed4e43f676c751b3cab..2b1ccc3e2bbf8030317316a6dee2ca46e89c718a 100644 (file)
--- a/control.c
+++ b/control.c
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2015 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2016 Roy Marples <roy@marples.name>
  * 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
index 1b5a61973a5f7a588a7b6ed1e28016cf45925d6d..d3dd85fa649a7f91e3b5377d1a46e09fa7ce87ea 100644 (file)
--- a/control.h
+++ b/control.h
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2015 Roy Marples <roy@marples.name>
+ * Copyright (c) 2006-2016 Roy Marples <roy@marples.name>
  * 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);
index 09a5dd0335c4e2c32324472bd1eb511433bcd64e..0e207430e05f79b0ad3147f45ba26dd023e6c977 100644 (file)
--- 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);