/
tc.os.c
1599 lines (1423 loc) · 36.7 KB
/
tc.os.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* tc.os.c: OS Dependent builtin functions
*/
/*-
* Copyright (c) 1980, 1991 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "sh.h"
#include "tw.h"
#include "ed.h"
#include "ed.defns.h" /* for the function names */
#include "sh.decls.h"
#ifdef _UWIN
#define TIOCGPGRP TIOCGETPGRP
#define TIOCSPGRP TIOCSETPGRP
#endif
/***
*** MACH
***/
#ifdef MACH
/* dosetpath -- setpath built-in command
*
**********************************************************************
* HISTORY
* 08-May-88 Richard Draves (rpd) at Carnegie-Mellon University
* Major changes to remove artificial limits on sizes and numbers
* of paths.
*
**********************************************************************
*/
#ifdef MACH
static Char STRCPATH[] = {'C', 'P', 'A', 'T', 'H', '\0'};
static Char STRLPATH[] = {'L', 'P', 'A', 'T', 'H', '\0'};
static Char STRMPATH[] = {'M', 'P', 'A', 'T', 'H', '\0'};
# if EPATH
static Char STREPATH[] = {'E', 'P', 'A', 'T', 'H', '\0'};
# endif
#endif /* MACH */
static Char *syspaths[] = {STRKPATH, STRCPATH, STRLPATH, STRMPATH,
#if EPATH
STREPATH,
#endif
0};
#define LOCALSYSPATH "/usr/local"
/*ARGSUSED*/
void
dosetpath(Char **arglist, struct command *c)
{
extern char *getenv();
Char **pathvars, **cmdargs;
char **spaths, **cpaths, **cmds;
char *tcp;
unsigned int npaths, ncmds;
int i, sysflag;
pintr_disabled++;
cleanup_push(&pintr_disabled, disabled_cleanup);
/*
* setpath(3) uses stdio and we want 0, 1, 2 to work...
*/
if (!didfds) {
(void) dcopy(SHIN, 0);
(void) dcopy(SHOUT, 1);
(void) dcopy(SHDIAG, 2);
didfds = 1;
}
for (i = 1; arglist[i] && (arglist[i][0] != '-'); i++);
npaths = i - 1;
cmdargs = &arglist[i];
for (; arglist[i]; i++);
ncmds = i - npaths - 1;
if (npaths) {
sysflag = 0;
pathvars = &arglist[1];
}
else {
sysflag = 1;
npaths = (sizeof syspaths / sizeof *syspaths) - 1;
pathvars = syspaths;
}
/* note that npaths != 0 */
spaths = xmalloc(npaths * sizeof *spaths);
setzero(spaths, npaths * sizeof *spaths);
cpaths = xmalloc((npaths + 1) * sizeof *cpaths);
setzero(cpaths, (npaths + 1) * sizeof *cpaths);
cmds = xmalloc((ncmds + 1) * sizeof *cmds);
setzero(cmds, (ncmds + 1) * sizeof *cmds);
for (i = 0; i < npaths; i++) {
char *val = getenv(short2str(pathvars[i]));
if (val == NULL)
val = "";
spaths[i] = xmalloc((Strlen(pathvars[i]) + strlen(val) + 2) *
sizeof **spaths);
(void) strcpy(spaths[i], short2str(pathvars[i]));
(void) strcat(spaths[i], "=");
(void) strcat(spaths[i], val);
cpaths[i] = spaths[i];
}
for (i = 0; i < ncmds; i++) {
Char *val = globone(cmdargs[i], G_ERROR);/*FIXRESET*/
if (val == NULL)
goto abortpath;
cmds[i] = strsave(short2str(val));
}
if (setpath(cpaths, cmds, LOCALSYSPATH, sysflag, 1) < 0) {
abortpath:
if (spaths) {
for (i = 0; i < npaths; i++)
xfree(spaths[i]);
xfree(spaths);
}
xfree(cpaths);
if (cmds) {
for (i = 0; i < ncmds; i++)
xfree(cmds[i]);
xfree(cmds);
}
cleanup_until(&pintr_disabled);
donefds();
return;
}
for (i = 0; i < npaths; i++) {
Char *val, *name;
name = str2short(cpaths[i]);
for (val = str2short(cpaths[i]); val && *val && *val != '='; val++);
if (val && *val == '=') {
*val++ = '\0';
tsetenv(name, val);/*FIXRESET*/
if (Strcmp(name, STRKPATH) == 0) {
importpath(val);/*FIXRESET*/
if (havhash)
dohash(NULL, NULL);/*FIXRESET*/
}
*--val = '=';
}
}
cleanup_until(&pintr_disabled);
donefds();
}
#endif /* MACH */
/***
*** AIX
***/
#ifdef TCF
/* ARGSUSED */
void
dogetxvers(Char **v, struct command *c)
{
char xvers[MAXPATHLEN];
if (getxvers(xvers, MAXPATHLEN) == -1)
stderror(ERR_SYSTEM, "getxvers", strerror(errno));
xprintf("%s\n", xvers);
flush();
}
/*ARGSUSED*/
void
dosetxvers(Char **v, struct command *c)
{
char *xvers;
++v;
if (!*v || *v[0] == '\0')
xvers = "";
else
xvers = short2str(*v);
if (setxvers(xvers) == -1)
stderror(ERR_SYSTEM, "setxvers", strerror(errno));
}
#include <sf.h>
#ifdef _AIXPS2
# define XC_PDP11 0x01
# define XC_23 0x02
# define XC_Z8K 0x03
# define XC_8086 0x04
# define XC_68K 0x05
# define XC_Z80 0x06
# define XC_VAX 0x07
# define XC_16032 0x08
# define XC_286 0x09
# define XC_386 0x0a
# define XC_S370 0x0b
#else
# include <sys/x.out.h>
#endif /* _AIXPS2 */
static struct xc_cpu_t {
short xc_id;
char *xc_name;
} xcpu[] =
{
{ XC_PDP11, "pdp11" },
{ XC_23, "i370" },
{ XC_Z8K, "z8000" },
{ XC_8086, "i86" },
{ XC_68K, "mc68000" },
{ XC_Z80, "x80" },
{ XC_VAX, "vax" },
{ XC_16032, "ns16032" },
{ XC_286, "i286" },
{ XC_386, "i386" },
{ XC_S370, "xa370" },
{ 0, NULL }
};
/*
* our local hack table, stolen from x.out.h
*/
static char *
getxcode(short xcid)
{
int i;
for (i = 0; xcpu[i].xc_name != NULL; i++)
if (xcpu[i].xc_id == xcid)
return (xcpu[i].xc_name);
return (NULL);
}
static short
getxid(char *xcname)
{
int i;
for (i = 0; xcpu[i].xc_name != NULL; i++)
if (strcmp(xcpu[i].xc_name, xcname) == 0)
return (xcpu[i].xc_id);
return ((short) -1);
}
/*ARGSUSED*/
void
dogetspath(Char **v, struct command *c)
{
int i, j;
sitepath_t p[MAXSITE];
struct sf *st;
static char *local = "LOCAL ";
if ((j = getspath(p, MAXSITE)) == -1)
stderror(ERR_SYSTEM, "getspath", strerror(errno));
for (i = 0; i < j && (p[i] & SPATH_CPU) != NOSITE; i++) {
if (p[i] & SPATH_CPU) {
if ((p[i] & SPATH_MASK) == NULLSITE)
xprintf(local);
else if ((st = sfxcode((short) (p[i] & SPATH_MASK))) != NULL)
xprintf("%s ", st->sf_ctype);
else {
char *xc = getxcode(p[i] & SPATH_MASK);
if (xc != NULL)
xprintf("%s ", xc);
else
xprintf("*cpu %d* ", (int) (p[i] & SPATH_MASK));
/*
* BUG in the aix code... needs that cause if
* sfxcode fails once it fails for ever
*/
endsf();
}
}
else {
if (p[i] == NULLSITE)
xprintf(local);
else if ((st = sfnum(p[i])) != NULL)
xprintf("%s ", st->sf_sname);
else
xprintf("*site %d* ", (int) (p[i] & SPATH_MASK));
}
}
xputchar('\n');
flush();
}
/*ARGSUSED*/
void
dosetspath(Char **v, struct command *c)
{
int i;
short j;
char *s;
sitepath_t p[MAXSITE];
struct sf *st;
/*
* sfname() on AIX G9.9 at least, mallocs too pointers p, q
* then does the equivalent of while (*p++ == *q++) continue;
* and then tries to free(p,q) them! Congrats to the wizard who
* wrote that one. I bet he tested it really well too.
* Sooo, we set dont_free :-)
*/
dont_free = 1;
for (i = 0, v++; *v && *v[0] != '\0'; v++, i++) {
s = short2str(*v);
if (isdigit(*s))
p[i] = atoi(s);
else if (strcmp(s, "LOCAL") == 0)
p[i] = NULLSITE;
else if ((st = sfctype(s)) != NULL)
p[i] = SPATH_CPU | st->sf_ccode;
else if ((j = getxid(s)) != -1)
p[i] = SPATH_CPU | j;
else if ((st = sfname(s)) != NULL)
p[i] = st->sf_id;
else {
setname(s);
stderror(ERR_NAME | ERR_STRING, CGETS(23, 1, "Bad cpu/site name"));
}
if (i == MAXSITE - 1)
stderror(ERR_NAME | ERR_STRING, CGETS(23, 2, "Site path too long"));
}
if (setspath(p, i) == -1)
stderror(ERR_SYSTEM, "setspath", strerror(errno));
dont_free = 0;
}
/* sitename():
* Return the site name where the process is running
*/
char *
sitename(pid_t pid)
{
siteno_t ss;
struct sf *st;
if ((ss = site(pid)) == -1 || (st = sfnum(ss)) == NULL)
return CGETS(23, 3, "unknown");
else
return st->sf_sname;
}
static int
migratepid(pit_t pid, siteno_t new_site)
{
struct sf *st;
int need_local;
need_local = (pid == 0) || (pid == getpid());
if (kill3(pid, SIGMIGRATE, new_site) < 0) {
xprintf("%d: %s\n", pid, strerror(errno));
return (-1);
}
if (need_local) {
if ((new_site = site(0)) == -1) {
xprintf(CGETS(23, 4, "site: %s\n"), strerror(errno));
return (-1);
}
if ((st = sfnum(new_site)) == NULL) {
xprintf(CGETS(23, 5, "%d: Site not found\n"), new_site);
return (-1);
}
if (setlocal(st->sf_local, strlen(st->sf_local)) == -1) {
xprintf(CGETS(23, 6, "setlocal: %s: %s\n"),
st->sf_local, strerror(errno));
return (-1);
}
}
return (0);
}
/*ARGSUSED*/
void
domigrate(Char **v, struct command *c)
{
struct sf *st;
char *s;
Char *cp;
struct process *pp;
int err1 = 0;
int pid = 0;
siteno_t new_site = 0;
pchild_disabled++;
cleanup_push(&pchild_disabled, disabled_cleanup);
if (setintr) {
pintr_disabled++;
cleanup_push(&pintr_disabled, disabled_cleanup);
}
++v;
if (*v[0] == '-') {
/*
* Do the -site.
*/
s = short2str(&v[0][1]);
/*
* see comment in setspath()
*/
dont_free = 1;
if ((st = sfname(s)) == NULL) {
dont_free = 0;
setname(s);
stderror(ERR_NAME | ERR_STRING, CGETS(23, 7, "Site not found"));
}
dont_free = 0;
new_site = st->sf_id;
++v;
}
if (!*v || *v[0] == '\0') {
if (migratepid(0, new_site) == -1)
err1++;
}
else {
Char **globbed;
v = glob_all_or_error(v);
globbed = v;
cleanup_push(globbed, blk_cleanup);
while (v && (cp = *v)) {
if (*cp == '%') {
pp = pfind(cp);
if (kill3(- pp->p_jobid, SIGMIGRATE, new_site) < 0) {
xprintf("%S: %s\n", cp, strerror(errno));
err1++;
}
}
else if (!(Isdigit(*cp) || *cp == '-'))
stderror(ERR_NAME | ERR_JOBARGS);
else {
pid = atoi(short2str(cp));
if (migratepid(pid, new_site) == -1)
err1++;
}
v++;
}
cleanup_until(globbed);
}
done:
cleanup_until(&pchild_disabled);
if (err1)
stderror(ERR_SILENT);
}
#endif /* TCF */
/***
*** CRAY ddmode <velo@sesun3.epfl.ch> (Martin Ouwehand EPFL-SIC/SE)
***/
#if defined(_CRAY) && !defined(_CRAYMPP)
void
dodmmode(Char **v, struct command *c)
{
Char *cp = v[1];
USE(c);
if ( !cp ) {
int mode;
mode = dmmode(0);
dmmode(mode);
xprintf("%d\n",mode);
}
else {
if (cp[1] != '\0')
stderror(ERR_NAME | ERR_STRING,
CGETS(23, 30, "Too many arguments"));
else
switch(*cp) {
case '0':
dmmode(0);
break;
case '1':
dmmode(1);
break;
default:
stderror(ERR_NAME | ERR_STRING,
CGETS(23, 31, "Invalid argument"));
}
}
}
#endif /* _CRAY && !_CRAYMPP */
/***
*** CONVEX Warps.
***/
#ifdef WARP
/*
* handle the funky warping of symlinks
*/
#include <warpdb.h>
#include <sys/warp.h>
static jmp_buf sigsys_buf;
static void
catch_sigsys(void)
{
sigset_t set;
sigemptyset(&set, SIGSYS);
(void)sigprocmask(SIG_UNBLOCK, &set, NULL);
longjmp(sigsys_buf, 1);
}
/*ARGSUSED*/
void
dowarp(Char **v, struct command *c)
{
int warp, oldwarp;
struct warpent *we;
volatile struct sigaction old_sigsys_handler;
char *newwarp;
if (setjmp(sigsys_buf)) {
sigaction(SIGSYS, &old_sigsys_handler, NULL);
stderror(ERR_NAME | ERR_STRING,
CGETS(23, 8, "You're trapped in a universe you never made"));
return;
}
sigaction(SIGSYS, NULL, &old_sigsys_handler);
signal(SIGSYS, catch_sigsys);
warp = getwarp();
v++;
if (*v == 0) { /* display warp value */
if (warp < 0)
stderror(ERR_NAME | ERR_STRING, CGETS(23, 9, "Getwarp failed"));
we = getwarpbyvalue(warp);
if (we)
printf("%s\n", we->w_name);
else
printf("%d\n", warp);
}
else { /* set warp value */
oldwarp = warp;
newwarp = short2str(*v);
if (Isdigit(*v[0]))
warp = atoi(newwarp);
else {
we = getwarpbyname(newwarp);
if (we)
warp = we->w_value;
else
warp = -1;
}
if ((warp < 0) || (warp >= WARP_MAXLINK))
stderror(ERR_NAME | ERR_STRING, CGETS(23, 10, "Invalid warp"));
if ((setwarp(warp) < 0) || (getwarp() != warp)) {
(void) setwarp(oldwarp);
stderror(ERR_NAME | ERR_STRING, CGETS(23, 11, "Setwarp failed"));
}
}
sigaction(SIGSYS, &old_sigsys_handler, NULL);
}
#endif /* WARP */
/***
*** Masscomp or HCX
***/
/* Added, DAS DEC-90. */
#if defined(masscomp) || defined(_CX_UX)
static void
setuniverse_cleanup(void *xbuf)
{
char *buf;
buf = xbuf;
setuniverse(buf);
}
/*ARGSUSED*/
void
douniverse(Char **v, struct command *c)
{
Char *cp = v[1];
Char *cp2; /* dunno how many elements v comes in with */
char ubuf[100];
if (cp == 0) {
(void) getuniverse(ubuf);
xprintf("%s\n", ubuf);
}
else {
cp2 = v[2];
if (cp2 == 0) {
if (*cp == '\0' || setuniverse(short2str(cp)) != 0)
stderror(ERR_NAME | ERR_STRING, CGETS(23, 12, "Illegal universe"));
}
else {
(void) getuniverse(ubuf);
if (*cp == '\0' || setuniverse(short2str(cp)) != 0)
stderror(ERR_NAME | ERR_STRING, CGETS(23, 12, "Illegal universe"));
cleanup_push(ubuf, setuniverse_cleanup);
if (setintr) {
pintr_disabled++;
cleanup_push(&pintr_disabled, disabled_cleanup);
}
lshift(v, 2);
if (setintr)
cleanup_until(&pintr_disabled);
reexecute(c);
cleanup_until(ubuf);
}
}
}
#endif /* masscomp || _CX_UX */
/***
*** BS2000/OSD POSIX (Fujitsu Siemens Computers)
***/
#if defined(_OSD_POSIX)
static int
bs2upcase(char *str)
{
enum { outside = ' ', singlequote='\'', doublequote='"'} string = outside;
char *white;
for (white = str + strlen(str) - 1; isspace(*white) && white > str; --white)
*white = '\0';
for (; *str != '\0'; ++str)
{
if (string == outside)
{
*str = toupper (*str);
}
if (*str == '\'')
{
if (string == outside)
string = singlequote;
else if (string != doublequote)
string = outside;
}
else if (*str == '"')
{
if (string == outside)
string = doublequote;
else if (string != singlequote)
string = outside;
}
}
if (string != outside)
{
stderror(ERR_NAME | ERR_UNMATCHED, (Char) string);
return 1;
}
return 0;
}
static int
bs2cmdlist(char *str)
{
char *str_beg = NULL;
int ret = 0;
enum { outside = ' ', singlequote='\'', doublequote='"'} string = outside;
while (*str != '\0')
{
while (isspace(*str))
++str;
if (*str == '\0')
break;
str_beg = str;
for (; *str != '\0'; ++str)
{
if (string == outside && *str == ';') /* End of command */
{
*str++ = '\0';
break; /* continue with next command */
}
if (*str == '\'')
{
if (string == outside)
string = singlequote;
else if (string != doublequote)
string = outside;
}
else if (*str == '"')
{
if (string == outside)
string = doublequote;
else if (string != singlequote)
string = outside;
}
}
if (strlen(str_beg) != 0)
{
ret = bs2system(str_beg);
flush();
if (ret != 0 /*&& !option.err_ignore*/)
break; /* do not continue after errors */
}
}
if (string != outside)
{
stderror(ERR_NAME | ERR_UNMATCHED, (Char) string);
return -1;
}
return ret;
}
/*ARGSUSED*/
void
dobs2cmd(Char **v, struct command *c)
{
Char *cp, **globbed;
int i = 0, len = 0;
char *cmd = NULL;
int pvec[2];
struct command faket;
Char *fakecom[2];
char tibuf[BUFSIZE];
int icnt, old_pintr_disabled;
static const Char STRbs2cmd[] = { 'b','s','2','c','m','d','\0' };
v++;
if (setintr)
pintr_push_enable(&old_pintr_disabled);
v = glob_all_or_error(v);
if (setintr)
cleanup_until(&old_pintr_disabled);
globbed = v;
cleanup_push(globbed, blk_cleanup);
/* First round: count the string lengths */
for (i=0; v[i]; ++i) {
len += Strlen(v[i]) + (v[i+1] != NULL);
}
cmd = xmalloc(len+1); /* 1 for the final '\0' *//* FIXME: memory leak? */
/* 2nd round: fill cmd buffer */
i = 0;
while ((cp = *v++) != 0) {
int c;
while (c = *cp++)
cmd[i++] = (char)c;
if (*v)
cmd[i++] = ' ';
}
cmd[i] = '\0';
/* Make upper case */
bs2upcase(cmd);
faket.t_dtyp = NODE_COMMAND;
faket.t_dflg = F_BACKQ|F_STDERR;
faket.t_dlef = 0;
faket.t_drit = 0;
faket.t_dspr = 0;
faket.t_dcom = fakecom;
fakecom[0] = (Char *)STRbs2cmd;
fakecom[1] = 0;
mypipe(pvec);
cleanup_push(&pvec[0], open_cleanup);
cleanup_push(&pvec[1], open_cleanup);
if (pfork(&faket, -1) == 0) {
sigset_t set;
/* child */
xclose(pvec[0]);
(void) dmove(pvec[1], 1);
(void) dmove(SHDIAG, 2);
initdesc();
sigemptyset(&set);
sigaddset(&set, SIGINT);
(void)sigprocmask(SIG_UNBLOCK, &set, NULL);
#ifdef SIGTSTP
signal(SIGTSTP, SIG_IGN);
#endif
#ifdef SIGTTIN
signal(SIGTTIN, SIG_IGN);
#endif
#ifdef SIGTTOU
signal(SIGTTOU, SIG_IGN);
#endif
xexit(bs2cmdlist(cmd));
}
cleanup_until(&pvec[1]);
for (;;) {
int old_pintr_disabled;
if (setintr)
pintr_push_enable(&old_pintr_disabled);
icnt = xread(pvec[0], tibuf, sizeof(tibuf));
if (setintr)
cleanup_until(&old_pintr_disabled);
if (icnt <= 0)
break;
for (i = 0; i < icnt; i++)
xputchar((unsigned char) tibuf[i]);
}
cleanup_until(&pvec[0]);
pwait();
flush();
cleanup_until(globbed);
}
#endif /* _OSD_POSIX */
#if defined(_CX_UX)
static void
setuniverse_cleanup(void *xbuf)
{
char *buf;
buf = xbuf;
setuniverse(buf);
}
/*ARGSUSED*/
void
doatt(Char **v, struct command *c)
{
Char *cp = v[1];
char ubuf[100];
if (cp == 0)
(void) setuniverse("att");
else {
(void) getuniverse(ubuf);
(void) setuniverse("att");
cleanup_push(ubuf, setuniverse_cleanup);
if (setintr) {
pintr_disabled++;
cleanup_push(&pintr_disabled, disabled_cleanup);
}
lshift(v, 1);
if (setintr)
cleanup_until(&pintr_disabled);
reexecute(c);
cleanup_until(ubuf);
}
}
/*ARGSUSED*/
void
doucb(Char **v, struct command *c)
{
Char *cp = v[1];
char ubuf[100];
if (cp == 0)
(void) setuniverse("ucb");
else {
(void) getuniverse(ubuf);
(void) setuniverse("ucb");
cleanup_push(ubuf, setuniverse_cleanup);
if (setintr) {
pintr_disabled++;
cleanup_push(&pintr_disabled, disabled_cleanup);
}
lshift(v, 1);
if (setintr)
cleanup_until(&pintr_disabled);
reexecute(c);
cleanup_until(ubuf);
}
}
#endif /* _CX_UX */
#ifdef _SEQUENT_
/*
* Compute the difference in process stats.
*/
void
pr_stat_sub(struct process_stats *p2, struct process_stats *p1,
struct process_stats *pr)
{
pr->ps_utime.tv_sec = p2->ps_utime.tv_sec - p1->ps_utime.tv_sec;
pr->ps_utime.tv_usec = p2->ps_utime.tv_usec - p1->ps_utime.tv_usec;
if (pr->ps_utime.tv_usec < 0) {
pr->ps_utime.tv_sec -= 1;
pr->ps_utime.tv_usec += 1000000;
}
pr->ps_stime.tv_sec = p2->ps_stime.tv_sec - p1->ps_stime.tv_sec;
pr->ps_stime.tv_usec = p2->ps_stime.tv_usec - p1->ps_stime.tv_usec;
if (pr->ps_stime.tv_usec < 0) {
pr->ps_stime.tv_sec -= 1;
pr->ps_stime.tv_usec += 1000000;
}
pr->ps_maxrss = p2->ps_maxrss - p1->ps_maxrss;
pr->ps_pagein = p2->ps_pagein - p1->ps_pagein;
pr->ps_reclaim = p2->ps_reclaim - p1->ps_reclaim;
pr->ps_zerofill = p2->ps_zerofill - p1->ps_zerofill;
pr->ps_pffincr = p2->ps_pffincr - p1->ps_pffincr;
pr->ps_pffdecr = p2->ps_pffdecr - p1->ps_pffdecr;
pr->ps_swap = p2->ps_swap - p1->ps_swap;
pr->ps_syscall = p2->ps_syscall - p1->ps_syscall;
pr->ps_volcsw = p2->ps_volcsw - p1->ps_volcsw;
pr->ps_involcsw = p2->ps_involcsw - p1->ps_involcsw;
pr->ps_signal = p2->ps_signal - p1->ps_signal;
pr->ps_lread = p2->ps_lread - p1->ps_lread;
pr->ps_lwrite = p2->ps_lwrite - p1->ps_lwrite;
pr->ps_bread = p2->ps_bread - p1->ps_bread;
pr->ps_bwrite = p2->ps_bwrite - p1->ps_bwrite;
pr->ps_phread = p2->ps_phread - p1->ps_phread;
pr->ps_phwrite = p2->ps_phwrite - p1->ps_phwrite;
}
#endif /* _SEQUENT_ */
#ifndef HAVE_MEMSET
/* This is a replacement for a missing memset function */
void *xmemset(void *loc, int value, size_t len)
{
char *ptr = loc;
while (len--)
*ptr++ = value;
return loc;
}
#endif /* !HAVE_MEMSET */
#ifndef HAVE_MEMMOVE
/* memmove():
* This is the ANSI form of bcopy() with the arguments backwards...
* Unlike memcpy(), it handles overlaps between source and
* destination memory
*/
void *
xmemmove(void *vdst, const void *vsrc, size_t len)
{
const char *src = vsrc;
char *dst = vdst;
if (src == dst)
return vdst;
if (src > dst) {
while (len--)
*dst++ = *src++;
}
else {
src += len;
dst += len;
while (len--)
*--dst = *--src;
}
return vdst;
}
#endif /* HAVE_MEMMOVE */