1 // $Id: defaulttty.c,v 1.2 2005/01/26 15:30:40 ensc Exp $ --*- c -*--
3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "vserver-start.h"
24 #include <pathconfig.h>
26 #include <lib_internal/string.h>
33 #define ENSC_WRAPPERS_UNISTD 1
34 #define ENSC_WRAPPERS_FCNTL 1
39 checkTTY(char const /*@null@*/ *p)
41 return p!=0 && access(p, R_OK|W_OK)==0;
45 setDefaultTTY(PathInfo const *cfgdir, char const *dflt)
47 PathInfo subpath = ENSC_STRING_FIXED("/apps/init/tty");
48 char buf[ENSC_PI_APPSZ(*cfgdir, subpath)];
49 char const * new_tty = 0;
52 PathInfo ttypath = *cfgdir;
54 PathInfo_append(&ttypath, &subpath, buf);
55 new_tty = String_c_str(&ttypath, buf);
56 if (checkTTY(new_tty)) break;
58 new_tty = CONFDIR "/.defaults/apps/init/tty";
59 if (checkTTY(new_tty)) break;
62 if (checkTTY(new_tty)) break;
64 new_tty = "/dev/null";
67 int fd_in = Eopen(new_tty, O_RDONLY, 0);
73 int fd_out = Eopen(new_tty, O_WRONLY, 0600);