Changeset b2eb48c in rtems-libbsd
- Timestamp:
- 05/02/18 07:01:32 (6 years ago)
- Branches:
- 5, 5-freebsd-12, 6-freebsd-12, master
- Children:
- e1d62e8
- Parents:
- 8bd38d6
- git-author:
- Sebastian Huber <sebastian.huber@…> (05/02/18 07:01:32)
- git-committer:
- Sebastian Huber <sebastian.huber@…> (05/08/18 05:37:17)
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
dhcpcd/dhcpcd.c
r8bd38d6 rb2eb48c 1600 1600 exit(EXIT_SUCCESS); 1601 1601 } 1602 #ifdef __rtems__ 1603 int 1604 dhcpcd_script_runreason_do_nothing(const struct interface *ifp, 1605 const char *reason) 1606 { 1607 return 0; 1608 } 1609 1610 /* 1611 * Do not pull in the script support if it is not used, e.g. no call to 1612 * rtems_dhcpcd_add_hook() is present. 1613 */ 1614 __weak_reference(dhcpcd_script_runreason_do_nothing, dhcpcd_script_runreason); 1615 #endif /* __rtems__ */ -
dhcpcd/namespace.h
r8bd38d6 rb2eb48c 157 157 #define read_config dhcpcd_read_config 158 158 #define read_lease dhcpcd_read_lease 159 #define script_runreason dhcpcd_script_runreason 159 160 #define select_profile dhcpcd_select_profile 160 161 #define set_cloexec dhcpcd_set_cloexec -
dhcpcd/script.c
r8bd38d6 rb2eb48c 52 52 #include "net.h" 53 53 #include "script.h" 54 54 #ifdef __rtems__ 55 #include <rtems/dhcpcd.h> 56 57 static SLIST_HEAD(, rtems_dhcpcd_hook) dhcpcd_hooks = 58 SLIST_HEAD_INITIALIZER(dhcpcd_hooks); 59 60 void 61 rtems_dhcpcd_add_hook(rtems_dhcpcd_hook *hook) 62 { 63 rtems_recursive_mutex_lock(&dhcpcd_mutex); 64 SLIST_INSERT_HEAD(&dhcpcd_hooks, hook, node); 65 rtems_recursive_mutex_unlock(&dhcpcd_mutex); 66 } 67 68 void 69 rtems_dhcpcd_remove_hook(rtems_dhcpcd_hook *hook) 70 { 71 rtems_recursive_mutex_lock(&dhcpcd_mutex); 72 SLIST_REMOVE(&dhcpcd_hooks, hook, rtems_dhcpcd_hook, node); 73 rtems_recursive_mutex_unlock(&dhcpcd_mutex); 74 } 75 #endif /* __rtems__ */ 76 77 #ifndef __rtems__ 55 78 #define DEFAULT_PATH "PATH=/usr/bin:/usr/sbin:/bin:/sbin" 56 79 … … 105 128 return pid; 106 129 } 130 #endif /* __rtems__ */ 107 131 108 132 #ifdef INET … … 169 193 #endif 170 194 195 #ifndef __rtems__ 171 196 static size_t 172 197 arraytostr(const char *const *argv, char **s) … … 192 217 return len; 193 218 } 219 #endif /* __rtems__ */ 194 220 195 221 static ssize_t … … 436 462 } 437 463 464 #ifndef __rtems__ 438 465 static int 439 466 send_interface1(int fd, const struct interface *iface, const char *reason) … … 508 535 return retval; 509 536 } 537 #endif /* __rtems__ */ 510 538 511 539 int 512 540 script_runreason(const struct interface *ifp, const char *reason) 513 541 { 542 #ifndef __rtems__ 514 543 char *const argv[2] = { UNCONST(ifp->options->script), NULL }; 544 #endif /* __rtems__ */ 515 545 char **env = NULL, **ep; 546 #ifndef __rtems__ 516 547 char *path, *bigenv; 517 548 ssize_t e, elen = 0; 518 549 pid_t pid; 550 #else /* __rtems__ */ 551 ssize_t elen; 552 rtems_dhcpcd_hook *hook; 553 rtems_dhcpcd_hook *hook2; 554 #endif /* __rtems__ */ 519 555 int status = 0; 556 #ifndef __rtems__ 520 557 const struct fd_list *fd; 521 558 struct iovec iov[2]; 559 #endif /* __rtems__ */ 522 560 523 561 if (ifp->options->script == NULL || … … 526 564 return 0; 527 565 566 #ifndef __rtems__ 528 567 syslog(LOG_DEBUG, "%s: executing `%s' %s", 529 568 ifp->name, argv[0], reason); 569 #endif /* __rtems__ */ 530 570 531 571 /* Make our env */ 532 572 elen = make_env(ifp, reason, &env); 573 #ifndef __rtems__ 533 574 ep = realloc(env, sizeof(char *) * (elen + 2)); 534 575 if (ep == NULL) { … … 597 638 598 639 out: 640 #else /* __rtems__ */ 641 rtems_recursive_mutex_lock(&dhcpcd_mutex); 642 643 SLIST_FOREACH_SAFE(hook, &dhcpcd_hooks, node, hook2) { 644 syslog(LOG_DEBUG, "%s: executing `%s' %s", ifp->name, 645 hook->name, reason); 646 (*hook->handler)(hook, env); 647 } 648 649 rtems_recursive_mutex_unlock(&dhcpcd_mutex); 650 #endif /* __rtems__ */ 599 651 /* Cleanup */ 600 652 ep = env; -
dhcpcd/script.h
r8bd38d6 rb2eb48c 34 34 #ifndef __rtems__ 35 35 int send_interface(int, const struct interface *); 36 int script_runreason(const struct interface *, const char *);37 36 #else /* __rtems__ */ 38 37 static inline int send_interface(int fd, const struct interface *iface) … … 40 39 return 0; 41 40 } 42 static inline int script_runreason(const struct interface *ifp, const char *reason)43 {44 return 0;45 }46 41 #endif /* __rtems__ */ 42 int script_runreason(const struct interface *, const char *); 47 43 48 44 #endif -
libbsd.py
r8bd38d6 rb2eb48c 4554 4554 'dhcpcd/net.c', 4555 4555 'dhcpcd/platform-bsd.c', 4556 'dhcpcd/script.c', 4556 4557 'dhcpcd/compat/pselect.c', 4557 4558 'dhcpcd/crypt/hmac_md5.c', -
rtemsbsd/include/rtems/dhcpcd.h
r8bd38d6 rb2eb48c 41 41 #define _RTEMS_DHCPCD_H_ 42 42 43 #include <sys/cdefs.h> 44 #include <sys/queue.h> 45 43 46 #include <rtems.h> 44 47 … … 76 79 rtems_status_code rtems_dhcpcd_start(const rtems_dhcpcd_config *config); 77 80 81 typedef struct rtems_dhcpcd_hook { 82 SLIST_ENTRY(rtems_dhcpcd_hook) node; 83 const char *name; 84 void (*handler)(struct rtems_dhcpcd_hook *hook, char *const *env); 85 } rtems_dhcpcd_hook; 86 87 /** 88 * @brief Adds a DHCP client hook. 89 * 90 * The hook handler is invoked with an environment list (NULL terminated) of 91 * strings ('\0' terminated). Each string of the environment list has usually 92 * the format "key=value", e.g. "interface=eth0", "reason=BOUND". 93 * 94 * The hook handler are called by the DHCP client task. It is safe to 95 * add/remove hooks in the hook handler. 96 */ 97 void rtems_dhcpcd_add_hook(rtems_dhcpcd_hook *hook); 98 99 /** 100 * @brief Removes a DHCP client hook. 101 */ 102 void rtems_dhcpcd_remove_hook(rtems_dhcpcd_hook *hook); 103 78 104 /** @} */ 79 105 -
testsuite/dhcpcd01/test_main.c
r8bd38d6 rb2eb48c 1 1 /* 2 * Copyright (c) 2013 -2014embedded brains GmbH. All rights reserved.2 * Copyright (c) 2013, 2018 embedded brains GmbH. All rights reserved. 3 3 * 4 4 * embedded brains GmbH … … 31 31 32 32 #include <assert.h> 33 #include <stdio.h> 33 34 34 35 #include <rtems.h> 36 #include <rtems/dhcpcd.h> 35 37 36 38 #define TEST_NAME "LIBBSD DHCPCD 1" 37 39 38 40 static void 41 dhcpcd_hook_handler(rtems_dhcpcd_hook *hook, char *const *env) 42 { 43 44 (void)hook; 45 46 while (*env != NULL) { 47 printf("%s\n", *env); 48 ++env; 49 } 50 } 51 52 static rtems_dhcpcd_hook dhcpcd_hook = { 53 .name = "test", 54 .handler = dhcpcd_hook_handler 55 }; 56 57 static void 39 58 test_main(void) 40 59 { 60 61 rtems_dhcpcd_add_hook(&dhcpcd_hook); 62 41 63 rtems_task_delete(RTEMS_SELF); 42 64 assert(0);
Note: See TracChangeset
for help on using the changeset viewer.