summaryrefslogtreecommitdiff
path: root/libcons/init-init.c
diff options
context:
space:
mode:
authorMarcus Brinkmann <marcus@gnu.org>2002-08-22 19:24:19 +0000
committerMarcus Brinkmann <marcus@gnu.org>2002-08-22 19:24:19 +0000
commit9cc0d6d3f8a89f35ddea92e30bdc2822c4164358 (patch)
treed182cfe90532231aaff4411a9d0118e9e5a15e7e /libcons/init-init.c
parent4062fb2fcf938bb6a9c5d8f6404586cab11fe227 (diff)
libcons/
2002-08-22 Marcus Brinkmann <marcus@gnu.org> * demuxer.c, init-init.c, init-loop.c, opts-version.c, extra-version.c, dir-changed.c, file-changed.c, opts-std-startup.c, cons-lookup.c, cons-switch.c, vcons-remove.c, vcons-add.c, vcons-open.c, vcons-close.c, vcons-refresh.c, priv.h, mutations.h, cons.h: New files.
Diffstat (limited to 'libcons/init-init.c')
-rw-r--r--libcons/init-init.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/libcons/init-init.c b/libcons/init-init.c
new file mode 100644
index 00000000..e84f0e67
--- /dev/null
+++ b/libcons/init-init.c
@@ -0,0 +1,99 @@
+/* init-init.c - Initialize the console library.
+ Copyright (C) 1995, 1996, 2002 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell, p/BSG and Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd 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, or (at
+ your option) any later version.
+
+ The GNU Hurd 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+
+#include <errno.h>
+#include <malloc.h>
+
+#include <hurd.h>
+#include <hurd/ports.h>
+
+#include <mach.h>
+
+#include "cons.h"
+#include "priv.h"
+
+ struct port_bucket *cons_port_bucket;
+ struct port_class *cons_port_class;
+
+error_t
+cons_init (void)
+{
+ error_t err;
+ cons_t cons;
+ cons_notify_t dir_notify_port;
+ mach_port_t dir_notify;
+
+ cons_port_bucket = ports_create_bucket ();
+ if (!cons_port_bucket)
+ return errno;
+
+ cons_port_class = ports_create_class (NULL, NULL);
+ if (!cons_port_class)
+ return errno;
+
+ /* Create the console structure. */
+ cons = malloc (sizeof (*cons));
+ if (!cons)
+ return errno;
+ mutex_init (&cons->lock);
+ cons->vcons_list = NULL;
+ cons->vcons_last = NULL;
+ cons->active = NULL;
+ cons->dir = opendir (_cons_file);
+ cons->slack = _cons_slack;
+ if (!cons->dir)
+ {
+ free (cons);
+ return errno;
+ }
+ cons->dirport = getdport (dirfd (cons->dir));
+ if (cons->dirport == MACH_PORT_NULL)
+ {
+ closedir (cons->dir);
+ free (cons);
+ return errno;
+ }
+
+ /* Request directory notifications. */
+ err = ports_create_port (cons_port_class, cons_port_bucket,
+ sizeof (*dir_notify_port), &dir_notify_port);
+ if (err)
+ {
+ mach_port_deallocate (mach_task_self (), cons->dirport);
+ closedir (cons->dir);
+ free (cons);
+ return err;
+ }
+ dir_notify_port->cons = cons;
+ dir_notify_port->vcons = NULL;
+
+ dir_notify = ports_get_right (dir_notify_port);
+ err = dir_notice_changes (cons->dirport, dir_notify,
+ MACH_MSG_TYPE_MAKE_SEND);
+ if (err)
+ {
+ mach_port_deallocate (mach_task_self (), cons->dirport);
+ closedir (cons->dir);
+ free (cons);
+ return err;
+ }
+ return 0;
+}