dnsd fix; option_mask32 added. dnsd needs more love.

This commit is contained in:
Denis Vlasenko 2006-10-06 09:49:47 +00:00
parent 4e6ceb4455
commit c12f53090b
8 changed files with 154 additions and 148 deletions

View File

@ -206,9 +206,10 @@ extern void xsetgid(gid_t gid);
extern void xsetuid(uid_t uid); extern void xsetuid(uid_t uid);
extern off_t fdlength(int fd); extern off_t fdlength(int fd);
#define BB_GETOPT_ERROR 0x80000000UL enum { BB_GETOPT_ERROR = 0x80000000 };
extern const char *opt_complementary; extern const char *opt_complementary;
extern const struct option *applet_long_options; extern const struct option *applet_long_options;
extern uint32_t option_mask32;
extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...); extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...);
extern int bb_vfprintf(FILE * __restrict stream, const char * __restrict format, extern int bb_vfprintf(FILE * __restrict stream, const char * __restrict format,

View File

@ -302,6 +302,8 @@ static const struct option bb_default_long_options[] = {
const struct option *applet_long_options = bb_default_long_options; const struct option *applet_long_options = bb_default_long_options;
#endif #endif
uint32_t option_mask32;
uint32_t uint32_t
getopt32(int argc, char **argv, const char *applet_opts, ...) getopt32(int argc, char **argv, const char *applet_opts, ...)
{ {
@ -512,5 +514,7 @@ loop_arg_is_opt:
argc -= optind; argc -= optind;
if (argc < min_arg || (max_arg >= 0 && argc > max_arg)) if (argc < min_arg || (max_arg >= 0 && argc > max_arg))
bb_show_usage(); bb_show_usage();
option_mask32 = flags;
return flags; return flags;
} }

View File

@ -693,7 +693,6 @@ enum { STRVERSIONLEN = 32 };
/*======================================================================*/ /*======================================================================*/
static unsigned option_mask;
#define OPTION_STR "sLo:fkvqx" USE_FEATURE_INSMOD_LOAD_MAP("m") #define OPTION_STR "sLo:fkvqx" USE_FEATURE_INSMOD_LOAD_MAP("m")
enum { enum {
OPT_s = 0x1, // -s /* log to syslog */ OPT_s = 0x1, // -s /* log to syslog */
@ -713,13 +712,13 @@ enum {
OPT_x = 0x80, // -x /* do not export externs */ OPT_x = 0x80, // -x /* do not export externs */
OPT_m = 0x100, // -m /* print module load map */ OPT_m = 0x100, // -m /* print module load map */
}; };
#define flag_force_load (option_mask & OPT_f) #define flag_force_load (option_mask32 & OPT_f)
#define flag_autoclean (option_mask & OPT_k) #define flag_autoclean (option_mask32 & OPT_k)
#define flag_verbose (option_mask & OPT_v) #define flag_verbose (option_mask32 & OPT_v)
#define flag_quiet (option_mask & OPT_q) #define flag_quiet (option_mask32 & OPT_q)
#define flag_noexport (option_mask & OPT_x) #define flag_noexport (option_mask32 & OPT_x)
#ifdef CONFIG_FEATURE_INSMOD_LOAD_MAP #ifdef CONFIG_FEATURE_INSMOD_LOAD_MAP
#define flag_print_load_map (option_mask & OPT_m) #define flag_print_load_map (option_mask32 & OPT_m)
#else #else
#define flag_print_load_map 0 #define flag_print_load_map 0
#endif #endif
@ -3983,8 +3982,8 @@ int insmod_main( int argc, char **argv)
struct utsname myuname; struct utsname myuname;
/* Parse any options */ /* Parse any options */
option_mask = getopt32(argc, argv, OPTION_STR, &opt_o); getopt32(argc, argv, OPTION_STR, &opt_o);
if (option_mask & OPT_o) { // -o /* name the output module */ if (option_mask32 & OPT_o) { // -o /* name the output module */
free(m_name); free(m_name);
m_name = xstrdup(opt_o); m_name = xstrdup(opt_o);
} }

View File

@ -23,6 +23,12 @@ static char *fileconf = "/etc/dnsd.conf";
#define LOCK_FILE "/var/run/dnsd.lock" #define LOCK_FILE "/var/run/dnsd.lock"
#define LOG_FILE "/var/log/dnsd.log" #define LOG_FILE "/var/log/dnsd.log"
// Must matct getopt32 call
#define OPT_daemon (option_mask32 & 0x10)
#define OPT_verbose (option_mask32 & 0x20)
//#define DEBUG 1
enum { enum {
MAX_HOST_LEN = 16, // longest host name allowed is 15 MAX_HOST_LEN = 16, // longest host name allowed is 15
IP_STRING_LEN = 18, // .xxx.xxx.xxx.xxx\0 IP_STRING_LEN = 18, // .xxx.xxx.xxx.xxx\0
@ -70,7 +76,8 @@ struct dns_entry { // element of known name, ip address and reversed ip address
}; };
static struct dns_entry *dnsentry = NULL; static struct dns_entry *dnsentry = NULL;
static int daemonmode = 0; // FIXME! unused! :(
static int daemonmode;
static uint32_t ttl = DEFAULT_TTL; static uint32_t ttl = DEFAULT_TTL;
/* /*
@ -79,7 +86,7 @@ static uint32_t ttl = DEFAULT_TTL;
static void convname(char *a, uint8_t *q) static void convname(char *a, uint8_t *q)
{ {
int i = (q[0] == '.') ? 0 : 1; int i = (q[0] == '.') ? 0 : 1;
for(; i < MAX_HOST_LEN-1 && *q; i++, q++) for (; i < MAX_HOST_LEN-1 && *q; i++, q++)
a[i] = tolower(*q); a[i] = tolower(*q);
a[0] = i - 1; a[0] = i - 1;
a[i] = 0; a[i] = 0;
@ -91,9 +98,10 @@ static void convname(char *a, uint8_t *q)
static void undot(uint8_t * rip) static void undot(uint8_t * rip)
{ {
int i = 0, s = 0; int i = 0, s = 0;
while(rip[i]) i++; while (rip[i])
for(--i; i >= 0; i--) { i++;
if(rip[i] == '.') { for (--i; i >= 0; i--) {
if (rip[i] == '.') {
rip[i] = s; rip[i] = s;
s = 0; s = 0;
} else s++; } else s++;
@ -124,41 +132,42 @@ static void log_message(char *filename, char *message)
* converting to a length/string substring for that label. * converting to a length/string substring for that label.
*/ */
static int getfileentry(FILE * fp, struct dns_entry *s, int verb) static int getfileentry(FILE * fp, struct dns_entry *s)
{ {
unsigned int a,b,c,d; unsigned int a,b,c,d;
char *r, *name; char *r, *name;
restart: restart:
if(!(r = bb_get_line_from_file(fp))) r = bb_get_line_from_file(fp);
if (!r)
return -1; return -1;
while(*r == ' ' || *r == '\t') { while (*r == ' ' || *r == '\t') {
r++; r++;
if(!*r || *r == '#' || *r == '\n') if (!*r || *r == '#' || *r == '\n')
goto restart; /* skipping empty/blank and commented lines */ goto restart; /* skipping empty/blank and commented lines */
} }
name = r; name = r;
while(*r != ' ' && *r != '\t') while (*r != ' ' && *r != '\t')
r++; r++;
*r++ = 0; *r++ = 0;
if(sscanf(r,"%u.%u.%u.%u",&a,&b,&c,&d) != 4) if (sscanf(r, "%u.%u.%u.%u", &a, &b, &c, &d) != 4)
goto restart; /* skipping wrong lines */ goto restart; /* skipping wrong lines */
sprintf(s->ip,"%u.%u.%u.%u",a,b,c,d); sprintf(s->ip, "%u.%u.%u.%u", a, b, c, d);
sprintf(s->rip,".%u.%u.%u.%u",d,c,b,a); sprintf(s->rip, ".%u.%u.%u.%u", d, c, b, a);
undot((uint8_t*)s->rip); undot((uint8_t*)s->rip);
convname(s->name,(uint8_t*)name); convname(s->name,(uint8_t*)name);
if(verb) if (OPT_verbose)
fprintf(stderr,"\tname:%s, ip:%s\n",&(s->name[1]),s->ip); fprintf(stderr, "\tname:%s, ip:%s\n", &(s->name[1]),s->ip);
return 0; /* warningkiller */ return 0;
} }
/* /*
* Read hostname/IP records from file * Read hostname/IP records from file
*/ */
static void dnsentryinit(int verb) static void dnsentryinit(void)
{ {
FILE *fp; FILE *fp;
struct dns_entry *m, *prev; struct dns_entry *m, *prev;
@ -170,7 +179,7 @@ static void dnsentryinit(int verb)
m = xmalloc(sizeof(struct dns_entry)); m = xmalloc(sizeof(struct dns_entry));
m->next = NULL; m->next = NULL;
if (getfileentry(fp, m, verb)) if (getfileentry(fp, m))
break; break;
if (prev == NULL) if (prev == NULL)
@ -224,28 +233,32 @@ static int table_lookup(uint16_t type, uint8_t * as, uint8_t * qs)
char *p,*q; char *p,*q;
q = (char *)&(qs[1]); q = (char *)&(qs[1]);
p = &(d->name[1]); p = &(d->name[1]);
fprintf(stderr, "\ntest: %d <%s> <%s> %d", strlen(p), p, q, strlen(q)); fprintf(stderr, "\n%s: %d/%d p:%s q:%s %d",
__FUNCTION__, strlen(p), (int)(d->name[0]), p, q, strlen(q));
#endif #endif
if (type == REQ_A) { /* search by host name */ if (type == REQ_A) { /* search by host name */
for(i = 1; i <= (int)(d->name[0]); i++) for (i = 1; i <= (int)(d->name[0]); i++)
if(tolower(qs[i]) != d->name[i]) if (tolower(qs[i]) != d->name[i])
continue; break;
if (i > (int)(d->name[0])) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, " OK"); fprintf(stderr, " OK");
#endif #endif
strcpy((char *)as, d->ip); strcpy((char *)as, d->ip);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, " %s ", as); fprintf(stderr, " as:%s\n", as);
#endif #endif
return 0; return 0;
} }
else if (type == REQ_PTR) { /* search by IP-address */ } else
if (type == REQ_PTR) { /* search by IP-address */
if (!strncmp((char*)&d->rip[1], (char*)&qs[1], strlen(d->rip)-1)) { if (!strncmp((char*)&d->rip[1], (char*)&qs[1], strlen(d->rip)-1)) {
strcpy((char *)as, d->name); strcpy((char *)as, d->name);
return 0; return 0;
} }
} }
} while ((d = d->next) != NULL); d = d->next;
} while (d);
return -1; return -1;
} }
@ -253,7 +266,7 @@ static int table_lookup(uint16_t type, uint8_t * as, uint8_t * qs)
/* /*
* Decode message and generate answer * Decode message and generate answer
*/ */
#define eret(s) do { fprintf (stderr, "%s\n", s); return -1; } while (0) #define eret(s) do { fputs(s, stderr); return -1; } while (0)
static int process_packet(uint8_t * buf) static int process_packet(uint8_t * buf)
{ {
struct dns_head *head; struct dns_head *head;
@ -269,13 +282,13 @@ static int process_packet(uint8_t * buf)
head = (struct dns_head *)buf; head = (struct dns_head *)buf;
if (head->nquer == 0) if (head->nquer == 0)
eret("no queries"); eret("no queries\n");
if ((head->flags & 0x8000)) if (head->flags & 0x8000)
eret("ignoring response packet"); eret("ignoring response packet\n");
from = (void *)&head[1]; // start of query string from = (void *)&head[1]; // start of query string
next = answb = from + strlen((char *)&head[1]) + 1 + sizeof(struct dns_prop); // where to append answer block next = answb = from + strlen((char *)from) + 1 + sizeof(struct dns_prop); // where to append answer block
outr.rlen = 0; // may change later outr.rlen = 0; // may change later
outr.r = NULL; outr.r = NULL;
@ -299,9 +312,8 @@ static int process_packet(uint8_t * buf)
goto empty_packet; goto empty_packet;
// We have a standard query // We have a standard query
log_message(LOG_FILE, (char *)from);
log_message(LOG_FILE, (char *)head); lookup_result = table_lookup(type, answstr, (uint8_t*)from);
lookup_result = table_lookup(type, answstr, (uint8_t*)(&head[1]));
if (lookup_result != 0) { if (lookup_result != 0) {
outr.flags = 3 | 0x0400; //name do not exist and auth outr.flags = 3 | 0x0400; //name do not exist and auth
goto empty_packet; goto empty_packet;
@ -335,7 +347,7 @@ static int process_packet(uint8_t * buf)
memcpy(next, (void *)answstr, outr.rlen); memcpy(next, (void *)answstr, outr.rlen);
next += outr.rlen; next += outr.rlen;
empty_packet: empty_packet:
flags = ntohs(head->flags); flags = ntohs(head->flags);
// clear rcode and RA, set responsebit and our new flags // clear rcode and RA, set responsebit and our new flags
@ -358,35 +370,31 @@ static void interrupt(int x)
exit(2); exit(2);
} }
#define is_daemon() (flags&16)
#define is_verbose() (flags&32)
//#define DEBUG 1
int dnsd_main(int argc, char **argv) int dnsd_main(int argc, char **argv)
{ {
int udps; int udps;
uint16_t port = 53; uint16_t port = 53;
uint8_t buf[MAX_PACK_LEN]; uint8_t buf[MAX_PACK_LEN];
unsigned long flags = 0;
char *listen_interface = "0.0.0.0"; char *listen_interface = "0.0.0.0";
char *sttl=NULL, *sport=NULL; char *sttl, *sport;
if(argc > 1) getopt32(argc, argv, "i:c:t:p:dv", &listen_interface, &fileconf, &sttl, &sport);
flags = getopt32(argc, argv, "i:c:t:p:dv", &listen_interface, &fileconf, &sttl, &sport); //if (option_mask32 & 0x1) // -i
if(sttl) //if (option_mask32 & 0x2) // -c
if(!(ttl = atol(sttl))) if (option_mask32 & 0x4) // -t
if (!(ttl = atol(sttl)))
bb_show_usage(); bb_show_usage();
if(sport) if (option_mask32 & 0x8) // -p
if(!(port = atol(sport))) if (!(port = atol(sport)))
bb_show_usage(); bb_show_usage();
if(is_verbose()) { if (OPT_verbose) {
fprintf(stderr,"listen_interface: %s\n", listen_interface); bb_info_msg("listen_interface: %s", listen_interface);
fprintf(stderr,"ttl: %d, port: %d\n", ttl, port); bb_info_msg("ttl: %d, port: %d", ttl, port);
fprintf(stderr,"fileconf: %s\n", fileconf); bb_info_msg("fileconf: %s", fileconf);
} }
if(is_daemon()) if (OPT_daemon)
#ifdef BB_NOMMU #ifdef BB_NOMMU
/* reexec for vfork() do continue parent */ /* reexec for vfork() do continue parent */
vfork_daemon_rexec(1, 0, argc, argv, "-d"); vfork_daemon_rexec(1, 0, argc, argv, "-d");
@ -394,7 +402,7 @@ int dnsd_main(int argc, char **argv)
xdaemon(1, 0); xdaemon(1, 0);
#endif #endif
dnsentryinit(is_verbose()); dnsentryinit();
signal(SIGINT, interrupt); signal(SIGINT, interrupt);
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
@ -417,20 +425,20 @@ int dnsd_main(int argc, char **argv)
FD_ZERO(&fdset); FD_ZERO(&fdset);
FD_SET(udps, &fdset); FD_SET(udps, &fdset);
// Block until a message arrives // Block until a message arrives
if((r = select(udps + 1, &fdset, NULL, NULL, NULL)) < 0) r = select(udps + 1, &fdset, NULL, NULL, NULL);
if (r < 0)
bb_perror_msg_and_die("select error"); bb_perror_msg_and_die("select error");
else if (r == 0)
if(r == 0)
bb_perror_msg_and_die("select spurious return"); bb_perror_msg_and_die("select spurious return");
/* Can this test ever be false? */ /* Can this test ever be false? - yes */
if (FD_ISSET(udps, &fdset)) { if (FD_ISSET(udps, &fdset)) {
struct sockaddr_in from; struct sockaddr_in from;
int fromlen = sizeof(from); int fromlen = sizeof(from);
r = recvfrom(udps, buf, sizeof(buf), 0, r = recvfrom(udps, buf, sizeof(buf), 0,
(struct sockaddr *)&from, (struct sockaddr *)&from,
(void *)&fromlen); (void *)&fromlen);
if(is_verbose()) if (OPT_verbose)
fprintf(stderr, "\n--- Got UDP "); fprintf(stderr, "\n--- Got UDP ");
log_message(LOG_FILE, "\n--- Got UDP "); log_message(LOG_FILE, "\n--- Got UDP ");
@ -445,9 +453,7 @@ int dnsd_main(int argc, char **argv)
r, 0, (struct sockaddr *)&from, r, 0, (struct sockaddr *)&from,
fromlen); fromlen);
} }
} // end if } // end if
} // end while } // end while
return 0; return 0;
} }

View File

@ -89,7 +89,6 @@ struct interfaces_file_t
struct mapping_defn_t *mappings; struct mapping_defn_t *mappings;
}; };
static unsigned option_mask;
#define OPTION_STR "anvf" USE_FEATURE_IFUPDOWN_MAPPING("m") "i:" #define OPTION_STR "anvf" USE_FEATURE_IFUPDOWN_MAPPING("m") "i:"
enum { enum {
OPT_do_all = 0x1, OPT_do_all = 0x1,
@ -98,11 +97,11 @@ enum {
OPT_force = 0x8, OPT_force = 0x8,
OPT_no_mappings = 0x10, OPT_no_mappings = 0x10,
}; };
#define DO_ALL (option_mask & OPT_do_all) #define DO_ALL (option_mask32 & OPT_do_all)
#define NO_ACT (option_mask & OPT_no_act) #define NO_ACT (option_mask32 & OPT_no_act)
#define VERBOSE (option_mask & OPT_verbose) #define VERBOSE (option_mask32 & OPT_verbose)
#define FORCE (option_mask & OPT_force) #define FORCE (option_mask32 & OPT_force)
#define NO_MAPPINGS (option_mask & OPT_no_mappings) #define NO_MAPPINGS (option_mask32 & OPT_no_mappings)
static char **__myenviron; static char **__myenviron;
@ -881,10 +880,10 @@ static void set_environ(struct interface_defn_t *iface, const char *mode)
static int doit(char *str) static int doit(char *str)
{ {
if (option_mask & (OPT_no_act|OPT_verbose)) { if (option_mask32 & (OPT_no_act|OPT_verbose)) {
puts(str); puts(str);
} }
if (!(option_mask & OPT_no_act)) { if (!(option_mask32 & OPT_no_act)) {
pid_t child; pid_t child;
int status; int status;
@ -1088,7 +1087,7 @@ int ifupdown_main(int argc, char **argv)
cmds = iface_down; cmds = iface_down;
} }
option_mask = getopt32(argc, argv, OPTION_STR, &interfaces); getopt32(argc, argv, OPTION_STR, &interfaces);
if (argc - optind > 0) { if (argc - optind > 0) {
if (DO_ALL) bb_show_usage(); if (DO_ALL) bb_show_usage();
} else } else

View File

@ -34,8 +34,7 @@ typedef int (*cmp_t)(procps_status_t *P, procps_status_t *Q);
static procps_status_t *top; /* Hehe */ static procps_status_t *top; /* Hehe */
static int ntop; static int ntop;
static unsigned option_mask; #define OPT_BATCH_MODE (option_mask32 & 0x4)
#define OPT_BATCH_MODE (option_mask & 0x4)
#ifdef CONFIG_FEATURE_USE_TERMIOS #ifdef CONFIG_FEATURE_USE_TERMIOS
static int pid_sort(procps_status_t *P, procps_status_t *Q) static int pid_sort(procps_status_t *P, procps_status_t *Q)
@ -398,11 +397,11 @@ int top_main(int argc, char **argv)
/* do normal option parsing */ /* do normal option parsing */
interval = 5; interval = 5;
opt_complementary = "-"; opt_complementary = "-";
option_mask = getopt32(argc, argv, "d:n:b", getopt32(argc, argv, "d:n:b",
&sinterval, &siterations); &sinterval, &siterations);
if (option_mask & 0x1) interval = atoi(sinterval); // -d if (option_mask32 & 0x1) interval = atoi(sinterval); // -d
if (option_mask & 0x2) iterations = atoi(siterations); // -n if (option_mask32 & 0x2) iterations = atoi(siterations); // -n
//if (option_mask & 0x4) // -b //if (option_mask32 & 0x4) // -b
/* change to /proc */ /* change to /proc */
xchdir("/proc"); xchdir("/proc");

View File

@ -2,13 +2,12 @@
#include <dirent.h> #include <dirent.h>
static unsigned option_mask;
// Must match constants in chpst_main! // Must match constants in chpst_main!
#define OPT_verbose (option_mask & 0x2000) #define OPT_verbose (option_mask32 & 0x2000)
#define OPT_pgrp (option_mask & 0x4000) #define OPT_pgrp (option_mask32 & 0x4000)
#define OPT_nostdin (option_mask & 0x8000) #define OPT_nostdin (option_mask32 & 0x8000)
#define OPT_nostdout (option_mask & 0x10000) #define OPT_nostdout (option_mask32 & 0x10000)
#define OPT_nostderr (option_mask & 0x20000) #define OPT_nostderr (option_mask32 & 0x20000)
static char *set_user; static char *set_user;
static char *env_user; static char *env_user;
@ -224,28 +223,28 @@ int chpst_main(int argc, char **argv)
{ {
char *m,*d,*o,*p,*f,*c,*r,*t,*n; char *m,*d,*o,*p,*f,*c,*r,*t,*n;
option_mask = getopt32(argc, argv, "u:U:e:m:d:o:p:f:c:r:t:/:n:vP012", getopt32(argc, argv, "u:U:e:m:d:o:p:f:c:r:t:/:n:vP012",
&set_user,&env_user,&env_dir, &set_user,&env_user,&env_dir,
&m,&d,&o,&p,&f,&c,&r,&t,&root,&n); &m,&d,&o,&p,&f,&c,&r,&t,&root,&n);
// if (option_mask & 0x1) // -u // if (option_mask32 & 0x1) // -u
// if (option_mask & 0x2) // -U // if (option_mask32 & 0x2) // -U
// if (option_mask & 0x4) // -e // if (option_mask32 & 0x4) // -e
if (option_mask & 0x8) limits = limitl = limita = limitd = bb_xgetularg10(m); // -m if (option_mask32 & 0x8) limits = limitl = limita = limitd = bb_xgetularg10(m); // -m
if (option_mask & 0x10) limitd = bb_xgetularg10(d); // -d if (option_mask32 & 0x10) limitd = bb_xgetularg10(d); // -d
if (option_mask & 0x20) limito = bb_xgetularg10(o); // -o if (option_mask32 & 0x20) limito = bb_xgetularg10(o); // -o
if (option_mask & 0x40) limitp = bb_xgetularg10(p); // -p if (option_mask32 & 0x40) limitp = bb_xgetularg10(p); // -p
if (option_mask & 0x80) limitf = bb_xgetularg10(f); // -f if (option_mask32 & 0x80) limitf = bb_xgetularg10(f); // -f
if (option_mask & 0x100) limitc = bb_xgetularg10(c); // -c if (option_mask32 & 0x100) limitc = bb_xgetularg10(c); // -c
if (option_mask & 0x200) limitr = bb_xgetularg10(r); // -r if (option_mask32 & 0x200) limitr = bb_xgetularg10(r); // -r
if (option_mask & 0x400) limitt = bb_xgetularg10(t); // -t if (option_mask32 & 0x400) limitt = bb_xgetularg10(t); // -t
// if (option_mask & 0x800) // -/ // if (option_mask32 & 0x800) // -/
if (option_mask & 0x1000) nicelvl = bb_xgetlarg_bnd_sfx(n, 10, -20, 20, NULL); // -n if (option_mask32 & 0x1000) nicelvl = bb_xgetlarg_bnd_sfx(n, 10, -20, 20, NULL); // -n
// The below consts should match #defines at top! // The below consts should match #defines at top!
//if (option_mask & 0x2000) OPT_verbose = 1; // -v //if (option_mask32 & 0x2000) OPT_verbose = 1; // -v
//if (option_mask & 0x4000) OPT_pgrp = 1; // -P //if (option_mask32 & 0x4000) OPT_pgrp = 1; // -P
//if (option_mask & 0x8000) OPT_nostdin = 1; // -0 //if (option_mask32 & 0x8000) OPT_nostdin = 1; // -0
//if (option_mask & 0x10000) OPT_nostdout = 1; // -1 //if (option_mask32 & 0x10000) OPT_nostdout = 1; // -1
//if (option_mask & 0x20000) OPT_nostderr = 1; // -2 //if (option_mask32 & 0x20000) OPT_nostderr = 1; // -2
} }
argv += optind; argv += optind;
if (!argv || !*argv) bb_show_usage(); if (!argv || !*argv) bb_show_usage();
@ -311,19 +310,19 @@ static void envdir(int argc, char **argv)
static void softlimit(int argc, char **argv) static void softlimit(int argc, char **argv)
{ {
char *a,*c,*d,*f,*l,*m,*o,*p,*r,*s,*t; char *a,*c,*d,*f,*l,*m,*o,*p,*r,*s,*t;
option_mask = getopt32(argc, argv, "a:c:d:f:l:m:o:p:r:s:t:", getopt32(argc, argv, "a:c:d:f:l:m:o:p:r:s:t:",
&a,&c,&d,&f,&l,&m,&o,&p,&r,&s,&t); &a,&c,&d,&f,&l,&m,&o,&p,&r,&s,&t);
if (option_mask & 0x001) limita = bb_xgetularg10(a); // -a if (option_mask32 & 0x001) limita = bb_xgetularg10(a); // -a
if (option_mask & 0x002) limitc = bb_xgetularg10(c); // -c if (option_mask32 & 0x002) limitc = bb_xgetularg10(c); // -c
if (option_mask & 0x004) limitd = bb_xgetularg10(d); // -d if (option_mask32 & 0x004) limitd = bb_xgetularg10(d); // -d
if (option_mask & 0x008) limitf = bb_xgetularg10(f); // -f if (option_mask32 & 0x008) limitf = bb_xgetularg10(f); // -f
if (option_mask & 0x010) limitl = bb_xgetularg10(l); // -l if (option_mask32 & 0x010) limitl = bb_xgetularg10(l); // -l
if (option_mask & 0x020) limits = limitl = limita = limitd = bb_xgetularg10(m); // -m if (option_mask32 & 0x020) limits = limitl = limita = limitd = bb_xgetularg10(m); // -m
if (option_mask & 0x040) limito = bb_xgetularg10(o); // -o if (option_mask32 & 0x040) limito = bb_xgetularg10(o); // -o
if (option_mask & 0x080) limitp = bb_xgetularg10(p); // -p if (option_mask32 & 0x080) limitp = bb_xgetularg10(p); // -p
if (option_mask & 0x100) limitr = bb_xgetularg10(r); // -r if (option_mask32 & 0x100) limitr = bb_xgetularg10(r); // -r
if (option_mask & 0x200) limits = bb_xgetularg10(s); // -s if (option_mask32 & 0x200) limits = bb_xgetularg10(s); // -s
if (option_mask & 0x400) limitt = bb_xgetularg10(t); // -t if (option_mask32 & 0x400) limitt = bb_xgetularg10(t); // -t
argv += optind; argv += optind;
if (!argv[0]) bb_show_usage(); if (!argv[0]) bb_show_usage();
slimit(); slimit();

View File

@ -55,7 +55,6 @@ static struct sockaddr_in remoteaddr;
#endif #endif
/* options */ /* options */
static unsigned option_mask;
/* Correct regardless of combination of CONFIG_xxx */ /* Correct regardless of combination of CONFIG_xxx */
enum { enum {
OPTBIT_mark = 0, // -m OPTBIT_mark = 0, // -m
@ -298,7 +297,7 @@ static void message(char *fmt, ...)
fl.l_len = 1; fl.l_len = 1;
#ifdef CONFIG_FEATURE_IPC_SYSLOG #ifdef CONFIG_FEATURE_IPC_SYSLOG
if ((option_mask & OPT_circularlog) && shbuf) { if ((option_mask32 & OPT_circularlog) && shbuf) {
char b[1024]; char b[1024];
va_start(arguments, fmt); va_start(arguments, fmt);
@ -404,7 +403,7 @@ static void logMessage(int pri, char *msg)
/* todo: supress duplicates */ /* todo: supress duplicates */
#ifdef CONFIG_FEATURE_REMOTE_LOG #ifdef CONFIG_FEATURE_REMOTE_LOG
if (option_mask & OPT_remotelog) { if (option_mask32 & OPT_remotelog) {
char line[MAXLINE + 1]; char line[MAXLINE + 1];
/* trying connect the socket */ /* trying connect the socket */
if (-1 == remotefd) { if (-1 == remotefd) {
@ -419,12 +418,12 @@ static void logMessage(int pri, char *msg)
} }
} }
if (option_mask & OPT_locallog) if (option_mask32 & OPT_locallog)
#endif #endif
{ {
/* now spew out the message to wherever it is supposed to go */ /* now spew out the message to wherever it is supposed to go */
if (pri == 0 || LOG_PRI(pri) < logLevel) { if (pri == 0 || LOG_PRI(pri) < logLevel) {
if (option_mask & OPT_small) if (option_mask32 & OPT_small)
message("%s %s\n", timestamp, msg); message("%s %s\n", timestamp, msg);
else else
message("%s %s %s %s\n", timestamp, LocalHostName, res, msg); message("%s %s %s %s\n", timestamp, LocalHostName, res, msg);
@ -531,7 +530,7 @@ static void doSyslogd(void)
if (chmod(lfile, 0666) < 0) { if (chmod(lfile, 0666) < 0) {
bb_perror_msg_and_die("cannot set permission on %s", lfile); bb_perror_msg_and_die("cannot set permission on %s", lfile);
} }
if (ENABLE_FEATURE_IPC_SYSLOG && (option_mask & OPT_circularlog)) { if (ENABLE_FEATURE_IPC_SYSLOG && (option_mask32 & OPT_circularlog)) {
ipcsyslog_init(); ipcsyslog_init();
} }
@ -575,26 +574,26 @@ int syslogd_main(int argc, char **argv)
char *p; char *p;
/* do normal option parsing */ /* do normal option parsing */
option_mask = getopt32(argc, argv, OPTION_STR, OPTION_PARAM); getopt32(argc, argv, OPTION_STR, OPTION_PARAM);
if (option_mask & OPT_mark) MarkInterval = atoi(opt_m) * 60; // -m if (option_mask32 & OPT_mark) MarkInterval = atoi(opt_m) * 60; // -m
//if (option_mask & OPT_nofork) // -n //if (option_mask32 & OPT_nofork) // -n
//if (option_mask & OPT_outfile) // -O //if (option_mask32 & OPT_outfile) // -O
if (option_mask & OPT_loglevel) { // -l if (option_mask32 & OPT_loglevel) { // -l
logLevel = atoi(opt_l); logLevel = atoi(opt_l);
/* Valid levels are between 1 and 8 */ /* Valid levels are between 1 and 8 */
if (logLevel < 1 || logLevel > 8) if (logLevel < 1 || logLevel > 8)
bb_show_usage(); bb_show_usage();
} }
//if (option_mask & OPT_small) // -S //if (option_mask32 & OPT_small) // -S
#if ENABLE_FEATURE_ROTATE_LOGFILE #if ENABLE_FEATURE_ROTATE_LOGFILE
if (option_mask & OPT_filesize) logFileSize = atoi(opt_s) * 1024; // -s if (option_mask32 & OPT_filesize) logFileSize = atoi(opt_s) * 1024; // -s
if (option_mask & OPT_rotatecnt) { // -b if (option_mask32 & OPT_rotatecnt) { // -b
logFileRotate = atoi(opt_b); logFileRotate = atoi(opt_b);
if (logFileRotate > 99) logFileRotate = 99; if (logFileRotate > 99) logFileRotate = 99;
} }
#endif #endif
#if ENABLE_FEATURE_REMOTE_LOG #if ENABLE_FEATURE_REMOTE_LOG
if (option_mask & OPT_remotelog) { // -R if (option_mask32 & OPT_remotelog) { // -R
int port = 514; int port = 514;
char *host = xstrdup(opt_R); char *host = xstrdup(opt_R);
p = strchr(host, ':'); p = strchr(host, ':');
@ -608,10 +607,10 @@ int syslogd_main(int argc, char **argv)
remoteaddr.sin_port = htons(port); remoteaddr.sin_port = htons(port);
free(host); free(host);
} }
//if (option_mask & OPT_locallog) // -L //if (option_mask32 & OPT_locallog) // -L
#endif #endif
#if ENABLE_FEATURE_IPC_SYSLOG #if ENABLE_FEATURE_IPC_SYSLOG
if (option_mask & OPT_circularlog) { // -C if (option_mask32 & OPT_circularlog) { // -C
if (opt_C) { if (opt_C) {
int buf_size = atoi(opt_C); int buf_size = atoi(opt_C);
if (buf_size >= 4) if (buf_size >= 4)
@ -621,8 +620,8 @@ int syslogd_main(int argc, char **argv)
#endif #endif
/* If they have not specified remote logging, then log locally */ /* If they have not specified remote logging, then log locally */
if (ENABLE_FEATURE_REMOTE_LOG && !(option_mask & OPT_remotelog)) if (ENABLE_FEATURE_REMOTE_LOG && !(option_mask32 & OPT_remotelog))
option_mask |= OPT_locallog; option_mask32 |= OPT_locallog;
/* Store away localhost's name before the fork */ /* Store away localhost's name before the fork */
gethostname(LocalHostName, sizeof(LocalHostName)); gethostname(LocalHostName, sizeof(LocalHostName));
@ -633,7 +632,7 @@ int syslogd_main(int argc, char **argv)
umask(0); umask(0);
if (!(option_mask & OPT_nofork)) { if (!(option_mask32 & OPT_nofork)) {
#ifdef BB_NOMMU #ifdef BB_NOMMU
vfork_daemon_rexec(0, 1, argc, argv, "-n"); vfork_daemon_rexec(0, 1, argc, argv, "-n");
#else #else