~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to pvm3/src/pvmcruft.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
static char rcsid[] =
3
 
        "$Id: pvmcruft.c,v 1.17 1997/12/01 19:20:48 pvmsrc Exp $";
 
3
        "$Id: pvmcruft.c,v 1.2 2002/10/14 14:37:51 chanceli Exp $";
4
4
 
5
5
/*
6
6
 *         PVM version 3.4:  Parallel Virtual Machine System
35
35
 *
36
36
 *      Missing links and other wonk.
37
37
 *
38
 
$Log: pvmcruft.c,v $
 
38
 * $Log: pvmcruft.c,v $
 
39
 * Revision 1.2  2002/10/14 14:37:51  chanceli
 
40
 * update
 
41
 *
 
42
 * Revision 1.38  2001/09/27 21:25:10  pvmsrc
 
43
 * BEOSCYLD port.
 
44
 *      - submitted by Joe Vitale <vitale@scyld.com>.
 
45
 *      (we renamed it from BEOWULF to BEOSCYLD, but it's his port... :-)
 
46
 * (Spanker=kohl)
 
47
 *
 
48
 * Revision 1.37  2001/09/26 22:04:20  pvmsrc
 
49
 * Modified temp file prefix in pvmtmpnam().
 
50
 *      - tmp* -> pvmtmp*.
 
51
 * (Spanker=kohl)
 
52
 *
 
53
 * Revision 1.36  2001/09/26 21:22:59  pvmsrc
 
54
 * Append VMID string to PVMD socket file name in pvmdsockfile().
 
55
 *      - if set in PVM_VMID env var.
 
56
 *      - not restricted to be integer as in SGI, can be arbitrary
 
57
 *              string...  heh, heh...  :-}
 
58
 * (Spanker=kohl)
 
59
 *
 
60
 * Revision 1.35  2001/09/25 21:21:02  pvmsrc
 
61
 * Yanked "char *pvmgettmp();" decl - now in pvm3.h...
 
62
 * (Spanker=kohl)
 
63
 *
 
64
 * Revision 1.34  2001/02/09 15:23:47  pvmsrc
 
65
 * Minor tweak to pvmgettmp() for Markus.
 
66
 *      - check %PVM_TMP% & registry before resorting to %TEMP%.
 
67
 * (Spanker=kohl)
 
68
 *
 
69
 * Revision 1.33  2001/02/07 23:15:51  pvmsrc
 
70
 * 2nd Half of CYGWIN Check-ins...
 
71
 * (Spanker=kohl)
 
72
 *
 
73
 * Revision 1.32  2001/02/02 14:50:26  pvmsrc
 
74
 * Win32 fixes & additions.
 
75
 * (Spanker=kohl)
 
76
 *
 
77
 * Revision 1.31  2000/03/29 20:04:12  pvmsrc
 
78
 * Added prototype for pvm_readregistry() routine.
 
79
 * (Spanker=sscott)
 
80
 *
 
81
 * Revision 1.30  2000/02/17 23:12:15  pvmsrc
 
82
 * *** Changes for new BEOLIN port ***
 
83
 *      - MPP-like, similar to SP2, etc.
 
84
 *      - submitted by Paul Springer <pls@smokeymt.jpl.nasa.gov>.
 
85
 *      - format-checked & cleaned up by Jeembo...  :-)
 
86
 * (Spanker=kohl)
 
87
 *
 
88
 * Revision 1.29  2000/02/16 23:30:24  pvmsrc
 
89
 * Added back in read_pvmregistry() calls.
 
90
 *      - for PVM_ROOT and PVM_TMP, if env vars not present on WIN32.
 
91
 *      - couldn't find reference to PVM_ARCH anywhere, Markus?!
 
92
 * (Spanker=kohl)
 
93
 *
 
94
 * Revision 1.28  2000/02/14 20:32:11  pvmsrc
 
95
 * Added new pvmgetrsh() routine
 
96
 *      - checks for PVM_RSH or else uses old RSHCOMMAND interface.
 
97
 *      - one-stop shopping for rsh...
 
98
 * (Spanker=kohl)
 
99
 *
 
100
 * Revision 1.27  2000/02/10 20:45:15  pvmsrc
 
101
 * Replaced hard-coded /tmp usage.
 
102
 *      - modified pvmgettmp() to try $PVM_TMP env var for Unix, too.
 
103
 *      - use for TDSOCKNAME / TDSOCKNAME_CSPP in pvmdsockfile().
 
104
 * Also in pvmdsockfile():
 
105
 *      - fixed WIN32 chdir() problem, cleaned up string manip.
 
106
 * (Spanker=kohl)
 
107
 *
 
108
 * Revision 1.26  1999/12/13 18:13:55  pvmsrc
 
109
 * Moved pvmmatchstring() here from msgbox.c.
 
110
 *      - for use by pvmtester stuff...
 
111
 * (Spanker=kohl)
 
112
 *
 
113
 * Revision 1.25  1999/07/08 19:00:06  kohl
 
114
 * Fixed "Log" keyword placement.
 
115
 *      - indent with " * " for new CVS.
 
116
 *
 
117
 * Revision 1.24  1999/03/16  16:29:56  pvmsrc
 
118
 * Oops...  Fixed typing problem for WIN32 in pvmsleep()...
 
119
 * (Spanker=kohl)
 
120
 *
 
121
 * Revision 1.23  1999/03/15  19:06:32  pvmsrc
 
122
 * Added new pvmsleep() routine.
 
123
 *      - Unix / Win32, C / Fortran compat...
 
124
 *      - invokes Sleep() on WIN32 (with secs * 1000 :-)~
 
125
 * (Spanker=kohl)
 
126
 *
 
127
 * Revision 1.22  1999/03/05  17:21:15  pvmsrc
 
128
 * improved to work with registry/environment on NT/win95-98
 
129
 * and devstudio 5/6
 
130
 * (Spanker=sscott)
 
131
 *
 
132
 * Revision 1.21  1999/02/09  23:06:53  pvmsrc
 
133
 * Cleaned up temp file stuff (mainly for WIN32).
 
134
 *      - extracted new pvmgettmp() routine for returning tmp directory.
 
135
 * (Spanker=kohl)
 
136
 *
 
137
 * Revision 1.20  1999/02/09  20:10:10  pvmsrc
 
138
 * Cleaned up pvmgetroot().
 
139
 *      - some arch cases not properly executed.
 
140
 *      - for WIN32, if read_pvmregistry() fails, give the env var a shot.
 
141
 * (Spanker=kohl)
 
142
 *
 
143
 * Revision 1.19  1998/10/02  15:44:04  pvmsrc
 
144
 * Single source code merge of Win32 and Unix code.
 
145
 * (Spanker=sscott)
 
146
 *
 
147
 * Revision 1.18  1998/09/23  15:23:42  pvmsrc
 
148
 *      changes to use WIN32 registry as per Markus.
 
149
 *      ifdef in pvmd.c::colonsep() to include WIN32 and OS2
 
150
 * (Spanker=phil)
 
151
 *
39
152
 * Revision 1.17  1997/12/01  19:20:48  pvmsrc
40
153
 * Replaced #ifdef IMA_OS2 fd_set declarations:
41
154
 *      - new #ifdef FDSETNOTSTRUCT.
173
286
#include "lpvm.h"
174
287
#include "global.h"
175
288
 
 
289
#ifdef WIN32
 
290
char *read_pvmregistry  __ProtoGlarp__(( const char * ));
 
291
#endif
176
292
 
177
293
/***************
178
294
 **  Globals  **
179
295
 **           **
180
296
 ***************/
181
297
 
 
298
#ifndef RSHCOMMAND
 
299
#define RSHCOMMAND  "/usr/ucb/rsh"
 
300
#endif
 
301
 
182
302
char *getenv();
183
303
 
184
304
#ifdef WIN32
185
305
extern char *username;
186
306
#endif
187
307
 
 
308
#ifdef IMA_BEOSCYLD
 
309
#include <sys/bproc.h>
 
310
#endif
 
311
 
 
312
 
188
313
/***************
189
314
 **  Private  **
190
315
 **           **
313
438
 
314
439
#endif
315
440
 
316
 
 
 
441
#ifndef IMA_WIN32_WATCOM
317
442
extern char **environ;
 
443
#endif
318
444
 
319
445
/*      pvmputenv()
320
446
*
600
726
        char *buf;
601
727
{
602
728
        static int n = 0;
603
 
        static char scratch[32];
 
729
        static char scratch[255];
 
730
 
 
731
        char *pvmtmp;
 
732
 
 
733
        if (!buf)
 
734
                buf = scratch;
 
735
 
 
736
        pvmtmp = pvmgettmp();
604
737
 
605
738
#ifndef WIN32
606
 
 
607
 
        if (!buf)
608
 
                buf = scratch;
609
 
        sprintf(buf, "/tmp/tmp%06d.%d", getpid(), n++ % 10000);
610
 
 
 
739
        sprintf(buf, "%s/pvmtmp%06d.%d", pvmtmp, getpid(), n++ % 10000);
611
740
#else
612
 
 
613
 
        char tmptmp[32];
614
 
 
615
 
        if (!buf)
616
 
                buf = scratch;
617
 
        if (!getenv("PVM_TMP")) {
618
 
                fprintf(stderr,
619
 
                                "Could not get PVM_TMP, defaulting to %Temp% \n");
620
 
                if (!getenv("TEMP")) {
621
 
                        fprintf(stderr,
622
 
                                        "Could not get TEMP, defaulting to c:\temp \n");
623
 
                        sprintf(buf,"c:\temp");
624
 
                } else  sprintf(buf,getenv("TEMP"));
625
 
        } else sprintf(buf,getenv("PVM_TMP"));
626
 
 
627
 
        sprintf(tmptmp, "/tmp%06d.%d", _getpid(), n++ % 10000);
628
 
        strcat(buf,tmptmp);
629
 
 
 
741
        sprintf(buf, "%s\\pvmtmp%06d.%d", pvmtmp, getpid(), n++ % 10000);
630
742
#endif
631
743
 
632
744
        return buf;
634
746
#endif  /*NOTMPNAM*/
635
747
 
636
748
 
 
749
#ifdef IMA_BEOSCYLD
 
750
 
 
751
/*
 
752
 * Implement a version of gethostname() that gives the "right" answer
 
753
 * for a Scyld Beowulf cluster; calling bproc_currnode() here is why
 
754
 * both the pvm daemon and the pvm library are linked with libbproc
 
755
 */
 
756
 
 
757
int
 
758
gethostname(name, len)
 
759
        char * name;
 
760
        size_t len;
 
761
{
 
762
        int retval;
 
763
 
 
764
        retval = snprintf(name,len,".%d",bproc_currnode());
 
765
 
 
766
        return( (retval == -1) ? retval : 0 );
 
767
}
 
768
 
 
769
#endif
 
770
 
637
771
pvmhdump(cp, n, pad)
638
772
        char *cp;               /* bytes */
639
773
        int n;                  /* length */
684
818
pvmgethome()
685
819
{
686
820
        static char *hd = 0;
687
 
 
 
821
#ifndef WIN32 /* which registry should we use otherwise ? */
688
822
        if (!hd) {
689
823
                if (hd = getenv("HOME")) {
690
824
                        hd = STRALLOC(hd);
694
828
                        hd = "/";
695
829
                }
696
830
        }
 
831
#else
 
832
        hd="\\";
 
833
#endif
697
834
        return hd;
698
835
}
699
836
 
708
845
{
709
846
        static char *rd = 0;
710
847
 
711
 
        if (!rd && !(rd = getenv("PVM_ROOT"))) {
712
 
                pvmlogerror("PVM_ROOT environment variable not set.\n");
 
848
        if (!rd) {
 
849
 
713
850
#ifdef IMA_CSPP
714
 
                {
715
 
                        struct stat buf;
716
 
 
717
 
                        rd = STRALLOC("/usr/convex/pvm");
718
 
                        if (stat(rd, &buf) == -1) {
719
 
                                pvmlogperror("Unable to default PVM_ROOT to /usr/convex/pvm");
720
 
                                pvmbailout(0);
721
 
                                exit(1);                /* the other meaning of bail out */
 
851
 
 
852
                struct stat buf;
 
853
 
 
854
                rd = STRALLOC("/usr/convex/pvm");
 
855
                if (stat(rd, &buf) == -1) {
 
856
                        pvmlogperror(
 
857
                                "Unable to default PVM_ROOT to /usr/convex/pvm");
 
858
                        pvmbailout(0);
 
859
                        exit(1);                /* the other meaning of bail out */
 
860
                }
 
861
                pvmputenv("PVM_ROOT=/usr/convex/pvm");
 
862
                pvmlogerror("Defaulting PVM_ROOT to /usr/convex/pvm");
 
863
 
 
864
#else
 
865
 
 
866
#ifdef CYGWIN
 
867
                rd = getenv("PVM_ROOT_U");
 
868
#else
 
869
                rd = getenv("PVM_ROOT");
 
870
#endif
 
871
 
 
872
#ifdef WIN32
 
873
                if (!rd)
 
874
                        rd = read_pvmregistry("PVM_ROOT");
 
875
#endif
 
876
 
 
877
#endif
 
878
 
 
879
                if (!rd) {
 
880
                        pvmlogerror("PVM_ROOT environment variable not set.\n");
 
881
                        pvmbailout(0);
 
882
                        exit(1);                /* the other meaning of bail out */
 
883
                }
 
884
        }
 
885
 
 
886
        return rd;
 
887
}
 
888
 
 
889
 
 
890
/*      pvmgettmp()
 
891
*
 
892
*       Return absolute path of PVM temporary directory.
 
893
*/
 
894
 
 
895
char *
 
896
pvmgettmp()
 
897
{
 
898
        static char *td = 0;
 
899
 
 
900
        if (!td) {
 
901
#ifndef WIN32
 
902
                if ( !(td=getenv("PVM_TMP")) )
 
903
#ifdef IMA_BEOLIN
 
904
                        td = "/tmps";   /* the shared tmp */
 
905
#else
 
906
                        td = "/tmp";
 
907
#endif
 
908
#else
 
909
                if ( !(td=getenv("PVM_TMP")) ) {
 
910
                        if ( !(td=read_pvmregistry("PVM_TMP")) ) {
 
911
                                if ( !(td=getenv("TEMP")) ) {
 
912
                                        td = "C:\\TEMP";
 
913
                                        fprintf(stderr,
 
914
                                                        "Could not get %%PVM_TMP%% or %%TEMP%% ");
 
915
                                        fprintf(stderr, "-> using \"%s\".\n", td);
 
916
                                        fprintf(stderr,
 
917
                                                        "Please check your PVM installation.\n");
 
918
                                }
722
919
                        }
723
 
                        pvmputenv("PVM_ROOT=/usr/convex/pvm");
724
 
                        pvmlogerror("Defaulting PVM_ROOT to /usr/convex/pvm");
725
920
                }
726
921
#endif
727
 
                pvmbailout(0);
728
 
                exit(1);                /* the other meaning of bail out */
729
 
        }
 
922
        }
 
923
 
 
924
        return td;
 
925
}
 
926
 
 
927
 
 
928
/*      pvmgetrsh()
 
929
*
 
930
*       Return absolute path of the rsh executable for the local system.
 
931
*/
 
932
 
 
933
char *
 
934
pvmgetrsh()
 
935
{
 
936
        static char *rd = 0;
 
937
 
 
938
        if (!rd) {
 
939
                if ( !(rd=getenv("PVM_RSH")) )
 
940
                        rd = RSHCOMMAND;
 
941
        }
 
942
 
730
943
        return rd;
731
944
}
732
945
 
764
977
char *
765
978
pvmdsockfile()
766
979
{
767
 
        static char buf[160];
768
 
#ifdef WIN32
769
 
        char TDSOCKSPEC[256];
770
 
#endif
 
980
        static char buf[255];
 
981
 
771
982
        char hna[128];
 
983
        char *pvmtmp;
772
984
        char *p;
 
985
 
773
986
#ifdef  IMA_CSPP
774
987
        int scid = get_scid();  /* default (system) subcomplex ID is 1 */
775
988
#endif
776
989
 
 
990
        pvmtmp = pvmgettmp();
 
991
 
777
992
#ifdef  SHAREDTMP
778
993
 
779
994
        if (gethostname(hna, sizeof(hna)-1) == -1) {
785
1000
 
786
1001
#ifdef  IMA_CSPP
787
1002
        if (scid > 1)
788
 
                (void)sprintf(buf, TDSOCKNAME_CSPP, pvm_useruid, scid, hna);
 
1003
                (void)sprintf(buf, TDSOCKNAME_CSPP,
 
1004
                                pvmtmp, pvm_useruid, scid, hna);
789
1005
        else
790
1006
#endif
791
 
                (void)sprintf(buf, TDSOCKNAME, pvm_useruid, hna);
 
1007
                (void)sprintf(buf, TDSOCKNAME, pvmtmp, pvm_useruid, hna);
792
1008
 
793
1009
#else
794
1010
 
795
1011
#ifdef  IMA_CSPP
796
1012
        if (scid > 1)
797
 
                (void)sprintf(buf, TDSOCKNAME_CSPP, pvm_useruid, scid);
 
1013
                (void)sprintf(buf, TDSOCKNAME_CSPP, pvmtmp, pvm_useruid, scid);
798
1014
        else
799
1015
#endif
800
1016
#ifdef WIN32
801
 
                if (!getenv("PVM_TMP"))
802
 
                {
803
 
                        (void)sprintf(buf, TDSOCKNAME, username);
804
 
                        pvmlogprintf("Could not get PVM_TMP, continuing with %s\n",
805
 
                                        buf);
806
 
                } else {
807
 
                        strcpy(TDSOCKSPEC,getenv("PVM_TMP"));
808
 
                        if (_chdir(getenv("PVM_TMP")) == -1) {
809
 
                                pvmlogerror("Could Not retrieve PVM_TMP directory \n");
810
 
                                pvmbailout(0);
811
 
                        }
812
 
                        sprintf(buf,"/pvmd.%s",username);
813
 
                        strcat(TDSOCKSPEC,buf);
814
 
                        sprintf(buf,TDSOCKSPEC);
815
 
                }
 
1017
                sprintf( buf, "%s\\pvmd.%s", pvmtmp, username );
816
1018
#else
817
 
                (void)sprintf(buf, TDSOCKNAME, pvm_useruid);
818
 
#endif
819
 
 
820
 
#endif
 
1019
                (void)sprintf(buf, TDSOCKNAME, pvmtmp, pvm_useruid);
 
1020
#endif
 
1021
 
 
1022
#endif
 
1023
 
 
1024
        /* Append a Virtual Machine ID, If Set */
 
1025
        if ( p = getenv("PVM_VMID") ) {
 
1026
                strcat( buf, "." );
 
1027
                strcat( buf, p );
 
1028
        }
821
1029
 
822
1030
        return buf;
823
1031
}
1118
1326
}
1119
1327
 
1120
1328
 
 
1329
/*  pvmsleep()
 
1330
*
 
1331
*   A consistent way to invoke sleep(), from:
 
1332
*     Unix / Windows, C / Fortran
 
1333
*/
 
1334
 
 
1335
int
 
1336
pvmsleep( secs )
 
1337
int secs;
 
1338
{
 
1339
        int ret;
 
1340
#ifdef WIN32
 
1341
        Sleep( secs * 1000 );
 
1342
        ret = secs;
 
1343
#else
 
1344
        ret = (int) sleep( secs );
 
1345
#endif
 
1346
        return( ret );
 
1347
}
 
1348
 
 
1349
 
 
1350
/*      pvmmatchstring()
 
1351
*
 
1352
*       Replacement for GNU Regex pattern matching.
 
1353
*/
 
1354
 
 
1355
int
 
1356
pvmmatchstring( str, pattern )
 
1357
char *str;
 
1358
char *pattern;
 
1359
{
 
1360
        char *start;
 
1361
        char *save;
 
1362
        char *x;
 
1363
        char *y;
 
1364
 
 
1365
        /* Find Start of Search String (Ignore Preceding '*'s) */
 
1366
 
 
1367
        start = pattern;
 
1368
 
 
1369
        while ( *start == '*' && *start != '\0' )
 
1370
                start++;
 
1371
 
 
1372
        /* Null Search - Always Matches */
 
1373
 
 
1374
        if ( *start == '\0' )
 
1375
                return( 1 );
 
1376
 
 
1377
        /* Initialize Pointers */
 
1378
 
 
1379
        x = str;
 
1380
 
 
1381
        y = start;
 
1382
 
 
1383
        /* Search Line for Start of Search String */
 
1384
 
 
1385
        while ( *x != '\0' )
 
1386
        {
 
1387
                /* Starting Match Found...  Check it Out */
 
1388
 
 
1389
                if ( *x == *y )
 
1390
                {
 
1391
                        /* Save Continuation Pointer */
 
1392
 
 
1393
                        save = x + 1;
 
1394
 
 
1395
                        /* Traverse Line Until No Longer Matches */
 
1396
 
 
1397
                        while ( *x != '\0' && *y != '\0' && *x == *y )
 
1398
                        {
 
1399
                                x++;
 
1400
                                y++;
 
1401
 
 
1402
                                /* Nested '*' Search Expansion */
 
1403
 
 
1404
                                if ( *y == '*' )
 
1405
                                {
 
1406
                                        if ( pvmmatchstring( x, y + 1 ) )
 
1407
                                                return( 1 );
 
1408
 
 
1409
                                        else
 
1410
                                                break;
 
1411
                                }
 
1412
 
 
1413
                                /* Skip Over '\' for Escaped '*'s */
 
1414
 
 
1415
                                else if ( *y == '\\' && *(y+1) == '*' )
 
1416
                                        y++;
 
1417
                        }
 
1418
 
 
1419
                        /* It's a Match! */
 
1420
 
 
1421
                        if ( *y == '\0' )
 
1422
                                return( 1 );
 
1423
 
 
1424
                        /* Reset and Continue */
 
1425
 
 
1426
                        x = save;
 
1427
 
 
1428
                        y = start;
 
1429
                }
 
1430
 
 
1431
                else
 
1432
                        x++;
 
1433
        }
 
1434
 
 
1435
        return( 0 );
 
1436
}
 
1437