Commit dd08c50c authored by Christian Persch's avatar Christian Persch
Browse files

Add VtePty and adapt the VteTerminal APIs to it

Add VtePty as a GObject holding the info about the PTY. Add new API to
VteTerminal to set a VtePty, and deprecate the old API that takes a FD
to the PTY. Also deprecate the whole of the undocumented _vte_pty_*()
APIs.

Add vte_terminal_fork_command_full() variant that allow providing a
custom child setup function and that returns a GError on failure.

Bug #585841, bug #320128, bug #514447, bug #588871.
parent 9103412c
......@@ -19,7 +19,7 @@ endif
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = vte.pc
DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc
DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc --disable-silent-rules
MAINTAINERCLEANFILES = \
ChangeLog \
......
......@@ -55,6 +55,9 @@
<chapter>
<xi:include href="xml/vte-terminal.xml"/>
</chapter>
<chapter>
<xi:include href="xml/vte-pty.xml"/>
</chapter>
<chapter>
<xi:include href="xml/vte-version.xml"/>
</chapter>
......
......@@ -10,10 +10,6 @@ VteTerminalWriteFlags
VteSelectionFunc
vte_terminal_new
vte_terminal_im_append_menuitems
vte_terminal_fork_command
vte_terminal_forkpty
vte_terminal_set_pty
vte_terminal_get_pty
vte_terminal_feed
vte_terminal_feed_child
vte_terminal_feed_child_binary
......@@ -88,6 +84,18 @@ vte_terminal_get_encoding
vte_terminal_get_status_line
vte_terminal_get_padding
vte_terminal_write_contents
<SUBSECTION>
vte_terminal_fork_command
vte_terminal_fork_command_full
vte_terminal_forkpty
vte_terminal_get_pty
vte_terminal_get_pty_object
vte_terminal_pty_new
vte_terminal_set_pty
vte_terminal_set_pty_object
vte_terminal_watch_child
<SUBSECTION Standard>
VTE_TYPE_TERMINAL_CURSOR_BLINK_MODE
vte_terminal_cursor_blink_mode_get_type
......@@ -125,6 +133,40 @@ VteCharAttributes
VteTerminalPrivate
</SECTION>
<SECTION>
<FILE>vte-pty</FILE>
<TITLE>Vte PTY</TITLE>
VtePtyFlags
VtePtyError
VtePty
vte_pty_new
vte_pty_new_foreign
vte_pty_close
vte_pty_child_setup
vte_pty_get_fd
vte_pty_set_size
vte_pty_get_size
vte_pty_set_term
vte_pty_set_utf8
<SUBSECTION Standard>
vte_pty_flags_get_type
VTE_TYPE_PTY_FLAGS
vte_pty_error_get_type
VTE_TYPE_PTY_ERROR
vte_pty_error_quark
VTE_PTY_ERROR
vte_pty_get_type
VTE_TYPE_PTY
VTE_PTY
VTE_PTY_CLASS
VTE_IS_PTY
VTE_IS_PTY_CLASS
VTE_PTY_GET_CLASS
VtePtyClass
</SECTION>
<SECTION>
<FILE>vte-version</FILE>
<TITLE>Version Information</TITLE>
......
......@@ -5,15 +5,18 @@
#include "vte.h"
#include "vteversion.h"
#include "vteaccess.h"
#include "vtepty.h"
#include "vtetypebuiltins.h"
#include "reaper.h"
vte_pty_get_type
vte_reaper_get_type
vte_terminal_get_type
vte_terminal_accessible_get_type
vte_terminal_accessible_factory_get_type
vte_pty_error_get_type
vte_pty_flags_get_type
vte_terminal_anti_alias_get_type
vte_terminal_cursor_blink_mode_get_type
vte_terminal_cursor_shape_get_type
......
......@@ -10,7 +10,10 @@ AC_PROG_CC
AC_STDC_HEADERS
AM_PROG_CC_STDC
AM_MAINTAINER_MODE
if test -z "$enable_maintainer_mode"; then
enable_maintainer_mode=yes
fi
AM_MAINTAINER_MODE([enable])
AC_CHECK_HEADERS(sys/syslimits.h sys/time.h sys/types.h sys/un.h alloca.h lastlog.h libutil.h paths.h pty.h stropts.h termios.h ttyent.h util.h utmp.h utmpx.h pty.h util.h libutil.h ttyent.h)
have_openpty=0
......
......@@ -4,7 +4,7 @@ EXTRA_DIST = iso2022.txt
# The library
pkginclude_HEADERS = pty.h reaper.h vte.h vteaccess.h vtetypebuiltins.h vteversion.h
pkginclude_HEADERS = pty.h reaper.h vte.h vteaccess.h vtepty.h vtetypebuiltins.h vteversion.h
lib_LTLIBRARIES = libvte.la
......@@ -65,6 +65,8 @@ libvte_la_SOURCES = \
vtedraw.c \
vtedraw.h \
vteint.h \
vtepty.h \
vtepty-private.h \
vteregex.c \
vteregex.h \
vterowdata.c \
......@@ -96,7 +98,7 @@ libvte_la_CFLAGS = $(VTE_CFLAGS)
libvte_la_LIBADD = $(VTE_LIBS)
libvte_la_LDFLAGS = \
-version-info $(LIBVTE_LTVERSION) \
-export-symbols-regex "^vte_terminal_.*|^_vte_pty_.*|^vte_reaper_.*|_vte_debug_.*" \
-export-symbols-regex "^vte_terminal_.*|^vte_pty_.*|^_vte_pty_.*|^vte_reaper_.*|_vte_debug_.*" \
@LIBTOOL_EXPORT_OPTIONS@ @LIBTOOL_FLAGS@
......@@ -116,14 +118,14 @@ marshal.h: marshal.list
vtetypebuiltins.h: stamp-vtetypebuiltins.h
@true
stamp-vtetypebuiltins.h: vtetypebuiltins.h.template vte.h
$(AM_V_GEN) $(GLIB_MKENUMS) --template $< $(filter-out $<,$^) > xgen-vtbh \
stamp-vtetypebuiltins.h: vtetypebuiltins.h.template vte.h vtepty.h
$(AM_V_GEN) $(GLIB_MKENUMS) --template $< $(filter %.h,$^) > xgen-vtbh \
&& (cmp -s xgen-vtbh vtetypebuiltins.h || cp xgen-vtbh vtetypebuiltins.h ) \
&& rm -f xgen-vtbh \
&& echo timestamp > $(@F)
vtetypebuiltins.c: vtetypebuiltins.c.template vte.h
$(AM_V_GEN) $(GLIB_MKENUMS) --template $< $(filter-out $<,$^) > xgen-vtbc \
vtetypebuiltins.c: vtetypebuiltins.c.template vte.h vtepty.h
$(AM_V_GEN) $(GLIB_MKENUMS) --template $< $(filter %.h,$^) > xgen-vtbc \
&& (cmp -s xgen-vtbc vtetypebuiltins.c || cp xgen-vtbc vtetypebuiltins.c ) \
&& rm -f xgen-vtbc
......
This diff is collapsed.
......@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef VTE_DISABLE_DEPRECATED
#ifndef vte_pty_h_included
#define vte_pty_h_included
......@@ -45,4 +47,6 @@ void _vte_pty_close(int pty);
G_END_DECLS
#endif
#endif /* vte_pty_h_included */
#endif /* !VTE_DISABLE_DEPRECATED */
......@@ -169,8 +169,7 @@ struct _VteTerminalPrivate {
int default_column_count, default_row_count; /* default sizes */
/* PTY handling data. */
const char *shell; /* shell we started */
int pty_master; /* pty master descriptor */
VtePty *pty;
GIOChannel *pty_channel; /* master channel */
guint pty_input_source;
guint pty_output_source;
......
This diff is collapsed.
......@@ -28,6 +28,7 @@
#define __VTE_VTE_H_INSIDE__ 1
#include "vtepty.h"
#include "vtetypebuiltins.h"
#include "vteversion.h"
......@@ -264,21 +265,39 @@ GType vte_terminal_get_type(void);
VTE_TYPE_TERMINAL)
#define VTE_TERMINAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VTE_TYPE_TERMINAL, VteTerminalClass))
/* You can get by with just these two functions. */
GtkWidget *vte_terminal_new(void);
VtePty *vte_terminal_pty_new (VteTerminal *terminal,
VtePtyFlags flags,
GError **error);
void vte_terminal_watch_child (VteTerminal *terminal,
GPid child_pid);
#ifndef VTE_DISABLE_DEPRECATED
pid_t vte_terminal_fork_command(VteTerminal *terminal,
const char *command, char **argv,
char **envv, const char *directory,
char **envv, const char *working_directory,
gboolean lastlog,
gboolean utmp,
gboolean wtmp);
/* Users of libzvt may find this useful. */
gboolean wtmp) G_GNUC_DEPRECATED;
pid_t vte_terminal_forkpty(VteTerminal *terminal,
char **envv, const char *directory,
char **envv, const char *working_directory,
gboolean lastlog,
gboolean utmp,
gboolean wtmp);
gboolean wtmp) G_GNUC_DEPRECATED;
#endif /* VTE_DISABLE_DEPRECATED */
gboolean vte_terminal_fork_command_full(VteTerminal *terminal,
VtePtyFlags pty_flags,
const char *working_directory,
char **argv,
char **envv,
GSpawnFlags spawn_flags,
GSpawnChildSetupFunc child_setup,
gpointer child_setup_data,
GPid *child_pid /* out */,
GError **error);
/* Send data to the terminal to display, or to the terminal's forked command
* to handle in some way. If it's 'cat', they should be the same. */
......@@ -453,10 +472,13 @@ const char *vte_terminal_get_status_line(VteTerminal *terminal);
void vte_terminal_get_padding(VteTerminal *terminal, int *xpad, int *ypad) G_GNUC_DEPRECATED;
#endif
/* Attach an existing PTY master side to the terminal widget. Use
* instead of vte_terminal_fork_command(). */
#ifndef VTE_DISABLE_DEPRECATED
void vte_terminal_set_pty(VteTerminal *terminal, int pty_master);
int vte_terminal_get_pty(VteTerminal *terminal);
#endif
void vte_terminal_set_pty_object(VteTerminal *terminal, VtePty *pty);
VtePty *vte_terminal_get_pty_object(VteTerminal *terminal);
/* Accessors for bindings. */
GtkAdjustment *vte_terminal_get_adjustment(VteTerminal *terminal);
......
......@@ -881,13 +881,35 @@ main(int argc, char **argv)
if (!console) {
if (shell) {
/* Launch a shell. */
GError *err = NULL;
char **command_argv = NULL;
int command_argc;
GPid pid = -1;
_VTE_DEBUG_IF(VTE_DEBUG_MISC)
vte_terminal_feed(terminal, message, -1);
vte_terminal_fork_command(terminal,
command, NULL, env_add,
working_directory,
TRUE, TRUE, TRUE);
if (command == NULL)
command = "/bin/sh"; // FIXMEchpe
if (command != NULL) {
if (!g_shell_parse_argv(command, &command_argc, &command_argv, &err) ||
!vte_terminal_fork_command_full(terminal,
VTE_PTY_DEFAULT,
NULL,
command_argv,
env_add,
0,
NULL, NULL,
&pid,
&err)) {
g_warning("Failed to fork: %s\n", err->message);
g_error_free(err);
} else {
g_print("Fork succeeded, PID %d\n", pid);
}
}
g_strfreev(command_argv);
#ifdef VTE_DEBUG
if (command == NULL) {
vte_terminal_feed_child(terminal,
......
/*
* Copyright © 2009, 2010 Christian Persch
*
* This is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
G_BEGIN_DECLS
VtePtyFlags __vte_pty_get_pty_flags(gboolean lastlog,
gboolean utmp,
gboolean wtmp);
char **__vte_pty_get_argv (const char *command,
char **argv,
GSpawnFlags *flags /* inout */);
gboolean __vte_pty_spawn (VtePty *pty,
const char *working_directory,
char **argv,
char **envv,
GSpawnFlags spawn_flags,
GSpawnChildSetupFunc child_setup,
gpointer child_setup_data,
GPid *child_pid /* out */,
GError **error);
gboolean __vte_pty_fork(VtePty *pty,
GPid *pid,
GError **error);
G_END_DECLS
/*
* Copyright © 2009, 2010 Christian Persch
*
* This is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#if !defined (__VTE_VTE_H_INSIDE__) && !defined (VTE_COMPILATION)
#error "Only <vte/vte.h> can be included directly."
#endif
#ifndef VTE_PTY_H
#define VTE_PTY_H
#include <glib-object.h>
#include <sys/types.h> /* for pid_t */
G_BEGIN_DECLS
/**
* VtePtyFlags:
* @VTE_PTY_NO_LASTLOG: don't record the session in lastlog
* @VTE_PTY_NO_UTMP: don't record the session in utmp
* @VTE_PTY_NO_WTMP: don't record the session in wtmp
* @VTE_PTY_NO_HELPER: don't use the GNOME PTY helper to allocate the PTY
* @VTE_PTY_NO_FALLBACK: when allocating the PTY with the PTY helper fails,
* don't fall back to try using PTY98
* @VTE_PTY_DEFAULT: the default flags
*
* Since: 0.24
*/
typedef enum {
VTE_PTY_NO_LASTLOG = 1 << 0,
VTE_PTY_NO_UTMP = 1 << 1,
VTE_PTY_NO_WTMP = 1 << 2,
VTE_PTY_NO_HELPER = 1 << 3,
VTE_PTY_NO_FALLBACK = 1 << 4,
VTE_PTY_DEFAULT = 0
} VtePtyFlags;
/**
* VtePtyError:
* @VTE_PTY_ERROR_PTY_HELPER_FAILED: failure when using the GNOME PTY helper to
* allocate the PTY
* @VTE_PTY_ERROR_PTY98_FAILED: failure when using PTY98 to allocate the PTY
*
* Since: 0.24
*/
typedef enum {
VTE_PTY_ERROR_PTY_HELPER_FAILED = 0,
VTE_PTY_ERROR_PTY98_FAILED
} VtePtyError;
GQuark vte_pty_error_quark (void);
/**
* VTE_PTY_ERROR:
*
* Error domain for VTE PTY errors. Errors in this domain will be from the #VtePtyError
* enumeration. See #GError for more information on error domains.
*
* Since: 0.24
*/
#define VTE_PTY_ERROR (vte_pty_error_quark ())
/* VTE PTY object */
#define VTE_TYPE_PTY (vte_pty_get_type())
#define VTE_PTY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VTE_TYPE_PTY, VtePty))
#define VTE_PTY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VTE_TYPE_PTY, VtePtyClass))
#define VTE_IS_PTY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VTE_TYPE_PTY))
#define VTE_IS_PTY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VTE_TYPE_PTY))
#define VTE_PTY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VTE_TYPE_PTY, VtePtyClass))
typedef struct _VtePty VtePty;
typedef struct _VtePtyClass VtePtyClass;
GType vte_pty_get_type (void);
VtePty *vte_pty_new (VtePtyFlags flags,
GError **error);
VtePty *vte_pty_new_foreign (int fd);
int vte_pty_get_fd (VtePty *pty);
void vte_pty_close (VtePty *pty);
void vte_pty_child_setup (VtePty *pty);
gboolean vte_pty_get_size (VtePty *pty,
int *rows,
int *columns,
GError **error);
gboolean vte_pty_set_size (VtePty *pty,
int rows,
int columns,
GError **error);
void vte_pty_set_utf8 (VtePty *pty,
gboolean utf8);
void vte_pty_set_term (VtePty *pty,
const char *emulation);
G_END_DECLS
#endif /* VTE_PTY_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment