2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: apollo.c /main/4 1996/10/04 15:52:17 drk $ */
24 /***************************************************************
26 * AT&T - PROPRIETARY *
28 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF *
29 * AT&T BELL LABORATORIES *
30 * AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN *
31 * ACCORDANCE WITH APPLICABLE AGREEMENTS *
33 * Copyright (c) 1995 AT&T Corp. *
34 * Unpublished & Not for Publication *
35 * All Rights Reserved *
37 * The copyright notice above does not evidence any *
38 * actual or intended publication of such source code *
40 * This software was created by the *
41 * Advanced Software Technology Department *
42 * AT&T Bell Laboratories *
44 * For further information contact *
45 * {research,attmail}!dgk *
47 ***************************************************************/
49 /* : : generated by proto : : */
51 #if !defined(__PROTO__)
52 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
53 #if defined(__cplusplus)
54 #define __MANGLE__ "C"
59 #define __PROTO__(x) x
61 #define __PARAM__(n,o) n
62 #if !defined(__STDC__) && !defined(__cplusplus)
63 #if !defined(c_plusplus)
74 #define __PROTO__(x) ()
75 #define __OTORP__(x) x
76 #define __PARAM__(n,o) o
84 #if defined(__cplusplus) || defined(c_plusplus)
85 #define __VARARG__ ...
89 #if defined(__STDARG__)
90 #define __VA_START__(p,a) va_start(p,a)
92 #define __VA_START__(p,a) va_start(p)
100 #include "/sys/ins/base.ins.c"
101 #include "/sys/ins/pad.ins.c"
102 #include "/sys/ins/error.ins.c"
103 #include <sys/param.h> /* for maximum pathname length */
104 #include <apollo/sys/ubase.h>
105 #include <apollo/sys/name.h>
106 #include <apollo/error.h>
108 int pad_create __PARAM__((char *fname), (fname)) __OTORP__(char *fname;){
114 pad_$create (*fname, (short)strlen(fname), pad_$edit, oldfd,
115 pad_$bottom, 0, size, newfd, st);
117 error(ERROR_system(1),e_open,"dm pad");
121 pad_wait __PARAM__((int fd), (fd)) __OTORP__(int fd;){
124 pad_$edit_wait((stream_$id_t)fd, st);
126 return (st == 0 ? 0 : 1);
130 char *apollo_error __PARAM__((void), ()){
131 extern __MANGLE__ long unix_proc_$status;
132 char subsys[80], module[80], code[80];
133 short slen, mlen, clen;
134 static char retstr[256];
136 error_$get_text (unix_proc_$status, subsys, slen,
137 module, mlen, code, clen);
138 subsys[slen] = module[mlen] = code[clen] = 0;
140 sprintf (code, "status 0x%08lx", unix_proc_$status);
142 sprintf(retstr, "%s (%s/%s)", code, subsys, module );
144 sprintf(retstr, "%s (%s)", code, subsys );
150 * declarations to support the apollo builtin commands
151 * rootnode, inlib, and ver.
154 static char last_rootnode[MAXPATHLEN] = "/";
156 static char *preval = NULL, *sysval, *sysid = "SYSTYPE";
159 * code to support the apollo builtin functions rootnode,
163 int b_rootnode __PARAM__((int argn,char *argv[]), (argn, argv)) __OTORP__(int argn;char *argv[];){
165 { /* report current setting */
166 sfprintf(sfstdout,"%s\n",last_rootnode);
169 if (!is_valid_rootnode(argv[1]))
170 sh_cfail(e_rootnode);
171 if (rootnode(argv[1]) != 0)
173 perror("rootnode: "); /* ? */
174 sh_cfail(e_rootnode);
177 strcpy(last_rootnode, argv[1]);
181 sh_eval(sh_sfeval(argv),0);
182 if (rootnode(last_rootnode) != 0)
183 sh_cfail(e_rootnode);
188 int b_ver __PARAM__((int argn,char *argv[]), (argn, argv)) __OTORP__(int argn;char *argv[];){
191 std_$call unsigned char c_$decode_version(__VARARG__);
193 oldver = SYSTYPENOD->namval.cp;
194 if (argn == 1 || argn > 2)
198 preval = sysval = oldver;
202 if (!oldver || !sysval)
206 sfprintf(sfstdout,"%s\n",sysval);
211 if (!c_$decode_version (*argv[1], (short) strlen (argv[1]), i1, i2))
217 short namlen = strlen(sysid);
218 short arglen = strlen(argv[1]);
220 nv_unset(SYSTYPENOD);
221 nv_putval(SYSTYPENOD, argv[1],NV_RDONLY);
222 nv_onattr(SYSTYPENOD, NV_EXPORT | NV_NOFREE);
223 ev_$set_var (sysid, &namlen, argv[1], &arglen);
228 short namlen = strlen(sysid);
229 short arglen = strlen(argv[1]);
233 sh_eval(sh_sfeval(argv),0);
234 ev_$set_var(sysid, &namlen, sysval, &arglen);
235 if((fd=path_open(argv[0],path_get(argv[0]))) < 0)
237 arglen = (short)strlen(preval);
238 ev_$set_var (sysid, &namlen, preval, &arglen);
239 error(ERROR_system(1),e_open,argv[0]);
242 sh_eval(sfopen(argv[0],"s"),0);
243 arglen = (short)strlen(preval);
244 ev_$set_var (sysid, &namlen, preval, &arglen);
252 * rootnode.c - a chroot call which doesn't require you to be root...
257 01/24/88 brian Initial coding
262 # define NULL ((__V_ *) 0)
265 extern __MANGLE__ boolean
266 unix_fio_$status_to_errno __PROTO__((
272 is_valid_rootnode __PARAM__((const char *path), (path)) __OTORP__(const char *path;){
275 return (path[0] == '/' && path[1] == '/' && path[2] != '\0' &&
276 strchr(&path[2], '/') == NULL);
279 rootnode __PARAM__((char * path), (path)) __OTORP__(char * path;){
280 uid_$t dir_uid, rtn_uid;
281 name_$pname_t new_root_name, rest_path;
283 short rest_len, leaf_len, err;
286 strcpy(new_root_name, path);
288 name_$resolve_afayc(new_root_name, (short)strlen(new_root_name),
289 &dir_uid, &rtn_uid, rest_path, &rest_len, leaf, &leaf_len, &err, &status);
291 if (status.all != status_$ok) {
292 unix_fio_$status_to_errno(status, path, strlen(path));
296 name_$set_diru(rtn_uid, rest_path, (short) rest_len, name_$node_dir_type, &status);
298 if (status.all != status_$ok) {
299 unix_fio_$status_to_errno(status, path, strlen(path));
308 * Apollo system support library loads into the virtual address space
311 int b_inlib(argc,argv)
314 register char *a1 = argv[1];
317 std_$call void loader_$inlib(__VARARG__);
323 loader_$inlib(*a1, len, status);
325 error(3, e_badinlib);