Introduction
Introduction Statistics Contact Development Disclaimer Help
Support remove action - smdev - suckless mdev
git clone git://git.suckless.org/smdev
Log
Files
Refs
README
LICENSE
---
commit 489d08c79725cad5203a1d52ede57851b6d78ba0
parent 5f48a52f383ac2a646b4608195372a314a91e7e5
Author: sin <[email protected]>
Date: Fri, 23 Aug 2013 13:25:16 +0100
Support remove action
Diffstat:
M smdev.c | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
---
diff --git a/smdev.c b/smdev.c
@@ -44,6 +44,7 @@ static int matchrule(int ruleidx, char *devname);
static void runrule(struct rule *rule);
static void parsepath(struct rule *rule, char *devpath,
size_t devpathsz, char *devname);
+static int removedev(struct event *ev);
static int createdev(struct event *ev);
static int doevent(struct event *ev);
static int craftev(struct event *ev, enum action action,
@@ -195,6 +196,31 @@ parsepath(struct rule *rule, char *devpath, size_t devpath…
}
static int
+removedev(struct event *ev)
+{
+ struct rule *rule;
+ char buf[PATH_MAX];
+ char devpath[PATH_MAX];
+ char devname[PATH_MAX];
+
+ rule = ev->rule;
+ strlcpy(devname, ev->devname, sizeof(devname));
+ snprintf(devpath, sizeof(devpath), "/dev/%s", devname);
+ if (rule->path)
+ parsepath(rule, devpath, sizeof(devpath),
+ devname);
+ runrule(rule);
+ /* Delete device node */
+ unlink(devpath);
+ /* Delete symlink */
+ if (rule->path && rule->path[0] == '>') {
+ snprintf(buf, sizeof(buf), "/dev/%s", ev->devname);
+ unlink(buf);
+ }
+ return 0;
+}
+
+static int
createdev(struct event *ev)
{
struct rule *rule;
@@ -261,7 +287,7 @@ createdev(struct event *ev)
snprintf(buf, sizeof(buf), "/dev/%s", ev->devname);
if (symlink(devpath, buf))
eprintf("symlink %s -> %s:",
- ev->devname, devpath);
+ buf, devpath);
}
snprintf(buf, sizeof(buf), "SMDEV=%s", devpath);
@@ -286,6 +312,8 @@ doevent(struct event *ev)
switch (ev->action) {
case ADD_ACTION:
return createdev(ev);
+ case REMOVE_ACTION:
+ return removedev(ev);
default:
break;
}
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.