udev-event.c revision f2291cd07f24d2e1b7c3295ea6570f64b935ba55
/*
* Copyright (C) 2003-2010 Kay Sievers <kay.sievers@vrfy.org>
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include "udev.h"
{
struct udev_event *event;
return NULL;
return event;
}
{
return;
}
{
enum subst_type {
};
static const struct subst_map {
char *name;
char fmt;
enum subst_type type;
} map[] = {
};
const char *from;
char *s;
size_t l;
s = dest;
l = size;
while (1) {
char attrbuf[UTIL_PATH_SIZE];
while (from[0] != '\0') {
if (from[0] == '$') {
/* substitute named variable */
unsigned int i;
from++;
goto copy;
}
for (i = 0; i < ARRAY_SIZE(map); i++) {
goto subst;
}
}
} else if (from[0] == '%') {
/* substitute format char */
unsigned int i;
from++;
goto copy;
}
for (i = 0; i < ARRAY_SIZE(map); i++) {
from += 2;
goto subst;
}
}
}
copy:
/* copy char */
if (l == 0)
goto out;
s[0] = from[0];
from++;
s++;
l--;
}
goto out;
/* extract possible $format{attr} */
if (from[0] == '{') {
unsigned int i;
from++;
for (i = 0; from[i] != '}'; i++) {
if (from[i] == '\0') {
goto out;
}
}
if (i >= sizeof(attrbuf))
goto out;
attrbuf[i] = '\0';
from += i+1;
} else {
}
switch (type) {
case SUBST_DEVPATH:
break;
case SUBST_KERNEL:
break;
case SUBST_KERNEL_NUMBER:
break;
break;
case SUBST_ID:
break;
break;
case SUBST_DRIVER: {
const char *driver;
break;
break;
l = util_strpcpy(&s, l, driver);
break;
}
case SUBST_MAJOR: {
char num[UTIL_PATH_SIZE];
l = util_strpcpy(&s, l, num);
break;
}
case SUBST_MINOR: {
char num[UTIL_PATH_SIZE];
l = util_strpcpy(&s, l, num);
break;
}
case SUBST_RESULT: {
char *rest;
int i;
break;
/* get part part of the result string */
i = 0;
if (i > 0) {
char result[UTIL_PATH_SIZE];
char tmp[UTIL_PATH_SIZE];
char *cpos;
while (--i) {
cpos++;
cpos++;
}
if (i > 0) {
break;
}
/* %{2+}c copies the whole string from the second part on */
if (rest[0] != '+') {
if (cpos)
cpos[0] = '\0';
}
l = util_strpcpy(&s, l, tmp);
} else {
}
break;
}
case SUBST_ATTR: {
char vbuf[UTIL_NAME_SIZE];
int count;
break;
}
/* try to read the attribute the device */
/* try to read the attribute of the parent device, other matches have selected */
break;
/* strip trailing whitespace, and replace unwanted characters */
if (count > 0)
l = util_strpcpy(&s, l, vbuf);
break;
}
case SUBST_PARENT: {
struct udev_device *dev_parent;
const char *devnode;
if (dev_parent == NULL)
break;
}
break;
}
case SUBST_TEMP_NODE: {
char filename[UTIL_PATH_SIZE];
const char *devtype;
break;
}
break;
/* lookup kernel provided node */
l = util_strpcpy(&s, l, filename);
break;
}
}
/* lookup /dev/{char,block}/<maj>:<min> */
devtype = "block";
else
devtype = "char";
l = util_strpcpy(&s, l, filename);
break;
}
/* create temporary node */
break;
break;
}
case SUBST_NAME:
} else {
}
break;
case SUBST_LINKS: {
struct udev_list_entry *list_entry;
if (list_entry == NULL)
break;
break;
}
case SUBST_ROOT:
break;
case SUBST_SYS:
break;
case SUBST_ENV:
break;
} else {
const char *value;
break;
l = util_strpcpy(&s, l, value);
break;
}
default:
break;
}
}
out:
s[0] = '\0';
return l;
}
{
int klog;
FILE *f;
if (klog < 0)
return;
if (f == NULL) {
return;
}
fprintf(f, "<6>udev: renamed network interface %s to %s\n",
fclose(f);
}
{
int sk;
int err;
if (sk < 0) {
return -1;
}
if (err == 0)
else {
int loop;
/* see if the destination interface name already exists */
goto exit;
}
/* free our own name, another process may wait for us */
if (err != 0) {
goto exit;
}
/* wait 90 seconds for our target to become available */
while (loop--) {
if (err == 0) {
break;
}
break;
}
}
}
exit:
return err;
}
{
int err = 0;
}
} else {
/* disable watch during event processing */
}
/* rename a new network interface, if needed */
if (strcmp(udev_device_get_subsystem(dev), "net") == 0 && strcmp(udev_device_get_action(dev), "add") == 0 &&
char syspath[UTIL_PATH_SIZE];
char *pos;
if (err == 0) {
/* delete stale db file */
/* remember old name */
/* now change the devpath, because the kernel device name has changed */
pos++;
}
}
}
char filename[UTIL_PATH_SIZE];
}
/* no rule, use kernel provided name */
} else {
}
}
goto out;
}
if (udev_device_get_knodename(dev) != NULL && strcmp(udev_device_get_knodename(dev), event->name) != 0)
"please use SYMLINK+= or change the kernel to provide the proper name\n",
/* set device node name */
}
/* change default 0600 to 0660 if a group is assigned */
}
}
out:
return err;
}
{
struct udev_list_entry *list_entry;
int err = 0;
struct udev_monitor *monitor;
continue;
} else {
char program[UTIL_PATH_SIZE];
char **envp;
err = -1;
}
}
}
return err;
}