[gnome-nettool] utils: append EXTRA_PATH to user's path for util_find_program_in_path()
- From: GermÃn Poà CaamaÃo <gpoo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nettool] utils: append EXTRA_PATH to user's path for util_find_program_in_path()
- Date: Tue, 2 Oct 2012 02:52:01 +0000 (UTC)
commit 56407cdf45910a444a93e4fa4b52d13f171f93d0
Author: Alexandre Rostovtsev <tetromino gentoo org>
Date: Sun Apr 15 02:15:14 2012 -0400
utils: append EXTRA_PATH to user's path for util_find_program_in_path()
Normal users generally do not have /sbin or /usr/sbin in their paths,
and as a result, without EXTRA_PATH, util_find_program_in_path() fails
to find certain tools on some distros.
https://bugzilla.gnome.org/show_bug.cgi?id=674126
src/utils.c | 14 +++++++++++---
1 files changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/src/utils.c b/src/utils.c
index a97217f..eef3cbe 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -31,6 +31,8 @@
#include <string.h>
#include <glib/gi18n.h>
+#define EXTRA_PATH "/sbin:/usr/sbin:/usr/etc:/usr/local/bin:/usr/local/sbin:/usr/ucb"
+
#if (GLIB_MINOR_VERSION < 2)
gint
@@ -63,13 +65,14 @@ my_strchrnul (const gchar *str, gchar c)
}
/* Based on g_find_program_in_path, stolen from glib/gutils.c
- * It allow to ask in a specific PATH, if fail then as in the user PATH.
+ * It allow to ask in a specific PATH, if fail then as in the user PATH with
+ * EXTRA_PATH appended.
*/
gchar *
util_find_program_in_path (const gchar * program, const gchar * path)
{
const gchar *p;
- gchar *name, *freeme;
+ gchar *name, *freeme, *user_path = NULL;
size_t len;
size_t pathlen;
@@ -92,6 +95,10 @@ util_find_program_in_path (const gchar * program, const gchar * path)
if (path == NULL) {
path = "/bin:/usr/bin:.";
}
+
+ /* /sbin and /usr/sbin might not be in the user's path */
+ user_path = g_strconcat (path, ":", EXTRA_PATH, NULL);
+ path = user_path;
}
len = strlen (program) + 1;
@@ -124,12 +131,14 @@ util_find_program_in_path (const gchar * program, const gchar * path)
gchar *ret;
ret = g_strdup (startp);
g_free (freeme);
+ g_free (user_path);
return ret;
}
}
while (*p++ != '\0');
g_free (freeme);
+ g_free (user_path);
return NULL;
}
@@ -202,7 +211,6 @@ util_tree_model_to_string (GtkTreeView *treeview)
return result;
}
-#define EXTRA_PATH "/sbin:/usr/sbin:/usr/etc:/usr/local/bin:/usr/local/sbin:/usr/ucb"
/*
* Find a program in PATH and EXTRA_PATH. If fail, show a dialog box.
* Returns the abosulet path and program.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]