IFCONFIG(8): Initialize global variables in ctors

This commit is contained in:
Sebastian Huber 2013-10-18 16:30:27 +02:00
parent 8ff186f81f
commit 60618d5332
18 changed files with 179 additions and 9 deletions

View File

@ -169,9 +169,17 @@ static struct afswtch af_atalk = {
.af_addreq = &at_addreq, .af_addreq = &at_addreq,
}; };
#ifndef __rtems__
static __constructor void static __constructor void
#else /* __rtems__ */
void
#endif /* __rtems__ */
atalk_ctor(void) 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])) #define N(a) (sizeof(a) / sizeof(a[0]))
size_t i; size_t i;

View File

@ -197,8 +197,16 @@ static struct afswtch af_inet = {
.af_addreq = &in_addreq, .af_addreq = &in_addreq,
}; };
#ifndef __rtems__
static __constructor void static __constructor void
#else /* __rtems__ */
void
#endif /* __rtems__ */
inet_ctor(void) 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); af_register(&af_inet);
} }

View File

@ -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 }; static struct option in6_Lopt = { .opt = "L", .opt_usage = "[-L]", .cb = in6_Lopt_cb };
#ifndef __rtems__
static __constructor void static __constructor void
#else /* __rtems__ */
void
#endif /* __rtems__ */
inet6_ctor(void) 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])) #define N(a) (sizeof(a) / sizeof(a[0]))
size_t i; size_t i;

View File

@ -120,9 +120,16 @@ static struct afswtch af_lladdr = {
.af_addreq = &link_ridreq, .af_addreq = &link_ridreq,
}; };
#ifndef __rtems__
static __constructor void static __constructor void
#else /* __rtems__ */
void
#endif /* __rtems__ */
link_ctor(void) link_ctor(void)
{ {
#ifdef __rtems__
memset(&link_ridreq, 0, sizeof(link_ridreq));
#endif /* __rtems__ */
af_register(&af_link); af_register(&af_link);
af_register(&af_ether); af_register(&af_ether);
af_register(&af_lladdr); af_register(&af_lladdr);

View File

@ -222,7 +222,11 @@ static struct afswtch af_nd6 = {
.af_other_status= nd6_status, .af_other_status= nd6_status,
}; };
#ifndef __rtems__
static __constructor void static __constructor void
#else /* __rtems__ */
void
#endif /* __rtems__ */
nd6_ctor(void) nd6_ctor(void)
{ {
af_register(&af_nd6); af_register(&af_nd6);

View File

@ -746,7 +746,11 @@ static struct afswtch af_bridge = {
.af_other_status = bridge_status, .af_other_status = bridge_status,
}; };
#ifndef __rtems__
static __constructor void static __constructor void
#else /* __rtems__ */
void
#endif /* __rtems__ */
bridge_ctor(void) bridge_ctor(void)
{ {
#define N(a) (sizeof(a) / sizeof(a[0])) #define N(a) (sizeof(a) / sizeof(a[0]))

View File

@ -187,7 +187,11 @@ static struct afswtch af_carp = {
.af_other_status = carp_status, .af_other_status = carp_status,
}; };
#ifndef __rtems__
static __constructor void static __constructor void
#else /* __rtems__ */
void
#endif /* __rtems__ */
carp_ctor(void) carp_ctor(void)
{ {
#define N(a) (sizeof(a) / sizeof(a[0])) #define N(a) (sizeof(a) / sizeof(a[0]))

View File

@ -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 }; static struct option clone_Copt = { .opt = "C", .opt_usage = "[-C]", .cb = clone_Copt_cb };
#ifndef __rtems__
static __constructor void static __constructor void
#else /* __rtems__ */
void
#endif /* __rtems__ */
clone_ctor(void) clone_ctor(void)
{ {
#ifdef __rtems__
SLIST_INIT(&clone_defcbh);
#endif /* __rtems__ */
#define N(a) (sizeof(a) / sizeof(a[0])) #define N(a) (sizeof(a) / sizeof(a[0]))
size_t i; size_t i;

View File

@ -46,6 +46,8 @@ static const char rcsid[] =
#define option getopt_option #define option getopt_option
#include <getopt.h> #include <getopt.h>
#undef option #undef option
#include <machine/rtems-bsd-program.h>
#include <machine/rtems-bsd-commands.h>
#endif /* __rtems__ */ #endif /* __rtems__ */
#include <rtems/bsd/sys/param.h> #include <rtems/bsd/sys/param.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
@ -147,20 +149,39 @@ usage(void)
} }
#ifdef __rtems__ #ifdef __rtems__
#include <machine/rtems-bsd-program.h> static void ifconfig_ctor(void);
#include <machine/rtems-bsd-commands.h>
static int main(int argc, char *argv[]); static int main(int argc, char *argv[]);
int rtems_bsd_command_ifconfig(int argc, char *argv[]) int rtems_bsd_command_ifconfig(int argc, char *argv[])
{ {
descr = NULL; int exit_code;
descrlen = 64;
newaddr = 1;
supmedia = 0;
printkeys = 0;
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__ */ #endif /* __rtems__ */
int int
@ -1194,6 +1215,25 @@ static struct cmd basic_cmds[] = {
static __constructor void static __constructor void
ifconfig_ctor(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])) #define N(a) (sizeof(a) / sizeof(a[0]))
size_t i; size_t i;

View File

@ -34,7 +34,11 @@
* $FreeBSD$ * $FreeBSD$
*/ */
#ifndef __rtems__
#define __constructor __attribute__((constructor)) #define __constructor __attribute__((constructor))
#else /* __rtems__ */
#define __constructor
#endif /* __rtems__ */
struct afswtch; struct afswtch;
struct cmd; struct cmd;
@ -148,3 +152,21 @@ void clone_setdefcallback(const char *, clone_callback_func *);
* operations on ifmedia can avoid cmd line ordering confusion. * operations on ifmedia can avoid cmd line ordering confusion.
*/ */
struct ifmediareq *ifmedia_getstate(int s); 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__ */

View File

@ -121,7 +121,11 @@ static struct afswtch af_gif = {
.af_other_status = gif_status, .af_other_status = gif_status,
}; };
#ifndef __rtems__
static __constructor void static __constructor void
#else /* __rtems__ */
void
#endif /* __rtems__ */
gif_ctor(void) gif_ctor(void)
{ {
#define N(a) (sizeof(a) / sizeof(a[0])) #define N(a) (sizeof(a) / sizeof(a[0]))

View File

@ -85,7 +85,11 @@ static struct afswtch af_gre = {
.af_other_status = gre_status, .af_other_status = gre_status,
}; };
#ifndef __rtems__
static __constructor void static __constructor void
#else /* __rtems__ */
void
#endif /* __rtems__ */
gre_ctor(void) gre_ctor(void)
{ {
#define N(a) (sizeof(a) / sizeof(a[0])) #define N(a) (sizeof(a) / sizeof(a[0]))

View File

@ -172,7 +172,11 @@ static struct afswtch af_group = {
}; };
static struct option group_gopt = { "g:", "[-g groupname]", printgroup }; static struct option group_gopt = { "g:", "[-g groupname]", printgroup };
#ifndef __rtems__
static __constructor void static __constructor void
#else /* __rtems__ */
void
#endif /* __rtems__ */
group_ctor(void) group_ctor(void)
{ {
#define N(a) (sizeof(a) / sizeof(a[0])) #define N(a) (sizeof(a) / sizeof(a[0]))

View File

@ -181,9 +181,16 @@ static struct afswtch af_lagg = {
.af_other_status = lagg_status, .af_other_status = lagg_status,
}; };
#ifndef __rtems__
static __constructor void static __constructor void
#else /* __rtems__ */
void
#endif /* __rtems__ */
lagg_ctor(void) lagg_ctor(void)
{ {
#ifdef __rtems__
memset(&lacpbuf, 0, sizeof(lacpbuf));
#endif /* __rtems__ */
#define N(a) (sizeof(a) / sizeof(a[0])) #define N(a) (sizeof(a) / sizeof(a[0]))
int i; int i;

View File

@ -108,7 +108,11 @@ static struct afswtch af_mac = {
.af_other_status = maclabel_status, .af_other_status = maclabel_status,
}; };
#ifndef __rtems__
static __constructor void static __constructor void
#else /* __rtems__ */
void
#endif /* __rtems__ */
mac_ctor(void) mac_ctor(void)
{ {
#define N(a) (sizeof(a) / sizeof(a[0])) #define N(a) (sizeof(a) / sizeof(a[0]))

View File

@ -193,10 +193,15 @@ media_status(int s)
free(media_list); free(media_list);
} }
#ifdef __rtems__
static struct ifmediareq *ifmr = NULL;
#endif /* __rtems__ */
struct ifmediareq * struct ifmediareq *
ifmedia_getstate(int s) ifmedia_getstate(int s)
{ {
#ifndef __rtems__
static struct ifmediareq *ifmr = NULL; static struct ifmediareq *ifmr = NULL;
#endif /* __rtems__ */
int *mwords; int *mwords;
if (ifmr == NULL) { if (ifmr == NULL) {
@ -236,11 +241,16 @@ ifmedia_getstate(int s)
return ifmr; return ifmr;
} }
#ifdef __rtems__
static int did_it = 0;
#endif /* __rtems__ */
static void static void
setifmediacallback(int s, void *arg) setifmediacallback(int s, void *arg)
{ {
struct ifmediareq *ifmr = (struct ifmediareq *)arg; struct ifmediareq *ifmr = (struct ifmediareq *)arg;
#ifndef __rtems__
static int did_it = 0; static int did_it = 0;
#endif /* __rtems__ */
if (!did_it) { if (!did_it) {
ifr.ifr_media = ifmr->ifm_current; ifr.ifr_media = ifmr->ifm_current;
@ -822,9 +832,17 @@ static struct afswtch af_media = {
.af_other_status = media_status, .af_other_status = media_status,
}; };
#ifndef __rtems__
static __constructor void static __constructor void
#else /* __rtems__ */
void
#endif /* __rtems__ */
ifmedia_ctor(void) ifmedia_ctor(void)
{ {
#ifdef __rtems__
did_it = 0;
ifmr = NULL;
#endif /* __rtems__ */
#define N(a) (sizeof(a) / sizeof(a[0])) #define N(a) (sizeof(a) / sizeof(a[0]))
size_t i; size_t i;

View File

@ -202,7 +202,11 @@ static struct afswtch af_pfsync = {
.af_other_status = pfsync_status, .af_other_status = pfsync_status,
}; };
#ifndef __rtems__
static __constructor void static __constructor void
#else /* __rtems__ */
void
#endif /* __rtems__ */
pfsync_ctor(void) pfsync_ctor(void)
{ {
#define N(a) (sizeof(a) / sizeof(a[0])) #define N(a) (sizeof(a) / sizeof(a[0]))

View File

@ -190,9 +190,17 @@ static struct afswtch af_vlan = {
.af_other_status = vlan_status, .af_other_status = vlan_status,
}; };
#ifndef __rtems__
static __constructor void static __constructor void
#else /* __rtems__ */
void
#endif /* __rtems__ */
vlan_ctor(void) vlan_ctor(void)
{ {
#ifdef __rtems__
memset(&params, 0, sizeof(params));
params.vlr_tag = NOTAG;
#endif /* __rtems__ */
#define N(a) (sizeof(a) / sizeof(a[0])) #define N(a) (sizeof(a) / sizeof(a[0]))
size_t i; size_t i;