mirror of
https://github.com/sheumann/hush.git
synced 2024-09-12 15:54:56 +00:00
ifupdown: if $PATH is not set, do not set it to "" in children
Also random code shrink: function old new delta set_environ 328 330 +2 static.label_buf 4 - -4 startup_PATH 4 - -4 my_environ 4 - -4 ifupdown_main 2148 2134 -14 setlocalenv 117 90 -27 get_var 139 112 -27 ------------------------------------------------------------------------------ (add/remove: 0/3 grow/shrink: 1/3 up/down: 2/-80) Total: -78 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
035b4d77dc
commit
62152da892
@ -87,6 +87,7 @@ struct interfaces_file_t {
|
|||||||
struct mapping_defn_t *mappings;
|
struct mapping_defn_t *mappings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define OPTION_STR "anvf" IF_FEATURE_IFUPDOWN_MAPPING("m") "i:"
|
#define OPTION_STR "anvf" IF_FEATURE_IFUPDOWN_MAPPING("m") "i:"
|
||||||
enum {
|
enum {
|
||||||
OPT_do_all = 0x1,
|
OPT_do_all = 0x1,
|
||||||
@ -101,9 +102,14 @@ enum {
|
|||||||
#define FORCE (option_mask32 & OPT_force)
|
#define FORCE (option_mask32 & OPT_force)
|
||||||
#define NO_MAPPINGS (option_mask32 & OPT_no_mappings)
|
#define NO_MAPPINGS (option_mask32 & OPT_no_mappings)
|
||||||
|
|
||||||
static char **my_environ;
|
|
||||||
|
|
||||||
static const char *startup_PATH;
|
struct globals {
|
||||||
|
char **my_environ;
|
||||||
|
const char *startup_PATH;
|
||||||
|
};
|
||||||
|
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||||
|
#define INIT_G() do { } while (0)
|
||||||
|
|
||||||
|
|
||||||
#if ENABLE_FEATURE_IFUPDOWN_IPV4 || ENABLE_FEATURE_IFUPDOWN_IPV6
|
#if ENABLE_FEATURE_IFUPDOWN_IPV4 || ENABLE_FEATURE_IFUPDOWN_IPV6
|
||||||
|
|
||||||
@ -126,7 +132,7 @@ static int strncmpz(const char *l, const char *r, size_t llen)
|
|||||||
int i = strncmp(l, r, llen);
|
int i = strncmp(l, r, llen);
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
return -r[llen];
|
return - (unsigned char)r[llen];
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,16 +141,17 @@ static char *get_var(const char *id, size_t idlen, struct interface_defn_t *ifd)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (strncmpz(id, "iface", idlen) == 0) {
|
if (strncmpz(id, "iface", idlen) == 0) {
|
||||||
static char *label_buf;
|
// ubuntu's ifup doesn't do this:
|
||||||
|
//static char *label_buf;
|
||||||
//char *result;
|
//char *result;
|
||||||
|
//free(label_buf);
|
||||||
free(label_buf);
|
//label_buf = xstrdup(ifd->iface);
|
||||||
label_buf = xstrdup(ifd->iface);
|
// Remove virtual iface suffix
|
||||||
// Remove virtual iface suffix - why?
|
|
||||||
// ubuntu's ifup doesn't do this
|
|
||||||
//result = strchrnul(label_buf, ':');
|
//result = strchrnul(label_buf, ':');
|
||||||
//*result = '\0';
|
//*result = '\0';
|
||||||
return label_buf;
|
//return label_buf;
|
||||||
|
|
||||||
|
return ifd->iface;
|
||||||
}
|
}
|
||||||
if (strncmpz(id, "label", idlen) == 0) {
|
if (strncmpz(id, "label", idlen) == 0) {
|
||||||
return ifd->iface;
|
return ifd->iface;
|
||||||
@ -547,7 +554,7 @@ static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd, execfn *exec)
|
|||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) {
|
for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) {
|
||||||
if (exists_execable(ext_dhcp_clients[i].name)) {
|
if (exists_execable(ext_dhcp_clients[i].name)) {
|
||||||
result += execute(ext_dhcp_clients[i].stopcmd, ifd, exec);
|
result = execute(ext_dhcp_clients[i].stopcmd, ifd, exec);
|
||||||
if (result)
|
if (result)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -896,43 +903,40 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
|
|||||||
static char *setlocalenv(const char *format, const char *name, const char *value)
|
static char *setlocalenv(const char *format, const char *name, const char *value)
|
||||||
{
|
{
|
||||||
char *result;
|
char *result;
|
||||||
char *here;
|
char *dst;
|
||||||
char *there;
|
char *src;
|
||||||
|
char c;
|
||||||
|
|
||||||
result = xasprintf(format, name, value);
|
result = xasprintf(format, name, value);
|
||||||
|
|
||||||
for (here = there = result; *there != '=' && *there; there++) {
|
for (dst = src = result; (c = *src) != '=' && c; src++) {
|
||||||
if (*there == '-')
|
if (c == '-')
|
||||||
*there = '_';
|
c = '_';
|
||||||
if (isalpha(*there))
|
if (c >= 'a' && c <= 'z')
|
||||||
*there = toupper(*there);
|
c -= ('a' - 'A');
|
||||||
|
if (isalnum(c) || c == '_')
|
||||||
if (isalnum(*there) || *there == '_') {
|
*dst++ = c;
|
||||||
*here = *there;
|
|
||||||
here++;
|
|
||||||
}
|
}
|
||||||
}
|
overlapping_strcpy(dst, src);
|
||||||
memmove(here, there, strlen(there) + 1);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_environ(struct interface_defn_t *iface, const char *mode)
|
static void set_environ(struct interface_defn_t *iface, const char *mode)
|
||||||
{
|
{
|
||||||
char **environend;
|
|
||||||
int i;
|
int i;
|
||||||
const int n_env_entries = iface->n_options + 5;
|
char **pp;
|
||||||
char **ppch;
|
|
||||||
|
|
||||||
if (my_environ != NULL) {
|
if (G.my_environ != NULL) {
|
||||||
for (ppch = my_environ; *ppch; ppch++) {
|
for (pp = G.my_environ; *pp; pp++) {
|
||||||
free(*ppch);
|
free(*pp);
|
||||||
*ppch = NULL;
|
|
||||||
}
|
}
|
||||||
free(my_environ);
|
free(G.my_environ);
|
||||||
}
|
}
|
||||||
my_environ = xzalloc(sizeof(char *) * (n_env_entries + 1 /* for final NULL */ ));
|
|
||||||
environend = my_environ;
|
/* note: last element will stay NULL: */
|
||||||
|
G.my_environ = xzalloc(sizeof(char *) * (iface->n_options + 6));
|
||||||
|
pp = G.my_environ;
|
||||||
|
|
||||||
for (i = 0; i < iface->n_options; i++) {
|
for (i = 0; i < iface->n_options; i++) {
|
||||||
if (strcmp(iface->option[i].name, "up") == 0
|
if (strcmp(iface->option[i].name, "up") == 0
|
||||||
@ -942,14 +946,15 @@ static void set_environ(struct interface_defn_t *iface, const char *mode)
|
|||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*(environend++) = setlocalenv("IF_%s=%s", iface->option[i].name, iface->option[i].value);
|
*pp++ = setlocalenv("IF_%s=%s", iface->option[i].name, iface->option[i].value);
|
||||||
}
|
}
|
||||||
|
|
||||||
*(environend++) = setlocalenv("%s=%s", "IFACE", iface->iface);
|
*pp++ = setlocalenv("%s=%s", "IFACE", iface->iface);
|
||||||
*(environend++) = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name);
|
*pp++ = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name);
|
||||||
*(environend++) = setlocalenv("%s=%s", "METHOD", iface->method->name);
|
*pp++ = setlocalenv("%s=%s", "METHOD", iface->method->name);
|
||||||
*(environend++) = setlocalenv("%s=%s", "MODE", mode);
|
*pp++ = setlocalenv("%s=%s", "MODE", mode);
|
||||||
*(environend++) = setlocalenv("%s=%s", "PATH", startup_PATH);
|
if (G.startup_PATH)
|
||||||
|
*pp++ = setlocalenv("%s=%s", "PATH", G.startup_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int doit(char *str)
|
static int doit(char *str)
|
||||||
@ -967,7 +972,7 @@ static int doit(char *str)
|
|||||||
case -1: /* failure */
|
case -1: /* failure */
|
||||||
return 0;
|
return 0;
|
||||||
case 0: /* child */
|
case 0: /* child */
|
||||||
execle(DEFAULT_SHELL, DEFAULT_SHELL, "-c", str, (char *) NULL, my_environ);
|
execle(DEFAULT_SHELL, DEFAULT_SHELL, "-c", str, (char *) NULL, G.my_environ);
|
||||||
_exit(127);
|
_exit(127);
|
||||||
}
|
}
|
||||||
safe_waitpid(child, &status, 0);
|
safe_waitpid(child, &status, 0);
|
||||||
@ -1142,6 +1147,10 @@ int ifupdown_main(int argc, char **argv)
|
|||||||
const char *interfaces = "/etc/network/interfaces";
|
const char *interfaces = "/etc/network/interfaces";
|
||||||
bool any_failures = 0;
|
bool any_failures = 0;
|
||||||
|
|
||||||
|
INIT_G();
|
||||||
|
|
||||||
|
G.startup_PATH = getenv("PATH");
|
||||||
|
|
||||||
cmds = iface_down;
|
cmds = iface_down;
|
||||||
if (applet_name[2] == 'u') {
|
if (applet_name[2] == 'u') {
|
||||||
/* ifup command */
|
/* ifup command */
|
||||||
@ -1159,9 +1168,6 @@ int ifupdown_main(int argc, char **argv)
|
|||||||
defn = read_interfaces(interfaces);
|
defn = read_interfaces(interfaces);
|
||||||
debug_noise("\ndone reading %s\n\n", interfaces);
|
debug_noise("\ndone reading %s\n\n", interfaces);
|
||||||
|
|
||||||
startup_PATH = getenv("PATH");
|
|
||||||
if (!startup_PATH) startup_PATH = "";
|
|
||||||
|
|
||||||
/* Create a list of interfaces to work on */
|
/* Create a list of interfaces to work on */
|
||||||
if (DO_ALL) {
|
if (DO_ALL) {
|
||||||
target_list = defn->autointerfaces;
|
target_list = defn->autointerfaces;
|
||||||
|
Loading…
Reference in New Issue
Block a user