assorted static vars removal

function                                             old     new   delta
tcpudpsvd_main                                      1829    1839     +10
update_status                                        567     569      +2
sigterm                                                1       -      -1
.........
dhcprelay_signal_handler                               8       -      -8
nfs_strerror                                          60      49     -11
singlemount                                         4579    4564     -15
static.p                                              16       -     -16
svstatus                                              20       -     -20
dhcprelay_xid_list                                    32       -     -32
runsv_main                                          1785    1746     -39
static.buf                                            74      28     -46
svd                                                   56       -     -56
dhcprelay_main                                      1141    1080     -61
------------------------------------------------------------------------------
(add/remove: 0/20 grow/shrink: 2/10 up/down: 12/-386)        Total: -374 bytes
This commit is contained in:
Denis Vlasenko 2007-09-28 10:29:17 +00:00
parent c3122bca53
commit b925605441
5 changed files with 116 additions and 102 deletions

View File

@ -40,11 +40,24 @@
#include "ssl_io.h" #include "ssl_io.h"
#endif #endif
static unsigned verbose; struct globals {
static unsigned max_per_host; unsigned verbose;
static unsigned cur_per_host; unsigned max_per_host;
static unsigned cnum; unsigned cur_per_host;
static unsigned cmax = 30; unsigned cnum;
unsigned cmax;
};
#define G (*(struct globals*)&bb_common_bufsiz1)
#define verbose (G.verbose )
#define max_per_host (G.max_per_host)
#define cur_per_host (G.cur_per_host)
#define cnum (G.cnum )
#define cmax (G.cmax )
#define INIT_G() \
do { \
cmax = 30; \
} while (0)
static void xsetenv_proto(const char *proto, const char *n, const char *v) static void xsetenv_proto(const char *proto, const char *n, const char *v)
{ {
@ -147,6 +160,8 @@ int tcpudpsvd_main(int argc, char **argv)
int conn; int conn;
unsigned backlog = 20; unsigned backlog = 20;
INIT_G();
tcp = (applet_name[0] == 't'); tcp = (applet_name[0] == 't');
/* 3+ args, -i at most once, -p implies -h, -v is counter */ /* 3+ args, -i at most once, -p implies -h, -v is counter */

View File

@ -19,16 +19,16 @@
#define MAX_LIFETIME 2*60 /* lifetime of an xid entry in sec. */ #define MAX_LIFETIME 2*60 /* lifetime of an xid entry in sec. */
#define MAX_INTERFACES 9 #define MAX_INTERFACES 9
/* This list holds information about clients. The xid_* functions manipulate this list. */ /* This list holds information about clients. The xid_* functions manipulate this list. */
static struct xid_item { struct xid_item {
time_t timestamp;
int client;
uint32_t xid; uint32_t xid;
struct sockaddr_in ip; struct sockaddr_in ip;
int client;
time_t timestamp;
struct xid_item *next; struct xid_item *next;
} dhcprelay_xid_list = {0, {0}, 0, 0, NULL}; };
#define dhcprelay_xid_list (*(struct xid_item*)&bb_common_bufsiz1)
static struct xid_item *xid_add(uint32_t xid, struct sockaddr_in *ip, int client) static struct xid_item *xid_add(uint32_t xid, struct sockaddr_in *ip, int client)
{ {
@ -113,17 +113,6 @@ static int get_dhcp_packet_type(struct dhcpMessage *p)
return -1; return -1;
} }
/**
* signal_handler - handles signals ;-)
* sig - sent signal
*/
static smallint dhcprelay_stopflag;
static void dhcprelay_signal_handler(int sig)
{
dhcprelay_stopflag = 1;
}
/** /**
* get_client_devices - parses the devices list * get_client_devices - parses the devices list
* dev_list - comma separated list of devices * dev_list - comma separated list of devices
@ -160,27 +149,23 @@ static char **get_client_devices(char *dev_list, int *client_number)
} }
/* Creates listen sockets (in fds) and returns the number allocated. */ /* Creates listen sockets (in fds) and returns numerically max fd. */
static int init_sockets(char **client, int num_clients, static int init_sockets(char **client, int num_clients,
char *server, int *fds, int *max_socket) char *server, int *fds)
{ {
int i; int i, n;
/* talk to real server on bootps */ /* talk to real server on bootps */
fds[0] = listen_socket(/*INADDR_ANY,*/ 67, server); fds[0] = listen_socket(/*INADDR_ANY,*/ 67, server);
*max_socket = fds[0]; n = fds[0];
/* array starts at 1 since server is 0 */
num_clients++;
for (i = 1; i < num_clients; i++) { for (i = 1; i < num_clients; i++) {
/* listen for clients on bootps */ /* listen for clients on bootps */
fds[i] = listen_socket(/*NADDR_ANY,*/ 67, client[i-1]); fds[i] = listen_socket(/*NADDR_ANY,*/ 67, client[i-1]);
if (fds[i] > *max_socket) if (fds[i] > n)
*max_socket = fds[i]; n = fds[i];
} }
return n;
return i;
} }
@ -252,6 +237,8 @@ static void pass_back(struct dhcpMessage *p, int packet_len, int *fds)
xid_del(p->xid); xid_del(p->xid);
} }
static void dhcprelay_loop(int *fds, int num_sockets, int max_socket, char **clients,
struct sockaddr_in *server_addr, uint32_t gw_ip) ATTRIBUTE_NORETURN;
static void dhcprelay_loop(int *fds, int num_sockets, int max_socket, char **clients, static void dhcprelay_loop(int *fds, int num_sockets, int max_socket, char **clients,
struct sockaddr_in *server_addr, uint32_t gw_ip) struct sockaddr_in *server_addr, uint32_t gw_ip)
{ {
@ -263,7 +250,7 @@ static void dhcprelay_loop(int *fds, int num_sockets, int max_socket, char **cli
struct timeval tv; struct timeval tv;
int i; int i;
while (!dhcprelay_stopflag) { while (1) {
FD_ZERO(&rfds); FD_ZERO(&rfds);
for (i = 0; i < num_sockets; i++) for (i = 0; i < num_sockets; i++)
FD_SET(fds[i], &rfds); FD_SET(fds[i], &rfds);
@ -298,7 +285,7 @@ static void dhcprelay_loop(int *fds, int num_sockets, int max_socket, char **cli
int dhcprelay_main(int argc, char **argv); int dhcprelay_main(int argc, char **argv);
int dhcprelay_main(int argc, char **argv) int dhcprelay_main(int argc, char **argv)
{ {
int i, num_sockets, max_socket, fds[MAX_INTERFACES]; int num_sockets, max_socket, fds[MAX_INTERFACES];
uint32_t gw_ip; uint32_t gw_ip;
char **clients; char **clients;
struct sockaddr_in server_addr; struct sockaddr_in server_addr;
@ -316,23 +303,13 @@ int dhcprelay_main(int argc, char **argv)
clients = get_client_devices(argv[1], &num_sockets); clients = get_client_devices(argv[1], &num_sockets);
if (!clients) return 0; if (!clients) return 0;
signal(SIGTERM, dhcprelay_signal_handler); num_sockets++; /* for server socket at fds[0] */
signal(SIGQUIT, dhcprelay_signal_handler); max_socket = init_sockets(clients, num_sockets, argv[2], fds);
signal(SIGINT, dhcprelay_signal_handler);
num_sockets = init_sockets(clients, num_sockets, argv[2], fds, &max_socket);
if (read_interface(argv[2], NULL, &gw_ip, NULL)) if (read_interface(argv[2], NULL, &gw_ip, NULL))
return 1; return 1;
/* doesn't return */
dhcprelay_loop(fds, num_sockets, max_socket, clients, &server_addr, gw_ip); dhcprelay_loop(fds, num_sockets, max_socket, clients, &server_addr, gw_ip);
/* return 0; - not reached */
if (ENABLE_FEATURE_CLEAN_UP) {
for (i = 0; i < num_sockets; i++) {
close(fds[i]);
free(clients[i]);
}
}
return 0;
} }

View File

@ -61,8 +61,6 @@ static void gettimeofday_ns(struct timespec *ts)
/* Compare possibly overflowing unsigned counters */ /* Compare possibly overflowing unsigned counters */
#define LESS(a,b) ((int)((unsigned)(b) - (unsigned)(a)) > 0) #define LESS(a,b) ((int)((unsigned)(b) - (unsigned)(a)) > 0)
static int selfpipe[2];
/* state */ /* state */
#define S_DOWN 0 #define S_DOWN 0
#define S_RUN 1 #define S_RUN 1
@ -88,12 +86,27 @@ struct svdir {
int fdcontrolwrite; int fdcontrolwrite;
}; };
static struct svdir svd[2]; struct globals {
static smallint sigterm; smallint haslog;
static smallint haslog; smallint sigterm;
static smallint pidchanged = 1; smallint pidchanged;
static int logpipe[2]; int selfpipe[2];
static char *dir; int logpipe[2];
char *dir;
struct svdir svd[2];
};
#define G (*(struct globals*)&bb_common_bufsiz1)
#define haslog (G.haslog )
#define sigterm (G.sigterm )
#define pidchanged (G.pidchanged )
#define selfpipe (G.selfpipe )
#define logpipe (G.logpipe )
#define dir (G.dir )
#define svd (G.svd )
#define INIT_G() \
do { \
pidchanged = 1; \
} while (0)
static void fatal2_cannot(const char *m1, const char *m2) static void fatal2_cannot(const char *m1, const char *m2)
{ {
@ -434,6 +447,8 @@ int runsv_main(int argc, char **argv)
int r; int r;
char buf[256]; char buf[256];
INIT_G();
if (!argv[1] || argv[2]) if (!argv[1] || argv[2])
bb_show_usage(); bb_show_usage();
dir = argv[1]; dir = argv[1];

View File

@ -158,12 +158,22 @@ Exit Codes
#include "libbb.h" #include "libbb.h"
#include "runit_lib.h" #include "runit_lib.h"
static const char *acts; struct globals {
static char **service; const char *acts;
static unsigned rc; char **service;
unsigned rc;
/* "Bernstein" time format: unix + 0x400000000000000aULL */ /* "Bernstein" time format: unix + 0x400000000000000aULL */
static uint64_t tstart, tnow; uint64_t tstart, tnow;
static svstatus_t svstatus; svstatus_t svstatus;
};
#define G (*(struct globals*)&bb_common_bufsiz1)
#define acts (G.acts )
#define service (G.service )
#define rc (G.rc )
#define tstart (G.tstart )
#define tnow (G.tnow )
#define svstatus (G.svstatus )
#define INIT_G() do { } while (0)
static void fatal_cannot(const char *m1) ATTRIBUTE_NORETURN; static void fatal_cannot(const char *m1) ATTRIBUTE_NORETURN;
@ -418,6 +428,8 @@ int sv_main(int argc, char **argv)
int (*cbk)(const char*); int (*cbk)(const char*);
int curdir; int curdir;
INIT_G();
xfunc_error_retval = 100; xfunc_error_retval = 100;
x = getenv("SVDIR"); x = getenv("SVDIR");

View File

@ -66,10 +66,10 @@ enum {
/* Standard mount options (from -o options or --options), with corresponding /* Standard mount options (from -o options or --options), with corresponding
* flags */ * flags */
struct { static const struct {
const char *name; const char *name;
long flags; long flags;
} static mount_options[] = { } mount_options[] = {
// MS_FLAGS set a bit. ~MS_FLAGS disable that bit. 0 flags are NOPs. // MS_FLAGS set a bit. ~MS_FLAGS disable that bit. 0 flags are NOPs.
USE_FEATURE_MOUNT_LOOP( USE_FEATURE_MOUNT_LOOP(
@ -231,7 +231,7 @@ static llist_t *get_block_backed_filesystems(void)
return list; return list;
} }
llist_t *fslist = 0; static llist_t *fslist;
#if ENABLE_FEATURE_CLEAN_UP #if ENABLE_FEATURE_CLEAN_UP
static void delete_block_backed_filesystems(void) static void delete_block_backed_filesystems(void)
@ -562,14 +562,12 @@ static const struct {
static char *nfs_strerror(int status) static char *nfs_strerror(int status)
{ {
int i; int i;
static char buf[sizeof("unknown nfs status return value: ") + sizeof(int)*3];
for (i = 0; nfs_errtbl[i].stat != -1; i++) { for (i = 0; nfs_errtbl[i].stat != -1; i++) {
if (nfs_errtbl[i].stat == status) if (nfs_errtbl[i].stat == status)
return strerror(nfs_errtbl[i].errnum); return strerror(nfs_errtbl[i].errnum);
} }
sprintf(buf, "unknown nfs status return value: %d", status); return xasprintf("unknown nfs status return value: %d", status);
return buf;
} }
static bool_t xdr_fhandle(XDR *xdrs, fhandle objp) static bool_t xdr_fhandle(XDR *xdrs, fhandle objp)
@ -642,11 +640,7 @@ static bool_t xdr_mountres3(XDR *xdrs, mountres3 *objp)
#define MAX_NFSPROT ((nfs_mount_version >= 4) ? 3 : 2) #define MAX_NFSPROT ((nfs_mount_version >= 4) ? 3 : 2)
/* static smalluint nfs_mount_version;
* nfs_mount_version according to the sources seen at compile time.
*/
static int nfs_mount_version;
static int kernel_version;
/* /*
* Unfortunately, the kernel prints annoying console messages * Unfortunately, the kernel prints annoying console messages
@ -662,7 +656,9 @@ static int kernel_version;
static void static void
find_kernel_nfs_mount_version(void) find_kernel_nfs_mount_version(void)
{ {
if (kernel_version) int kernel_version;
if (nfs_mount_version)
return; return;
nfs_mount_version = 4; /* default */ nfs_mount_version = 4; /* default */
@ -679,15 +675,15 @@ find_kernel_nfs_mount_version(void)
} }
} }
static struct pmap * static void
get_mountport(struct sockaddr_in *server_addr, get_mountport(struct pmap *pm_mnt,
struct sockaddr_in *server_addr,
long unsigned prog, long unsigned prog,
long unsigned version, long unsigned version,
long unsigned proto, long unsigned proto,
long unsigned port) long unsigned port)
{ {
struct pmaplist *pmap; struct pmaplist *pmap;
static struct pmap p = {0, 0, 0, 0};
server_addr->sin_port = PMAPPORT; server_addr->sin_port = PMAPPORT;
/* glibc 2.4 (still) has pmap_getmaps(struct sockaddr_in *). /* glibc 2.4 (still) has pmap_getmaps(struct sockaddr_in *).
@ -698,35 +694,34 @@ get_mountport(struct sockaddr_in *server_addr,
version = MAX_NFSPROT; version = MAX_NFSPROT;
if (!prog) if (!prog)
prog = MOUNTPROG; prog = MOUNTPROG;
p.pm_prog = prog; pm_mnt->pm_prog = prog;
p.pm_vers = version; pm_mnt->pm_vers = version;
p.pm_prot = proto; pm_mnt->pm_prot = proto;
p.pm_port = port; pm_mnt->pm_port = port;
while (pmap) { while (pmap) {
if (pmap->pml_map.pm_prog != prog) if (pmap->pml_map.pm_prog != prog)
goto next; goto next;
if (!version && p.pm_vers > pmap->pml_map.pm_vers) if (!version && pm_mnt->pm_vers > pmap->pml_map.pm_vers)
goto next; goto next;
if (version > 2 && pmap->pml_map.pm_vers != version) if (version > 2 && pmap->pml_map.pm_vers != version)
goto next; goto next;
if (version && version <= 2 && pmap->pml_map.pm_vers > 2) if (version && version <= 2 && pmap->pml_map.pm_vers > 2)
goto next; goto next;
if (pmap->pml_map.pm_vers > MAX_NFSPROT || if (pmap->pml_map.pm_vers > MAX_NFSPROT ||
(proto && p.pm_prot && pmap->pml_map.pm_prot != proto) || (proto && pm_mnt->pm_prot && pmap->pml_map.pm_prot != proto) ||
(port && pmap->pml_map.pm_port != port)) (port && pmap->pml_map.pm_port != port))
goto next; goto next;
memcpy(&p, &pmap->pml_map, sizeof(p)); memcpy(pm_mnt, &pmap->pml_map, sizeof(*pm_mnt));
next: next:
pmap = pmap->pml_next; pmap = pmap->pml_next;
} }
if (!p.pm_vers) if (!pm_mnt->pm_vers)
p.pm_vers = MOUNTVERS; pm_mnt->pm_vers = MOUNTVERS;
if (!p.pm_port) if (!pm_mnt->pm_port)
p.pm_port = MOUNTPORT; pm_mnt->pm_port = MOUNTPORT;
if (!p.pm_prot) if (!pm_mnt->pm_prot)
p.pm_prot = IPPROTO_TCP; pm_mnt->pm_prot = IPPROTO_TCP;
return &p;
} }
#if BB_MMU #if BB_MMU
@ -1147,7 +1142,7 @@ static int nfsmount(struct mntent *mp, int vfsflags, char *filteropts)
{ {
struct timeval total_timeout; struct timeval total_timeout;
struct timeval retry_timeout; struct timeval retry_timeout;
struct pmap* pm_mnt; struct pmap pm_mnt;
time_t t; time_t t;
time_t prevt; time_t prevt;
time_t timeout; time_t timeout;
@ -1164,32 +1159,32 @@ retry:
if (t - prevt < 30) if (t - prevt < 30)
sleep(30); sleep(30);
pm_mnt = get_mountport(&mount_server_addr, get_mountport(&pm_mnt, &mount_server_addr,
mountprog, mountprog,
mountvers, mountvers,
proto, proto,
mountport); mountport);
nfsvers = (pm_mnt->pm_vers < 2) ? 2 : pm_mnt->pm_vers; nfsvers = (pm_mnt.pm_vers < 2) ? 2 : pm_mnt.pm_vers;
/* contact the mount daemon via TCP */ /* contact the mount daemon via TCP */
mount_server_addr.sin_port = htons(pm_mnt->pm_port); mount_server_addr.sin_port = htons(pm_mnt.pm_port);
msock = RPC_ANYSOCK; msock = RPC_ANYSOCK;
switch (pm_mnt->pm_prot) { switch (pm_mnt.pm_prot) {
case IPPROTO_UDP: case IPPROTO_UDP:
mclient = clntudp_create(&mount_server_addr, mclient = clntudp_create(&mount_server_addr,
pm_mnt->pm_prog, pm_mnt.pm_prog,
pm_mnt->pm_vers, pm_mnt.pm_vers,
retry_timeout, retry_timeout,
&msock); &msock);
if (mclient) if (mclient)
break; break;
mount_server_addr.sin_port = htons(pm_mnt->pm_port); mount_server_addr.sin_port = htons(pm_mnt.pm_port);
msock = RPC_ANYSOCK; msock = RPC_ANYSOCK;
case IPPROTO_TCP: case IPPROTO_TCP:
mclient = clnttcp_create(&mount_server_addr, mclient = clnttcp_create(&mount_server_addr,
pm_mnt->pm_prog, pm_mnt.pm_prog,
pm_mnt->pm_vers, pm_mnt.pm_vers,
&msock, 0, 0); &msock, 0, 0);
break; break;
default: default:
@ -1208,7 +1203,7 @@ retry:
*/ */
memset(&status, 0, sizeof(status)); memset(&status, 0, sizeof(status));
if (pm_mnt->pm_vers == 3) if (pm_mnt.pm_vers == 3)
clnt_stat = clnt_call(mclient, MOUNTPROC3_MNT, clnt_stat = clnt_call(mclient, MOUNTPROC3_MNT,
(xdrproc_t) xdr_dirpath, (xdrproc_t) xdr_dirpath,
(caddr_t) &pathname, (caddr_t) &pathname,