Changeset 8bd38d6 in rtems-libbsd for rtemsbsd/rtems/rtems-bsd-rc-conf-net.c


Ignore:
Timestamp:
May 2, 2018, 6:58:48 AM (13 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
5cb01f277962d3127d364bf871f799b34e6b6be6, 9a4ed64d5acc20cd3488a633bd78cad7d1708081
Children:
b2eb48c
Parents:
bd09f9f
git-author:
Sebastian Huber <sebastian.huber@…> (05/02/18 06:58:48)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/08/18 04:50:17)
Message:

dhcpcd: Add rtems_dhcpcd_start()

Use it throughout to start the DHCP client (dhcpcd).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rtemsbsd/rtems/rtems-bsd-rc-conf-net.c

    rbd09f9f r8bd38d6  
    6262
    6363#include <rtems/rtems-routes.h>
     64#include <rtems/dhcpcd.h>
    6465
    6566/*
     
    628629 */
    629630typedef struct dhcpcd_data {
     631  rtems_dhcpcd_config          config;
    630632  rtems_bsd_rc_conf_argc_argv* argc_argv;
    631633  bool                         verbose;
     
    634636
    635637static void
    636 dhcpcd_worker(rtems_task_argument arg)
    637 {
    638   dhcpcd_data*  dd = (dhcpcd_data*) arg;
    639   int           argc;
    640   const char**  argv;
    641   const char*   dhcpcd_argv[] = { "dhcpcd", NULL };
    642   int           r;
    643 
    644   if (dd->argc_argv->argc > 0) {
    645     argc = dd->argc_argv->argc;
    646     argv = dd->argc_argv->argv;
    647   }
    648   else {
    649     argc = 1;
    650     argv = dhcpcd_argv;
    651   }
     638dhcpcd_prepare(const rtems_dhcpcd_config *config, int argc, char **argv)
     639{
     640  const dhcpcd_data* dd = (const dhcpcd_data*) config;
    652641
    653642  if (dd->verbose) {
     643    int r;
     644
    654645    fprintf(stdout, "rc.conf: %s: dhcpcd ", dd->name);
    655646    for (r = 1; r < argc; ++r)
     
    657648    fprintf(stdout, "\n");
    658649  }
    659 
    660   r = rtems_bsd_command_dhcpcd(argc, argv);
    661   if (r != EX_OK)
     650}
     651
     652static void
     653dhcpcd_destroy(const rtems_dhcpcd_config *config, int exit_code)
     654{
     655  dhcpcd_data* dd = (dhcpcd_data*) config;
     656
     657  if (exit_code != EX_OK)
    662658    fprintf(stderr, "error: dhcpcd: stopped\n");
    663659
     
    665661  rtems_bsd_rc_conf_argc_argv_destroy(dd->argc_argv);
    666662  free(dd);
    667 
    668   rtems_task_delete(RTEMS_SELF);
    669663}
    670664
     
    674668  dhcpcd_data*        dd;
    675669  rtems_status_code   sc;
    676   rtems_id            id;
    677   rtems_task_priority priority = RTEMS_MAXIMUM_PRIORITY - 1;
     670  rtems_task_priority priority = 0;
    678671  char*               end = NULL;
    679672  int                 r;
     
    712705    if (dd->argc_argv->argc == 2) {
    713706      priority = strtoul(dd->argc_argv->argv[1], &end, 10);
    714       if (priority == 0 || *end != '\0')
    715         priority = RTEMS_MAXIMUM_PRIORITY - 1;
    716     }
    717   }
     707      if (*end != '\0')
     708        priority = 0;
     709    }
     710  }
     711  dd->config.priority = priority;
    718712
    719713  rtems_bsd_rc_conf_find(rc_conf, "dhcpcd_options", dd->argc_argv);
    720714
    721   sc = rtems_task_create(rtems_build_name('D', 'H', 'C', 'P'),
    722                          priority,
    723                          2 * RTEMS_MINIMUM_STACK_SIZE,
    724                          RTEMS_DEFAULT_MODES,
    725                          RTEMS_FLOATING_POINT,
    726                          &id);
    727   if (sc == RTEMS_SUCCESSFUL)
    728     sc = rtems_task_start(id, dhcpcd_worker, (rtems_task_argument) dd);
     715  if (dd->argc_argv->argc > 0) {
     716    dd->config.argc = dd->argc_argv->argc;
     717    dd->config.argv = dd->argc_argv->argv;
     718  }
     719
     720  dd->config.prepare = dhcpcd_prepare;
     721  dd->config.destroy = dhcpcd_destroy;
     722
     723  sc = rtems_dhcpcd_start(&dd->config);
    729724  if (sc != RTEMS_SUCCESSFUL) {
    730725    fprintf(stderr,
Note: See TracChangeset for help on using the changeset viewer.