[vte] Export vte_get_user_shell()



commit 219ea41b4382ab43ddb6b826d62a5401aab20e6e
Author: Christian Persch <chpe gnome org>
Date:   Wed Feb 16 20:34:41 2011 +0100

    Export vte_get_user_shell()
    
    Bug #642184. Also fixes bug #640179.

 doc/reference/vte-sections.txt |    3 ++
 src/Makefile.am                |    2 +-
 src/vte.c                      |   58 ++++++++++++++++++----------------------
 src/vte.h                      |    2 +
 src/vteapp.c                   |    3 ++
 5 files changed, 35 insertions(+), 33 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index 978ba3a..1a7d821 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -99,6 +99,9 @@ vte_terminal_search_set_gregex
 vte_terminal_search_set_wrap_around
 
 <SUBSECTION>
+vte_get_user_shell
+
+<SUBSECTION>
 vte_terminal_fork_command
 vte_terminal_fork_command_full
 vte_terminal_forkpty
diff --git a/src/Makefile.am b/src/Makefile.am
index ada20cb..5151187 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -105,7 +105,7 @@ libvte VTE_LIBRARY_SUFFIX_U@_la_LIBADD = $(VTE_LIBS)
 libvte VTE_LIBRARY_SUFFIX_U@_la_LDFLAGS = \
   $(VTE_LDFLAGS) \
 	-version-info $(LT_VERSION_INFO) \
-	-export-symbols-regex "^vte_terminal_.*|^vte_pty_.*|^_vte_pty_.*|^vte_reaper_.*|_vte_debug_.*" \
+	-export-symbols-regex "^vte_terminal_.*|^vte_pty_.*|^vte_get_.*|^_vte_pty_.*|^vte_reaper_.*|_vte_debug_.*" \
 	@LIBTOOL_EXPORT_OPTIONS@ @LIBTOOL_FLAGS@ \
 	$(AM_LDFLAGS)
 
diff --git a/src/vte.c b/src/vte.c
index 5083352..82dc3ac 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -3674,46 +3674,40 @@ vte_terminal_watch_child (VteTerminal *terminal,
         g_object_thaw_notify(object);
 }
 
-/*
- * _vte_terminal_get_user_shell:
+/**
+ * vte_get_user_shell:
  *
- * Uses getpwd() to determine the user's shell. If that fails, falls back
- * to using the SHELL environment variable. As last-ditch fallback, returns
- * "/bin/sh".
+ * Gets the user's shell, or %NULL. In the latter case, the
+ * system default (usually "/bin/sh") should be used.
  *
- * Returns: a newly allocated string containing the command to run the
- *   user's shell
+ * Returns: (tranfer full) (type filename): a newly allocated string with the
+ *   user's shell, or %NULL
  */
-static char *
-_vte_terminal_get_user_shell (void)
+char *
+vte_get_user_shell (void)
 {
 	struct passwd *pwd;
-	char *command;
 
 	pwd = getpwuid(getuid());
-	if (pwd != NULL) {
-	        command = g_strdup (pwd->pw_shell);
-	        _vte_debug_print(VTE_DEBUG_MISC,
-				"Using user's shell (%s).\n",
-				command ? command : "(null)");
-	}
-	if (command == NULL) {
-		if (g_getenv ("SHELL")) {
-			command = g_strdup (g_getenv ("SHELL"));
-			_vte_debug_print(VTE_DEBUG_MISC,
-					 "Using $SHELL shell (%s).\n",
-					 command);
-		} else {
-			command = g_strdup ("/bin/sh");
-			_vte_debug_print(VTE_DEBUG_MISC,
-					 "Using default shell (%s).\n",
-					 command);
-		}
-	}
+        if (pwd && pwd->pw_shell)
+                return g_strdup (pwd->pw_shell);
+
+        return NULL;
+}
+
+static char *
+_vte_terminal_get_user_shell_with_fallback (void)
+{
+        char *command;
+        const gchar *env;
+
+        if ((command = vte_get_user_shell ()))
+                return command;
 
-	g_assert (command != NULL);
+        if ((env = g_getenv ("SHELL")))
+                return g_strdup (env);
 
-	return command;
+        return g_strdup ("/bin/sh");
 }
 
 /*
@@ -3737,7 +3731,7 @@ _vte_terminal_get_argv (const char *command,
 	char **argv2;
         char *shell = NULL;
 
-        argv2 = __vte_pty_get_argv(command ? command : (shell = _vte_terminal_get_user_shell()),
+        argv2 = __vte_pty_get_argv(command ? command : (shell = _vte_terminal_get_user_shell_with_fallback ()),
                                    argv,
                                    flags);
         g_free(shell);
diff --git a/src/vte.h b/src/vte.h
index 879870a..4e514a1 100644
--- a/src/vte.h
+++ b/src/vte.h
@@ -483,6 +483,8 @@ const char *vte_terminal_get_status_line(VteTerminal *terminal);
 void vte_terminal_set_pty_object(VteTerminal *terminal, VtePty *pty);
 VtePty *vte_terminal_get_pty_object(VteTerminal *terminal);
 
+char *vte_get_user_shell (void);
+
 /* Accessors for bindings. */
 #if !GTK_CHECK_VERSION (2, 91, 2)
 GtkAdjustment *vte_terminal_get_adjustment(VteTerminal *terminal);
diff --git a/src/vteapp.c b/src/vteapp.c
index 45ed957..c6ab68a 100644
--- a/src/vteapp.c
+++ b/src/vteapp.c
@@ -994,6 +994,9 @@ main(int argc, char **argv)
 			_VTE_DEBUG_IF(VTE_DEBUG_MISC)
 				vte_terminal_feed(terminal, message, -1);
 
+                        if (command == NULL || *command == '\0')
+                                command = vte_get_user_shell ();
+
 			if (command == NULL || *command == '\0')
 				command = g_getenv ("SHELL");
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]