Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/3d/3d.sh
1808 views
1
########################################################################
2
# #
3
# This software is part of the ast package #
4
# Copyright (c) 1989-2011 AT&T Intellectual Property #
5
# and is licensed under the #
6
# Eclipse Public License, Version 1.0 #
7
# by AT&T Intellectual Property #
8
# #
9
# A copy of the License is available at #
10
# http://www.eclipse.org/org/documents/epl-v10.html #
11
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12
# #
13
# Information and Software Systems Research #
14
# AT&T Research #
15
# Florham Park NJ #
16
# #
17
# Glenn Fowler <[email protected]> #
18
# David Korn <[email protected]> #
19
# Eduardo Krell <[email protected]> #
20
# #
21
########################################################################
22
# NOTE: retain this comment
23
dir=$_ # NOTE: this line must appear before any commands
24
25
command=3d
26
27
case $RANDOM in
28
$RANDOM)exec ksh 3d "$@" ;;
29
esac
30
31
case $(getopts '[-][123:xyz]' opt --xyz 2>/dev/null; echo 0$opt) in
32
0123) ARGV0="-a $command"
33
USAGE=$'
34
[-?
35
@(#)$Id: 3d (AT&T Labs Research) 2006-10-01 $
36
]
37
'$USAGE_LICENSE$'
38
[+NAME?3d - execute a command with nDFS filesystem services enabled]
39
[+DESCRIPTION?\b3d\b executes a dynamically linked \acommand\a
40
with \an\a\bDFS\b filesystem services enabled. It intercepts pathname
41
system calls and applies the \an\a\bDFS\b operations specified
42
by the \bVPATH\b environment variable, the command line mounts,
43
and the \bvpath\b command. If \acommand\a is omitted then an
44
interactive \bsh\b(1) is started. All processes executed by \acommand\a
45
also have \an\a\bDFS\b enabled.]
46
[+?The main \b3d\b service is \aviewpathing\a. A \aviewpath\a mounts one
47
directory tree on top of another. Files in the top level
48
(directory tree) obscure files in the lower level. Lower level files
49
have copy-on-write semantics to the top level. i.e., files in the lower
50
level are readonly; if a lower level file is modified it is first
51
copied to the top level before modification. Viewpath mounted
52
directories can be chained. All levels but the top in a chain are
53
readonly. The traditional \bVPATH=\b\ad1:d2:d3\a viewpathing is
54
specified by the two \b3d\b mounts "\ad1 d2\a" and "\ad2 d3\a".]
55
[+?The following service mounts are initialized by default:]{
56
[+/dev/fd?\b/dev/fd/\b\an\a refers to the open file descriptor \an\a
57
in the current process.]
58
[+/dev/fdp?\b/dev/fdp/local/\aservice\a opens a 2-way stream to
59
\aservice\a on the local host. The stream supports file
60
descriptor exchange.]
61
[+/dev/tcp?\b/dev/tcp/\b\ahost\a\b/\b\aservice\a opens a 2-way
62
connection to \aservice\a on \ahost\a. \binetd\b(8) services
63
are named either by \binet.\b\aservice\a or by port number.]
64
[+/dev/udp?\b/dev/udb/\b\ahost\a\b/\b\aservice\a opens a datagram
65
connection to \aservice\a on \ahost\a. \binetd\b(8) services
66
are named either by \binet.\b\aservice\a or by port number.]
67
}
68
[c:command?Ignored; allows \b3d\b to be invoked like \bsh\b(1).]
69
[d:debug?Set the debug trace level to \alevel\a. Higher levels produce more
70
output.]#[level]
71
[l:lite?Disable the default service mounts.]
72
[m:mount?Mount the path \atop\a onto the path \abottom\a. If \abottom\a is a
73
directory then the directory \atop\a is viewpathed on top of \abottom\a.
74
Otherwise \abottom\a must match a \b3d\b \bfs\b path of the form
75
\b/#\b\aspecial\a.]:["top bottom"]
76
[n!:exec?Execute \acommand\a. \b--noexec\b shows how \acommand\a would be
77
invoked but does not execute.]
78
[o:output?\b--trace\b and \b--debug\b output is written to \afile\a instead
79
of the standard error.]:[file]
80
[s:shell?Sets the \bsh\b(1) executable path to \afile\a.]:[file:=ksh]
81
[t:trace?If \aid\a is \b1\b then intercepted system calls for all child
82
processes will be traced. If \aid\a is greater than \b1\b then
83
intercepted system calls for the current process and all
84
children will be traced.]#[id]
85
[v:version?Use \b3d\b version \amajor.minor\a instead of the latest
86
version.]:[major.minor]
87
[x:?Passed to the \b3d\b \bsh\b(1).]
88
[+FS PATHS?\b3d\b \bfs\b paths of the form \b/#\b\aspecial\a[\b/\b...]]
89
control the semantics of \b3d\b and allow services to be attached to
90
the file namespace. Unsupported \bfs\b paths are silently ignored. The
91
supported \bfs\b paths are:]{
92
[+/#fd? ]
93
[+/#fs/\aname\a[/\aoption\a/...]]? ]
94
[+/#map? ]
95
[+/#null? ]
96
[+/#option? ]{
97
[+2d? ]
98
[+3d? ]
99
[+boundary? ]
100
[+call=\avalue\a? ]
101
[+count=\avalue\a? ]
102
[+debug=\alevel\a? ]
103
[+dump=\b[\avalue\a]]? ]{
104
[+call=\avalue\a? ]
105
[+file=\avalue\a? ]
106
[+fs=\avalue\a? ]
107
[+map=\avalue\a? ]
108
[+mount=\avalue\a? ]
109
[+safe=\avalue\a? ]
110
[+state=\avalue\a? ]
111
[+view=\avalue\a? ]
112
}
113
[+file=\avalue\a? ]
114
[+fork? ]
115
[+init? ]
116
[+license=\apath\a? ]
117
[+mount=\avalue\a? ]
118
[+table=\avalue\a? ]
119
[+test=\abitmask\a? ]
120
[+timeout=\avalue\a? ]
121
[+timestamp? ]
122
[+trace=\avalue\a? ]
123
[+version=1? ]
124
}
125
[+/#pwd? ]
126
[+/#safe? ]
127
[+/#view? ]
128
}
129
[+DETAILS?\an\a\bDFS\b semantics are applied by intercepting system calls with
130
a dll that is preloaded at process startup before \amain\a() is called.
131
The interception mechanism may involve the environment on some systems;
132
in those cases commands like \benv\b(1) that clear the enviroment
133
before execution may defeat the \b3d\b intercepts. The intercepted
134
system calls are listed by \bvpath - /#option/dump=call\b. Note that
135
implementation system call names may differ from those listed in
136
section 2 of the manual; \bstat\b(2) is especially vulnerbale to
137
mangling.]
138
[+?\b3d\b ignores calls not present in a particular host system. In addition,
139
\b3d\b only works on dynamically linked executables that have neither
140
set-uid nor set-gid permissions. It may not have the intended effect
141
on programs written in a language or linked with a language runtime
142
that hides or mangles system call library symbols, or that
143
directly emit system call instruction sequences rather than using
144
the corresponding library functions, or that dynamically link
145
libraries outside of the scope of the \b3d\b intercepts.]
146
[+?Multi-process client-server applications may misbehave if the \b3d\b
147
environment between the related processes is not kept in sync.]
148
149
[ command [ arg ... ] ]
150
151
[+ENVIRONMENT?\b3d\b is implemented by four components: the \b3d\b script,
152
located on \b$PATH\b; the \b3d\b dll (shared library), located either
153
on \b$PATH\b or in one of the \b../lib\b* directories on \b$PATH\b,
154
depending on local compilation system conventions; and the \b2d\b
155
\bsh\b(1) alias and \b_2d\b \bsh\b(1) function that allow commands
156
to be run with \an\a\bDFS\b semantics disabled. Systems like
157
\bsgi.mips3\b that support multiple a.out formats may have multiple
158
versions of the \b3d\b dll. In all cases the \b3d\b script handles
159
the dll search.]
160
[+EXAMPLES?]{
161
[+\b$ 3d]
162
[+\b$ VPATH=$INSTALLROOT::$PACKAGEROOT 3d]
163
[+\b$ 3d ls -l]
164
[+\b$ 2d ls -l]
165
}
166
[+SEE ALSO?\benv\b(1), \bie\b(1), \bsh\b(1), \btrace\b(1), \bwarp\b(1),
167
\bstat\b(2)]
168
'
169
;;
170
*) ARGV0=""
171
USAGE='clnxd:m:o:s:t:v:[ command [ arg ... ] ]'
172
;;
173
esac
174
175
test . -ef "$PWD" || PWD=`pwd`
176
case $dir in
177
*/3d) ;;
178
*) case $0 in
179
*/*) dir=$0
180
;;
181
*) dir=`whence 3d 2>/dev/null`
182
dir=`whence -p $dir 2>/dev/null`
183
;;
184
esac
185
esac
186
case $dir in
187
/*) dir=${dir%/*} ;;
188
*) dir=${dir#./}; dir=$PWD/${dir%/*} ;;
189
esac
190
abi=
191
dir=${dir%/*}
192
case $dir in
193
*/arch/sgi.mips[0123456789]*)
194
if test -d /lib32 -o -d /lib64
195
then d=${dir%-*}
196
d=${d%?}
197
for a in 2: 3:N32 4:64
198
do t=${a#*:}
199
a=${a%:*}
200
if test -d $d$a
201
then abi="$abi $d$a:$t"
202
fi
203
done
204
fi
205
;;
206
esac
207
cflag=
208
full="/dev/fdp/local/nam/user /#fs/nam/name/unique /dev/fdp /#nam /dev/tcp /#nam /dev/udp /#nam /dev/fd /#fd"
209
mount="- -"
210
options=
211
output=
212
show=
213
shell=$SHELL
214
trace=
215
SHELL=
216
version=
217
case $VPATH in
218
*:*) ifs=${IFS-'
219
'}
220
IFS=:
221
o=
222
for a in $VPATH
223
do case $a in
224
""|-) ;;
225
*) case $o in
226
""|-) ;;
227
*) mount="$mount $o $a" ;;
228
esac
229
;;
230
esac
231
o=$a
232
done
233
IFS=$ifs
234
;;
235
esac
236
237
: grab the options
238
239
while getopts $ARGV0 "$USAGE" OPT
240
do case $OPT in
241
c) cflag=1; break ;;
242
d) trace="$trace/debug=$OPTARG" ;;
243
l) full= ;;
244
m) mount="$mount $OPTARG" ;;
245
n) show="print -u2 --" ;;
246
o) output=$OPTARG ;;
247
s) SHELL=$OPTARG ;;
248
t) trace="$trace/trace=$OPTARG" ;;
249
v) case $OPTARG in
250
/*) version=$OPTARG ;;
251
*) version=.$OPTARG ;;
252
esac
253
;;
254
x) options="$options -$OPT" ;;
255
*) exit 2 ;;
256
esac
257
done
258
set x "$@"
259
shift $OPTIND
260
case $cflag in
261
1) set -- -c "$@" ;;
262
esac
263
264
case $full in
265
?*) mount="$full $mount" ;;
266
esac
267
mount="- /#option/3d$trace $mount"
268
case $output in
269
?*) mount="$output /#fs/option $mount" ;;
270
esac
271
default=$version
272
case $version in
273
/*) ;;
274
*) if getconf LIBPREFIX >/dev/null 2>&1
275
then d=$(getconf LIBPATH)
276
d=${d##*,}
277
d=${d%%:*}
278
p=$(getconf LIBPREFIX)
279
s=$(getconf LIBSUFFIX)
280
else d=lib
281
p=lib
282
s='.s[lo]'
283
fi
284
for x in $dir/$d/${p}3d${s}$version $dir/$d/${p}3d${version//./}${s}
285
do case $x in
286
*/${p}3d${s}*[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]*|*/${p}3d$*[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]*${s})
287
;;
288
*) version=$x
289
break
290
;;
291
esac
292
done
293
;;
294
esac
295
exp=
296
if test -f "$version"
297
then if test -d $dir/3d
298
then dir=$dir/3d
299
fi
300
case :$FPATH: in
301
*:$dir/fun:*) ;;
302
*) export FPATH=$dir/fun${FPATH:+:$FPATH} ;;
303
esac
304
case :$PATH: in
305
*:$dir/bin:*) ;;
306
*) export PATH=$dir/bin:$PATH ;;
307
esac
308
exp="$exp LD_PRELOAD=$version"
309
case $abi:-:$version in
310
?*:-:$dir/*)
311
v=${version#$dir/}
312
for a in $abi
313
do d=${a%:*}
314
a=${a#*:}
315
exp="$exp _RLD${a}_LIST=$d/$v:DEFAULT"
316
done
317
;;
318
*) v=${version%.*}
319
s=${version##*.}
320
if test -f ${v}-n32.$s
321
then exp="$exp _RLD64_LIST=$version:DEFAULT _RLDN32_LIST=$version-n32.$s:DEFAULT _RLD_LIST=${v}-o32.$s:DEFAULT"
322
elif test -f ${v}-64.$s -o -f ${v}-o32.$s
323
then exp="$exp _RLD64_LIST=$version-64.$s:DEFAULT _RLDN32_LIST=$version:DEFAULT _RLD_LIST=${v}-o32.$s:DEFAULT"
324
else exp="$exp _RLD_LIST=$version:DEFAULT"
325
fi
326
if test -f ${dir}/lib/libdir64.$s
327
then exp="$exp:${dir}/lib/libdir64.$s"
328
fi
329
;;
330
esac
331
export $exp
332
case $mount in
333
??*) export __=${mount#' '} ;;
334
*) unset __ ;;
335
esac
336
unset VPATH
337
else print -u2 "$command: $version: no shared library"
338
case $default in
339
"*") ;;
340
*) exit 1 ;;
341
esac
342
version=
343
options=
344
fi
345
case $SHELL in
346
"") t=`whence ksh 2>/dev/null`
347
SHELL=`PATH=$dir/bin:$PATH whence -p $t 2>/dev/null`
348
;;
349
esac
350
SHELL=${SHELL:-$shell}
351
SHELL=${SHELL:-/bin/sh}
352
export SHELL
353
case `vpath /#option/3d 2>/dev/null` in
354
*/2d) $show vpath $mount ;;
355
esac
356
case $1:$#:$options in
357
-*) ;;
358
*:0:*|*:*:?*)
359
shell="$SHELL $options"
360
;;
361
*) t=`whence $1 2>/dev/null`
362
t=`whence -p $t 2>/dev/null`
363
case $t in
364
""|"''"|'""') shell="$SHELL $options" ;;
365
*) shell= ;;
366
esac
367
;;
368
esac
369
case $show in
370
"") exec $shell "$@" ;;
371
*) case $version in
372
"") $show __="'$__'" exec $shell "$@" ;;
373
*) $show __="'$__'" $exp exec $shell "$@" ;;
374
esac
375
;;
376
esac
377
378