Date: Wed, 02 Aug 2006 00:42:30 +0200 From: Michael Rasmussen <none@mir--datanom.net.lh.bsd-dk.dk> Subject: Re: Betatestere søges To: bsd-dk@bsd-dk.dk
Hej alle,
On 2006-07-31 23:51:05, Morten Juhl Johansen wrote:
>>
>> Du burde bruge environment variablen PATH n?r du s?ger efter
>> programmet.
>
> Det vil forenkle processen. Den ligger som antydet i
> /usr/X11R6/bin/firefox.
>
Jeg har lavet en ændring, som i meget gerne må afteste, der skulle løse
problemet.
Da jeg ikke er klar over, om vedhæftede filer fjernes, skriver jeg både
patchen inline og vedhæfter den til mailen.
Index: src/utils.c
===================================================================
RCS file: /var/lib/cvs/tptestgui/src/utils.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -u -r1.2 -r1.3
--- src/utils.c 30 Jul 2006 00:54:18 -0000 1.2
+++ src/utils.c 1 Aug 2006 12:06:56 -0000 1.3
@@ -129,35 +129,43 @@
BrowserInfo get_browser()
{
- size_t i;
- DIR* dir = NULL;
- struct dirent* ent = NULL;
- gchar* path = NULL;
- gchar* file = NULL;
+#define MAX_TOKENS 1000
+ size_t i;
+ gchar* env_path = NULL;
+ gchar* file = NULL;
+ gchar** path = NULL;
+ gchar** head = NULL;
+
my_browser.name = NULL;
my_browser.option = NULL;
+ head = g_malloc(sizeof(gchar*));
+
+ if ((env_path = getenv("PATH")) == NULL)
+ g_error(_("Could not get PATH from environment"));
+ path = g_strsplit(env_path, ":", MAX_TOKENS);
+ head = path;
+
+ if (path == NULL)
+ g_error(_("PATH is empty or not defined"));
+
for (i = 0; *browser_list[i] != NULL && !my_browser.name; i++)
{
if (DEBUG)
fprintf(stderr, "Looking for: %s\n", *browser_list[i]);
- if ((dir = opendir("/usr/bin")) == NULL)
- if ((dir = opendir("/usr/local/bin")) == NULL)
- g_error(_("No access to user binaries"));
- else
- path = "/usr/local/bin";
- else
- path = "/usr/bin";
- while ((ent = readdir(dir)) != NULL)
+ while (*path++)
{
- file = g_strdup(ent->d_name);
- if ((strncmp(file, ".", PATH_MAX) == 0) ||
- (strncmp(file, "..", PATH_MAX) == 0))
+ file = g_strdup_printf("%s/%s", *path, *browser_list[i]);
+ if (access(file, F_OK | R_OK | X_OK))
+ /* The above access modes was not allowed or
+ * the file could not be found - X_OK must be
+ * on the holde path tree
+ */
continue;
- if (strcmp(file, *browser_list[i]) == 0)
+ else
{
- my_browser.name = g_strdup_printf("%s/%s", path, file);
+ my_browser.name = g_strdup(file);
my_browser.option = g_strdup(browser_list[i][1]);
if (DEBUG)
{
@@ -167,9 +175,9 @@
break;
}
}
- closedir(dir);
}
g_free(file);
+ g_strfreev(head);
return my_browser;
}
-- Hilsen/Regards Michael RasmussenGet my public GnuPG keys: michael <at> rasmussen <dot> cc http://keyserver.veridis.com:11371/pks/lookup?op=get&search=0xD3C9A00E mir <at> datanom <dot> net http://keyserver.veridis.com:11371/pks/lookup?op=get&search=0xE501F51C mir <at> miras <dot> org http://keyserver.veridis.com:11371/pks/lookup?op=get&search=0xE3E80917 -------------------------------------------------------------- Make sure comments and code agree. - The Elements of Programming Style (Kernighan & Plaugher)
This archive was generated by hypermail 2b30 : Wed 15 Nov 2006 - 18:25:03 CET