From 683d394d66b6df3b7d9f7d424662c4e3dcdb8fee Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Thu, 4 Sep 2014 13:31:37 +0200 Subject: [PATCH] devmand: skip unconfigured script invocations . if a up/down script isn't specified, devmand would try to execute a command line with (null) in it, causing messy messages on startup . skip script at a higher level when missing, and add asserts for expected strings at the lower level Change-Id: Ia0d772076f3781caa5879ea4e64b53fa6c6e8478 --- minix/commands/devmand/main.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/minix/commands/devmand/main.c b/minix/commands/devmand/main.c index 9d840a6ef..694c676b1 100644 --- a/minix/commands/devmand/main.c +++ b/minix/commands/devmand/main.c @@ -89,6 +89,9 @@ int run_upscript(struct devmand_driver_instance *inst) cmdl[0] = 0; int ret; + assert(inst->drv->upscript); + assert(inst->label); + snprintf(cmdl, 1024, "%s up %s %d %d", inst->drv->upscript, inst->label, inst->major, inst->dev_id); dbg("Running Upscript: \"%s\"", cmdl); @@ -108,6 +111,9 @@ int run_cleanscript(struct devmand_usb_driver *drv) cmdl[0] = 0; int ret; + assert(drv->upscript); + assert(drv->devprefix); + snprintf(cmdl, 1024, "%s clean %s ", drv->upscript, drv->devprefix); dbg("Running Upscript: \"%s\"", cmdl); @@ -130,6 +136,9 @@ int run_downscript(struct devmand_driver_instance *inst) cmdl[0] = 0; int ret; + assert(inst->drv->downscript); + assert(inst->label); + snprintf(cmdl, 1024, "%s down %s %d", inst->drv->downscript, inst->label, inst->major); @@ -154,6 +163,8 @@ int stop_driver(struct devmand_driver_instance *inst) cmdl[0] = 0; int ret; + assert(inst->label); + snprintf(cmdl, 1024, "%s down %s %d", SERVICE_BINARY, inst->label, inst->dev_id); dbg("executing service: \"%s\"", cmdl); @@ -186,6 +197,9 @@ int start_driver(struct devmand_driver_instance *inst) return ENOMEM; } + assert(inst->drv->binary); + assert(inst->label); + snprintf(cmdl, 1024, "%s up %s -major %d -devid %d -label %s", SERVICE_BINARY, inst->drv->binary, inst->major, inst->dev_id, inst->label); @@ -389,7 +403,9 @@ static void cleanup() { /* quit all running drivers */ LIST_FOREACH(inst, &instances, list) { dbg("stopping driver %s", inst->label); - run_downscript (inst); + if(inst->drv->downscript) { + run_downscript (inst); + } stop_driver(inst); } unlink("/var/run/devmand.pid"); @@ -485,7 +501,9 @@ int main(int argc, char *argv[]) parse_config(); LIST_FOREACH(driver, &drivers, list) { - run_cleanscript(driver); + if (driver->upscript) { + run_cleanscript(driver); + } } signal(SIGINT, sig_int); -- 2.44.0