smdev

suckless mdev
git clone git://git.2f30.org/smdev.git
Log | Files | Refs | README | LICENSE

commit 4493e6f0efa782693f55b062e02d246a257efddf
parent 6599c9ea656da6b55aa06257c656ed85362964d7
Author: sin <sin@2f30.org>
Date:   Mon Sep  2 10:21:50 +0100

$SMDEV points to device name

Export $SMDEV for removedev() as well

Diffstat:
smdev.c | 33+++++++++++++++++++++++++++++----
1 file changed, 29 insertions(+), 4 deletions(-)
diff --git a/smdev.c b/smdev.c @@ -210,6 +210,7 @@ removedev(struct event *ev) { struct rule *rule; struct rulepath rpath; + char *ocwd; char buf[PATH_MAX]; rule = ev->rule; @@ -217,8 +218,24 @@ removedev(struct event *ev) if (rule->path && rule->path[0] == '!') return 0; + ocwd = agetcwd(); + parsepath(rule, &rpath, ev->devname); + + if (chdir("/dev") < 0) + eprintf("chdir /dev:"); + + snprintf(buf, sizeof(buf), "SMDEV=%s", ev->devname); + if (putenv(buf) < 0) + eprintf("putenv:"); + runrulecmd(rule); + + if (chdir(ocwd) < 0) + eprintf("chdir %s:", ocwd); + + free(ocwd); + /* Delete device node */ unlink(rpath.path); /* Delete symlink */ @@ -236,7 +253,7 @@ createdev(struct event *ev) struct rulepath rpath; struct passwd *pw; struct group *gr; - char *dirc; + char *dirc, *ocwd; char buf[BUFSIZ]; int type; @@ -249,6 +266,8 @@ createdev(struct event *ev) if ((type = devtype(buf)) < 0) return -1; + ocwd = agetcwd(); + /* Parse path and create the directory tree */ parsepath(rule, &rpath, ev->devname); if (!(dirc = strdup(rpath.path))) @@ -292,14 +311,20 @@ createdev(struct event *ev) buf, rpath.path); } - snprintf(buf, sizeof(buf), "SMDEV=%s", rpath.path); + if (chdir("/dev") < 0) + eprintf("chdir /dev:"); + + snprintf(buf, sizeof(buf), "SMDEV=%s", ev->devname); if (putenv(buf) < 0) eprintf("putenv:"); - /* XXX: should chdir to dirname(devpath) and set SMDEV - * to point to the actual device name */ runrulecmd(rule); + if (chdir(ocwd) < 0) + eprintf("chdir %s:", ocwd); + + free(ocwd); + return 0; }