[PATCH] restructure code to be able to actually get remove_node() to work.

This commit is contained in:
greg@kroah.com 2003-04-10 11:02:32 -07:00 committed by Greg KH
parent 85511f0246
commit 3f4967a1fb
1 changed files with 39 additions and 38 deletions

77
udev.c
View File

@ -183,21 +183,43 @@ static int create_node(char *name, char type, int major, int minor, int mode)
return retval; return retval;
} }
static int remove_node(char *name) static int add_node(char *device, char type)
{ {
return 0; char *name;
int major;
int minor;
int mode;
int retval = -EINVAL;
retval = get_major_minor(device, &major, &minor);
if (retval) {
dbg ("get_major_minor failed");
goto exit;
}
name = get_name(device, major, minor);
if (name == NULL) {
dbg ("get_name failed");
retval = -ENODEV;
goto exit;
}
mode = get_mode(name, device, major, minor);
if (mode < 0) {
dbg ("get_mode failed");
retval = -EINVAL;
goto exit;
}
return create_node(name, type, major, minor, mode);
exit:
return retval;
} }
static int do_it(char *action, char *name, char type, int major, int minor, int mode) static int remove_node(char *device)
{ {
if (strcmp(action, "add") == 0) return 0;
return create_node(name, type, major, minor, mode);
if (strcmp(action, "remove") == 0)
return remove_node(name);
dbg("Unknown action: %s", action);
return -EINVAL;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -205,11 +227,7 @@ int main(int argc, char *argv[])
char *subsystem; char *subsystem;
char *action; char *action;
char *device; char *device;
char *name;
char type; char type;
int major;
int minor;
int mode;
int retval = -EINVAL; int retval = -EINVAL;
if (argc != 2) { if (argc != 2) {
@ -237,31 +255,14 @@ int main(int argc, char *argv[])
} }
dbg("looking at %s", device); dbg("looking at %s", device);
retval = get_major_minor(device, &major, &minor); if (strcmp(action, "add") == 0)
if (retval) { return add_node(device, type);
dbg ("get_major_minor failed");
goto exit;
}
name = get_name(device, major, minor); if (strcmp(action, "remove") == 0)
if (name == NULL) { return remove_node(device);
dbg ("get_name failed");
retval = -ENODEV;
goto exit;
}
mode = get_mode(name, device, major, minor); dbg("Unknown action: %s", action);
if (mode < 0) { return -EINVAL;
dbg ("get_mode failed");
retval = -EINVAL;
goto exit;
}
retval = do_it(action, name, type, major, minor, mode);
if (retval) {
dbg ("do_it failed");
goto exit;
}
retval = 0; retval = 0;
exit: exit: