udev-event.c revision 33502ffe2eb7b56cdd018a4fb6830d7828519fad
/*
* 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 <sys/signalfd.h>
#include "udev.h"
{
struct udev_event *event;
return NULL;
return event;
}
{
return;
}
{
enum subst_type {
};
static const struct subst_map {
const char *name;
const char fmt;
enum subst_type type;
} map[] = {
};
const char *from;
char *s;
size_t l;
s = dest;
l = size;
for (;;) {
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 < ELEMENTSOF(map); i++) {
goto subst;
}
}
} else if (from[0] == '%') {
/* substitute format char */
unsigned int i;
from++;
goto copy;
}
for (i = 0; i < ELEMENTSOF(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) {
log_error("requested part of result string not found\n");
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;
log_error("missing file parameter for attr\n");
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_DEVNODE:
break;
case SUBST_NAME:
else
break;
case SUBST_LINKS: {
struct udev_list_entry *list_entry;
if (list_entry == NULL)
break;
l = util_strpcpyl(&s, l, " ", udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/"), NULL);
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 err;
int fd;
/* discard child output or connect to pipe */
if (fd >= 0) {
if (fd_stdout < 0)
if (fd_stderr < 0)
} else {
}
/* connect pipes to std{out,err} */
if (fd_stdout >= 0) {
}
if (fd_stderr >= 0) {
}
/* terminate child in case parent goes away */
/* restore original udev sigmask before exec */
if (sigmask)
/* exec failed */
return err;
}
const char *cmd,
{
int fd_ep = -1;
/* read from child if requested */
return;
if (fd_ep < 0) {
log_error("error creating epoll fd: %m\n");
goto out;
}
if (fd_stdout >= 0) {
log_error("fail to add fd to epoll: %m\n");
goto out;
}
}
if (fd_stderr >= 0) {
log_error("fail to add fd to epoll: %m\n");
goto out;
}
}
/* read child output */
int timeout;
int fdcount;
int i;
if (event->timeout_usec > 0) {
unsigned long long age_usec;
goto out;
}
} else {
timeout = -1;
}
if (fdcount < 0) {
continue;
log_error("failed to poll: %m\n");
goto out;
}
if (fdcount == 0) {
goto out;
}
for (i = 0; i < fdcount; i++) {
char buf[4096];
if (count <= 0)
continue;
/* store stdout result */
} else {
}
}
/* log debug output only if we watch stderr */
if (fd_stderr >= 0) {
char *pos;
char *line;
}
}
log_error("failed to remove fd from epoll: %m\n");
goto out;
}
*fd = -1;
}
}
}
/* return the child's stdout string */
out:
if (fd_ep >= 0)
}
{
int err = 0;
while (pid > 0) {
int timeout;
int fdcount;
if (event->timeout_usec > 0) {
unsigned long long age_usec;
timeout = 1000;
else
} else {
timeout = -1;
}
if (fdcount < 0) {
continue;
log_error("failed to poll: %m\n");
goto out;
}
if (fdcount == 0) {
}
struct signalfd_siginfo fdsi;
int status;
if (size != sizeof(struct signalfd_siginfo))
continue;
case SIGTERM:
break;
case SIGCHLD:
break;
if (WEXITSTATUS(status) != 0)
err = -1;
} else if (WIFSIGNALED(status)) {
log_error("'%s' [%u] terminated by signal %i (%s)\n", cmd, pid, WTERMSIG(status), strsignal(WTERMSIG(status)));
err = -1;
} else if (WIFSTOPPED(status)) {
err = -1;
} else if (WIFCONTINUED(status)) {
err = -1;
} else {
err = -1;
}
pid = 0;
break;
}
}
}
out:
return err;
}
{
int i = 0;
char *pos;
goto out;
}
if (pos[0] == '\'') {
/* do not separate quotes */
pos++;
while (pos[0] == ' ')
pos++;
} else {
while (pos[0] == ' ')
pos++;
}
i++;
}
out:
if (argc)
*argc = i;
return 0;
}
{
char arg[UTIL_PATH_SIZE];
char *argv[128];
char program[UTIL_PATH_SIZE];
int err = 0;
/* pipes from child to parent */
log_error("pipe failed: %m\n");
goto out;
}
}
log_error("pipe failed: %m\n");
goto out;
}
}
if (argv[0][0] != '/') {
}
switch(pid) {
case 0:
/* child closes parent's ends of pipes */
}
}
_exit(2 );
case -1:
err = -1;
goto out;
default:
/* parent closed child's ends of pipes */
}
}
}
out:
return err;
}
{
int klog;
FILE *f;
if (klog < 0)
return;
if (f == NULL) {
return;
}
fprintf(f, "<30>udevd[%u]: renamed network interface %s to %s\n",
fclose(f);
}
{
int sk;
int loop;
int err;
log_debug("changing net interface name from '%s' to '%s'\n",
if (sk < 0) {
log_error("error opening socket: %m\n");
return err;
}
if (err == 0) {
goto out;
}
/* keep trying if the destination interface name already exists */
goto out;
/* free our own name, another process may wait for us */
if (err < 0) {
goto out;
}
/* log temporary name */
/* wait a maximum of 90 seconds for our target to become available */
while (loop--) {
if (err == 0) {
break;
}
break;
}
out:
if (err < 0)
return err;
}
int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules, const sigset_t *sigmask)
{
int err = 0;
return -1;
} else {
/* disable watch during event processing */
}
/* rename a new network interface, if needed */
char syspath[UTIL_PATH_SIZE];
char *pos;
if (err == 0) {
/* remember old name */
/* now change the devpath, because the kernel device name has changed */
pos++;
}
}
}
if (udev_device_get_devnode_mode(dev) > 0) {
/* kernel supplied value */
/* default 0660 if a group is assigned */
} else {
/* default 0600 */
}
}
}
/* preserve old, or get new initialization timestamp */
/* (re)write database file */
}
return err;
}
{
struct udev_list_entry *list_entry;
if (builtin_cmd < UDEV_BUILTIN_MAX) {
char command[UTIL_PATH_SIZE];
} else {
char program[UTIL_PATH_SIZE];
char **envp;
if (event->exec_delay > 0) {
}
}
}
}