udev_rules.c revision ac528431dd60c6b7f6b664ba430b937a11a32230
/*
* Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
* Copyright (C) 2003-2006 Kay Sievers <kay.sievers@vrfy.org>
*
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <ctype.h>
#include <unistd.h>
#include <errno.h>
#include <syslog.h>
#include <fnmatch.h>
#include "udev.h"
#include "udev_rules.h"
/* extract possible {attr} and move str behind it */
static char *get_format_attribute(char **str)
{
char *pos;
if (*str[0] == '{') {
err("missing closing brace for format");
return NULL;
}
pos[0] = '\0';
}
return attr;
}
/* extract possible format length and move str behind it*/
static int get_format_len(char **str)
{
int num;
char *tail;
if (num > 0) {
return num;
} else {
}
}
return -1;
}
{
char *linepos;
char *temp;
if (!linepos)
return -1;
dbg("escaped characters are not supported, skip");
return -1;
}
/* skip whitespace */
linepos++;
/* get the key */
while (1) {
linepos++;
if (linepos[0] == '\0')
return -1;
break;
if (linepos[0] == '=')
break;
}
/* terminate key */
linepos[0] = '\0';
linepos++;
/* skip whitespace */
linepos++;
/* get the value*/
if (linepos[0] == '"') {
linepos++;
if (!temp) {
dbg("missing closing quote");
return -1;
}
dbg("value is quoted");
temp[0] = '\0';
} else if (linepos[0] == '\'') {
linepos++;
if (!temp) {
dbg("missing closing quote");
return -1;
}
dbg("value is quoted");
temp[0] = '\0';
} else if (linepos[0] == '\0') {
dbg("value is empty");
} else {
temp++;
temp[0] = '\0';
}
return 0;
}
{
const char *bufline;
char *linepos;
char *variable;
char *value;
int lineno;
/* loop through the whole buffer */
lineno = 0;
cur = 0;
lineno++;
continue;
}
/* eat the whitespace */
bufline++;
count--;
}
if (count == 0)
continue;
/* see if this is a comment */
if (bufline[0] == COMMENT_CHARACTER)
continue;
}
}
return 0;
}
{
char *buf;
return -1;
}
return 0;
}
{
char result[1024];
if (run_program(program, udev->dev->subsystem, result, sizeof(result), &reslen, (udev_log_priority >= LOG_INFO)) != 0)
return -1;
}
{
struct sysfs_device *dev_parent;
int rc = -1;
if (dev_parent != NULL) {
struct udevice *udev_parent;
struct name_entry *name_loop;
if (udev_parent == NULL)
return -1;
/* import the udev_db of the parent */
char *pos;
if (pos) {
pos[0] = '\0';
pos++;
} else
}
}
rc = 0;
} else
dbg("parent not found in database");
}
return rc;
}
#define WAIT_LOOP_PER_SECOND 50
{
char devicepath[PATH_SIZE];
while (--loop) {
/* lookup file */
return 0;
}
/* make sure the device does not have disappeared in the meantime */
return -2;
}
}
return -1;
}
{
int len;
int i;
int count;
enum subst_type {
};
static const struct subst_map {
char *name;
char fmt;
enum subst_type type;
} map[] = {
{ NULL, '\0', 0 }
};
enum subst_type type;
while (1) {
len = -1;
while (head[0] != '\0') {
if (head[0] == '$') {
/* substitute named variable */
break;
head++;
continue;
}
head[0] = '\0';
goto found;
}
}
} else if (head[0] == '%') {
/* substitute format char */
break;
head++;
continue;
}
head[0] = '\0';
tail++;
goto found;
}
}
}
head++;
}
break;
switch (type) {
case SUBST_DEVPATH:
break;
case SUBST_KERNEL:
break;
case SUBST_KERNEL_NUMBER:
break;
case SUBST_ID:
}
break;
case SUBST_MAJOR:
break;
case SUBST_MINOR:
break;
case SUBST_RESULT:
break;
/* get part part of the result string */
i = 0;
if (i > 0) {
dbg("request part #%d of result string", i);
while (--i) {
cpos++;
cpos++;
}
if (i > 0) {
err("requested part of result string not found");
break;
}
/* %{2+}c copies the whole string from the second part on */
if (rest[0] != '+') {
if (cpos)
cpos[0] = '\0';
}
} else {
}
break;
case SUBST_ATTR:
dbg("missing attribute");
break;
} else {
struct sysfs_device *dev_parent;
const char *value;
do {
break;
}
} while (dev_parent != NULL);
/* strip trailing whitespace of sysfs value */
temp2[--i] = '\0';
if (count)
}
break;
case SUBST_PARENT:
{
struct sysfs_device *dev_parent;
if (dev_parent != NULL) {
struct udevice *udev_parent;
if (udev_parent != NULL) {
/* lookup the name in the udev_db with the DEVPATH of the parent */
} else
dbg("parent not found in database");
}
}
}
break;
case SUBST_TEMP_NODE:
dbg("create temporary device node for callout");
}
break;
case SUBST_ROOT:
break;
case SUBST_ENV:
dbg("missing attribute");
break;
}
break;
}
break;
default:
break;
}
/* possibly truncate to format-char specified length */
if (len != -1) {
}
}
}
{
}
{
}
static int match_key(const char *key_name, struct udev_rule *rule, struct key *key, const char *val)
{
int match;
char *key_value;
char *pos;
return 0;
while (key_value) {
if (pos) {
pos[0] = '\0';
pos++;
}
return 0;
}
return 0;
}
}
return -1;
}
/* match a single rule against a given device and possibly its parent devices */
{
int i;
goto nomatch;
goto nomatch;
goto nomatch;
goto nomatch;
goto nomatch;
/* match NAME against a value assigned by an earlier rule */
goto nomatch;
/* we only check for matches, assignments will be handled later */
if (!value) {
value = "";
}
goto nomatch;
}
}
int found;
goto nomatch;
}
/* check for matching sysfs attribute pairs */
const char *value;
char val[VALUE_SIZE];
goto nomatch;
/* strip trailing whitespace of value, if not asked to match for it */
}
goto nomatch;
}
}
/* walk up the chain of parent devices and find a match */
while (1) {
/* check for matching kernel device name */
goto try_parent;
/* check for matching subsystem value */
goto try_parent;
/* check for matching driver */
goto try_parent;
/* check for matching sysfs attrubute pairs */
const char *value;
char val[VALUE_SIZE];
goto try_parent;
/* strip trailing whitespace of value, if not asked to match for it */
}
goto try_parent;
}
}
/* found matching device */
break;
/* move to parent device */
dbg("try parent sysfs device");
goto nomatch;
}
/* execute external program */
if (run_program(program, udev->dev->subsystem, result, sizeof(result), NULL, (udev_log_priority >= LOG_INFO)) != 0) {
dbg("PROGRAM is false");
goto nomatch;
} else {
int count;
dbg("PROGRAM matches");
if (count)
dbg("PROGRAM returned successful");
goto nomatch;
}
dbg("PROGRAM key is true");
}
/* check for matching result of external program */
goto nomatch;
/* import variables returned from program or or file into environment */
int rc = -1;
}
if (rc != 0) {
dbg("IMPORT failed");
goto nomatch;
} else
dbg("IMPORT key is true");
}
/* rule matches, if we have ENV assignments export it */
char temp_value[NAME_SIZE];
char *key_value;
/* make sure we don't write to the same string we possibly read from */
break;
}
}
/* if we have ATTR assignements write value to sysfs file */
FILE *f;
if (f != NULL) {
fclose(f);
} else
}
}
return 0;
return -1;
}
{
int name_set = 0;
/* look for a matching rule to apply */
while (1) {
break;
if (name_set &&
dbg("node name already set, rule ignored");
continue;
}
dbg("process rule");
/* apply options */
if (rule->ignore_device) {
return 0;
}
if (rule->ignore_remove) {
dbg("remove event should be ignored");
}
/* apply all_partitions option only at a main block device */
if (rule->partitions &&
dbg("creation of partition nodes requested");
}
/* apply permissions */
}
}
}
/* collect symlinks */
int count;
info("reset symlink list");
}
if (count)
/* add multiple symlinks separated by spaces */
pos++;
while (next) {
next[0] = '\0';
next++;
}
if (pos[0] != '\0') {
}
}
/* set name, later rules with name set will be ignored */
int count;
name_set = 1;
if (count)
dbg("name, '%s' is going to have owner='%s', group='%s', mode=%#o partitions=%i",
}
info("reset run list");
}
}
dbg("last rule to be applied");
break;
}
}
}
}
if (!name_set) {
}
dbg("removing temporary device node");
}
return 0;
}
{
/* look for a matching rule to apply */
while (1) {
break;
dbg("process rule");
rule->mode_operation != KEY_OP_UNSET || rule->owner.operation != KEY_OP_UNSET || rule->group.operation != KEY_OP_UNSET) {
dbg("skip rule that names a device");
continue;
}
if (rule->ignore_device) {
return 0;
}
info("reset run list");
}
break;
}
dbg("last rule to be applied");
break;
}
}
}
}
return 0;
}