mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-07-23 05:31:54 +08:00
IFCONFIG(8): Initialize global variables in ctors
This commit is contained in:
parent
8ff186f81f
commit
60618d5332
@ -169,9 +169,17 @@ static struct afswtch af_atalk = {
|
||||
.af_addreq = &at_addreq,
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static __constructor void
|
||||
#else /* __rtems__ */
|
||||
void
|
||||
#endif /* __rtems__ */
|
||||
atalk_ctor(void)
|
||||
{
|
||||
#ifdef __rtems__
|
||||
memset(&at_nr, 0, sizeof(at_nr));
|
||||
memset(&at_addreq, 0, sizeof(at_addreq));
|
||||
#endif /* __rtems__ */
|
||||
#define N(a) (sizeof(a) / sizeof(a[0]))
|
||||
size_t i;
|
||||
|
||||
|
@ -197,8 +197,16 @@ static struct afswtch af_inet = {
|
||||
.af_addreq = &in_addreq,
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static __constructor void
|
||||
#else /* __rtems__ */
|
||||
void
|
||||
#endif /* __rtems__ */
|
||||
inet_ctor(void)
|
||||
{
|
||||
#ifdef __rtems__
|
||||
memset(&in_addreq, 0, sizeof(in_addreq));
|
||||
memset(&in_ridreq, 0, sizeof(in_ridreq));
|
||||
#endif /* __rtems__ */
|
||||
af_register(&af_inet);
|
||||
}
|
||||
|
@ -533,9 +533,22 @@ in6_Lopt_cb(const char *optarg __unused)
|
||||
}
|
||||
static struct option in6_Lopt = { .opt = "L", .opt_usage = "[-L]", .cb = in6_Lopt_cb };
|
||||
|
||||
#ifndef __rtems__
|
||||
static __constructor void
|
||||
#else /* __rtems__ */
|
||||
void
|
||||
#endif /* __rtems__ */
|
||||
inet6_ctor(void)
|
||||
{
|
||||
#ifdef __rtems__
|
||||
memset(&in6_ridreq, 0, sizeof(in6_ridreq));
|
||||
memset(&in6_addreq, 0, sizeof(in6_addreq));
|
||||
in6_addreq.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
|
||||
in6_addreq.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
|
||||
ip6lifetime = 0;
|
||||
explicit_prefix = 0;
|
||||
memset(&addr_buf, 0, sizeof(addr_buf));
|
||||
#endif /* __rtems__ */
|
||||
#define N(a) (sizeof(a) / sizeof(a[0]))
|
||||
size_t i;
|
||||
|
||||
|
@ -120,9 +120,16 @@ static struct afswtch af_lladdr = {
|
||||
.af_addreq = &link_ridreq,
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static __constructor void
|
||||
#else /* __rtems__ */
|
||||
void
|
||||
#endif /* __rtems__ */
|
||||
link_ctor(void)
|
||||
{
|
||||
#ifdef __rtems__
|
||||
memset(&link_ridreq, 0, sizeof(link_ridreq));
|
||||
#endif /* __rtems__ */
|
||||
af_register(&af_link);
|
||||
af_register(&af_ether);
|
||||
af_register(&af_lladdr);
|
||||
|
@ -222,7 +222,11 @@ static struct afswtch af_nd6 = {
|
||||
.af_other_status= nd6_status,
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static __constructor void
|
||||
#else /* __rtems__ */
|
||||
void
|
||||
#endif /* __rtems__ */
|
||||
nd6_ctor(void)
|
||||
{
|
||||
af_register(&af_nd6);
|
||||
|
@ -746,7 +746,11 @@ static struct afswtch af_bridge = {
|
||||
.af_other_status = bridge_status,
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static __constructor void
|
||||
#else /* __rtems__ */
|
||||
void
|
||||
#endif /* __rtems__ */
|
||||
bridge_ctor(void)
|
||||
{
|
||||
#define N(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
@ -187,7 +187,11 @@ static struct afswtch af_carp = {
|
||||
.af_other_status = carp_status,
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static __constructor void
|
||||
#else /* __rtems__ */
|
||||
void
|
||||
#endif /* __rtems__ */
|
||||
carp_ctor(void)
|
||||
{
|
||||
#define N(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
@ -181,9 +181,16 @@ clone_Copt_cb(const char *optarg __unused)
|
||||
}
|
||||
static struct option clone_Copt = { .opt = "C", .opt_usage = "[-C]", .cb = clone_Copt_cb };
|
||||
|
||||
#ifndef __rtems__
|
||||
static __constructor void
|
||||
#else /* __rtems__ */
|
||||
void
|
||||
#endif /* __rtems__ */
|
||||
clone_ctor(void)
|
||||
{
|
||||
#ifdef __rtems__
|
||||
SLIST_INIT(&clone_defcbh);
|
||||
#endif /* __rtems__ */
|
||||
#define N(a) (sizeof(a) / sizeof(a[0]))
|
||||
size_t i;
|
||||
|
||||
|
@ -46,6 +46,8 @@ static const char rcsid[] =
|
||||
#define option getopt_option
|
||||
#include <getopt.h>
|
||||
#undef option
|
||||
#include <machine/rtems-bsd-program.h>
|
||||
#include <machine/rtems-bsd-commands.h>
|
||||
#endif /* __rtems__ */
|
||||
#include <rtems/bsd/sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
@ -147,20 +149,39 @@ usage(void)
|
||||
}
|
||||
|
||||
#ifdef __rtems__
|
||||
#include <machine/rtems-bsd-program.h>
|
||||
#include <machine/rtems-bsd-commands.h>
|
||||
|
||||
static void ifconfig_ctor(void);
|
||||
static int main(int argc, char *argv[]);
|
||||
|
||||
int rtems_bsd_command_ifconfig(int argc, char *argv[])
|
||||
{
|
||||
descr = NULL;
|
||||
descrlen = 64;
|
||||
newaddr = 1;
|
||||
supmedia = 0;
|
||||
printkeys = 0;
|
||||
int exit_code;
|
||||
|
||||
return rtems_bsd_program_call_main("ifconfig", main, argc, argv);
|
||||
rtems_bsd_program_lock();
|
||||
|
||||
ifconfig_ctor();
|
||||
|
||||
atalk_ctor();
|
||||
bridge_ctor();
|
||||
carp_ctor();
|
||||
clone_ctor();
|
||||
gif_ctor();
|
||||
gre_ctor();
|
||||
group_ctor();
|
||||
ifmedia_ctor();
|
||||
inet_ctor();
|
||||
inet6_ctor();
|
||||
lagg_ctor();
|
||||
link_ctor();
|
||||
mac_ctor();
|
||||
nd6_ctor();
|
||||
pfsync_ctor();
|
||||
vlan_ctor();
|
||||
|
||||
exit_code = rtems_bsd_program_call_main("ifconfig", main, argc, argv);
|
||||
|
||||
rtems_bsd_program_unlock();
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
#endif /* __rtems__ */
|
||||
int
|
||||
@ -1194,6 +1215,25 @@ static struct cmd basic_cmds[] = {
|
||||
static __constructor void
|
||||
ifconfig_ctor(void)
|
||||
{
|
||||
#ifdef __rtems__
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
memset(&name, 0, sizeof(name));
|
||||
descr = NULL;
|
||||
descrlen = 64;
|
||||
setaddr = 0;
|
||||
setmask = 0;
|
||||
doalias = 0;
|
||||
clearaddr = 0;
|
||||
newaddr = 1;
|
||||
verbose = 0;
|
||||
noload = 0;
|
||||
supmedia = 0;
|
||||
printkeys = 0;
|
||||
opts = NULL;
|
||||
afs = NULL;
|
||||
callbacks = NULL;
|
||||
cmds = NULL;
|
||||
#endif /* __rtems__ */
|
||||
#define N(a) (sizeof(a) / sizeof(a[0]))
|
||||
size_t i;
|
||||
|
||||
|
@ -34,7 +34,11 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef __rtems__
|
||||
#define __constructor __attribute__((constructor))
|
||||
#else /* __rtems__ */
|
||||
#define __constructor
|
||||
#endif /* __rtems__ */
|
||||
|
||||
struct afswtch;
|
||||
struct cmd;
|
||||
@ -148,3 +152,21 @@ void clone_setdefcallback(const char *, clone_callback_func *);
|
||||
* operations on ifmedia can avoid cmd line ordering confusion.
|
||||
*/
|
||||
struct ifmediareq *ifmedia_getstate(int s);
|
||||
#ifdef __rtems__
|
||||
void atalk_ctor(void);
|
||||
void bridge_ctor(void);
|
||||
void carp_ctor(void);
|
||||
void clone_ctor(void);
|
||||
void gif_ctor(void);
|
||||
void gre_ctor(void);
|
||||
void group_ctor(void);
|
||||
void ifmedia_ctor(void);
|
||||
void inet6_ctor(void);
|
||||
void inet_ctor(void);
|
||||
void lagg_ctor(void);
|
||||
void link_ctor(void);
|
||||
void mac_ctor(void);
|
||||
void nd6_ctor(void);
|
||||
void pfsync_ctor(void);
|
||||
void vlan_ctor(void);
|
||||
#endif /* __rtems__ */
|
||||
|
@ -121,7 +121,11 @@ static struct afswtch af_gif = {
|
||||
.af_other_status = gif_status,
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static __constructor void
|
||||
#else /* __rtems__ */
|
||||
void
|
||||
#endif /* __rtems__ */
|
||||
gif_ctor(void)
|
||||
{
|
||||
#define N(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
@ -85,7 +85,11 @@ static struct afswtch af_gre = {
|
||||
.af_other_status = gre_status,
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static __constructor void
|
||||
#else /* __rtems__ */
|
||||
void
|
||||
#endif /* __rtems__ */
|
||||
gre_ctor(void)
|
||||
{
|
||||
#define N(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
@ -172,7 +172,11 @@ static struct afswtch af_group = {
|
||||
};
|
||||
static struct option group_gopt = { "g:", "[-g groupname]", printgroup };
|
||||
|
||||
#ifndef __rtems__
|
||||
static __constructor void
|
||||
#else /* __rtems__ */
|
||||
void
|
||||
#endif /* __rtems__ */
|
||||
group_ctor(void)
|
||||
{
|
||||
#define N(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
@ -181,9 +181,16 @@ static struct afswtch af_lagg = {
|
||||
.af_other_status = lagg_status,
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static __constructor void
|
||||
#else /* __rtems__ */
|
||||
void
|
||||
#endif /* __rtems__ */
|
||||
lagg_ctor(void)
|
||||
{
|
||||
#ifdef __rtems__
|
||||
memset(&lacpbuf, 0, sizeof(lacpbuf));
|
||||
#endif /* __rtems__ */
|
||||
#define N(a) (sizeof(a) / sizeof(a[0]))
|
||||
int i;
|
||||
|
||||
|
@ -108,7 +108,11 @@ static struct afswtch af_mac = {
|
||||
.af_other_status = maclabel_status,
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static __constructor void
|
||||
#else /* __rtems__ */
|
||||
void
|
||||
#endif /* __rtems__ */
|
||||
mac_ctor(void)
|
||||
{
|
||||
#define N(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
@ -193,10 +193,15 @@ media_status(int s)
|
||||
free(media_list);
|
||||
}
|
||||
|
||||
#ifdef __rtems__
|
||||
static struct ifmediareq *ifmr = NULL;
|
||||
#endif /* __rtems__ */
|
||||
struct ifmediareq *
|
||||
ifmedia_getstate(int s)
|
||||
{
|
||||
#ifndef __rtems__
|
||||
static struct ifmediareq *ifmr = NULL;
|
||||
#endif /* __rtems__ */
|
||||
int *mwords;
|
||||
|
||||
if (ifmr == NULL) {
|
||||
@ -236,11 +241,16 @@ ifmedia_getstate(int s)
|
||||
return ifmr;
|
||||
}
|
||||
|
||||
#ifdef __rtems__
|
||||
static int did_it = 0;
|
||||
#endif /* __rtems__ */
|
||||
static void
|
||||
setifmediacallback(int s, void *arg)
|
||||
{
|
||||
struct ifmediareq *ifmr = (struct ifmediareq *)arg;
|
||||
#ifndef __rtems__
|
||||
static int did_it = 0;
|
||||
#endif /* __rtems__ */
|
||||
|
||||
if (!did_it) {
|
||||
ifr.ifr_media = ifmr->ifm_current;
|
||||
@ -822,9 +832,17 @@ static struct afswtch af_media = {
|
||||
.af_other_status = media_status,
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static __constructor void
|
||||
#else /* __rtems__ */
|
||||
void
|
||||
#endif /* __rtems__ */
|
||||
ifmedia_ctor(void)
|
||||
{
|
||||
#ifdef __rtems__
|
||||
did_it = 0;
|
||||
ifmr = NULL;
|
||||
#endif /* __rtems__ */
|
||||
#define N(a) (sizeof(a) / sizeof(a[0]))
|
||||
size_t i;
|
||||
|
||||
|
@ -202,7 +202,11 @@ static struct afswtch af_pfsync = {
|
||||
.af_other_status = pfsync_status,
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static __constructor void
|
||||
#else /* __rtems__ */
|
||||
void
|
||||
#endif /* __rtems__ */
|
||||
pfsync_ctor(void)
|
||||
{
|
||||
#define N(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
@ -190,9 +190,17 @@ static struct afswtch af_vlan = {
|
||||
.af_other_status = vlan_status,
|
||||
};
|
||||
|
||||
#ifndef __rtems__
|
||||
static __constructor void
|
||||
#else /* __rtems__ */
|
||||
void
|
||||
#endif /* __rtems__ */
|
||||
vlan_ctor(void)
|
||||
{
|
||||
#ifdef __rtems__
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.vlr_tag = NOTAG;
|
||||
#endif /* __rtems__ */
|
||||
#define N(a) (sizeof(a) / sizeof(a[0]))
|
||||
size_t i;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user