From a5511c9cd1bf1465bdf2f55cf72227266807bcd3 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Fri, 11 Dec 2009 01:41:59 +0200 Subject: [PATCH] daemon: use basename when deducing app name from app command-line. Closes #22 --- daemon/app_supervisor.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/daemon/app_supervisor.c b/daemon/app_supervisor.c index 043a77a2..1ac69363 100644 --- a/daemon/app_supervisor.c +++ b/daemon/app_supervisor.c @@ -520,6 +520,7 @@ static void run_custom(struct dbus_method_call * call_ptr) const char * commandline; const char * name_param; char * name; + char * name_buffer; size_t len; char * end; unsigned int index; @@ -544,13 +545,15 @@ static void run_custom(struct dbus_method_call * call_ptr) { /* allocate and copy app name */ len = strlen(name_param); - name = malloc(len + 100); - if (name == NULL) + name_buffer = malloc(len + 100); + if (name_buffer == NULL) { lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "malloc of app name failed"); return; } + name = name_buffer; + strcpy(name, name_param); end = name + len; @@ -559,17 +562,17 @@ static void run_custom(struct dbus_method_call * call_ptr) { /* allocate app name */ len = strlen(commandline) + 100; - name = malloc(len); - if (name == NULL) + name_buffer = malloc(len); + if (name_buffer == NULL) { lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "malloc of app name failed"); return; } - strcpy(name, commandline); + strcpy(name_buffer, commandline); /* use first word as name */ - end = name; + end = name_buffer; while (*end) { if (isspace(*end)) @@ -580,6 +583,16 @@ static void run_custom(struct dbus_method_call * call_ptr) end++; } + + name = strrchr(name_buffer, '/'); + if (name == NULL) + { + name = name_buffer; + } + else + { + name++; + } } /* make the app name unique */ @@ -592,7 +605,7 @@ static void run_custom(struct dbus_method_call * call_ptr) app_ptr = add_app_internal(supervisor_ptr, name, commandline, terminal, true, 0); - free(name); + free(name_buffer); if (app_ptr == NULL) { -- 2.11.4.GIT