[maemo-commits] [maemo-commits] r12989 - in projects/haf/trunk/maemo-launcher: . debian launcher

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Thu Aug 2 01:18:01 EEST 2007
Author: guillem
Date: 2007-08-02 01:17:57 +0300 (Thu, 02 Aug 2007)
New Revision: 12989

Added:
   projects/haf/trunk/maemo-launcher/launcher/search.c
   projects/haf/trunk/maemo-launcher/launcher/search.h
Modified:
   projects/haf/trunk/maemo-launcher/ChangeLog
   projects/haf/trunk/maemo-launcher/debian/changelog
   projects/haf/trunk/maemo-launcher/launcher/Makefile.am
   projects/haf/trunk/maemo-launcher/launcher/invoker.c
   projects/haf/trunk/maemo-launcher/launcher/launcher.c
   projects/haf/trunk/maemo-launcher/launcher/prog.c
   projects/haf/trunk/maemo-launcher/launcher/prog.h
   projects/haf/trunk/maemo-launcher/launcher/summoner.c
Log:
- Use memmove over overlapping memory in maemo-summoner. (Fixes: NB#49872)
- Support path resolution from maemo-summoner and maemo-invoker.
  (Fixes: NM#1741, NB#55873)
- Strip '.launch' from invoked or summoned programs. (Fixes: NB#52432)
- Correctly set argv contents for summoned programs.
  (Fixes: NB#52434, NB#52435)


Modified: projects/haf/trunk/maemo-launcher/ChangeLog
===================================================================
--- projects/haf/trunk/maemo-launcher/ChangeLog	2007-08-01 15:19:32 UTC (rev 12988)
+++ projects/haf/trunk/maemo-launcher/ChangeLog	2007-08-01 22:17:57 UTC (rev 12989)
@@ -1,3 +1,20 @@
+2007-08-02  Guillem Jover  <guillem.jover at nokia.com>
+
+	* launcher/search.c: New file.
+	* launcher/search.h: Likewise.
+	* launcher/prog.c (set_progname): Add a fourth argument specifying
+	the argv index to start copying from. Fix all callers. Use memmove
+	instead of strncpy to support overlapping memory.
+	* launcher/prog.h (set_progname): Fix prototype.
+	* launcher/invoker.c: Include "search.h".
+	(main): Strip '.launch' from argv. Support searching binaries on the
+	path.
+	* launcher/summoner.c: Likewise. Do not offset the argv assigned to
+	prog.argv, as it's being fixed afterwards by set_progname.
+	* launcher/Makefile.am (maemo_invoker_SOURCES): Add 'search.c' and
+	'search.h'.
+	(maemo_summoner_SOURCES): Likewise.
+
 2007-07-27  Johannes Schmid  <johannes.schmid at openismus.com>
             Guillem Jover  <guillem.jover at nokia.com>
 

Modified: projects/haf/trunk/maemo-launcher/debian/changelog
===================================================================
--- projects/haf/trunk/maemo-launcher/debian/changelog	2007-08-01 15:19:32 UTC (rev 12988)
+++ projects/haf/trunk/maemo-launcher/debian/changelog	2007-08-01 22:17:57 UTC (rev 12989)
@@ -4,6 +4,12 @@
     - Update gtk booster module to support gtk+ 2.10. (Fixes: NM#952)
       Thanks to Johannes Schmid <johannes.schmid at openismus.com> for the
       initial patch.
+    - Use memmove over overlapping memory in maemo-summoner. (Fixes: NB#49872)
+    - Support path resolution from maemo-summoner and maemo-invoker.
+      (Fixes: NM#1741, NB#55873)
+    - Strip '.launch' from invoked or summoned programs. (Fixes: NB#52432)
+    - Correctly set argv contents for summoned programs.
+      (Fixes: NB#52434, NB#52435)
   * Remove Build-Depends on libxft-dev.
   * Add new package maemo-launcher-dev and include the header file
     for the boosters and the pkgconfig file. (Fixes: NM#1027)

Modified: projects/haf/trunk/maemo-launcher/launcher/Makefile.am
===================================================================
--- projects/haf/trunk/maemo-launcher/launcher/Makefile.am	2007-08-01 15:19:32 UTC (rev 12988)
+++ projects/haf/trunk/maemo-launcher/launcher/Makefile.am	2007-08-01 22:17:57 UTC (rev 12989)
@@ -54,10 +54,14 @@
 #        functions.
 maemo_launcher_LDFLAGS = -rdynamic
 
-maemo_invoker_SOURCES = invoker.c invokelib.c invokelib.h report.c report.h
+maemo_invoker_SOURCES = \
+	invoker.c invokelib.c invokelib.h report.c report.h \
+	search.c search.h
 maemo_invoker_CPPFLAGS = -DPROG_NAME="\"maemo-invoker\""
 
-maemo_summoner_SOURCES = summoner.c report.c report.h prog.c prog.h
+maemo_summoner_SOURCES = \
+	summoner.c report.c report.h prog.c prog.h \
+	search.c search.h
 maemo_summoner_CPPFLAGS = -DPROG_NAME="\"maemo-summoner\""
 maemo_summoner_LDADD = -ldl
 

Modified: projects/haf/trunk/maemo-launcher/launcher/invoker.c
===================================================================
--- projects/haf/trunk/maemo-launcher/launcher/invoker.c	2007-08-01 15:19:32 UTC (rev 12988)
+++ projects/haf/trunk/maemo-launcher/launcher/invoker.c	2007-08-01 22:17:57 UTC (rev 12989)
@@ -1,7 +1,7 @@
 /*
  * $Id$
  *
- * Copyright (C) 2005, 2006 Nokia Corporation
+ * Copyright (C) 2005, 2006, 2007 Nokia Corporation
  *
  * Author: Guillem Jover <guillem.jover at nokia.com>
  *
@@ -37,6 +37,7 @@
 #include "config.h"
 #include "report.h"
 #include "invokelib.h"
+#include "search.h"
 
 #define DEFAULT_DELAY 0
 
@@ -347,7 +348,12 @@
 	usage(1);
       else
       {
-	prog_name = argv[i];
+	char *period;
+
+	prog_name = search_program(argv[i]);
+	period = strstr(argv[i], ".launch");
+	if (period)
+		*period = '\0';
 	prog_argc = argc - i;
 	prog_argv = &argv[i];
 	break;
@@ -360,7 +366,7 @@
      * Do not try to parse any arguments. */
     if (asprintf(&launch, "%s.launch", argv[0]) < 0)
       die(1, "allocating program name buffer");
-    prog_name = launch;
+    prog_name = search_program(launch);
     prog_argc = argc;
     prog_argv = argv;
 
@@ -391,6 +397,8 @@
 
   if (launch)
     free(launch);
+  if (prog_name)
+    free(prog_name);
 
   if (delay)
   {

Modified: projects/haf/trunk/maemo-launcher/launcher/launcher.c
===================================================================
--- projects/haf/trunk/maemo-launcher/launcher/launcher.c	2007-08-01 15:19:32 UTC (rev 12988)
+++ projects/haf/trunk/maemo-launcher/launcher/launcher.c	2007-08-01 22:17:57 UTC (rev 12989)
@@ -1,7 +1,7 @@
 /*
  * $Id$
  *
- * Copyright (C) 2005, 2006 Nokia Corporation
+ * Copyright (C) 2005, 2006, 2007 Nokia Corporation
  *
  * Authors: Michael Natterer <mitch at imendio.com>
  *	    Guillem Jover <guillem.jover at nokia.com>
@@ -820,7 +820,7 @@
       if (prog.filename)
       {
         info("invoking '%s'\n", prog.filename);
-        set_progname(prog.argv[0], argc, argv);
+        set_progname(prog.argv[0], argc, argv, -1);
 
 	boosters_init(boosters, prog.argv[0]);
 

Modified: projects/haf/trunk/maemo-launcher/launcher/prog.c
===================================================================
--- projects/haf/trunk/maemo-launcher/launcher/prog.c	2007-08-01 15:19:32 UTC (rev 12988)
+++ projects/haf/trunk/maemo-launcher/launcher/prog.c	2007-08-01 22:17:57 UTC (rev 12989)
@@ -1,7 +1,7 @@
 /*
  * $Id$
  *
- * Copyright (C) 2005, 2006 Nokia Corporation
+ * Copyright (C) 2005, 2006, 2007 Nokia Corporation
  *
  * Authors: Guillem Jover <guillem.jover at nokia.com>
  *
@@ -85,17 +85,35 @@
 #endif
 
 void
-set_progname(char *progname, int argc, char **argv)
+set_progname(char *progname, int argc, char **argv, int copy_index)
 {
   int argvlen = 0;
+  int proglen = strlen(progname) + 1;
   int i;
 
   for (i = 0; i < argc; i++)
     argvlen += strlen(argv[i]) + 1;
 
-  memset(argv[0], 0, argvlen);
-  strncpy(argv[0], progname, argvlen - 1);
+  if (proglen > argvlen)
+    proglen = argvlen;
 
+  memmove(argv[0], progname, proglen);
+
+  if (copy_index > 0) {
+    int j;
+
+    for (j = 0; j + copy_index < argc; j++)
+    {
+      int arglen = strlen(argv[j + copy_index]) + 1;
+
+      argv[j + 1] = argv[0] + proglen;
+      memmove(argv[j + 1], argv[j + copy_index], arglen);
+      proglen += arglen;
+    }
+  }
+
+  memset(&argv[0][proglen], 0, argvlen - proglen);
+
   set_process_name(progname);
 
   setenv("_", progname, true);

Modified: projects/haf/trunk/maemo-launcher/launcher/prog.h
===================================================================
--- projects/haf/trunk/maemo-launcher/launcher/prog.h	2007-08-01 15:19:32 UTC (rev 12988)
+++ projects/haf/trunk/maemo-launcher/launcher/prog.h	2007-08-01 22:17:57 UTC (rev 12989)
@@ -1,7 +1,7 @@
 /*
  * $Id$
  *
- * Copyright (C) 2005, 2006 Nokia Corporation
+ * Copyright (C) 2005, 2006, 2007 Nokia Corporation
  *
  * Authors: Guillem Jover <guillem.jover at nokia.com>
  *
@@ -39,7 +39,7 @@
 void load_main(prog_t *prog);
 void print_prog_env_argv(prog_t *prog);
 
-void set_progname(char *progname, int argc, char **argv);
+void set_progname(char *progname, int argc, char **argv, int copy_index);
 
 #endif
 

Added: projects/haf/trunk/maemo-launcher/launcher/search.c
===================================================================
--- projects/haf/trunk/maemo-launcher/launcher/search.c	2007-08-01 15:19:32 UTC (rev 12988)
+++ projects/haf/trunk/maemo-launcher/launcher/search.c	2007-08-01 22:17:57 UTC (rev 12989)
@@ -0,0 +1,105 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2007 Nokia Corporation
+ *
+ * Contact: Guillem Jover <guillem.jover at nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ *
+ */
+
+#define _GNU_SOURCE
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "report.h"
+#include "search.h"
+
+static char *
+merge_paths(const char *base_path, const char *rel_path)
+{
+  char *path;
+
+  if (asprintf(&path, "%s%s%s", base_path,
+               (base_path[strlen(base_path) - 1] == '/' ? "" : "/"),
+               rel_path) < 0)
+    die(1, "allocating merge path buffer");
+
+  return path;
+}
+
+char *
+search_program(const char *progname)
+{
+  char *launch = NULL;
+  char *cwd;
+
+  if (progname[0] == '/')
+  {
+    launch = strdup(progname);
+    if (!launch)
+      die(1, "allocating program name buffer");
+  }
+  else if (strchr(progname, '/') != NULL)
+  {
+    cwd = get_current_dir_name();
+    launch = merge_paths(cwd, progname);
+    free(cwd);
+  }
+  else
+  {
+    char *path = getenv("PATH");
+    char *saveptr = NULL;
+    char *token;
+
+    if (path == NULL)
+      die(1, "could not get PATH environment variable");
+    path = strdup(path);
+
+    for (token = strtok_r(path, ":", &saveptr); token != NULL;
+         token = strtok_r(NULL, ":", &saveptr))
+    {
+      launch = merge_paths(token, progname);
+
+      if (access(launch, X_OK) == 0)
+	break;
+
+      free(launch);
+      launch = NULL;
+    }
+
+    free(path);
+
+    if (launch == NULL)
+      die(1, "could not locate program to launch");
+
+    if (launch[0] != '/')
+    {
+      char *relative = launch;
+
+      cwd = get_current_dir_name();
+      launch = merge_paths(cwd, relative);
+
+      free(cwd);
+      free(relative);
+    }
+  }
+
+  return launch;
+}
+


Property changes on: projects/haf/trunk/maemo-launcher/launcher/search.c
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Added: projects/haf/trunk/maemo-launcher/launcher/search.h
===================================================================
--- projects/haf/trunk/maemo-launcher/launcher/search.h	2007-08-01 15:19:32 UTC (rev 12988)
+++ projects/haf/trunk/maemo-launcher/launcher/search.h	2007-08-01 22:17:57 UTC (rev 12989)
@@ -0,0 +1,29 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2007 Nokia Corporation
+ *
+ * Contact: Guillem Jover <guillem.jover at nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ *
+ */
+
+#ifndef SEARCH_H
+#define SEARCH_H
+
+char *search_program(const char *progname);
+
+#endif
+


Property changes on: projects/haf/trunk/maemo-launcher/launcher/search.h
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Modified: projects/haf/trunk/maemo-launcher/launcher/summoner.c
===================================================================
--- projects/haf/trunk/maemo-launcher/launcher/summoner.c	2007-08-01 15:19:32 UTC (rev 12988)
+++ projects/haf/trunk/maemo-launcher/launcher/summoner.c	2007-08-01 22:17:57 UTC (rev 12989)
@@ -1,7 +1,7 @@
 /*
  * $Id$
  *
- * Copyright (C) 2006 Nokia
+ * Copyright (C) 2006, 2007 Nokia Corporation
  *
  * Authors: Guillem Jover <guillem.jover at nokia.com>
  *
@@ -31,6 +31,7 @@
 #include "config.h"
 #include "report.h"
 #include "prog.h"
+#include "search.h"
 
 static void
 summon_process(prog_t *prog)
@@ -75,6 +76,8 @@
 
   if (strstr(argv[0], PROG_NAME))
   {
+    char *argv0 = NULL;
+
     /* Called with our default name. Parse arguments. */
     for (i = 1; i < argc; ++i)
     {
@@ -86,9 +89,16 @@
 	usage(1);
       else
       {
-	prog.filename = strdup(argv[i]);
+	char *period;
+
+	argv0 = strdup(argv[i]);
+	period = strstr(argv0, ".launch");
+	if (period)
+		*period = '\0';
+
+	prog.filename = search_program(argv[i]);
 	prog.argc = argc - i;
-	prog.argv = &argv[i];
+	prog.argv = argv;
 	break;
       }
     }
@@ -96,7 +106,9 @@
     if (!prog.filename)
       usage(1);
 
-    set_progname(prog.argv[0], argc, argv);
+    set_progname(argv0, argc, argv, i + 1);
+
+    free(argv0);
   }
   else
   {
@@ -106,9 +118,11 @@
      * Do not try to parse any arguments. */
     if (asprintf(&launch, "%s.launch", argv[0]) < 0)
       die(1, "allocating program name buffer");
-    prog.filename = launch;
+    prog.filename = search_program(launch);
     prog.argc = argc;
     prog.argv = argv;
+
+    free(launch);
   }
 
   /* Summon it. */


More information about the maemo-commits mailing list