diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-05-02 08:58:48 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-05-08 06:50:17 +0200 |
commit | 8bd38d645ca2a3bc481a2c1dbfa78fbcb9882378 (patch) | |
tree | 8a3bd431075685a3aa212af743e17dcfe134ea00 /rtemsbsd/rtems/rtems-bsd-shell-dhcpcd.c | |
parent | rc_conf: Do not create directories used by dhcpcd (diff) | |
download | rtems-libbsd-8bd38d645ca2a3bc481a2c1dbfa78fbcb9882378.tar.bz2 |
dhcpcd: Add rtems_dhcpcd_start()
Use it throughout to start the DHCP client (dhcpcd).
Diffstat (limited to '')
-rw-r--r-- | rtemsbsd/rtems/rtems-bsd-shell-dhcpcd.c | 68 |
1 files changed, 65 insertions, 3 deletions
diff --git a/rtemsbsd/rtems/rtems-bsd-shell-dhcpcd.c b/rtemsbsd/rtems/rtems-bsd-shell-dhcpcd.c index 24893748..d02e2f44 100644 --- a/rtemsbsd/rtems/rtems-bsd-shell-dhcpcd.c +++ b/rtemsbsd/rtems/rtems-bsd-shell-dhcpcd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 embedded brains GmbH. All rights reserved. + * Copyright (c) 2013, 2018 embedded brains GmbH. All rights reserved. * * embedded brains GmbH * Dornierstr. 4 @@ -30,11 +30,73 @@ */ #include <rtems/netcmds-config.h> -#include <machine/rtems-bsd-commands.h> + +#include <rtems.h> +#include <rtems/dhcpcd.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +typedef struct { + rtems_dhcpcd_config config; + char *argv[RTEMS_ZERO_LENGTH_ARRAY]; +} dhcpcd_command_config; + +static void +dhcpcd_command_destroy_config(const rtems_dhcpcd_config *config, int exit_code) +{ + char **argv; + + (void)exit_code; + + argv = config->argv; + while (*argv != NULL) { + free(*argv); + ++argv; + } + + free(RTEMS_DECONST(rtems_dhcpcd_config *, config)); +} + +static int +dhcpcd_command(int argc, char **argv) +{ + dhcpcd_command_config *config; + rtems_status_code sc; + int i; + + config = calloc(1, sizeof(*config) + (argc + 1) * sizeof(char *)); + if (config == NULL) { + fprintf(stdout, "dhcpcd error: not enough memory\n"); + return 1; + } + + for (i = 0; i < argc; ++i) { + config->argv[i] = strdup(argv[i]); + if (config->argv[i] == NULL) { + dhcpcd_command_destroy_config(&config->config, 0); + fprintf(stdout, "dhcpcd error: not enough memory\n"); + return 1; + } + } + + config->config.argc = argc; + config->config.argv = &config->argv[0]; + config->config.destroy = dhcpcd_command_destroy_config; + + sc = rtems_dhcpcd_start(&config->config); + if (sc != RTEMS_SUCCESSFUL) { + dhcpcd_command_destroy_config(&config->config, 0); + fprintf(stdout, "dhcpcd start failed: %s\n", rtems_status_text(sc)); + } + + return 0; +} rtems_shell_cmd_t rtems_shell_DHCPCD_Command = { .name = "dhcpcd", .usage = "dhcpcd [args]", .topic = "net", - .command = rtems_bsd_command_dhcpcd + .command = dhcpcd_command }; |