rpms/upstart/devel upstart-tty-stack.patch, NONE, 1.1 upstart.spec, 1.4, 1.5
Casey Dahlin (sadmac)
fedora-extras-commits at redhat.com
Sun Mar 2 21:54:28 UTC 2008
Author: sadmac
Update of /cvs/pkgs/rpms/upstart/devel
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv19880/devel
Modified Files:
upstart.spec
Added Files:
upstart-tty-stack.patch
Log Message:
Add tty stack initctl commands
upstart-tty-stack.patch:
--- NEW FILE upstart-tty-stack.patch ---
=== modified file 'init/Makefile.am'
--- init/Makefile.am 2007-10-11 21:00:43 +0000
+++ init/Makefile.am 2008-02-29 21:38:58 +0000
@@ -16,6 +16,7 @@
init_SOURCES = \
main.c \
+ tty.c tty.h\
errors.h paths.h \
process.c process.h \
job.c job.h \
=== modified file 'init/control.c'
--- init/control.c 2007-03-13 17:25:34 +0000
+++ init/control.c 2008-03-01 08:00:46 +0000
@@ -43,6 +43,7 @@
#include <upstart/message.h>
#include "job.h"
+#include "tty.h"
#include "control.h"
#include "notify.h"
@@ -57,6 +58,11 @@
static int control_job_find (void *data, pid_t pid,
UpstartMessageType type,
const char *pattern);
+static int control_push_tty (void *data, pid_t pid,
+ UpstartMessageType type,
+ const char *device);
+static int control_pop_tty (void *data, pid_t pid,
+ UpstartMessageType type);
static int control_job_query (void *data, pid_t pid,
UpstartMessageType type,
const char *name, unsigned int id);
@@ -96,6 +102,10 @@
static UpstartMessage message_handlers[] = {
{ -1, UPSTART_VERSION_QUERY,
(UpstartMessageHandler)control_version_query },
+ { -1, UPSTART_PUSH_TTY,
+ (UpstartMessageHandler)control_push_tty },
+ { -1, UPSTART_POP_TTY,
+ (UpstartMessageHandler)control_pop_tty },
{ -1, UPSTART_LOG_PRIORITY,
(UpstartMessageHandler)control_log_priority },
{ -1, UPSTART_JOB_FIND,
@@ -308,6 +318,66 @@
nih_io_send_message (control_io, message);
}
+/**
+ * control_push_tty:
+ * @data: data pointer,
+ * @pid: origin process id,
+ * @type: message type received.
+ *
+ * This function is called to change the current tty.
+ *
+ * Returns: zero on success, negative value on raised error.
+ **/
+static int
+control_push_tty (void *data,
+ pid_t pid,
+ UpstartMessageType type,
+ const char *device)
+{
+ NihIoMessage *reply;
+
+ nih_assert (pid > 0);
+ nih_assert (type == UPSTART_PUSH_TTY);
+
+ nih_info (_("Control request to change tty"));
+
+ NIH_MUST (reply = upstart_message_new (control_io, pid,
+ UPSTART_TTY,
+ push_tty (device)));
+ nih_io_send_message (control_io, reply);
+
+ return 0;
+}
+
+/**
+ * control_pop_tty:
+ * @data: data pointer,
+ * @pid: origin process id,
+ * @type: message type received.
+ *
+ * This function is called to revert the most recent tty change.
+ *
+ * Returns: zero on success, negative value on raised error.
+ **/
+static int
+control_pop_tty (void *data,
+ pid_t pid,
+ UpstartMessageType type)
+{
+ NihIoMessage *reply;
+
+ nih_assert (pid > 0);
+ nih_assert (type == UPSTART_POP_TTY);
+
+ nih_info (_("Control request to revert changed tty"));
+
+ NIH_MUST (reply = upstart_message_new (control_io, pid,
+ UPSTART_TTY,
+ pop_tty ()));
+ nih_io_send_message (control_io, reply);
+
+ return 0;
+}
/**
* control_version_query:
=== modified file 'init/main.c'
--- init/main.c 2007-03-13 19:13:19 +0000
+++ init/main.c 2008-03-02 03:14:59 +0000
@@ -58,6 +58,7 @@
#include "control.h"
#include "cfgfile.h"
#include "paths.h"
+#include "tty.h"
/* Prototypes for static functions */
@@ -190,6 +191,8 @@
if (! (restart || rescue))
reset_console ();
+ tty_stack_init ();
+
/* Set the PATH environment variable */
setenv ("PATH", PATH, TRUE);
=== modified file 'init/process.c'
--- init/process.c 2007-10-11 21:08:38 +0000
+++ init/process.c 2008-03-02 21:22:05 +0000
@@ -51,6 +51,7 @@
#include "job.h"
#include "process.h"
#include "paths.h"
+#include "tty.h"
/* Prototypes for static functions */
@@ -385,10 +386,11 @@
break;
- case CONSOLE_OUTPUT:
+ case CONSOLE_OUTPUT: {
/* Ordinary console input and output */
- fd = open (CONSOLE, O_RDWR | O_NOCTTY);
+ fd = open (current_tty (), O_RDWR | O_NOCTTY);
break;
+ }
case CONSOLE_OWNER:
/* As CONSOLE_OUTPUT but with ^C, etc. sent */
=== added file 'init/tty.c'
--- init/tty.c 1970-01-01 00:00:00 +0000
+++ init/tty.c 2008-03-02 21:18:03 +0000
@@ -0,0 +1,97 @@
+/* upstart
+ *
+ * tty.c - tty change events
+ *
+ * Copyright © 2007 Canonical Ltd.
+ * Author: Scott James Remnant <scott at ubuntu.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; either version 2 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 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
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <nih/logging.h>
[...1956 lines suppressed...]
+++ upstart/message.h 2008-02-28 04:52:36 +0000
@@ -57,11 +57,20 @@
* UPSTART_VERSION message in reply.
*
* Clients may send UPSTART_LOG_PRIORITY, without any reply.
+ *
+ * Clients may send UPSTART_PUSH_TTY and recieve an UPSTART_TTY message
+ * in reply
+ *
+ * Clients may send UPSTART_POP_TTY and recieve an UPSTART_TTY message
+ * in reply
*/
UPSTART_NO_OP = 0x0000,
UPSTART_VERSION_QUERY = 0x0001,
UPSTART_LOG_PRIORITY = 0x0002,
UPSTART_VERSION = 0x0010,
+ UPSTART_PUSH_TTY = 0x0011,
+ UPSTART_POP_TTY = 0x0012,
+ UPSTART_TTY = 0x0013,
/* Job requests and responses.
*
=== modified file 'util/initctl.c'
--- util/initctl.c 2007-03-13 18:08:31 +0000
+++ util/initctl.c 2008-03-02 21:05:23 +0000
@@ -99,6 +99,9 @@
static char *output_name (unsigned int id, const char *name);
/* Prototypes of response handler functions */
+static int handle_tty (void *data, pid_t pid,
+ UpstartMessageType type,
+ const char *tty);
static int handle_version (void *data, pid_t pid,
UpstartMessageType type,
const char *version);
@@ -159,6 +162,8 @@
/* Prototypes for option and command functions */
int env_option (NihOption *option, const char *arg);
+int push_tty_action (NihCommand *command, char * const *args);
+int pop_tty_action (NihCommand *command, char * const *args);
int start_action (NihCommand *command, char * const *args);
int stop_action (NihCommand *command, char * const *args);
int status_action (NihCommand *command, char * const *args);
@@ -296,6 +301,8 @@
{ -1, UPSTART_VERSION,
(UpstartMessageHandler)handle_version },
+ { -1, UPSTART_TTY,
+ (UpstartMessageHandler)handle_tty },
{ -1, UPSTART_JOB,
(UpstartMessageHandler)handle_job },
{ -1, UPSTART_JOB_FINISHED,
@@ -687,6 +694,40 @@
}
/**
+ * handle_tty:
+ * @data: data passed to handler,
+ * @pid: origin of message,
+ * @type: message type,
+ * @version: tty device in use.
+ *
+ * Handles receipt of the UPSTART_TTY reply from the server, which is
+ * sent in response to an UPSTART_PUSH_TTY or UPSTART_POP_TTY message.
+ *
+ * Output the version string received and mark it as a response.
+ *
+ * Returns: zero on success, negative value on error or positive value if the
+ * command should exit with that exit status.
+ **/
+static int
+handle_tty (void *data,
+ pid_t pid,
+ UpstartMessageType type,
+ const char *tty)
+{
+ nih_assert (pid > 0);
+ nih_assert (type == UPSTART_TTY);
+ nih_assert (tty != NULL);
+
+ if (! event_caused)
+ num_responses++;
+
+ event_caused = FALSE;
+
+ nih_message ("%s", tty);
+
+ return 0;
+}
+/**
* handle_job:
* @data: data passed to handler,
* @pid: origin of message,
@@ -1802,6 +1843,61 @@
}
/**
+ * pop_tty_action:
+ * @command: NihCommand invoked,
+ * @args: command-line arguments.
+ *
+ * This function is called for the "pop_tty" command; it takes no arguments.
+ *
+ * It reverts the last push_tty command, and replies with the new tty.
+ *
+ * Returns: command exit status.
+ **/
+int
+pop_tty_action (NihCommand *command,
+ char * const *args)
+{
+ nih_assert (command != NULL);
+ nih_assert (args != NULL);
+
+ if (initctl_send (UPSTART_POP_TTY) < 0)
+ return 1;
+
+ return initctl_recv (1);
+}
+
+/**
+ * push_tty_action:
+ * @command: NihCommand invoked,
+ * @args: command-line arguments.
+ *
+ * This function is called for the "push_tty" command; it takes a tty device
+ * name.
+ *
+ * It causes upstart to begin using that tty, and replies with the new tty.
+ *
+ * Returns: command exit status.
+ **/
+int
+push_tty_action (NihCommand *command,
+ char * const *args)
+{
+ nih_assert (command != NULL);
+ nih_assert (args != NULL);
+
+ if (! args[0]) {
+ fprintf (stderr, _("%s: missing device name\n"), program_name);
+ nih_main_suggest_help ();
+ return 1;
+ }
+
+ if (initctl_send (UPSTART_PUSH_TTY, args[0]) < 0)
+ return 1;
+
+ return initctl_recv (1);
+}
+
+/**
* emit_action:
* @command: NihCommand invoked,
* @args: command-line arguments.
@@ -2079,6 +2175,24 @@
};
/**
+ * pop_tty_options:
+ *
+ * Command-line options accepted for the pop_tty command.
+ **/
+NihOption pop_tty_options[] = {
+ NIH_OPTION_LAST
+};
+
+/**
+ * push_tty_options:
+ *
+ * Command-line options accepted for the push_tty command.
+ **/
+NihOption push_tty_options[] = {
+ NIH_OPTION_LAST
+};
+
+/**
* log_priority_options:
*
* Command-line options accepted for the log-priority command.
@@ -2156,6 +2270,16 @@
NULL,
&event_commands, events_options, events_action },
+ { "push-tty", NULL,
+ N_("Change the init daemon's tty device"),
+ NULL,
+ NULL, push_tty_options, push_tty_action },
+
+ { "pop-tty", NULL,
+ N_("Revert the last change to the init daemon's tty device"),
+ NULL,
+ NULL, pop_tty_options, pop_tty_action },
+
{ "version", NULL,
N_("Request the version of the init daemon."),
NULL,
Index: upstart.spec
===================================================================
RCS file: /cvs/pkgs/rpms/upstart/devel/upstart.spec,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- upstart.spec 16 Feb 2008 03:53:32 -0000 1.4
+++ upstart.spec 2 Mar 2008 21:53:54 -0000 1.5
@@ -1,6 +1,6 @@
Name: upstart
Version: 0.3.9
-Release: 5%{?dist}
+Release: 6%{?dist}
Summary: An event-driven init system
Group: System Environment/Base
@@ -9,6 +9,7 @@
Source0: http://upstart.ubuntu.com/download/0.3/upstart-%{version}.tar.bz2
Patch0: upstart-gcc43.patch
Patch1: upstart-force-on-shutdown-reboot.patch
+Patch2: upstart-tty-stack.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: gettext
@@ -22,6 +23,7 @@
%setup -q
%patch0 -p1
%patch1 -p1
+%patch2
%build
%configure --enable-compat=sysv --sbindir=/sbin --libdir=/%{_lib}
@@ -83,6 +85,9 @@
%{_mandir}/man8/telinit.8.gz
%changelog
+* Sun Mar 03 2008 Casey Dahlin <cjdahlin at ncsu.edu> - 0.3.9-6
+- Added patch to allow runtime tty changes
+
* Fri Feb 15 2008 Casey Dahlin <cjdahlin at ncsu.edu> - 0.3.9-5
- Added patch to imply --force on runlevels 0 and 6
More information about the fedora-extras-commits
mailing list