smdev

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

commit 7550047abc4f7db1da453ae8927866b512f95a03
parent ddacaa6b20569d4fb4be3de615434f5f59fe9b28
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun,  6 Apr 2014 15:59:39 +0200

smdev SMDEV environment fix and small optimization

Use setenv() with overwrite flag to set environment variable. This fixes an issue where SMDEV was still set to a previous rule environment (symlinked my /dev/cdrom to usb2 :)).
Optimization: check if rule->cmd is set, else don't change directory to /dev and don't set the environment variable.

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>

Diffstat:
Msmdev.c | 30++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/smdev.c b/smdev.c @@ -223,14 +223,13 @@ removedev(struct event *ev) 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(rule->cmd) { + if (chdir("/dev") < 0) + eprintf("chdir /dev:"); + if (setenv("SMDEV", ev->devname, 1) < 0) + eprintf("setenv:"); + runrulecmd(rule); + } if (chdir(ocwd) < 0) eprintf("chdir %s:", ocwd); @@ -313,14 +312,13 @@ createdev(struct event *ev) } runrule: - if (chdir("/dev") < 0) - eprintf("chdir /dev:"); - - snprintf(buf, sizeof(buf), "SMDEV=%s", ev->devname); - if (putenv(buf) < 0) - eprintf("putenv:"); - - runrulecmd(rule); + if(rule->cmd) { + if (chdir("/dev") < 0) + eprintf("chdir /dev:"); + if (setenv("SMDEV", ev->devname, 1) < 0) + eprintf("setenv:"); + runrulecmd(rule); + } if (chdir(ocwd) < 0) eprintf("chdir %s:", ocwd);