Merge branch 'master' of git+ssh://vda@busybox.net/var/lib/git/busybox

This commit is contained in:
Denys Vlasenko 2012-05-19 22:37:07 +02:00
commit aaf827203d
4 changed files with 40 additions and 49 deletions

View file

@ -60,8 +60,8 @@
#if !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_FEATURE_SEAMLESS_BZ2 #if !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_FEATURE_SEAMLESS_BZ2
/* Do not pass gzip flag to writeTarFile() */ /* Do not pass gzip flag to writeTarFile() */
#define writeTarFile(tar_fd, verboseFlag, dereferenceFlag, include, exclude, gzip) \ #define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \
writeTarFile(tar_fd, verboseFlag, dereferenceFlag, include, exclude) writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude)
#endif #endif
@ -598,7 +598,7 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
/* gcc 4.2.1 inlines it, making code bigger */ /* gcc 4.2.1 inlines it, making code bigger */
static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
int dereferenceFlag, const llist_t *include, int recurseFlags, const llist_t *include,
const llist_t *exclude, int gzip) const llist_t *exclude, int gzip)
{ {
int errorFlag = FALSE; int errorFlag = FALSE;
@ -621,8 +621,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
/* Read the directory/files and iterate over them one at a time */ /* Read the directory/files and iterate over them one at a time */
while (include) { while (include) {
if (!recursive_action(include->data, ACTION_RECURSE | if (!recursive_action(include->data, recurseFlags,
(dereferenceFlag ? ACTION_FOLLOWLINKS : 0),
writeFileToTarball, writeFileToTarball, &tbInfo, 0) writeFileToTarball, writeFileToTarball, &tbInfo, 0)
) { ) {
errorFlag = TRUE; errorFlag = TRUE;
@ -662,7 +661,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
} }
#else #else
int writeTarFile(int tar_fd, int verboseFlag, int writeTarFile(int tar_fd, int verboseFlag,
int dereferenceFlag, const llist_t *include, int recurseFlags, const llist_t *include,
const llist_t *exclude, int gzip); const llist_t *exclude, int gzip);
#endif /* FEATURE_TAR_CREATE */ #endif /* FEATURE_TAR_CREATE */
@ -749,6 +748,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
// o no-same-owner // o no-same-owner
// p same-permissions // p same-permissions
// k keep-old // k keep-old
// no-recursion
// numeric-owner // numeric-owner
// no-same-permissions // no-same-permissions
// overwrite // overwrite
@ -768,6 +768,7 @@ enum {
IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,) // 16th bit IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,) // 16th bit
IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,) IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,)
#if ENABLE_FEATURE_TAR_LONG_OPTIONS #if ENABLE_FEATURE_TAR_LONG_OPTIONS
OPTBIT_NORECURSION,
IF_FEATURE_TAR_TO_COMMAND(OPTBIT_2COMMAND ,) IF_FEATURE_TAR_TO_COMMAND(OPTBIT_2COMMAND ,)
OPTBIT_NUMERIC_OWNER, OPTBIT_NUMERIC_OWNER,
OPTBIT_NOPRESERVE_PERM, OPTBIT_NOPRESERVE_PERM,
@ -791,6 +792,7 @@ enum {
OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z
OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z
OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m
OPT_NORECURSION = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION )) + 0, // no-recursion
OPT_2COMMAND = IF_FEATURE_TAR_TO_COMMAND( (1 << OPTBIT_2COMMAND )) + 0, // to-command OPT_2COMMAND = IF_FEATURE_TAR_TO_COMMAND( (1 << OPTBIT_2COMMAND )) + 0, // to-command
OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner
OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions
@ -835,6 +837,7 @@ static const char tar_longopts[] ALIGN1 =
# if ENABLE_FEATURE_TAR_NOPRESERVE_TIME # if ENABLE_FEATURE_TAR_NOPRESERVE_TIME
"touch\0" No_argument "m" "touch\0" No_argument "m"
# endif # endif
"no-recursion\0" No_argument "\xfa"
# if ENABLE_FEATURE_TAR_TO_COMMAND # if ENABLE_FEATURE_TAR_TO_COMMAND
"to-command\0" Required_argument "\xfb" "to-command\0" Required_argument "\xfb"
# endif # endif
@ -1050,7 +1053,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
zipMode = 2; zipMode = 2;
#endif #endif
/* NB: writeTarFile() closes tar_handle->src_fd */ /* NB: writeTarFile() closes tar_handle->src_fd */
return writeTarFile(tar_handle->src_fd, verboseFlag, opt & OPT_DEREFERENCE, return writeTarFile(tar_handle->src_fd, verboseFlag,
(opt & OPT_DEREFERENCE ? ACTION_FOLLOWLINKS : 0)
| (opt & OPT_NORECURSION ? 0 : ACTION_RECURSE),
tar_handle->accept, tar_handle->accept,
tar_handle->reject, zipMode); tar_handle->reject, zipMode);
} }

View file

@ -7,8 +7,14 @@
# instead of the default 0:0 660. # instead of the default 0:0 660.
# #
# Syntax: # Syntax:
# %s %d:%d %s # [-]devicename_regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
# devicename_regex user:group mode # [-]$ENVVAR=regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
# [-]@maj,min[-min2] user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
#
# [-]: do not stop on this match, continue reading mdev.conf
# =: move, >: move and create a symlink
# !: do not create device node
# @|$|*: run@cmd if $ACTION=add, $cmd if $ACTION=remove, *cmd in all cases
null 0:0 666 null 0:0 666
zero 0:0 666 zero 0:0 666

View file

@ -7,10 +7,14 @@
# instead of the default 0:0 660. # instead of the default 0:0 660.
# #
# Syntax: # Syntax:
# [-]devicename_regex user:group mode [>|=path] [@|$|*cmd args...] # [-]devicename_regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
# [-]$ENVVAR=regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
# [-]@maj,min[-min2] user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
# #
# [-]: do not stop on this match, continue reading mdev.conf
# =: move, >: move and create a symlink # =: move, >: move and create a symlink
# @|$|*: run $cmd on delete, @cmd on create, *cmd on both # !: do not create device node
# @|$|*: run cmd if $ACTION=remove, @cmd if $ACTION=add, *cmd in all cases
# support module loading on hotplug # support module loading on hotplug
$MODALIAS=.* root:root 660 @modprobe "$MODALIAS" $MODALIAS=.* root:root 660 @modprobe "$MODALIAS"
@ -49,7 +53,6 @@ sr[0-9]* root:cdrom 660 @ln -sf $MDEV cdrom
fd[0-9]* root:floppy 660 fd[0-9]* root:floppy 660
# net devices # net devices
-net/.* root:root 600 @nameif
tun[0-9]* root:root 600 =net/ tun[0-9]* root:root 600 =net/
tap[0-9]* root:root 600 =net/ tap[0-9]* root:root 600 =net/

View file

@ -236,7 +236,6 @@ enum { OP_add, OP_remove };
struct rule { struct rule {
bool keep_matching; bool keep_matching;
bool regex_compiled; bool regex_compiled;
bool regex_has_slash;
mode_t mode; mode_t mode;
int maj, min0, min1; int maj, min0, min1;
struct bb_uidgid_t ugid; struct bb_uidgid_t ugid;
@ -340,7 +339,6 @@ static void parse_next_rule(void)
} }
xregcomp(&G.cur_rule.match, val, REG_EXTENDED); xregcomp(&G.cur_rule.match, val, REG_EXTENDED);
G.cur_rule.regex_compiled = 1; G.cur_rule.regex_compiled = 1;
G.cur_rule.regex_has_slash = (strchr(val, '/') != NULL);
} }
/* 2nd field: uid:gid - device ownership */ /* 2nd field: uid:gid - device ownership */
@ -467,11 +465,10 @@ static char *build_alias(char *alias, const char *device_name)
*/ */
static void make_device(char *device_name, char *path, int operation) static void make_device(char *device_name, char *path, int operation)
{ {
char *subsystem_slash_devname;
int major, minor, type, len; int major, minor, type, len;
if (G.verbose) if (G.verbose)
bb_error_msg("make_device: %s, %s, op:%d", device_name, path, operation); bb_error_msg("device: %s, %s", device_name, path);
/* Try to read major/minor string. Note that the kernel puts \n after /* Try to read major/minor string. Note that the kernel puts \n after
* the data, so we don't need to worry about null terminating the string * the data, so we don't need to worry about null terminating the string
@ -479,7 +476,7 @@ static void make_device(char *device_name, char *path, int operation)
* We also depend on path having writeable space after it. * We also depend on path having writeable space after it.
*/ */
major = -1; major = -1;
if (operation != OP_remove) { if (operation == OP_add) {
char *dev_maj_min = path + strlen(path); char *dev_maj_min = path + strlen(path);
strcpy(dev_maj_min, "/dev"); strcpy(dev_maj_min, "/dev");
@ -490,7 +487,10 @@ static void make_device(char *device_name, char *path, int operation)
return; return;
/* no "dev" file, but we can still run scripts /* no "dev" file, but we can still run scripts
* based on device name */ * based on device name */
} else if (sscanf(++dev_maj_min, "%u:%u", &major, &minor) != 2) { } else if (sscanf(++dev_maj_min, "%u:%u", &major, &minor) == 2) {
if (G.verbose)
bb_error_msg("maj,min: %u,%u", major, minor);
} else {
major = -1; major = -1;
} }
} }
@ -502,29 +502,12 @@ static void make_device(char *device_name, char *path, int operation)
/* http://kernel.org/doc/pending/hotplug.txt says that only /* http://kernel.org/doc/pending/hotplug.txt says that only
* "/sys/block/..." is for block devices. "/sys/bus" etc is not. * "/sys/block/..." is for block devices. "/sys/bus" etc is not.
* But since 2.6.25 block devices are also in /sys/class/block. * But since 2.6.25 block devices are also in /sys/class/block.
* We use strstr("/block/") to forestall future surprises. */ * We use strstr("/block/") to forestall future surprises.
*/
type = S_IFCHR; type = S_IFCHR;
if (strstr(path, "/block/") || (G.subsystem && strncmp(G.subsystem, "block", 5) == 0)) if (strstr(path, "/block/") || (G.subsystem && strncmp(G.subsystem, "block", 5) == 0))
type = S_IFBLK; type = S_IFBLK;
/* Make path point to "subsystem/device_name" */
subsystem_slash_devname = NULL;
/* Check for coldplug invocations first */
if (strncmp(path, "/sys/block/", 11) == 0) /* legacy case */
path += sizeof("/sys/") - 1;
else if (strncmp(path, "/sys/class/", 11) == 0)
path += sizeof("/sys/class/") - 1;
else {
/* Example of a hotplug invocation:
* SUBSYSTEM="block"
* DEVPATH="/sys" + "/devices/virtual/mtd/mtd3/mtdblock3"
* ("/sys" is added by mdev_main)
* - path does not contain subsystem
*/
subsystem_slash_devname = concat_path_file(G.subsystem, device_name);
path = subsystem_slash_devname;
}
#if ENABLE_FEATURE_MDEV_CONF #if ENABLE_FEATURE_MDEV_CONF
G.rule_idx = 0; /* restart from the beginning (think mdev -s) */ G.rule_idx = 0; /* restart from the beginning (think mdev -s) */
#endif #endif
@ -537,7 +520,7 @@ static void make_device(char *device_name, char *path, int operation)
char *node_name; char *node_name;
const struct rule *rule; const struct rule *rule;
str_to_match = ""; str_to_match = device_name;
rule = next_rule(); rule = next_rule();
@ -555,12 +538,8 @@ static void make_device(char *device_name, char *path, int operation)
dbg("getenv('%s'):'%s'", rule->envvar, str_to_match); dbg("getenv('%s'):'%s'", rule->envvar, str_to_match);
if (!str_to_match) if (!str_to_match)
continue; continue;
} else {
//TODO: $DEVNAME can have slashes too,
// we should stop abusing '/' as a special syntax in our regex'es
/* regex to match [subsystem/]device_name */
str_to_match = (rule->regex_has_slash ? path : device_name);
} }
/* else: str_to_match = device_name */
if (rule->regex_compiled) { if (rule->regex_compiled) {
int regex_match = regexec(&rule->match, str_to_match, ARRAY_SIZE(off), off, 0); int regex_match = regexec(&rule->match, str_to_match, ARRAY_SIZE(off), off, 0);
@ -669,12 +648,12 @@ static void make_device(char *device_name, char *path, int operation)
bb_error_msg("mknod: %s (%d,%d) %o", node_name, major, minor, rule->mode | type); bb_error_msg("mknod: %s (%d,%d) %o", node_name, major, minor, rule->mode | type);
if (mknod(node_name, rule->mode | type, makedev(major, minor)) && errno != EEXIST) if (mknod(node_name, rule->mode | type, makedev(major, minor)) && errno != EEXIST)
bb_perror_msg("can't create '%s'", node_name); bb_perror_msg("can't create '%s'", node_name);
if (major == G.root_major && minor == G.root_minor)
symlink(node_name, "root");
if (ENABLE_FEATURE_MDEV_CONF) { if (ENABLE_FEATURE_MDEV_CONF) {
chmod(node_name, rule->mode); chmod(node_name, rule->mode);
chown(node_name, rule->ugid.uid, rule->ugid.gid); chown(node_name, rule->ugid.uid, rule->ugid.gid);
} }
if (major == G.root_major && minor == G.root_minor)
symlink(node_name, "root");
if (ENABLE_FEATURE_MDEV_RENAME && alias) { if (ENABLE_FEATURE_MDEV_RENAME && alias) {
if (aliaslink == '>') { if (aliaslink == '>') {
//TODO: on devtmpfs, device_name already exists and symlink() fails. //TODO: on devtmpfs, device_name already exists and symlink() fails.
@ -723,8 +702,6 @@ static void make_device(char *device_name, char *path, int operation)
if (!ENABLE_FEATURE_MDEV_CONF || !rule->keep_matching) if (!ENABLE_FEATURE_MDEV_CONF || !rule->keep_matching)
break; break;
} /* for (;;) */ } /* for (;;) */
free(subsystem_slash_devname);
} }
/* File callback for /sys/ traversal */ /* File callback for /sys/ traversal */
@ -890,13 +867,13 @@ int mdev_main(int argc UNUSED_PARAM, char **argv)
* DEVPATH is like "/block/sda" or "/class/input/mice" * DEVPATH is like "/block/sda" or "/class/input/mice"
*/ */
action = getenv("ACTION"); action = getenv("ACTION");
op = index_in_strings(keywords, action);
env_devname = getenv("DEVNAME"); /* can be NULL */ env_devname = getenv("DEVNAME"); /* can be NULL */
env_devpath = getenv("DEVPATH"); env_devpath = getenv("DEVPATH");
G.subsystem = getenv("SUBSYSTEM"); G.subsystem = getenv("SUBSYSTEM");
if (!action || !env_devpath /*|| !G.subsystem*/) if (!action || !env_devpath /*|| !G.subsystem*/)
bb_show_usage(); bb_show_usage();
fw = getenv("FIRMWARE"); fw = getenv("FIRMWARE");
op = index_in_strings(keywords, action);
/* If it exists, does /dev/mdev.seq match $SEQNUM? /* If it exists, does /dev/mdev.seq match $SEQNUM?
* If it does not match, earlier mdev is running * If it does not match, earlier mdev is running
* in parallel, and we need to wait */ * in parallel, and we need to wait */
@ -927,7 +904,7 @@ int mdev_main(int argc UNUSED_PARAM, char **argv)
if (logfd >= 0) { if (logfd >= 0) {
xmove_fd(logfd, STDERR_FILENO); xmove_fd(logfd, STDERR_FILENO);
G.verbose = 1; G.verbose = 1;
bb_error_msg("pid: %u seq: %s action: %s", getpid(), seq, action); bb_error_msg("seq: %s action: %s", seq, action);
} }
} }