author | Claus Gittinger <cg@exept.de> |
Sat, 16 Dec 1995 13:29:09 +0100 | |
changeset 774 | e0ee05157570 |
parent 771 | 1ad3f852e201 |
child 792 | 06ec639ead96 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
185 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
Object subclass:#OperatingSystem |
|
616 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'HostName DomainName LastErrorNumber LastExecStatus OSSignals |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
756
diff
changeset
|
16 |
SlowFork ForkFailed ErrorSignal AccessDeniedErrorSignal |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
756
diff
changeset
|
17 |
FileNotFoundErrorSignal' |
616 | 18 |
poolDictionaries:'' |
19 |
category:'System-Support' |
|
1 | 20 |
! |
21 |
||
437 | 22 |
!OperatingSystem primitiveDefinitions! |
406 | 23 |
%{ |
443 | 24 |
#if defined(_AIX) |
439 | 25 |
# ifndef WANT_REALPATH |
26 |
# define WANT_REALPATH |
|
27 |
# endif |
|
513
0347f6d11d76
interruptable system() on AIX
Claus Gittinger <cg@exept.de>
parents:
512
diff
changeset
|
28 |
# ifndef WANT_SYSTEM |
0347f6d11d76
interruptable system() on AIX
Claus Gittinger <cg@exept.de>
parents:
512
diff
changeset
|
29 |
# define WANT_SYSTEM |
0347f6d11d76
interruptable system() on AIX
Claus Gittinger <cg@exept.de>
parents:
512
diff
changeset
|
30 |
# endif |
406 | 31 |
#endif |
32 |
||
433 | 33 |
#ifdef LINUX |
439 | 34 |
# ifndef WANT_SYSTEM |
35 |
# define WANT_SYSTEM |
|
36 |
# endif |
|
443 | 37 |
# define WANT_SHM |
433 | 38 |
#endif |
39 |
||
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
40 |
#ifdef IRIX5 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
41 |
# define WANT_SYSTEM |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
42 |
#endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
43 |
|
514
81fa80a953e2
system() now interruptable with ultrix
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
44 |
#ifdef ultrix |
81fa80a953e2
system() now interruptable with ultrix
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
45 |
# define WANT_SYSTEM |
81fa80a953e2
system() now interruptable with ultrix
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
46 |
#endif |
81fa80a953e2
system() now interruptable with ultrix
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
47 |
|
515
43d76695a662
interruptable system() on hpux
Claus Gittinger <cg@exept.de>
parents:
514
diff
changeset
|
48 |
#ifdef hpux |
43d76695a662
interruptable system() on hpux
Claus Gittinger <cg@exept.de>
parents:
514
diff
changeset
|
49 |
# define WANT_SYSTEM |
43d76695a662
interruptable system() on hpux
Claus Gittinger <cg@exept.de>
parents:
514
diff
changeset
|
50 |
#endif |
43d76695a662
interruptable system() on hpux
Claus Gittinger <cg@exept.de>
parents:
514
diff
changeset
|
51 |
|
520
9620f7dc79d2
interruptable system() on unixware - should now move WANT_SYSTEM into xxxIntern files
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
52 |
#ifdef unixware |
9620f7dc79d2
interruptable system() on unixware - should now move WANT_SYSTEM into xxxIntern files
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
53 |
# define WANT_SYSTEM |
9620f7dc79d2
interruptable system() on unixware - should now move WANT_SYSTEM into xxxIntern files
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
54 |
#endif |
9620f7dc79d2
interruptable system() on unixware - should now move WANT_SYSTEM into xxxIntern files
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
55 |
|
439 | 56 |
#ifdef WANT_REALPATH |
57 |
# include <sys/param.h> |
|
58 |
# define _SYS_PARAM_H_INCLUDED_ |
|
59 |
||
60 |
# include <errno.h> |
|
61 |
# define _ERRNO_H_INCLUDED_ |
|
62 |
||
63 |
# include <sys/stat.h> |
|
64 |
# define _SYS_STAT_H_INCLUDED_ |
|
443 | 65 |
|
439 | 66 |
#endif /* WANT_REALPATH */ |
67 |
||
434 | 68 |
#ifdef WANT_SHM |
443 | 69 |
extern int shmctl(), shmget(), shmdt(); |
70 |
extern char * shmat(); |
|
71 |
||
434 | 72 |
# include <sys/types.h> |
437 | 73 |
# define _SYS_TYPES_H_INCLUDED_ |
439 | 74 |
|
434 | 75 |
# include <sys/ipc.h> |
437 | 76 |
# define _SYS_IPC_H_INCLUDED_ |
439 | 77 |
|
434 | 78 |
# include <sys/shm.h> |
437 | 79 |
# define _SYS_SHM_H_INCLUDED_ |
439 | 80 |
#endif /* WANT_SHM */ |
434 | 81 |
|
82 |
#ifdef IRIX5 |
|
83 |
# include <sys/syssgi.h> |
|
84 |
#endif |
|
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
85 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
86 |
#ifdef transputer |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
87 |
# define unlink(f) ((remove(f) == 0) ? 0 : -1) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
88 |
#else |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
89 |
# include <signal.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
90 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
91 |
# ifdef SYSV |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
92 |
# include <sys/types.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
93 |
# include <sys/param.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
94 |
# include <sys/times.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
95 |
# include <sys/file.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
96 |
# if ! defined(sco3_2) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
97 |
# include <unistd.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
98 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
99 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
100 |
# if defined(isc3_2) || defined(sco3_2) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
101 |
# include <sys/time.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
102 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
103 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
104 |
# if !defined(isc3_2) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
105 |
# if defined(PCS) && defined(mips) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
106 |
# include "/usr/include/bsd/sys/time.h" |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
107 |
# include "/usr/include/sys/time.h" |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
108 |
# else |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
109 |
# include <time.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
110 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
111 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
112 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
113 |
# if defined(isc3_2) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
114 |
# include <sys/bsdtypes.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
115 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
116 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
117 |
# else /* not SYSV */ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
118 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
119 |
# include <sys/time.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
120 |
# include <sys/types.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
121 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
122 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
123 |
# ifdef aix |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
124 |
# include <time.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
125 |
# include <sys/select.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
126 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
127 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
128 |
# include <pwd.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
129 |
# include <grp.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
130 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
131 |
# include <sys/stat.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
132 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
133 |
# include <errno.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
134 |
# define _ERRNO_H_INCLUDED_ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
135 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
136 |
# include <stdio.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
137 |
# define _STDIO_H_INCLUDED_ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
138 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
139 |
# include <fcntl.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
140 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
141 |
/* |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
142 |
* posix systems should define these ... |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
143 |
* but on some (older) systems, they are not. |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
144 |
*/ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
145 |
# ifndef S_IXUSR |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
146 |
# ifdef S_IEXEC |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
147 |
# define S_IXUSR S_IEXEC |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
148 |
# define S_IXGRP (S_IEXEC>>3) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
149 |
# define S_IXOTH (S_IEXEC>>6) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
150 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
151 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
152 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
153 |
# ifndef S_IXUSR |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
154 |
# define S_IXUSR 0100 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
155 |
# define S_IXGRP 0010 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
156 |
# define S_IXOTH 0001 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
157 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
158 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
159 |
# ifndef S_IRUSR |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
160 |
# define S_IRUSR 0400 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
161 |
# define S_IRGRP 0040 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
162 |
# define S_IROTH 0004 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
163 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
164 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
165 |
# ifndef S_IWUSR |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
166 |
# define S_IWUSR 0200 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
167 |
# define S_IWGRP 0020 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
168 |
# define S_IWOTH 0002 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
169 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
170 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
171 |
# ifndef MAXPATHLEN |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
172 |
# include <sys/param.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
173 |
# ifndef MAXPATHLEN |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
174 |
# define MAXPATHLEN 1024 |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
175 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
176 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
177 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
178 |
# if defined(HAS_UNAME) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
179 |
# include <sys/utsname.h> |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
180 |
# endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
181 |
|
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
182 |
# if defined(SYSV4) |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
183 |
# include <stropts.h> |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
184 |
# endif |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
185 |
|
763
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
186 |
/* |
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
187 |
* sigaction dummies (you won't believe these call themself ``POSIC'' systems ...) |
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
188 |
*/ |
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
189 |
# ifndef SA_RESTART |
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
190 |
# define SA_RESTART 0 |
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
191 |
# endif |
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
192 |
# ifndef SA_SIGINFO |
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
193 |
# define SA_SIGINFO 0 |
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
194 |
# endif |
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
195 |
|
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
196 |
#endif /* ! transputer */ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
197 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
198 |
/* |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
199 |
* on some systems errno is a macro ... check for it here |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
200 |
*/ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
201 |
#ifndef errno |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
202 |
extern errno; |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
203 |
#endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
204 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
205 |
/* |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
206 |
* some (old ?) systems do not define this ... |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
207 |
*/ |
675 | 208 |
#if !defined(R_OK) && !defined(_AIX) |
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
209 |
# define R_OK 4 /* Test for Read permission */ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
210 |
# define W_OK 2 /* Test for Write permission */ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
211 |
# define X_OK 1 /* Test for eXecute permission */ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
212 |
# define F_OK 0 /* Test for existence of File */ |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
213 |
#endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
214 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
215 |
#define UNIX_LIKE |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
216 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
217 |
#if defined(NT) || defined(MSWINDOWS) || defined(OS2) || defined(MSDOS) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
218 |
# define MSDOS_LIKE |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
219 |
# undef UNIX_LIKE |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
220 |
#endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
221 |
|
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
222 |
#if defined(transputer) |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
223 |
# undef UNIX_LIKE |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
224 |
#endif |
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
225 |
|
437 | 226 |
%} |
227 |
! ! |
|
228 |
||
229 |
!OperatingSystem primitiveFunctions! |
|
230 |
%{ |
|
231 |
||
232 |
/* |
|
233 |
* some systems' system() is broken in that it does not correctly |
|
234 |
* handle EINTR and returns failure even though it actually succeeded. |
|
235 |
* (LINUX is one of them) |
|
236 |
* Here is a fixed version. If you encounter EINTR returns from |
|
237 |
* OperatingSystem>>executeCommand, you ought to define WANT_SYSTEM |
|
238 |
* in the xxxIntern.h file to get this fixed version. |
|
239 |
* |
|
240 |
* As an added BONUS, this system() enables interrupts while waiting |
|
241 |
* for the child which enables other threads to continue. |
|
507
a7780fc27ee9
mad system interuptable (needs WANT_SYSTEM to be defined in xxxIntern.h)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
242 |
* (i.e. it is RT safe) |
437 | 243 |
*/ |
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
244 |
|
433 | 245 |
#if defined(WANT_SYSTEM) |
246 |
||
434 | 247 |
/* # define DPRINTF(x) printf x */ |
248 |
# define DPRINTF(x) /* nothing */ |
|
433 | 249 |
|
437 | 250 |
# ifndef _STDDEF_H_INCLUDED_ |
251 |
# include <stddef.h> |
|
252 |
# define _STDDEF_H_INCLUDED_ |
|
253 |
# endif |
|
254 |
||
255 |
# ifndef _STDLIB_H_INCLUDED_ |
|
256 |
# include <stdlib.h> |
|
257 |
# define _STDLIB_H_INCLUDED_ |
|
258 |
# endif |
|
259 |
||
260 |
# ifndef _UNISTD_H_INCLUDED_ |
|
261 |
# include <unistd.h> |
|
262 |
# define _UNISTD_H_INCLUDED_ |
|
263 |
# endif |
|
264 |
||
265 |
# ifndef _SYS_WAIT_H_INCLUDED |
|
266 |
# include <sys/wait.h> |
|
267 |
# define _SYS_WAIT_H_INCLUDED |
|
268 |
# endif |
|
269 |
||
270 |
# ifndef _SIGNAL_H_INCLUDED_ |
|
271 |
# include <signal.h> |
|
272 |
# define _SIGNAL_H_INCLUDED_ |
|
273 |
# endif |
|
274 |
||
275 |
# ifndef _SYS_TYPES_H_INCLUDED_ |
|
276 |
# include <sys/types.h> |
|
277 |
# define _SYS_TYPES_H_INCLUDED_ |
|
278 |
# endif |
|
433 | 279 |
|
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
280 |
# if (!defined(HAVE_GNU_LD) && !defined (__ELF__)) || !defined(LINUX) |
433 | 281 |
# define __environ environ |
512 | 282 |
# if !defined(LINUX) |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
283 |
# define __sigemptyset sigemptyset |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
284 |
# define __sigaction sigaction |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
285 |
# define __sigaddset sigaddset |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
286 |
# define __sigprocmask sigprocmask |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
287 |
# define __execve execve |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
288 |
# define __wait wait |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
289 |
# define __waitpid waitpid |
674 | 290 |
# if defined(HAS_VFORK) |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
291 |
# define FORK vfork |
514
81fa80a953e2
system() now interruptable with ultrix
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
292 |
# else |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
293 |
# define FORK fork |
514
81fa80a953e2
system() now interruptable with ultrix
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
294 |
# endif |
512 | 295 |
# endif /* ! LINUX */ |
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
296 |
extern char **environ; |
433 | 297 |
# endif |
298 |
||
299 |
# define SHELL_PATH "/bin/sh" /* Path of the shell. */ |
|
300 |
# define SHELL_NAME "sh" /* Name to give it. */ |
|
301 |
||
302 |
# ifndef FORK |
|
303 |
# define FORK __fork |
|
304 |
# endif |
|
305 |
||
306 |
# ifndef CONST |
|
307 |
# ifdef __GNUC__ |
|
308 |
# define CONST const |
|
309 |
# else |
|
310 |
# define CONST /* nothing */ |
|
311 |
# endif |
|
312 |
# endif |
|
313 |
||
670
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
314 |
static int |
511
7626c5474c7f
interruptable system() for IRIX5
Claus Gittinger <cg@exept.de>
parents:
507
diff
changeset
|
315 |
mySystem(line) |
433 | 316 |
register CONST char *line; |
317 |
{ |
|
318 |
int status, save; |
|
319 |
pid_t pid; |
|
320 |
struct sigaction sa, intr, quit; |
|
321 |
sigset_t block, omask; |
|
322 |
||
323 |
if (line == NULL) |
|
670
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
324 |
return -1; |
433 | 325 |
|
326 |
sa.sa_handler = SIG_IGN; |
|
327 |
sa.sa_flags = 0; |
|
328 |
__sigemptyset (&sa.sa_mask); |
|
329 |
||
330 |
if (__sigaction (SIGINT, &sa, &intr) < 0) { |
|
331 |
DPRINTF(("1: errno=%d\n", errno)); |
|
332 |
return -1; |
|
333 |
} |
|
334 |
if (__sigaction (SIGQUIT, &sa, &quit) < 0) { |
|
335 |
save = errno; |
|
336 |
(void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL); |
|
337 |
errno = save; |
|
338 |
DPRINTF(("2: errno=%d\n", errno)); |
|
339 |
return -1; |
|
340 |
} |
|
341 |
||
342 |
__sigemptyset (&block); |
|
343 |
__sigaddset (&block, SIGCHLD); |
|
344 |
save = errno; |
|
345 |
if (__sigprocmask(SIG_BLOCK, &block, &omask) < 0) { |
|
346 |
if (errno == ENOSYS) |
|
347 |
errno = save; |
|
348 |
else { |
|
349 |
save = errno; |
|
350 |
(void) __sigaction(SIGINT, &intr, (struct sigaction *) NULL); |
|
351 |
(void) __sigaction(SIGQUIT, &quit, (struct sigaction *) NULL); |
|
352 |
errno = save; |
|
353 |
DPRINTF(("3: errno=%d\n", errno)); |
|
354 |
return -1; |
|
355 |
} |
|
356 |
} |
|
357 |
||
358 |
pid = FORK (); |
|
359 |
if (pid == (pid_t) 0) { |
|
360 |
/* Child side. */ |
|
361 |
CONST char *new_argv[4]; |
|
362 |
new_argv[0] = SHELL_NAME; |
|
363 |
new_argv[1] = "-c"; |
|
364 |
new_argv[2] = line; |
|
365 |
new_argv[3] = NULL; |
|
366 |
||
367 |
/* Restore the signals. */ |
|
368 |
(void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL); |
|
369 |
(void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL); |
|
370 |
(void) __sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL); |
|
371 |
||
372 |
/* Exec the shell. */ |
|
373 |
(void) __execve (SHELL_PATH, (char *CONST *) new_argv, __environ); |
|
374 |
_exit (127); |
|
375 |
} else { |
|
376 |
if (pid < (pid_t) 0) { |
|
377 |
/* The fork failed. */ |
|
378 |
DPRINTF(("4: errno=%d\n", errno)); |
|
379 |
status = -1; |
|
380 |
} else { |
|
381 |
/* Parent side. */ |
|
382 |
#ifdef NO_WAITPID |
|
383 |
pid_t child; |
|
384 |
||
385 |
do { |
|
386 |
child = __wait (&status); |
|
387 |
if (child <= -1) { |
|
388 |
DPRINTF(("5: errno=%d\n", errno)); |
|
389 |
status = -1; |
|
390 |
break; |
|
391 |
} |
|
392 |
} while (child != pid); |
|
393 |
#else |
|
394 |
pid_t child; |
|
395 |
||
396 |
/* claus: the original did not care for EINTR here ... */ |
|
397 |
do { |
|
398 |
child = __waitpid (pid, &status, 0); |
|
399 |
} while ((child != pid) && (errno == EINTR)); |
|
400 |
if (child != pid) { |
|
401 |
DPRINTF(("6: errno=%d\n", errno)); |
|
402 |
status = -1; |
|
403 |
} |
|
404 |
#endif /* NO_WAITPID */ |
|
405 |
} |
|
406 |
} |
|
407 |
save = errno; |
|
408 |
if ((__sigaction (SIGINT, &intr, (struct sigaction *) NULL) |
|
409 |
| __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL) |
|
410 |
| __sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL)) != 0) { |
|
411 |
if (errno == ENOSYS) { |
|
412 |
errno = save; |
|
413 |
} else { |
|
414 |
status = -1; |
|
415 |
DPRINTF(("7: errno=%d\n", errno)); |
|
416 |
} |
|
417 |
} |
|
418 |
||
419 |
return status; |
|
420 |
} |
|
421 |
#endif /* WANT_SYSTEM */ |
|
422 |
||
670
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
423 |
|
433 | 424 |
/* |
425 |
* some systems do not have realpath(); |
|
426 |
* the alternative of reading from a 'pwp'-pipe |
|
427 |
* is way too slow. Here is a realpath for the rest of us. |
|
440 | 428 |
* define WANT_REALPATH in the xxxIntern-file to get it. |
433 | 429 |
*/ |
443 | 430 |
|
440 | 431 |
#if defined(HAS_REALPATH) |
432 |
# undef WANT_REALPATH |
|
433 |
#endif |
|
434 |
#if !defined(HAS_GETWD) && !defined(HAS_GETCWD) |
|
435 |
# undef WANT_REALPATH |
|
436 |
#endif |
|
437 |
||
438 |
#if defined(WANT_REALPATH) |
|
406 | 439 |
|
440 |
# ifndef NULL |
|
441 |
# define NULL (char *)0 |
|
442 |
# endif |
|
443 |
||
439 | 444 |
# define MAX_READLINKS 32 |
445 |
||
446 |
# ifndef MAXPATHLEN |
|
447 |
# define MAXPATHLEN 1024 |
|
448 |
# endif |
|
406 | 449 |
|
450 |
static |
|
451 |
char *realpath(path, resolved_path) |
|
452 |
char *path; |
|
453 |
char resolved_path []; |
|
454 |
{ |
|
455 |
char copy_path[MAXPATHLEN]; |
|
456 |
char link_path[MAXPATHLEN]; |
|
457 |
char *new_path = resolved_path; |
|
458 |
char *max_path; |
|
459 |
int readlinks = 0; |
|
460 |
int n; |
|
461 |
||
462 |
/* Make a copy of the source path since we may need to modify it. */ |
|
463 |
strcpy(copy_path, path); |
|
464 |
path = copy_path; |
|
465 |
max_path = copy_path + MAXPATHLEN - 2; |
|
466 |
/* If it's a relative pathname use getwd for starters. */ |
|
467 |
if (*path != '/') { |
|
468 |
#ifdef HAS_GETCWD |
|
469 |
getcwd(new_path, MAXPATHLEN - 1); |
|
470 |
#else |
|
471 |
getwd(new_path); |
|
472 |
#endif |
|
473 |
new_path += strlen(new_path); |
|
474 |
if (new_path[-1] != '/') |
|
475 |
*new_path++ = '/'; |
|
476 |
} |
|
477 |
else { |
|
478 |
*new_path++ = '/'; |
|
479 |
path++; |
|
480 |
} |
|
481 |
/* Expand each slash-separated pathname component. */ |
|
482 |
while (*path != '\0') { |
|
483 |
/* Ignore stray "/". */ |
|
484 |
if (*path == '/') { |
|
485 |
path++; |
|
486 |
continue; |
|
487 |
} |
|
488 |
if (*path == '.') { |
|
489 |
/* Ignore ".". */ |
|
490 |
if (path[1] == '\0' || path[1] == '/') { |
|
491 |
path++; |
|
492 |
continue; |
|
493 |
} |
|
494 |
if (path[1] == '.') { |
|
495 |
if (path[2] == '\0' || path[2] == '/') { |
|
496 |
path += 2; |
|
497 |
/* Ignore ".." at root. */ |
|
498 |
if (new_path == resolved_path + 1) |
|
499 |
continue; |
|
500 |
/* Handle ".." by backing up. */ |
|
501 |
while ((--new_path)[-1] != '/') |
|
502 |
; |
|
503 |
continue; |
|
504 |
} |
|
505 |
} |
|
506 |
} |
|
507 |
/* Safely copy the next pathname component. */ |
|
508 |
while (*path != '\0' && *path != '/') { |
|
509 |
if (path > max_path) { |
|
510 |
errno = ENAMETOOLONG; |
|
511 |
return NULL; |
|
512 |
} |
|
513 |
*new_path++ = *path++; |
|
514 |
} |
|
515 |
#ifdef S_IFLNK |
|
516 |
/* Protect against infinite loops. */ |
|
517 |
if (readlinks++ > MAX_READLINKS) { |
|
518 |
errno = ELOOP; |
|
519 |
return NULL; |
|
520 |
} |
|
521 |
/* See if latest pathname component is a symlink. */ |
|
522 |
*new_path = '\0'; |
|
523 |
n = readlink(resolved_path, link_path, MAXPATHLEN - 1); |
|
524 |
if (n < 0) { |
|
525 |
/* EINVAL means the file exists but isn't a symlink. */ |
|
526 |
if (errno != EINVAL) |
|
527 |
return NULL; |
|
528 |
} |
|
529 |
else { |
|
530 |
/* Note: readlink doesn't add the null byte. */ |
|
531 |
link_path[n] = '\0'; |
|
532 |
if (*link_path == '/') |
|
533 |
/* Start over for an absolute symlink. */ |
|
534 |
new_path = resolved_path; |
|
535 |
else |
|
536 |
/* Otherwise back up over this component. */ |
|
537 |
while (*(--new_path) != '/') |
|
538 |
; |
|
539 |
/* Safe sex check. */ |
|
540 |
if (strlen(path) + n >= MAXPATHLEN) { |
|
541 |
errno = ENAMETOOLONG; |
|
542 |
return NULL; |
|
543 |
} |
|
544 |
/* Insert symlink contents into path. */ |
|
545 |
strcat(link_path, path); |
|
546 |
strcpy(copy_path, link_path); |
|
547 |
path = copy_path; |
|
548 |
} |
|
549 |
#endif /* S_IFLNK */ |
|
550 |
*new_path++ = '/'; |
|
551 |
} |
|
552 |
/* Delete trailing slash but don't whomp a lone slash. */ |
|
553 |
if (new_path != resolved_path + 1 && new_path[-1] == '/') |
|
554 |
new_path--; |
|
555 |
/* Make sure it's null terminated. */ |
|
556 |
*new_path = '\0'; |
|
557 |
return resolved_path; |
|
558 |
} |
|
559 |
# define HAS_REALPATH |
|
560 |
#endif /* WANT_REALPATH && not HAS_REALPATH */ |
|
438 | 561 |
|
562 |
#ifdef VMS |
|
563 |
char *getwd(p) |
|
564 |
char *p; |
|
565 |
{ |
|
566 |
int c; |
|
567 |
char *root_dir,*l2; |
|
568 |
||
569 |
getcwd(p,512,0); /* get current working directory in unix format*/ |
|
570 |
||
571 |
root_dir = strstr ( p, "/000000" ); |
|
572 |
if ( root_dir != NULL ) { |
|
573 |
/* trim root directory out of specification */ |
|
574 |
if ( (strlen(root_dir) == 7) && |
|
575 |
(strpbrk(p+1,"/") == root_dir) ) *root_dir = '\0'; |
|
576 |
} |
|
577 |
/* special kludge for "/" directory */ |
|
578 |
if ( strcmp ( p, "/DEVICE_LIST_ROOT" ) == 0 ) |
|
579 |
strcpy ( p, "/" ); |
|
580 |
return(p); |
|
581 |
} |
|
582 |
||
583 |
unlink(p) |
|
584 |
char *p; |
|
585 |
{ |
|
586 |
#ifdef VMSDEBUG |
|
587 |
printf("unlink: '%s'\n",p); |
|
588 |
#endif |
|
589 |
delete(p); |
|
590 |
} |
|
591 |
||
592 |
int |
|
593 |
lstat(f,st) /* fake a stat operation to return file type */ |
|
594 |
char *f; |
|
595 |
stat_t *st; |
|
596 |
{ |
|
597 |
char *dirext, *name; |
|
598 |
int extlen; |
|
599 |
||
600 |
st->st_mode = S_IFREG; /* default to normal file */ |
|
601 |
name = strrchr ( f, '/' ); /* locate rightmost slash */ |
|
602 |
if ( name == NULL ) name = f; else name++; |
|
603 |
||
604 |
dirext = strstr ( name, ".DIR" ); |
|
605 |
if ( dirext != NULL ) { |
|
606 |
/* make it an exact match */ |
|
607 |
extlen = strcspn(&dirext[1],".;"); |
|
608 |
if ( (extlen == 0) || (extlen == 3) ) { |
|
609 |
st->st_mode = S_IFDIR; |
|
610 |
if ( strncmp ( name, "000000.", 7 ) == 0 ) return 0; |
|
611 |
else return (stat ( f, st )); |
|
612 |
} |
|
613 |
} |
|
614 |
return 0; |
|
615 |
} |
|
616 |
# endif /* VMS */ |
|
617 |
||
406 | 618 |
%} |
619 |
! ! |
|
620 |
||
2 | 621 |
!OperatingSystem class methodsFor:'documentation'! |
622 |
||
88 | 623 |
copyright |
624 |
" |
|
625 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
185 | 626 |
All Rights Reserved |
88 | 627 |
|
628 |
This software is furnished under a license and may be used |
|
629 |
only in accordance with the terms of that license and with the |
|
630 |
inclusion of the above copyright notice. This software may not |
|
631 |
be provided or otherwise made available to, or used by, any |
|
632 |
other person. No title to or ownership of the software is |
|
633 |
hereby transferred. |
|
634 |
" |
|
635 |
! |
|
636 |
||
2 | 637 |
documentation |
638 |
" |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
639 |
this class realizes access to most (all ?) required operating system services; |
68 | 640 |
some of it is very specific for unix, so do not depend on |
641 |
things available here in your applications - some may not |
|
370 | 642 |
be found in other OS's or be slightly different ... |
68 | 643 |
|
644 |
(On the other hand: I do not want to hide all features |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
756
diff
changeset
|
645 |
from you - in some situations it MAY be interesting to be |
68 | 646 |
able to get down to a select or fork system call easily. |
647 |
You decide - portability vs. functionality) |
|
648 |
||
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
649 |
Currently, there is only this class available - once others than |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
650 |
Unix are supported, the corresponding class will be bound to the |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
651 |
global variable OperatingSystem. |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
652 |
|
68 | 653 |
Class variables: |
654 |
||
185 | 655 |
HostName <String> remembered hostname |
656 |
||
575
4ad726f27891
oops cached HostName was clobbered by a domainName query
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
657 |
DomainName <String> remembered domainname |
4ad726f27891
oops cached HostName was clobbered by a domainName query
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
658 |
|
185 | 659 |
LastErrorNumber <Integer> the last value of errno |
660 |
||
661 |
LastExecStatus <Integer> the returned exec status after |
|
662 |
the last call of system |
|
663 |
||
664 |
OSSignals <Array> Array of signals to be raised for corresponding |
|
665 |
OperatingSystem signals. |
|
308 | 666 |
|
667 |
ForkFailed <Boolean> set if a fork (or popen) has failed; |
|
668 |
ST/X will avoid doing more forks/popens |
|
669 |
if this flag is set, for a slightly |
|
670 |
smoother operation. |
|
671 |
||
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
672 |
SlowFork <Boolean> if set, fork and popen are avoided; |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
520
diff
changeset
|
673 |
(more or less obsolete now) |
540
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
674 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
675 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
676 |
ErrorSignal <Signal> Parentsignal of all OS error signals. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
677 |
not directly raised. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
678 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
679 |
AccessDeniedErrorSignal |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
680 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
681 |
FileNotFoundErrorSignal |
2 | 682 |
" |
683 |
! ! |
|
684 |
||
95 | 685 |
!OperatingSystem class methodsFor:'initialization'! |
686 |
||
687 |
initialize |
|
185 | 688 |
"initialize the class" |
689 |
||
540
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
690 |
ObjectMemory addDependent:self. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
691 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
692 |
ErrorSignal isNil ifTrue:[ |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
693 |
ErrorSignal := Object errorSignal newSignalMayProceed:true.. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
694 |
ErrorSignal nameClass:self message:#errorSignal. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
695 |
ErrorSignal notifierString:'OS error encountered'. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
696 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
697 |
AccessDeniedErrorSignal := ErrorSignal newSignalMayProceed:true. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
698 |
AccessDeniedErrorSignal nameClass:self message:#accessDeniedError. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
699 |
AccessDeniedErrorSignal notifierString:'OS access denied'. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
700 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
701 |
FileNotFoundErrorSignal := ErrorSignal newSignalMayProceed:true. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
702 |
FileNotFoundErrorSignal nameClass:self message:#fileNotFoundErrorSignal. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
703 |
FileNotFoundErrorSignal notifierString:'OS file not found'. |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
704 |
] |
95 | 705 |
! |
706 |
||
707 |
update:something |
|
708 |
something == #earlyRestart ifTrue:[ |
|
185 | 709 |
" |
710 |
flush cached data |
|
711 |
" |
|
712 |
HostName := nil. |
|
575
4ad726f27891
oops cached HostName was clobbered by a domainName query
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
713 |
DomainName := nil. |
185 | 714 |
LastErrorNumber := nil. |
715 |
LastExecStatus := nil |
|
95 | 716 |
] |
717 |
! ! |
|
718 |
||
616 | 719 |
!OperatingSystem class methodsFor:'OS signal constants'! |
720 |
||
721 |
sigABRT |
|
722 |
"return the signal number for SIGABRT - 0 if not supported by OS |
|
723 |
(the numeric value is not the same across unix-systems)" |
|
724 |
||
725 |
%{ /* NOCONTEXT */ |
|
726 |
#ifdef SIGABRT |
|
710 | 727 |
RETURN ( _MKSMALLINT(SIGABRT) ); |
616 | 728 |
#else |
710 | 729 |
RETURN ( _MKSMALLINT(0) ); |
616 | 730 |
#endif |
731 |
%} |
|
732 |
! |
|
733 |
||
734 |
sigALRM |
|
735 |
"return the signal number for SIGALRM - 0 if not supported |
|
736 |
(the numeric value is not the same across unix-systems)" |
|
737 |
||
738 |
%{ /* NOCONTEXT */ |
|
739 |
#ifdef SIGALRM |
|
710 | 740 |
RETURN ( _MKSMALLINT(SIGALRM) ); |
616 | 741 |
#else |
710 | 742 |
RETURN ( _MKSMALLINT(0) ); |
616 | 743 |
#endif |
744 |
%} |
|
745 |
! |
|
746 |
||
747 |
sigBUS |
|
748 |
"return the signal number for SIGBUS - 0 if not supported |
|
749 |
(the numeric value is not the same across unix-systems)" |
|
750 |
||
751 |
%{ /* NOCONTEXT */ |
|
752 |
#ifdef SIGBUS |
|
710 | 753 |
RETURN ( _MKSMALLINT(SIGBUS) ); |
616 | 754 |
#else |
710 | 755 |
RETURN ( _MKSMALLINT(0) ); |
616 | 756 |
#endif |
757 |
%} |
|
758 |
! |
|
759 |
||
760 |
sigCHLD |
|
761 |
"return the signal number for SIGCHLD - 0 if not supported |
|
762 |
(the numeric value is not the same across unix-systems)" |
|
763 |
||
764 |
%{ /* NOCONTEXT */ |
|
765 |
#if defined(SIGCHLD) |
|
710 | 766 |
RETURN ( _MKSMALLINT(SIGCHLD) ); |
616 | 767 |
#else |
768 |
# if defined(SIGCLD) |
|
710 | 769 |
RETURN ( _MKSMALLINT(SIGCLD) ); |
616 | 770 |
# else |
710 | 771 |
RETURN ( _MKSMALLINT(0) ); |
616 | 772 |
# endif |
773 |
#endif |
|
774 |
%} |
|
775 |
! |
|
776 |
||
777 |
sigCONT |
|
778 |
"return the signal number for SIGCONT - 0 if not supported |
|
779 |
(the numeric value is not the same across unix-systems)" |
|
780 |
||
781 |
%{ /* NOCONTEXT */ |
|
782 |
#if defined(SIGCONT) |
|
710 | 783 |
RETURN ( _MKSMALLINT(SIGCONT) ); |
616 | 784 |
#else |
710 | 785 |
RETURN ( _MKSMALLINT(0) ); |
616 | 786 |
#endif |
787 |
%} |
|
788 |
! |
|
789 |
||
790 |
sigDANGER |
|
791 |
"return the signal number for SIGDANGER - 0 if not supported |
|
792 |
(seems to be an AIX special)" |
|
793 |
||
794 |
%{ /* NOCONTEXT */ |
|
710 | 795 |
#if defined(SIGDANGER) |
796 |
RETURN ( _MKSMALLINT(SIGDANGER) ); |
|
616 | 797 |
#else |
710 | 798 |
RETURN ( _MKSMALLINT(0) ); |
616 | 799 |
#endif |
800 |
%} |
|
801 |
! |
|
802 |
||
803 |
sigEMT |
|
804 |
"return the signal number for SIGEMT - 0 if not supported by OS |
|
805 |
(the numeric value is not the same across unix-systems)" |
|
806 |
||
807 |
%{ /* NOCONTEXT */ |
|
808 |
#ifdef SIGEMT |
|
710 | 809 |
RETURN ( _MKSMALLINT(SIGEMT) ); |
616 | 810 |
#else |
710 | 811 |
RETURN ( _MKSMALLINT(0) ); |
616 | 812 |
#endif |
813 |
%} |
|
814 |
! |
|
815 |
||
816 |
sigFP |
|
817 |
"return the signal number for SIGFP - 0 if not supported by OS |
|
818 |
(the numeric value is not the same across unix-systems)" |
|
819 |
||
820 |
%{ /* NOCONTEXT */ |
|
821 |
#ifdef SIGFPE |
|
710 | 822 |
RETURN ( _MKSMALLINT(SIGFPE) ); |
616 | 823 |
#else |
710 | 824 |
RETURN ( _MKSMALLINT(0) ); |
616 | 825 |
#endif |
826 |
%} |
|
827 |
! |
|
828 |
||
829 |
sigGRANT |
|
830 |
"return the signal number for SIGGRANT - 0 if not supported |
|
831 |
(seems to be an AIX special)" |
|
832 |
||
833 |
%{ /* NOCONTEXT */ |
|
834 |
#if defined(SIGGRANT) |
|
710 | 835 |
RETURN ( _MKSMALLINT(SIGGRANT) ); |
616 | 836 |
#else |
710 | 837 |
RETURN ( _MKSMALLINT(0) ); |
616 | 838 |
#endif |
839 |
%} |
|
840 |
! |
|
841 |
||
842 |
sigHUP |
|
843 |
"return the signal number for SIGHUP |
|
844 |
(the numeric value is not the same across unix-systems)" |
|
845 |
||
846 |
%{ /* NOCONTEXT */ |
|
847 |
#ifdef SIGHUP |
|
710 | 848 |
RETURN ( _MKSMALLINT(SIGHUP) ); |
616 | 849 |
#else |
710 | 850 |
RETURN ( _MKSMALLINT(0) ); |
616 | 851 |
#endif |
852 |
%} |
|
853 |
! |
|
854 |
||
855 |
sigILL |
|
856 |
"return the signal number for SIGILL - 0 if not supported by OS |
|
857 |
(the numeric value is not the same across unix-systems)" |
|
858 |
||
859 |
%{ /* NOCONTEXT */ |
|
860 |
#ifdef SIGILL |
|
710 | 861 |
RETURN ( _MKSMALLINT(SIGILL) ); |
616 | 862 |
#else |
710 | 863 |
RETURN ( _MKSMALLINT(0) ); |
616 | 864 |
#endif |
865 |
%} |
|
866 |
! |
|
867 |
||
868 |
sigINT |
|
869 |
"return the signal number for SIGINT |
|
870 |
(the numeric value is not the same across unix-systems)" |
|
871 |
||
872 |
%{ /* NOCONTEXT */ |
|
873 |
#ifdef SIGINT |
|
710 | 874 |
RETURN ( _MKSMALLINT(SIGINT) ); |
616 | 875 |
#else |
710 | 876 |
RETURN ( _MKSMALLINT(0) ); |
616 | 877 |
#endif |
878 |
%} |
|
879 |
! |
|
880 |
||
881 |
sigIO |
|
882 |
"return the signal number for SIGIO - 0 if not supported |
|
883 |
(the numeric value is not the same across unix-systems)" |
|
884 |
||
885 |
%{ /* NOCONTEXT */ |
|
886 |
#if defined(SIGIO) |
|
710 | 887 |
RETURN ( _MKSMALLINT(SIGIO) ); |
616 | 888 |
#else |
710 | 889 |
RETURN ( _MKSMALLINT(0) ); |
616 | 890 |
#endif |
891 |
%} |
|
892 |
! |
|
893 |
||
894 |
sigIOT |
|
895 |
"return the signal number for SIGIOT - 0 if not supported by OS |
|
896 |
(the numeric value is not the same across unix-systems)" |
|
897 |
||
898 |
%{ /* NOCONTEXT */ |
|
899 |
#ifdef SIGIOT |
|
710 | 900 |
RETURN ( _MKSMALLINT(SIGIOT) ); |
616 | 901 |
#else |
710 | 902 |
RETURN ( _MKSMALLINT(0) ); |
616 | 903 |
#endif |
904 |
%} |
|
905 |
! |
|
906 |
||
907 |
sigKILL |
|
908 |
"return the signal number for SIGKILL |
|
909 |
(the numeric value is not the same across unix-systems)" |
|
910 |
||
911 |
%{ /* NOCONTEXT */ |
|
912 |
#ifdef SIGKILL |
|
710 | 913 |
RETURN ( _MKSMALLINT(SIGKILL) ); |
616 | 914 |
#else |
710 | 915 |
RETURN ( _MKSMALLINT(0) ); |
616 | 916 |
#endif |
917 |
%} |
|
918 |
! |
|
919 |
||
920 |
sigLOST |
|
921 |
"return the signal number for SIGLOST - 0 if not supported |
|
922 |
(the numeric value is not the same across unix-systems)" |
|
923 |
||
924 |
%{ /* NOCONTEXT */ |
|
925 |
#if defined(SIGLOST) |
|
710 | 926 |
RETURN ( _MKSMALLINT(SIGLOST) ); |
616 | 927 |
#else |
710 | 928 |
RETURN ( _MKSMALLINT(0) ); |
616 | 929 |
#endif |
930 |
%} |
|
931 |
! |
|
932 |
||
933 |
sigMIGRATE |
|
934 |
"return the signal number for SIGMIGRATE - 0 if not supported |
|
935 |
(seems to be an AIX special)" |
|
936 |
||
937 |
%{ /* NOCONTEXT */ |
|
938 |
#if defined(SIGMIGRATE) |
|
710 | 939 |
RETURN ( _MKSMALLINT(SIGMIGRATE) ); |
616 | 940 |
#else |
710 | 941 |
RETURN ( _MKSMALLINT(0) ); |
616 | 942 |
#endif |
943 |
%} |
|
944 |
! |
|
945 |
||
946 |
sigMSG |
|
947 |
"return the signal number for SIGMSG - 0 if not supported |
|
948 |
(seems to be an AIX special)" |
|
949 |
||
950 |
%{ /* NOCONTEXT */ |
|
951 |
#if defined(SIGMSG) |
|
710 | 952 |
RETURN ( _MKSMALLINT(SIGMSG) ); |
616 | 953 |
#else |
710 | 954 |
RETURN ( _MKSMALLINT(0) ); |
616 | 955 |
#endif |
956 |
%} |
|
957 |
! |
|
958 |
||
959 |
sigPIPE |
|
960 |
"return the signal number for SIGPIPE - 0 if not supported |
|
961 |
(the numeric value is not the same across unix-systems)" |
|
962 |
||
963 |
%{ /* NOCONTEXT */ |
|
964 |
#ifdef SIGPIPE |
|
710 | 965 |
RETURN ( _MKSMALLINT(SIGPIPE) ); |
616 | 966 |
#else |
710 | 967 |
RETURN ( _MKSMALLINT(0) ); |
616 | 968 |
#endif |
969 |
%} |
|
970 |
! |
|
971 |
||
972 |
sigPOLL |
|
973 |
"return the signal number for SIGPOLL - 0 if not supported |
|
974 |
(the numeric value is not the same across unix-systems)" |
|
975 |
||
976 |
%{ /* NOCONTEXT */ |
|
977 |
#if defined(SIGPOLL) |
|
710 | 978 |
RETURN ( _MKSMALLINT(SIGPOLL) ); |
616 | 979 |
#else |
710 | 980 |
RETURN ( _MKSMALLINT(0) ); |
616 | 981 |
#endif |
982 |
%} |
|
983 |
! |
|
984 |
||
985 |
sigPRE |
|
986 |
"return the signal number for SIGPRE - 0 if not supported |
|
987 |
(seems to be an AIX special)" |
|
988 |
||
989 |
%{ /* NOCONTEXT */ |
|
990 |
#if defined(SIGPRE) |
|
710 | 991 |
RETURN ( _MKSMALLINT(SIGPRE) ); |
616 | 992 |
#else |
710 | 993 |
RETURN ( _MKSMALLINT(0) ); |
616 | 994 |
#endif |
995 |
%} |
|
996 |
! |
|
997 |
||
998 |
sigPROF |
|
999 |
"return the signal number for SIGPROF - 0 if not supported |
|
1000 |
(the numeric value is not the same across unix-systems)" |
|
1001 |
||
1002 |
%{ /* NOCONTEXT */ |
|
1003 |
#if defined(SIGPROF) |
|
710 | 1004 |
RETURN ( _MKSMALLINT(SIGPROF) ); |
616 | 1005 |
#else |
710 | 1006 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1007 |
#endif |
1008 |
%} |
|
1009 |
! |
|
1010 |
||
1011 |
sigPWR |
|
1012 |
"return the signal number for SIGPWR - 0 if not supported |
|
1013 |
(not available on all systems)" |
|
1014 |
||
1015 |
%{ /* NOCONTEXT */ |
|
1016 |
#if defined(SIGPWR) |
|
710 | 1017 |
RETURN ( _MKSMALLINT(SIGPWR) ); |
616 | 1018 |
#else |
710 | 1019 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1020 |
#endif |
1021 |
%} |
|
1022 |
! |
|
1023 |
||
1024 |
sigQUIT |
|
1025 |
"return the signal number for SIGQUIT |
|
1026 |
(the numeric value is not the same across unix-systems)" |
|
1027 |
||
1028 |
%{ /* NOCONTEXT */ |
|
1029 |
#ifdef SIGQUIT |
|
710 | 1030 |
RETURN ( _MKSMALLINT(SIGQUIT) ); |
616 | 1031 |
#else |
710 | 1032 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1033 |
#endif |
1034 |
%} |
|
1035 |
! |
|
1036 |
||
1037 |
sigRETRACT |
|
1038 |
"return the signal number for SIGRETRACT - 0 if not supported |
|
1039 |
(seems to be an AIX special)" |
|
1040 |
||
1041 |
%{ /* NOCONTEXT */ |
|
1042 |
#if defined(SIGRETRACT) |
|
710 | 1043 |
RETURN ( _MKSMALLINT(SIGRETRACT) ); |
616 | 1044 |
#else |
710 | 1045 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1046 |
#endif |
1047 |
%} |
|
1048 |
! |
|
1049 |
||
1050 |
sigSAK |
|
1051 |
"return the signal number for SIGSAK - 0 if not supported |
|
1052 |
(seems to be an AIX special)" |
|
1053 |
||
1054 |
%{ /* NOCONTEXT */ |
|
1055 |
#if defined(SIGSAK) |
|
710 | 1056 |
RETURN ( _MKSMALLINT(SIGSAK) ); |
616 | 1057 |
#else |
710 | 1058 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1059 |
#endif |
1060 |
%} |
|
1061 |
! |
|
1062 |
||
1063 |
sigSEGV |
|
1064 |
"return the signal number for SIGSEGV - 0 if not supported |
|
1065 |
(the numeric value is not the same across unix-systems)" |
|
1066 |
||
1067 |
%{ /* NOCONTEXT */ |
|
1068 |
#ifdef SIGSEGV |
|
710 | 1069 |
RETURN ( _MKSMALLINT(SIGSEGV) ); |
616 | 1070 |
#else |
710 | 1071 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1072 |
#endif |
1073 |
%} |
|
1074 |
! |
|
1075 |
||
1076 |
sigSOUND |
|
1077 |
"return the signal number for SIGSOUND - 0 if not supported |
|
1078 |
(seems to be an AIX special)" |
|
1079 |
||
1080 |
%{ /* NOCONTEXT */ |
|
1081 |
#if defined(SIGSOUND) |
|
710 | 1082 |
RETURN ( _MKSMALLINT(SIGSOUND) ); |
616 | 1083 |
#else |
710 | 1084 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1085 |
#endif |
1086 |
%} |
|
1087 |
! |
|
1088 |
||
1089 |
sigSTOP |
|
1090 |
"return the signal number for SIGSTOP - 0 if not supported |
|
1091 |
(the numeric value is not the same across unix-systems)" |
|
1092 |
||
1093 |
%{ /* NOCONTEXT */ |
|
1094 |
#if defined(SIGSTOP) |
|
710 | 1095 |
RETURN ( _MKSMALLINT(SIGSTOP) ); |
616 | 1096 |
#else |
710 | 1097 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1098 |
#endif |
1099 |
%} |
|
1100 |
! |
|
1101 |
||
1102 |
sigSYS |
|
1103 |
"return the signal number for SIGSYS - 0 if not supported |
|
1104 |
(the numeric value is not the same across unix-systems)" |
|
1105 |
||
1106 |
%{ /* NOCONTEXT */ |
|
1107 |
#ifdef SIGSYS |
|
710 | 1108 |
RETURN ( _MKSMALLINT(SIGSYS) ); |
616 | 1109 |
#else |
710 | 1110 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1111 |
#endif |
1112 |
%} |
|
1113 |
! |
|
1114 |
||
1115 |
sigTERM |
|
1116 |
"return the signal number for SIGTERM - 0 if not supported |
|
1117 |
(the numeric value is not the same across unix-systems)" |
|
1118 |
||
1119 |
%{ /* NOCONTEXT */ |
|
1120 |
#ifdef SIGTERM |
|
710 | 1121 |
RETURN ( _MKSMALLINT(SIGTERM) ); |
616 | 1122 |
#else |
710 | 1123 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1124 |
#endif |
1125 |
%} |
|
1126 |
! |
|
1127 |
||
1128 |
sigTRAP |
|
1129 |
"return the signal number for SIGTRAP - 0 if not supported by OS |
|
1130 |
(the numeric value is not the same across unix-systems)" |
|
1131 |
||
1132 |
%{ /* NOCONTEXT */ |
|
1133 |
#ifdef SIGTRAP |
|
710 | 1134 |
RETURN ( _MKSMALLINT(SIGTRAP) ); |
616 | 1135 |
#else |
710 | 1136 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1137 |
#endif |
1138 |
%} |
|
1139 |
! |
|
1140 |
||
1141 |
sigTSTP |
|
1142 |
"return the signal number for SIGTSTP - 0 if not supported |
|
1143 |
(the numeric value is not the same across unix-systems)" |
|
1144 |
||
1145 |
%{ /* NOCONTEXT */ |
|
1146 |
#if defined(SIGTSTP) |
|
710 | 1147 |
RETURN ( _MKSMALLINT(SIGTSTP) ); |
616 | 1148 |
#else |
710 | 1149 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1150 |
#endif |
1151 |
%} |
|
1152 |
! |
|
1153 |
||
1154 |
sigTTIN |
|
1155 |
"return the signal number for SIGTTIN - 0 if not supported |
|
1156 |
(the numeric value is not the same across unix-systems)" |
|
1157 |
||
1158 |
%{ /* NOCONTEXT */ |
|
1159 |
#if defined(SIGTTIN) |
|
710 | 1160 |
RETURN ( _MKSMALLINT(SIGTTIN) ); |
616 | 1161 |
#else |
710 | 1162 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1163 |
#endif |
1164 |
%} |
|
1165 |
! |
|
1166 |
||
1167 |
sigTTOU |
|
1168 |
"return the signal number for SIGTTOU - 0 if not supported |
|
1169 |
(the numeric value is not the same across unix-systems)" |
|
1170 |
||
1171 |
%{ /* NOCONTEXT */ |
|
1172 |
#if defined(SIGTTOU) |
|
710 | 1173 |
RETURN ( _MKSMALLINT(SIGTTOU) ); |
616 | 1174 |
#else |
710 | 1175 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1176 |
#endif |
1177 |
%} |
|
1178 |
! |
|
1179 |
||
1180 |
sigURG |
|
1181 |
"return the signal number for SIGURG - 0 if not supported |
|
1182 |
(the numeric value is not the same across unix-systems)" |
|
1183 |
||
1184 |
%{ /* NOCONTEXT */ |
|
1185 |
#if defined(SIGURG) |
|
710 | 1186 |
RETURN ( _MKSMALLINT(SIGURG) ); |
616 | 1187 |
#else |
710 | 1188 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1189 |
#endif |
1190 |
%} |
|
1191 |
! |
|
1192 |
||
1193 |
sigUSR1 |
|
1194 |
"return the signal number for SIGUSR1 - 0 if not supported |
|
1195 |
(the numeric value is not the same across unix-systems)" |
|
1196 |
||
1197 |
%{ /* NOCONTEXT */ |
|
1198 |
#if defined(SIGUSR1) |
|
710 | 1199 |
RETURN ( _MKSMALLINT(SIGUSR1) ); |
616 | 1200 |
#else |
710 | 1201 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1202 |
#endif |
1203 |
%} |
|
1204 |
! |
|
1205 |
||
1206 |
sigUSR2 |
|
1207 |
"return the signal number for SIGUSR2 - 0 if not supported |
|
1208 |
(the numeric value is not the same across unix-systems)" |
|
1209 |
||
1210 |
%{ /* NOCONTEXT */ |
|
1211 |
#if defined(SIGUSR2) |
|
710 | 1212 |
RETURN ( _MKSMALLINT(SIGUSR2) ); |
616 | 1213 |
#else |
710 | 1214 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1215 |
#endif |
1216 |
%} |
|
1217 |
! |
|
1218 |
||
1219 |
sigVTALRM |
|
1220 |
"return the signal number for SIGVTALRM - 0 if not supported |
|
1221 |
(the numeric value is not the same across unix-systems)" |
|
1222 |
||
1223 |
%{ /* NOCONTEXT */ |
|
1224 |
#if defined(SIGVTALRM) |
|
710 | 1225 |
RETURN ( _MKSMALLINT(SIGVTALRM) ); |
616 | 1226 |
#else |
710 | 1227 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1228 |
#endif |
1229 |
%} |
|
1230 |
! |
|
1231 |
||
1232 |
sigWINCH |
|
1233 |
"return the signal number for SIGWINCH - 0 if not supported |
|
1234 |
(the numeric value is not the same across unix-systems)" |
|
1235 |
||
1236 |
%{ /* NOCONTEXT */ |
|
1237 |
#if defined(SIGWINCH) |
|
710 | 1238 |
RETURN ( _MKSMALLINT(SIGWINCH) ); |
616 | 1239 |
#else |
710 | 1240 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1241 |
#endif |
1242 |
%} |
|
1243 |
! |
|
1244 |
||
1245 |
sigXCPU |
|
1246 |
"return the signal number for SIGXCPU - 0 if not supported |
|
1247 |
(the numeric value is not the same across unix-systems)" |
|
1248 |
||
1249 |
%{ /* NOCONTEXT */ |
|
1250 |
#if defined(SIGXCPU) |
|
710 | 1251 |
RETURN ( _MKSMALLINT(SIGXCPU) ); |
616 | 1252 |
#else |
710 | 1253 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1254 |
#endif |
1255 |
%} |
|
1256 |
! |
|
1257 |
||
1258 |
sigXFSZ |
|
1259 |
"return the signal number for SIGXFSZ - 0 if not supported |
|
1260 |
(the numeric value is not the same across unix-systems)" |
|
1261 |
||
1262 |
%{ /* NOCONTEXT */ |
|
1263 |
#if defined(SIGXFSZ) |
|
710 | 1264 |
RETURN ( _MKSMALLINT(SIGXFSZ) ); |
616 | 1265 |
#else |
710 | 1266 |
RETURN ( _MKSMALLINT(0) ); |
616 | 1267 |
#endif |
1268 |
%} |
|
1269 |
! ! |
|
1270 |
||
540
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1271 |
!OperatingSystem class methodsFor:'Signal constants'! |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1272 |
|
616 | 1273 |
accessDeniedErrorSignal |
1274 |
"return the signal raised when a (file-) access is denied." |
|
1275 |
||
1276 |
^ AccessDeniedErrorSignal |
|
1277 |
! |
|
1278 |
||
540
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1279 |
errorSignal |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1280 |
"return the OS signals parent signal." |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1281 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1282 |
^ ErrorSignal |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1283 |
! |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1284 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1285 |
fileNotFoundErrorSignal |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1286 |
"return the signal raised when a file was not found." |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1287 |
|
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1288 |
^ FileNotFoundErrorSignal |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1289 |
! ! |
c34cd0a2fd5f
OS signals added (more to come)
Claus Gittinger <cg@exept.de>
parents:
535
diff
changeset
|
1290 |
|
1 | 1291 |
!OperatingSystem class methodsFor:'error messages'! |
1292 |
||
85 | 1293 |
currentErrorNumber |
68 | 1294 |
"returns the OS's last error nr (i.e. the value of errno). |
1295 |
Notice, that the value of this flag is only valid immediately |
|
1296 |
after the error occurred - it gets updated with every other |
|
85 | 1297 |
request to the OS. |
1298 |
Use lastErrorNumber - currentErrorNumber is invalidated by |
|
1299 |
many, many internal calls." |
|
68 | 1300 |
|
1301 |
%{ /* NOCONTEXT */ |
|
1302 |
||
1303 |
RETURN ( _MKSMALLINT(errno) ); |
|
1304 |
%} |
|
1305 |
" |
|
85 | 1306 |
OperatingSystem currentErrorNumber |
1307 |
" |
|
1308 |
! |
|
1309 |
||
1 | 1310 |
errorTextForNumber:errNr |
1311 |
"return a message string from a unix errorNumber |
|
68 | 1312 |
(as returned by a system call). |
1313 |
Should be replaced by a resource lookup." |
|
1 | 1314 |
|
77 | 1315 |
%{ |
1316 |
/* claus: |
|
1317 |
* I made this some primitive code, since errnos are not |
|
1318 |
* standard across unixes |
|
1319 |
*/ |
|
1320 |
char *msg = "unknown error"; |
|
1321 |
char buffer[50]; |
|
1322 |
||
252 | 1323 |
if (__isSmallInteger(errNr)) { |
185 | 1324 |
switch (_intVal(errNr)) { |
1325 |
/* |
|
1326 |
* POSIX errnos - these should be defined |
|
1327 |
*/ |
|
443 | 1328 |
#ifdef EPERM |
185 | 1329 |
case EPERM: |
1330 |
msg = "Operation not permitted"; |
|
1331 |
break; |
|
443 | 1332 |
#endif |
1333 |
#ifdef ENOENT |
|
185 | 1334 |
case ENOENT: |
1335 |
msg = "No such file or directory"; |
|
1336 |
break; |
|
443 | 1337 |
#endif |
1338 |
#ifdef ESRCH |
|
185 | 1339 |
case ESRCH: |
1340 |
msg = "No such process"; |
|
1341 |
break; |
|
443 | 1342 |
#endif |
1343 |
#ifdef EINTR |
|
185 | 1344 |
case EINTR: |
1345 |
msg = "Interrupted system call"; |
|
1346 |
break; |
|
443 | 1347 |
#endif |
1348 |
#ifdef EIO |
|
185 | 1349 |
case EIO: |
1350 |
msg = "I/O error"; |
|
1351 |
break; |
|
443 | 1352 |
#endif |
1353 |
#ifdef ENXIO |
|
185 | 1354 |
case ENXIO: |
1355 |
msg = "No such device or address"; |
|
1356 |
break; |
|
443 | 1357 |
#endif |
1358 |
#ifdef E2BIG |
|
185 | 1359 |
case E2BIG: |
1360 |
msg = "Arg list too long"; |
|
1361 |
break; |
|
443 | 1362 |
#endif |
1363 |
#ifdef ENOEXEC |
|
185 | 1364 |
case ENOEXEC: |
1365 |
msg = "Exec format error"; |
|
1366 |
break; |
|
443 | 1367 |
#endif |
1368 |
#ifdef EBADF |
|
185 | 1369 |
case EBADF: |
1370 |
msg = "Bad file number"; |
|
1371 |
break; |
|
443 | 1372 |
#endif |
1373 |
#ifdef ECHILD |
|
185 | 1374 |
case ECHILD: |
1375 |
msg = "No child processes"; |
|
1376 |
break; |
|
443 | 1377 |
#endif |
77 | 1378 |
#if !defined(EWOULDBLOCK) && defined(EAGAIN) && (EWOULDBLOCK != EAGAIN) |
185 | 1379 |
case EAGAIN: |
1380 |
msg = "Try again"; |
|
1381 |
break; |
|
77 | 1382 |
#endif |
443 | 1383 |
#ifdef ENOMEM |
185 | 1384 |
case ENOMEM: |
1385 |
msg = "Out of memory"; |
|
1386 |
break; |
|
443 | 1387 |
#endif |
1388 |
#ifdef EACCES |
|
185 | 1389 |
case EACCES: |
1390 |
msg = "Permission denied"; |
|
1391 |
break; |
|
443 | 1392 |
#endif |
1393 |
#ifdef EFAULT |
|
185 | 1394 |
case EFAULT: |
1395 |
msg = "Bad address"; |
|
1396 |
break; |
|
443 | 1397 |
#endif |
1398 |
#ifdef EBUSY |
|
185 | 1399 |
case EBUSY: |
1400 |
msg = "Device or resource busy"; |
|
1401 |
break; |
|
443 | 1402 |
#endif |
1403 |
#ifdef EEXIST |
|
185 | 1404 |
case EEXIST: |
1405 |
msg = "File exists"; |
|
1406 |
break; |
|
443 | 1407 |
#endif |
1408 |
#ifdef EXDEV |
|
185 | 1409 |
case EXDEV: |
1410 |
msg = "Cross-device link"; |
|
1411 |
break; |
|
443 | 1412 |
#endif |
1413 |
#ifdef ENODEV |
|
185 | 1414 |
case ENODEV: |
1415 |
msg = "No such device"; |
|
1416 |
break; |
|
443 | 1417 |
#endif |
1418 |
#ifdef ENOTDIR |
|
185 | 1419 |
case ENOTDIR: |
1420 |
msg = "Not a directory"; |
|
1421 |
break; |
|
443 | 1422 |
#endif |
1423 |
#ifdef EISDIR |
|
185 | 1424 |
case EISDIR: |
1425 |
msg = "Is a directory"; |
|
1426 |
break; |
|
443 | 1427 |
#endif |
1428 |
#ifdef EINVAL |
|
185 | 1429 |
case EINVAL: |
1430 |
msg = "Invalid argument"; |
|
1431 |
break; |
|
443 | 1432 |
#endif |
1433 |
#ifdef ENFILE |
|
185 | 1434 |
case ENFILE: |
1435 |
msg = "File table overflow"; |
|
1436 |
break; |
|
443 | 1437 |
#endif |
1438 |
#ifdef EMFILE |
|
185 | 1439 |
case EMFILE: |
1440 |
msg = "Too many open files"; |
|
1441 |
break; |
|
443 | 1442 |
#endif |
1443 |
#ifdef ENOTTY |
|
185 | 1444 |
case ENOTTY: |
1445 |
msg = "Not a typewriter"; |
|
1446 |
break; |
|
443 | 1447 |
#endif |
1448 |
#ifdef EFBIG |
|
185 | 1449 |
case EFBIG: |
1450 |
msg = "File too large"; |
|
1451 |
break; |
|
443 | 1452 |
#endif |
1453 |
#ifdef ENOSPC |
|
185 | 1454 |
case ENOSPC: |
1455 |
msg = "No space left on device"; |
|
1456 |
break; |
|
443 | 1457 |
#endif |
1458 |
#ifdef ESPIPE |
|
185 | 1459 |
case ESPIPE: |
1460 |
msg = "Illegal seek"; |
|
1461 |
break; |
|
443 | 1462 |
#endif |
1463 |
#ifdef EROFS |
|
185 | 1464 |
case EROFS: |
1465 |
msg = "Read-only file system"; |
|
1466 |
break; |
|
443 | 1467 |
#endif |
1468 |
#ifdef EMLINK |
|
185 | 1469 |
case EMLINK: |
1470 |
msg = "Too many links"; |
|
1471 |
break; |
|
443 | 1472 |
#endif |
1473 |
#ifdef EPIPE |
|
185 | 1474 |
case EPIPE: |
1475 |
msg = "Broken pipe"; |
|
1476 |
break; |
|
443 | 1477 |
#endif |
1478 |
#ifdef EDOM |
|
185 | 1479 |
case EDOM: |
1480 |
msg = "Math argument out of domain"; |
|
1481 |
break; |
|
443 | 1482 |
#endif |
1483 |
#ifdef ERANGE |
|
185 | 1484 |
case ERANGE: |
1485 |
msg = "Math result not representable"; |
|
1486 |
break; |
|
443 | 1487 |
#endif |
77 | 1488 |
#ifdef EDEADLK |
308 | 1489 |
# if EDEADLK != EWOULDBLOCK |
185 | 1490 |
case EDEADLK: |
1491 |
msg = "Resource deadlock would occur"; |
|
1492 |
break; |
|
308 | 1493 |
# endif |
77 | 1494 |
#endif |
1495 |
#ifdef ENAMETOOLONG |
|
185 | 1496 |
case ENAMETOOLONG: |
1497 |
msg = "File name too long"; |
|
1498 |
break; |
|
77 | 1499 |
#endif |
1500 |
#ifdef ENOLCK |
|
185 | 1501 |
case ENOLCK: |
1502 |
msg = "No record locks available"; |
|
1503 |
break; |
|
77 | 1504 |
#endif |
1505 |
#ifdef ENOSYS |
|
185 | 1506 |
case ENOSYS: |
1507 |
msg = "Function not implemented"; |
|
1508 |
break; |
|
77 | 1509 |
#endif |
359 | 1510 |
#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST) |
185 | 1511 |
case ENOTEMPTY: |
1512 |
msg = "Directory not empty"; |
|
1513 |
break; |
|
77 | 1514 |
#endif |
1515 |
#ifdef EILSEQ |
|
185 | 1516 |
case EILSEQ: |
1517 |
msg = "Illegal byte sequence"; |
|
1518 |
break; |
|
77 | 1519 |
#endif |
185 | 1520 |
/* |
1521 |
* XPG3 errnos - defined on most systems |
|
1522 |
*/ |
|
77 | 1523 |
#ifdef ENOTBLK |
185 | 1524 |
case ENOTBLK: |
1525 |
msg = "Block device required"; |
|
1526 |
break; |
|
77 | 1527 |
#endif |
1528 |
#ifdef ETXTBSY |
|
185 | 1529 |
case ETXTBSY: |
1530 |
msg = "Text file busy"; |
|
1531 |
break; |
|
77 | 1532 |
#endif |
185 | 1533 |
/* |
1534 |
* some others |
|
1535 |
*/ |
|
77 | 1536 |
#ifdef EWOULDBLOCK |
185 | 1537 |
case EWOULDBLOCK: |
1538 |
msg = "Operation would block"; |
|
1539 |
break; |
|
77 | 1540 |
#endif |
1541 |
#ifdef ENOMSG |
|
185 | 1542 |
case ENOMSG: |
1543 |
msg = "No message of desired type"; |
|
1544 |
break; |
|
77 | 1545 |
#endif |
1546 |
#ifdef ELOOP |
|
185 | 1547 |
case ELOOP: |
1548 |
msg = "Too many levels of symbolic links"; |
|
1549 |
break; |
|
77 | 1550 |
#endif |
1551 |
||
185 | 1552 |
/* |
1553 |
* some stream errors |
|
1554 |
*/ |
|
77 | 1555 |
#ifdef ETIME |
185 | 1556 |
case ETIME: |
1557 |
msg = "Timer expired"; |
|
1558 |
break; |
|
77 | 1559 |
#endif |
1560 |
#ifdef ENOSR |
|
185 | 1561 |
case ENOSR: |
1562 |
msg = "Out of streams resources"; |
|
1563 |
break; |
|
77 | 1564 |
#endif |
1565 |
#ifdef ENOSTR |
|
185 | 1566 |
case ENOSTR: |
1567 |
msg = "Device not a stream"; |
|
1568 |
break; |
|
77 | 1569 |
#endif |
1570 |
#ifdef ECOMM |
|
185 | 1571 |
case ECOMM: |
1572 |
msg = "Communication error on send"; |
|
1573 |
break; |
|
77 | 1574 |
#endif |
1575 |
#ifdef EPROTO |
|
185 | 1576 |
case EPROTO: |
1577 |
msg = "Protocol error"; |
|
1578 |
break; |
|
77 | 1579 |
#endif |
185 | 1580 |
/* |
1581 |
* nfs errors |
|
1582 |
*/ |
|
77 | 1583 |
#ifdef ESTALE |
185 | 1584 |
case ESTALE: |
1585 |
msg = "Stale NFS file handle"; |
|
1586 |
break; |
|
77 | 1587 |
#endif |
1588 |
#ifdef EREMOTE |
|
185 | 1589 |
case EREMOTE: |
1590 |
msg = "Too many levels of remote in path"; |
|
1591 |
break; |
|
77 | 1592 |
#endif |
185 | 1593 |
/* |
1594 |
* some networking errors |
|
1595 |
*/ |
|
77 | 1596 |
#ifdef EINPROGRESS |
185 | 1597 |
case EINPROGRESS: |
1598 |
msg = "Operation now in progress"; |
|
1599 |
break; |
|
77 | 1600 |
#endif |
1601 |
#ifdef EALREADY |
|
185 | 1602 |
case EALREADY: |
1603 |
msg = "Operation already in progress"; |
|
1604 |
break; |
|
77 | 1605 |
#endif |
1606 |
#ifdef ENOTSOCK |
|
185 | 1607 |
case ENOTSOCK: |
1608 |
msg = "Socket operation on non-socket"; |
|
1609 |
break; |
|
77 | 1610 |
#endif |
1611 |
#ifdef EDESTADDRREQ |
|
185 | 1612 |
case EDESTADDRREQ: |
1613 |
msg = "Destination address required"; |
|
1614 |
break; |
|
77 | 1615 |
#endif |
1616 |
#ifdef EMSGSIZE |
|
185 | 1617 |
case EMSGSIZE: |
1618 |
msg = "Message too long"; |
|
1619 |
break; |
|
77 | 1620 |
#endif |
1621 |
#ifdef EPROTOTYPE |
|
185 | 1622 |
case EPROTOTYPE: |
1623 |
msg = "Protocol wrong type for socket"; |
|
1624 |
break; |
|
77 | 1625 |
#endif |
1626 |
#ifdef ENOPROTOOPT |
|
185 | 1627 |
case ENOPROTOOPT: |
1628 |
msg = "Protocol not available"; |
|
1629 |
break; |
|
77 | 1630 |
#endif |
1631 |
#ifdef EPROTONOSUPPORT |
|
185 | 1632 |
case EPROTONOSUPPORT: |
1633 |
msg = "Protocol not supported"; |
|
1634 |
break; |
|
77 | 1635 |
#endif |
1636 |
#ifdef ESOCKTNOSUPPORT |
|
185 | 1637 |
case ESOCKTNOSUPPORT: |
1638 |
msg = "Socket type not supported"; |
|
1639 |
break; |
|
77 | 1640 |
#endif |
1641 |
#ifdef EOPNOTSUPP |
|
185 | 1642 |
case EOPNOTSUPP: |
1643 |
msg = "Operation not supported on socket"; |
|
1644 |
break; |
|
77 | 1645 |
#endif |
1646 |
#ifdef EPFNOSUPPORT |
|
185 | 1647 |
case EPFNOSUPPORT: |
1648 |
msg = "Protocol family not supported"; |
|
1649 |
break; |
|
77 | 1650 |
#endif |
1651 |
#ifdef EAFNOSUPPORT |
|
185 | 1652 |
case EAFNOSUPPORT: |
1653 |
msg = "Address family not supported by protocol family"; |
|
1654 |
break; |
|
77 | 1655 |
#endif |
1656 |
#ifdef EADDRINUSE |
|
185 | 1657 |
case EADDRINUSE: |
1658 |
msg = "Address already in use"; |
|
1659 |
break; |
|
77 | 1660 |
#endif |
1661 |
#ifdef EADDRNOTAVAIL |
|
185 | 1662 |
case EADDRNOTAVAIL: |
1663 |
msg = "Can\'t assign requested address"; |
|
1664 |
break; |
|
77 | 1665 |
#endif |
1666 |
#ifdef ETIMEDOUT |
|
185 | 1667 |
case ETIMEDOUT: |
1668 |
msg = "Connection timed out"; |
|
1669 |
break; |
|
77 | 1670 |
#endif |
1671 |
#ifdef ECONNREFUSED |
|
185 | 1672 |
case ECONNREFUSED: |
1673 |
msg = "Connection refused"; |
|
1674 |
break; |
|
77 | 1675 |
#endif |
362 | 1676 |
#ifdef ENETDOWN |
1677 |
case ENETDOWN: |
|
1678 |
msg = "Network is down"; |
|
1679 |
break; |
|
1680 |
#endif |
|
1681 |
#ifdef ENETUNREACH |
|
1682 |
case ENETUNREACH: |
|
1683 |
msg = "Network is unreachable"; |
|
1684 |
break; |
|
1685 |
#endif |
|
1686 |
#ifdef ENETRESET |
|
1687 |
case ENETRESET: |
|
1688 |
msg = "Network dropped conn due to reset"; |
|
1689 |
break; |
|
1690 |
#endif |
|
1691 |
#ifdef ECONNABORTED |
|
1692 |
case ECONNABORTED: |
|
1693 |
msg = "Software caused connection abort"; |
|
1694 |
break; |
|
1695 |
#endif |
|
1696 |
#ifdef ECONNRESET |
|
1697 |
case ECONNRESET: |
|
1698 |
msg = "Connection reset by peer"; |
|
1699 |
break; |
|
1700 |
#endif |
|
1701 |
#ifdef EISCONN |
|
1702 |
case EISCONN: |
|
1703 |
msg = "Socket is already connected"; |
|
1704 |
break; |
|
1705 |
#endif |
|
1706 |
#ifdef ENOTCONN |
|
1707 |
case ENOTCONN: |
|
1708 |
msg = "Socket is not connected"; |
|
1709 |
break; |
|
1710 |
#endif |
|
1711 |
#ifdef ESHUTDOWN |
|
1712 |
case ESHUTDOWN: |
|
1713 |
msg = "Can't send after socket shutdown"; |
|
1714 |
break; |
|
1715 |
#endif |
|
1716 |
#ifdef EHOSTDOWN |
|
1717 |
case EHOSTDOWN: |
|
1718 |
msg = "Host is down"; |
|
1719 |
break; |
|
1720 |
#endif |
|
1721 |
#ifdef EHOSTUNREACH |
|
1722 |
case EHOSTUNREACH: |
|
1723 |
msg = "No route to host"; |
|
1724 |
break; |
|
1725 |
#endif |
|
1726 |
||
185 | 1727 |
default: |
368 | 1728 |
{ |
1729 |
#ifdef THISCONTEXT_IN_REGISTER |
|
1730 |
extern OBJ __thisContext__; |
|
1731 |
__thisContext__ = __thisContext; |
|
1732 |
#endif |
|
1733 |
sprintf(buffer, "ErrorNr: %d", _intVal(errNr)); |
|
1734 |
#ifdef THISCONTEXT_IN_REGISTER |
|
1735 |
__thisContext = __thisContext__; |
|
1736 |
__thisContext__ = nil; |
|
1737 |
#endif |
|
1738 |
} |
|
185 | 1739 |
msg = buffer; |
1740 |
break; |
|
1741 |
} |
|
77 | 1742 |
} |
1743 |
RETURN (_MKSTRING(msg COMMA_CON)); |
|
1744 |
%} |
|
616 | 1745 |
! |
1746 |
||
1747 |
lastErrorNumber |
|
1748 |
"return the last error number" |
|
1749 |
||
1750 |
^ LastErrorNumber |
|
1751 |
||
1752 |
" |
|
1753 |
OperatingSystem lastErrorNumber |
|
1754 |
" |
|
1755 |
! |
|
1756 |
||
1757 |
lastErrorString |
|
1758 |
"return a message string describing the last error" |
|
1759 |
||
1760 |
^ self errorTextForNumber:LastErrorNumber |
|
1761 |
||
1762 |
" |
|
1763 |
OperatingSystem lastErrorString |
|
1764 |
" |
|
1765 |
! |
|
1766 |
||
1767 |
lastExecStatus |
|
1768 |
"return the last execution status" |
|
1769 |
||
1770 |
^ LastExecStatus |
|
1771 |
||
1772 |
" |
|
1773 |
OperatingSystem lastExecStatus |
|
1774 |
" |
|
1 | 1775 |
! ! |
1776 |
||
616 | 1777 |
!OperatingSystem class methodsFor:'executing commands'! |
1778 |
||
1779 |
canExecuteCommand:aCommandString |
|
1780 |
"return true, if the OS can execute aCommand." |
|
1781 |
||
1782 |
|cmd| |
|
1783 |
||
1784 |
cmd := aCommandString asCollectionOfWords first. |
|
1785 |
^ (self pathOfCommand:cmd) notNil |
|
1786 |
||
1787 |
" |
|
1788 |
OperatingSystem canExecuteCommand:'fooBar' |
|
1789 |
OperatingSystem canExecuteCommand:'ls' |
|
1790 |
OperatingSystem canExecuteCommand:'cvs' |
|
1791 |
" |
|
1792 |
||
1793 |
"Created: 4.11.1995 / 19:13:54 / cg" |
|
68 | 1794 |
! |
1795 |
||
616 | 1796 |
exec:aPath withArguments:argArray |
1797 |
"execute the unix command specified by the argument, aPath, with |
|
1798 |
arguments in argArray (no arguments, if nil). |
|
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1799 |
If successful, this method does NOT return and smalltalk is gone. |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1800 |
If not successful, false is returned. Can be used with fork or to transfer |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1801 |
to another program." |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1802 |
|
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1803 |
self exec:aPath withArguments:argArray fork:false |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1804 |
! |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1805 |
|
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1806 |
exec:aPath withArguments:argArray fork:doFork |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1807 |
"Internal combined fork & exec; |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1808 |
If fork is false: |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1809 |
execute the unix command specified by the argument, aPath, with |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1810 |
arguments in argArray (no arguments, if nil). |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1811 |
If successful, this method does not return and smalltalk is gone. |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1812 |
If not successful, false is returned. Normal use is with forkForCommand. |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1813 |
if its true: |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1814 |
for a child to do the above. |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1815 |
The id of the child process is returned. |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1816 |
|
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1817 |
Notice: this used to be two separate ST-methods; however, in order to use |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1818 |
vfork on some machines, it had to be merged into one, to avoid write |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1819 |
accesses to ST/X memory from the vforked-child. The code below only does |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1820 |
read accesses." |
616 | 1821 |
|
1822 |
%{ |
|
1823 |
char **argv; |
|
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1824 |
int nargs, i, id; |
616 | 1825 |
OBJ arg; |
1826 |
||
1827 |
if (__isString(aPath) && ((argArray == nil) || __isArray(argArray))) { |
|
1828 |
nargs = argArray == nil ? 0 : _arraySize(argArray); |
|
1829 |
argv = (char **) malloc(sizeof(char *) * (nargs + 1)); |
|
1830 |
if (argv) { |
|
1831 |
for (i=0; i < nargs; i++) { |
|
1832 |
arg = _ArrayInstPtr(argArray)->a_element[i]; |
|
1833 |
if (__isString(arg)) { |
|
674 | 1834 |
argv[i] = (char *) __stringVal(arg); |
1835 |
} else { |
|
1836 |
argv[i] = ""; |
|
616 | 1837 |
} |
1838 |
} |
|
1839 |
argv[i] = NULL; |
|
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1840 |
|
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1841 |
if (doFork == true) { |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1842 |
#ifdef HAS_VFORK |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1843 |
id = vfork(); |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1844 |
#else |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1845 |
id = fork(); |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1846 |
#endif |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1847 |
if (id == 0) { |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1848 |
execv(_stringVal(aPath), argv); |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1849 |
/* should not be reached */ |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1850 |
_exit(1); |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1851 |
} |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1852 |
free(argv); |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1853 |
RETURN (__MKSMALLINT(id)); |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1854 |
} else { |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1855 |
execv(_stringVal(aPath), argv); |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1856 |
/* |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1857 |
* should not be reached |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1858 |
* (well, it is, if you pass a wrong command-path) |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1859 |
*/ |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1860 |
free(argv); |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1861 |
RETURN ( false ); |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1862 |
} |
616 | 1863 |
} |
1864 |
} |
|
1865 |
%}. |
|
1866 |
" |
|
1867 |
path-argument not string or |
|
1868 |
argArray not an array/nil or |
|
1869 |
malloc failed |
|
1870 |
" |
|
1871 |
^ self primitiveFailed |
|
1872 |
||
1873 |
" |
|
1874 |
|id| |
|
1875 |
||
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1876 |
id := OperatingSystem fork. |
616 | 1877 |
id == 0 ifTrue:[ |
1878 |
"I am the child" |
|
1879 |
OperatingSystem exec:'/bin/ls' withArguments:#('ls' '/tmp'). |
|
1880 |
"not reached" |
|
1881 |
] |
|
1882 |
" |
|
670
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
1883 |
" |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
1884 |
|id| |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
1885 |
|
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1886 |
id := OperatingSystem fork. |
670
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
1887 |
id == 0 ifTrue:[ |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
1888 |
"I am the child" |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
1889 |
OperatingSystem exec:'/bin/sh' withArguments:#('sh' '-c' 'sleep 2;echo 1;sleep 2;echo 2'). |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
1890 |
"not reached" |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
1891 |
]. |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
1892 |
id printNL. |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
1893 |
(Delay forSeconds:3.5) wait. |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
1894 |
'killing ...' printNL. |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
1895 |
OperatingSystem sendSignal:(OperatingSystem sigTERM) to:id. |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
1896 |
OperatingSystem sendSignal:(OperatingSystem sigKILL) to:id |
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
1897 |
" |
616 | 1898 |
! |
1899 |
||
1900 |
executeCommand:aCommandString |
|
1901 |
"execute the unix command specified by the argument, aCommandString. |
|
676 | 1902 |
The commandString is passed to a shell for execution - see the description of |
1903 |
'sh -c' in your UNIX manual. |
|
616 | 1904 |
Return true if successful, false otherwise. |
1905 |
The return value of the system()-call is available in the variable |
|
1906 |
LastExecStatus (which is zero after successful execution); this value |
|
1907 |
consists of the reason for termination (0=normal) in the upper 8bits and, |
|
1908 |
iff it was a normal return, the value passed to exit() in the low 8bits." |
|
1909 |
%{ |
|
1910 |
int status; |
|
1911 |
||
1912 |
if (__isString(aCommandString)) { |
|
1913 |
/* |
|
1914 |
* ST/X provides a modified (fixed) implementation of the |
|
1915 |
* system() libc-function, which is interruptable ... |
|
1916 |
*/ |
|
1917 |
# ifdef WANT_SYSTEM |
|
1918 |
__BEGIN_INTERRUPTABLE__ |
|
1919 |
status = mySystem((char *) _stringVal(aCommandString)); |
|
1920 |
__END_INTERRUPTABLE__ |
|
1921 |
# else |
|
1922 |
status = system((char *) _stringVal(aCommandString)); |
|
1923 |
# endif |
|
1924 |
OperatingSystem_LastExecStatus = _MKSMALLINT(status); |
|
1925 |
if (status == 0) { |
|
1926 |
RETURN ( true ); |
|
1927 |
} |
|
1928 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
1929 |
RETURN ( false ); |
|
1930 |
} |
|
1931 |
%}. |
|
1932 |
self primitiveFailed |
|
1933 |
||
1934 |
" |
|
1935 |
OperatingSystem executeCommand:'pwd'. |
|
1936 |
OperatingSystem lastExecStatus printNL. |
|
1937 |
||
1938 |
OperatingSystem executeCommand:'ls -l'. |
|
1939 |
OperatingSystem lastExecStatus printNL. |
|
1940 |
||
1941 |
OperatingSystem executeCommand:'invalidCommand'. |
|
1942 |
(OperatingSystem lastExecStatus printStringRadix:16) printNL. |
|
1943 |
||
1944 |
OperatingSystem executeCommand:'rm /tmp/foofoofoofoo'. |
|
1945 |
(OperatingSystem lastExecStatus printStringRadix:16) printNL. |
|
1946 |
" |
|
1947 |
! |
|
1948 |
||
1949 |
fork |
|
1950 |
"fork a new (HEAVY-weight) unix process. |
|
1951 |
Dont confuse this with Block>>fork, which creates |
|
1952 |
lightweight smalltalk processes. This method will return |
|
676 | 1953 |
0 to the child process, and a non-zero number (which is the childs |
1954 |
unix-process-id) to the parent (original) process. |
|
764
eadba1b6a721
vfork interface (for poor BSD ultrix) - without it, it takes 20 seconds
Claus Gittinger <cg@exept.de>
parents:
763
diff
changeset
|
1955 |
|
676 | 1956 |
In normal situations, you dont need to use this low level entry; see |
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
1957 |
#startProcess: and #executCommand: for higher level interfaces." |
68 | 1958 |
|
1959 |
%{ /* NOCONTEXT */ |
|
616 | 1960 |
|
1961 |
int pid; |
|
1962 |
||
1963 |
pid = fork(); |
|
1964 |
RETURN ( _MKSMALLINT(pid) ); |
|
68 | 1965 |
%} |
616 | 1966 |
" |
1967 |
|id| |
|
1968 |
||
1969 |
id := OperatingSystem fork. |
|
1970 |
id == 0 ifTrue:[ |
|
1971 |
OperatingSystem exit |
|
1972 |
] |
|
1973 |
" |
|
68 | 1974 |
! |
1975 |
||
616 | 1976 |
pathOfCommand:aCommand |
1977 |
"find where aCommand's executable file is" |
|
1978 |
||
1979 |
|path f| |
|
1980 |
||
1981 |
path := self getEnvironment:'PATH'. |
|
1982 |
path notNil ifTrue:[ |
|
1983 |
(path asCollectionOfSubstringsSeparatedBy:$:) do:[:path | |
|
1984 |
(f := (path asFilename construct:aCommand)) isExecutable ifTrue:[ |
|
1985 |
^ f pathName |
|
1986 |
] |
|
1987 |
]. |
|
1988 |
]. |
|
1989 |
^ nil |
|
1990 |
||
1991 |
" |
|
1992 |
OperatingSystem pathOfCommand:'fooBar' |
|
1993 |
OperatingSystem pathOfCommand:'ls' |
|
1994 |
OperatingSystem pathOfCommand:'cvs' |
|
1995 |
" |
|
704 | 1996 |
! |
1997 |
||
1998 |
startProcess:aCommandString |
|
1999 |
"start executing the unix command as specified by the argument, aCommandString |
|
714 | 2000 |
as a separate process; do not wait for the command to finish. |
704 | 2001 |
The commandString is passed to a shell for execution - see the description of |
2002 |
'sh -c' in your UNIX manual. |
|
2003 |
Return the processId if successful, nil otherwise. |
|
714 | 2004 |
Use #waitForProcess: for synchronization and exec status return, |
2005 |
or #killProcess: to stop it." |
|
704 | 2006 |
|
771
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2007 |
^ self |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2008 |
exec:'/bin/sh' |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2009 |
withArguments:(Array with:'sh' with:'-c' with:aCommandString) |
1ad3f852e201
merged fork/exec into one, in order to use vfork
Claus Gittinger <cg@exept.de>
parents:
766
diff
changeset
|
2010 |
fork:true. |
704 | 2011 |
|
2012 |
" |
|
2013 |
|pid| |
|
2014 |
||
2015 |
pid := OperatingSystem startProcess:'sleep 2; echo 1; sleep 2; echo 2'. |
|
2016 |
(Delay forSeconds:3) wait. |
|
2017 |
OperatingSystem killProcess:pid. |
|
2018 |
" |
|
616 | 2019 |
! ! |
2020 |
||
2021 |
!OperatingSystem class methodsFor:'file access'! |
|
2022 |
||
2023 |
accessMaskFor:aSymbol |
|
2024 |
"return the access bits mask for numbers as returned by |
|
2025 |
OperatingSystem>>accessModeOf: |
|
2026 |
and expected by OperatingSystem>>changeAccessModeOf:to:. |
|
2027 |
Since these numbers are OS dependent, always use the mask |
|
2028 |
(never hardcode 8rxxx into your code)." |
|
68 | 2029 |
|
2030 |
%{ /* NOCONTEXT */ |
|
616 | 2031 |
# ifndef S_IRUSR |
2032 |
/* posix systems should define these ... */ |
|
2033 |
# define S_IRUSR 0400 |
|
2034 |
# define S_IWUSR 0200 |
|
2035 |
# define S_IXUSR 0100 |
|
2036 |
# define S_IRGRP 0040 |
|
2037 |
# define S_IWGRP 0020 |
|
2038 |
# define S_IXGRP 0010 |
|
2039 |
# define S_IROTH 0004 |
|
2040 |
# define S_IWOTH 0002 |
|
2041 |
# define S_IXOTH 0001 |
|
2042 |
||
2043 |
# endif |
|
2044 |
||
2045 |
if (aSymbol == @symbol(readUser)) { |
|
710 | 2046 |
RETURN ( _MKSMALLINT(S_IRUSR) ); |
616 | 2047 |
} |
2048 |
if (aSymbol == @symbol(writeUser)) { |
|
710 | 2049 |
RETURN ( _MKSMALLINT(S_IWUSR) ); |
616 | 2050 |
} |
2051 |
if (aSymbol == @symbol(executeUser)) { |
|
710 | 2052 |
RETURN ( _MKSMALLINT(S_IXUSR) ); |
616 | 2053 |
} |
2054 |
if (aSymbol == @symbol(readGroup)) { |
|
710 | 2055 |
RETURN ( _MKSMALLINT(S_IRGRP) ); |
616 | 2056 |
} |
2057 |
if (aSymbol == @symbol(writeGroup)) { |
|
710 | 2058 |
RETURN ( _MKSMALLINT(S_IWGRP) ); |
616 | 2059 |
} |
2060 |
if (aSymbol == @symbol(executeGroup)) { |
|
710 | 2061 |
RETURN ( _MKSMALLINT(S_IXGRP) ); |
616 | 2062 |
} |
2063 |
if (aSymbol == @symbol(readOthers)) { |
|
710 | 2064 |
RETURN ( _MKSMALLINT(S_IROTH) ); |
616 | 2065 |
} |
2066 |
if (aSymbol == @symbol(writeOthers)) { |
|
710 | 2067 |
RETURN ( _MKSMALLINT(S_IWOTH) ); |
616 | 2068 |
} |
2069 |
if (aSymbol == @symbol(executeOthers)) { |
|
710 | 2070 |
RETURN ( _MKSMALLINT(S_IXOTH) ); |
616 | 2071 |
} |
2072 |
%}. |
|
2073 |
self primitiveFailed |
|
2074 |
||
2075 |
" |
|
2076 |
OperatingSystem accessMaskFor:#readUser |
|
2077 |
" |
|
68 | 2078 |
! |
2079 |
||
616 | 2080 |
accessModeOf:aPathName |
2081 |
"return a number representing access rights rwxrwxrwx for owner, |
|
2082 |
group and others. Return nil if such a file does not exist. |
|
2083 |
Notice that the returned number is OS dependent - use the |
|
2084 |
modeMasks as returned by OperatingSystem>>accessMaskFor:" |
|
2085 |
||
2086 |
" |
|
2087 |
this could have been implemented as: |
|
2088 |
(self infoOf:aPathName) at:#mode |
|
2089 |
but for huge directory searches the code below is faster |
|
2090 |
" |
|
345 | 2091 |
|
2092 |
%{ /* NOCONTEXT */ |
|
616 | 2093 |
|
2094 |
struct stat buf; |
|
2095 |
int ret; |
|
2096 |
||
2097 |
if (__isString(aPathName)) { |
|
2098 |
__BEGIN_INTERRUPTABLE__ |
|
2099 |
do { |
|
2100 |
ret = stat((char *) _stringVal(aPathName), &buf); |
|
2101 |
} while ((ret < 0) && (errno == EINTR)); |
|
2102 |
__END_INTERRUPTABLE__ |
|
2103 |
||
2104 |
if (ret < 0) { |
|
2105 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2106 |
RETURN ( nil ); |
|
2107 |
} |
|
2108 |
RETURN ( _MKSMALLINT(buf.st_mode & 0777) ); |
|
2109 |
} |
|
2110 |
%}. |
|
2111 |
self primitiveFailed |
|
2112 |
||
2113 |
" |
|
2114 |
(OperatingSystem accessModeOf:'/') printStringRadix:8 |
|
2115 |
" |
|
345 | 2116 |
! |
2117 |
||
616 | 2118 |
baseNameOf:aPathString |
2119 |
"return the baseName of the argument, aPathString |
|
2120 |
- thats the file/directory name without leading parent-dirs |
|
2121 |
(i.e. OperatingSystem baseNameOf:'/usr/lib/st/file' -> 'file' |
|
2122 |
and OperatingSystem baseNameOf:'/usr/lib' -> lib). |
|
2123 |
This method does not check if the path is valid |
|
2124 |
(i.e. if these directories really exist & is readable)." |
|
2125 |
||
2126 |
|prev index sep| |
|
2127 |
||
2128 |
sep := self fileSeparator. |
|
2129 |
((aPathString size == 1) and:[(aPathString at:1) == sep]) ifTrue:[ |
|
2130 |
^ aPathString |
|
2131 |
]. |
|
2132 |
prev := 1. |
|
2133 |
[true] whileTrue:[ |
|
2134 |
index := aPathString indexOf:sep startingAt:prev. |
|
2135 |
index == 0 ifTrue:[ |
|
2136 |
^ aPathString copyFrom:prev |
|
2137 |
]. |
|
2138 |
prev := index + 1 |
|
2139 |
] |
|
2140 |
||
2141 |
" |
|
2142 |
OperatingSystem baseNameOf:'/fee/foo/bar' |
|
2143 |
OperatingSystem baseNameOf:'foo/bar' |
|
2144 |
OperatingSystem baseNameOf:'../../foo/bar' |
|
2145 |
OperatingSystem baseNameOf:'hello' |
|
2146 |
" |
|
2147 |
! |
|
2148 |
||
2149 |
caseSensitiveFilenames |
|
2150 |
"return true, if the OS has caseSensitive file naming. |
|
2151 |
On MSDOS, this will return false. Since this is for Unix, we |
|
2152 |
return true." |
|
2153 |
||
2154 |
^ true |
|
2155 |
! |
|
2156 |
||
2157 |
changeAccessModeOf:aPathName to:modeBits |
|
2158 |
"change the access rights of aPathName to the OS dependent modeBits. |
|
2159 |
You should construct this mask using accessMaskFor, to be OS |
|
2160 |
independent. Return true if changed, |
|
2161 |
false if such a file does not exist or change was not allowd." |
|
68 | 2162 |
|
2163 |
%{ /* NOCONTEXT */ |
|
616 | 2164 |
int ret; |
2165 |
||
2166 |
if (__isString(aPathName) && __isSmallInteger(modeBits)) { |
|
2167 |
__BEGIN_INTERRUPTABLE__ |
|
2168 |
do { |
|
2169 |
ret = chmod((char *)_stringVal(aPathName), _intVal(modeBits)); |
|
2170 |
} while (ret < 0 && errno == EINTR); |
|
2171 |
__END_INTERRUPTABLE__ |
|
2172 |
if (ret < 0) { |
|
2173 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2174 |
RETURN ( false ); |
|
2175 |
} |
|
2176 |
RETURN ( true ); |
|
2177 |
} |
|
2178 |
%}. |
|
2179 |
self primitiveFailed |
|
2180 |
! |
|
2181 |
||
2182 |
compressPath:pathName |
|
2183 |
"return the pathName compressed - that is, remove all ..-entries |
|
2184 |
and . entries. This does not always (in case of symbolic links) |
|
2185 |
return the true pathName and is therefore used as a fallback |
|
2186 |
if realPath and popen failed." |
|
2187 |
||
2188 |
|names| |
|
2189 |
||
2190 |
names := pathName |
|
2191 |
asCollectionOfSubstringsSeparatedBy:self fileSeparator. |
|
2192 |
names := names asOrderedCollection. |
|
2193 |
" |
|
2194 |
cut off initial double-slashes |
|
2195 |
" |
|
2196 |
[names startsWith:#('' '')] whileTrue:[ |
|
2197 |
names removeFirst. |
|
2198 |
]. |
|
2199 |
" |
|
2200 |
cut off double-slashes at end |
|
2201 |
" |
|
2202 |
[names endsWith:#('')] whileTrue:[ |
|
2203 |
names removeLast. |
|
2204 |
]. |
|
2205 |
" |
|
2206 |
cut off current-dir at beginning |
|
2207 |
" |
|
2208 |
[(names size >= 2) and:[names startsWith:#('.')]] whileTrue:[ |
|
2209 |
names removeFirst. |
|
2210 |
]. |
|
2211 |
||
2212 |
" |
|
2213 |
cut off parent-dirs at end |
|
2214 |
" |
|
2215 |
[(names size > 2) |
|
2216 |
and:[(names endsWith:#('..')) |
|
2217 |
and:[((names at:(names size - 1)) startsWith:'.') not ]]] whileTrue:[ |
|
2218 |
names removeLast; removeLast |
|
2219 |
]. |
|
2220 |
||
2221 |
^ names asStringWith:self fileSeparator |
|
2222 |
from:1 |
|
2223 |
to:names size |
|
2224 |
compressTabs:false final:nil |
|
2225 |
||
2226 |
" |
|
2227 |
OperatingSystem compressPath:'./..' |
|
2228 |
OperatingSystem compressPath:'/foo/bar/baz/..' |
|
2229 |
OperatingSystem compressPath:'foo/bar/baz/..' |
|
2230 |
OperatingSystem compressPath:'foo/bar/baz/../' |
|
2231 |
OperatingSystem compressPath:'foo/bar/baz/..///' |
|
2232 |
OperatingSystem compressPath:'///foo/bar/baz/..///' |
|
2233 |
" |
|
68 | 2234 |
! |
2235 |
||
616 | 2236 |
createDirectory:newPathName |
2237 |
"create a new directory with name 'newPathName'. |
|
2238 |
Return true if successful, false if failed." |
|
2239 |
||
2240 |
"since createDirectory is not used too often, |
|
2241 |
you'll forgive me using mkdir ..." |
|
2242 |
||
2243 |
^ self executeCommand:('mkdir ' , newPathName) |
|
2244 |
||
2245 |
"OperatingSystem createDirectory:'foo'" |
|
2246 |
! |
|
2247 |
||
2248 |
directoryNameOf:aPathString |
|
2249 |
"return the directoryName of the argument, aPath |
|
2250 |
- thats the name of the directory where aPath is |
|
2251 |
(i.e. OperatingSystem directoryNameOf:'/usr/lib/st/file' -> '/usr/lib/st' |
|
2252 |
and OperatingSystem directoryNameOf:'/usr/lib' -> /usr'). |
|
2253 |
This method does not check if the path is valid |
|
2254 |
(i.e. if these directories really exist & are readable)." |
|
2255 |
||
2256 |
|last index sep sepString| |
|
2257 |
||
2258 |
sep := self fileSeparator. |
|
2259 |
sepString := sep asString. |
|
2260 |
(aPathString = sepString) ifTrue:[ |
|
2261 |
" |
|
2262 |
the trivial '/' case |
|
2263 |
" |
|
2264 |
^ aPathString |
|
2265 |
]. |
|
2266 |
(aPathString startsWith:sepString) ifFalse:[ |
|
2267 |
(aPathString endsWith:sepString) ifTrue:[ |
|
2268 |
^ aPathString copyTo:(aPathString size - 1) |
|
2269 |
]. |
|
2270 |
]. |
|
2271 |
last := 1. |
|
2272 |
[true] whileTrue:[ |
|
2273 |
index := aPathString indexOf:sep startingAt:(last + 1). |
|
2274 |
index == 0 ifTrue:[ |
|
2275 |
(last == 1) ifTrue:[ |
|
2276 |
(aPathString startsWith:sepString) ifTrue:[ |
|
2277 |
^ sepString |
|
2278 |
]. |
|
2279 |
^ '.' |
|
2280 |
]. |
|
2281 |
" |
|
2282 |
(aPathString startsWith:sepString) ifFalse:[ |
|
2283 |
(aPathString startsWith:('..' , sepString)) ifFalse:[ |
|
2284 |
^ './' , (aPathString copyTo:(last - 1)) |
|
2285 |
] |
|
2286 |
]. |
|
2287 |
" |
|
2288 |
^ aPathString copyTo:(last - 1) |
|
2289 |
]. |
|
2290 |
last := index. |
|
2291 |
] |
|
2292 |
||
2293 |
" |
|
2294 |
OperatingSystem directoryNameOf:'/fee/foo/bar' |
|
2295 |
OperatingSystem directoryNameOf:'foo/bar' |
|
2296 |
OperatingSystem directoryNameOf:'../../foo/bar' |
|
2297 |
OperatingSystem directoryNameOf:'bar' |
|
2298 |
OperatingSystem directoryNameOf:'/bar' |
|
2299 |
" |
|
2300 |
! |
|
2301 |
||
2302 |
fileSeparator |
|
2303 |
"return the character used to separate names in a path. |
|
2304 |
This character differs for MSDOS and other systems, |
|
2305 |
(but those are currently not supported - so this is some |
|
2306 |
preparation for the future)" |
|
2307 |
||
2308 |
^ $/ |
|
2309 |
! |
|
2310 |
||
2311 |
getCharacter |
|
2312 |
"read a character from keyboard - |
|
2313 |
this is a blocking low-level read, provided for debugger |
|
2314 |
and fatal conditions. Use Stdin or (even better) the event |
|
2315 |
mechanisms provided." |
|
68 | 2316 |
|
2317 |
%{ /* NOCONTEXT */ |
|
616 | 2318 |
|
2319 |
RETURN ( _MKSMALLINT(getchar()) ); |
|
68 | 2320 |
%} |
2321 |
! |
|
2322 |
||
616 | 2323 |
idOf:aPathName |
2324 |
"return the fileNumber (i.e. inode number) of a file" |
|
2325 |
||
2326 |
" |
|
2327 |
this could have been implemented as: |
|
2328 |
(self infoOf:aPathName) at:#id |
|
2329 |
but for huge directory searches the code below is faster |
|
2330 |
" |
|
68 | 2331 |
|
2332 |
%{ /* NOCONTEXT */ |
|
616 | 2333 |
|
2334 |
struct stat buf; |
|
2335 |
int ret; |
|
2336 |
||
2337 |
if (__isString(aPathName)) { |
|
2338 |
__BEGIN_INTERRUPTABLE__ |
|
2339 |
do { |
|
2340 |
ret = stat((char *) _stringVal(aPathName), &buf); |
|
2341 |
} while (ret < 0 && errno == EINTR); |
|
2342 |
__END_INTERRUPTABLE__ |
|
2343 |
if (ret >= 0) { |
|
2344 |
RETURN (_MKSMALLINT(buf.st_ino)); |
|
2345 |
} |
|
2346 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2347 |
RETURN (nil); |
|
2348 |
} |
|
68 | 2349 |
%} |
616 | 2350 |
. |
2351 |
self primitiveFailed |
|
2352 |
||
2353 |
"OperatingSystem idOf:'/'" |
|
68 | 2354 |
! |
2355 |
||
616 | 2356 |
infoOf:aPathName |
2357 |
"return a dictionary filled with info for the file 'aPathName'; |
|
2358 |
info is: (type->t mode->n uid->u gid->g size->s id->ino). |
|
2359 |
return nil if such a file does not exist. A dictionary is returned, |
|
2360 |
since we might need to add more info in the future without affecting |
|
2361 |
existing applications." |
|
2362 |
||
2363 |
|info type mode uid gid size id |
|
2364 |
atimeLow atimeHi mtimeLow mtimeHi ctimeLow ctimeHi| |
|
2365 |
||
2366 |
%{ |
|
2367 |
struct stat buf; |
|
2368 |
int ret; |
|
2369 |
||
2370 |
if (__isString(aPathName)) { |
|
2371 |
__BEGIN_INTERRUPTABLE__ |
|
2372 |
do { |
|
2373 |
ret = stat((char *) _stringVal(aPathName), &buf); |
|
2374 |
} while ((ret < 0) && (errno == EINTR)); |
|
2375 |
__END_INTERRUPTABLE__ |
|
2376 |
||
2377 |
if (ret < 0) { |
|
2378 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2379 |
RETURN ( nil ); |
|
2380 |
} |
|
2381 |
switch (buf.st_mode & S_IFMT) { |
|
2382 |
case S_IFDIR: |
|
2383 |
type = @symbol(directory); |
|
2384 |
break; |
|
2385 |
case S_IFREG: |
|
2386 |
type = @symbol(regular); |
|
2387 |
break; |
|
2388 |
#ifdef S_IFCHR |
|
2389 |
case S_IFCHR: |
|
2390 |
type = @symbol(characterSpecial); |
|
2391 |
break; |
|
2392 |
#endif |
|
2393 |
#ifdef S_IFBLK |
|
2394 |
case S_IFBLK: |
|
2395 |
type = @symbol(blockSpecial); |
|
2396 |
break; |
|
2397 |
#endif |
|
2398 |
#ifdef S_IFLNK |
|
2399 |
case S_IFLNK: |
|
2400 |
type = @symbol(symbolicLink); |
|
2401 |
break; |
|
2402 |
#endif |
|
2403 |
#ifdef S_IFSOCK |
|
2404 |
case S_IFSOCK: |
|
2405 |
type = @symbol(socket); |
|
2406 |
break; |
|
2407 |
#endif |
|
2408 |
#ifdef S_IFIFO |
|
2409 |
case S_IFIFO: |
|
2410 |
type = @symbol(fifo); |
|
2411 |
break; |
|
2412 |
#endif |
|
2413 |
default: |
|
2414 |
type = @symbol(unknown); |
|
2415 |
break; |
|
2416 |
} |
|
2417 |
mode = _MKSMALLINT(buf.st_mode & 0777); |
|
2418 |
uid = _MKSMALLINT(buf.st_uid); |
|
2419 |
gid = _MKSMALLINT(buf.st_gid); |
|
2420 |
size = _MKSMALLINT(buf.st_size); |
|
2421 |
id = _MKSMALLINT(buf.st_ino); |
|
2422 |
atimeLow = _MKSMALLINT(buf.st_atime & 0xFFFF); |
|
2423 |
atimeHi = _MKSMALLINT((buf.st_atime >> 16) & 0xFFFF); |
|
2424 |
mtimeLow = _MKSMALLINT(buf.st_mtime & 0xFFFF); |
|
2425 |
mtimeHi = _MKSMALLINT((buf.st_mtime >> 16) & 0xFFFF); |
|
2426 |
ctimeLow = _MKSMALLINT(buf.st_ctime & 0xFFFF); |
|
2427 |
ctimeHi = _MKSMALLINT((buf.st_ctime >> 16) & 0xFFFF); |
|
2428 |
} |
|
2429 |
%}. |
|
2430 |
mode notNil ifTrue:[ |
|
2431 |
info := IdentityDictionary new. |
|
2432 |
info at:#type put:type. |
|
2433 |
info at:#mode put:mode. |
|
2434 |
info at:#uid put:uid. |
|
2435 |
info at:#gid put:gid. |
|
2436 |
info at:#size put:size. |
|
2437 |
info at:#id put:id. |
|
2438 |
info at:#accessed put:(AbsoluteTime fromOSTimeLow:atimeLow and:atimeHi). |
|
2439 |
info at:#modified put:(AbsoluteTime fromOSTimeLow:mtimeLow and:mtimeHi). |
|
2440 |
info at:#statusChanged put:(AbsoluteTime fromOSTimeLow:ctimeLow and:ctimeHi). |
|
2441 |
^ info |
|
2442 |
]. |
|
2443 |
self primitiveFailed |
|
2444 |
||
2445 |
" |
|
2446 |
OperatingSystem infoOf:'/' |
|
2447 |
(OperatingSystem infoOf:'/') at:#uid |
|
2448 |
(OperatingSystem infoOf:'/') at:#accessed |
|
2449 |
" |
|
68 | 2450 |
! |
2451 |
||
616 | 2452 |
isDirectory:aPathName |
2453 |
"return true, if 'aPathName' is a valid directory path name. |
|
2454 |
(i.e. exists and is a directory)" |
|
68 | 2455 |
|
2456 |
%{ /* NOCONTEXT */ |
|
616 | 2457 |
|
2458 |
struct stat buf; |
|
2459 |
int ret; |
|
2460 |
||
2461 |
if (__isString(aPathName)) { |
|
2462 |
__BEGIN_INTERRUPTABLE__ |
|
2463 |
do { |
|
2464 |
ret = stat((char *) _stringVal(aPathName), &buf); |
|
2465 |
} while ((ret < 0) && (errno == EINTR)); |
|
2466 |
__END_INTERRUPTABLE__ |
|
2467 |
if (ret < 0) { |
|
2468 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2469 |
RETURN ( false ); |
|
2470 |
} |
|
2471 |
RETURN ( ((buf.st_mode & S_IFMT) == S_IFDIR) ? true : false); |
|
2472 |
} |
|
2473 |
%}. |
|
2474 |
self primitiveFailed |
|
2475 |
||
2476 |
"an alternative implementation would be: |
|
2477 |
^ (self infoOf:aPathName) at:#type == #directory |
|
2478 |
" |
|
68 | 2479 |
! |
2480 |
||
616 | 2481 |
isExecutable:aPathName |
2482 |
"return true, if the given file is executable" |
|
68 | 2483 |
|
2484 |
%{ /* NOCONTEXT */ |
|
616 | 2485 |
int ret; |
2486 |
||
2487 |
if (__isString(aPathName)) { |
|
2488 |
__BEGIN_INTERRUPTABLE__ |
|
2489 |
do { |
|
2490 |
ret = access(_stringVal(aPathName), X_OK); |
|
2491 |
} while ((ret < 0) && (errno == EINTR)); |
|
2492 |
__END_INTERRUPTABLE__ |
|
2493 |
if (ret < 0) { |
|
2494 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2495 |
} |
|
710 | 2496 |
RETURN ( ((ret == 0) ? true : false) ); |
616 | 2497 |
} |
2498 |
%}. |
|
2499 |
self primitiveFailed |
|
68 | 2500 |
! |
2501 |
||
616 | 2502 |
isReadable:aPathName |
2503 |
"return true, if the file/dir 'aPathName' is readable." |
|
68 | 2504 |
|
2505 |
%{ /* NOCONTEXT */ |
|
616 | 2506 |
int ret; |
2507 |
||
2508 |
if (__isString(aPathName)) { |
|
2509 |
__BEGIN_INTERRUPTABLE__ |
|
2510 |
do { |
|
2511 |
ret = access(_stringVal(aPathName), R_OK); |
|
2512 |
} while ((ret < 0) && (errno == EINTR)); |
|
2513 |
__END_INTERRUPTABLE__ |
|
2514 |
if (ret < 0) { |
|
2515 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2516 |
} |
|
710 | 2517 |
RETURN ( ((ret == 0) ? true : false) ); |
616 | 2518 |
} |
2519 |
%}. |
|
2520 |
self primitiveFailed |
|
68 | 2521 |
! |
2522 |
||
616 | 2523 |
isSymbolicLink:aPathName |
2524 |
"return true, if the given file is a symbolic link" |
|
2525 |
||
2526 |
^ (self linkInfoOf:aPathName) notNil |
|
2527 |
||
2528 |
" |
|
2529 |
OperatingSystem isSymbolicLink:'Make.proto' |
|
2530 |
OperatingSystem isSymbolicLink:'Makefile' |
|
2531 |
" |
|
2532 |
! |
|
2533 |
||
2534 |
isValidPath:aPathName |
|
2535 |
"return true, if 'aPathName' is a valid path name |
|
2536 |
(i.e. the file or directory exists)" |
|
68 | 2537 |
|
2538 |
%{ /* NOCONTEXT */ |
|
616 | 2539 |
|
2540 |
struct stat buf; |
|
2541 |
int ret; |
|
2542 |
||
2543 |
if (__isString(aPathName) || __isSymbol(aPathName) ) { |
|
2544 |
__BEGIN_INTERRUPTABLE__ |
|
2545 |
do { |
|
2546 |
ret = stat((char *) _stringVal(aPathName), &buf); |
|
2547 |
} while ((ret < 0) && (errno == EINTR)); |
|
2548 |
__END_INTERRUPTABLE__ |
|
2549 |
if (ret < 0) { |
|
2550 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2551 |
RETURN (false); |
|
2552 |
} |
|
2553 |
RETURN ( ret ? false : true ); |
|
2554 |
} |
|
68 | 2555 |
%} |
616 | 2556 |
. |
2557 |
self primitiveFailed |
|
68 | 2558 |
! |
2559 |
||
616 | 2560 |
isWritable:aPathName |
2561 |
"return true, if the given file is writable" |
|
68 | 2562 |
|
2563 |
%{ /* NOCONTEXT */ |
|
616 | 2564 |
int ret; |
2565 |
||
2566 |
if (__isString(aPathName)) { |
|
2567 |
__BEGIN_INTERRUPTABLE__ |
|
2568 |
do { |
|
2569 |
ret = access(_stringVal(aPathName), W_OK); |
|
2570 |
} while ((ret < 0) && (errno == EINTR)); |
|
2571 |
__END_INTERRUPTABLE__ |
|
2572 |
if (ret < 0) { |
|
2573 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2574 |
} |
|
710 | 2575 |
RETURN ( ((ret == 0) ? true : false) ); |
616 | 2576 |
} |
2577 |
%}. |
|
2578 |
self primitiveFailed |
|
68 | 2579 |
! |
2580 |
||
616 | 2581 |
linkFile:oldPath to:newPath |
2582 |
"link the file 'oldPath' to 'newPath'. The link will be a hard link. |
|
2583 |
Return true if successful, false if not." |
|
68 | 2584 |
|
2585 |
%{ /* NOCONTEXT */ |
|
616 | 2586 |
int ret; |
2587 |
||
2588 |
if (__isString(oldPath) && __isString(newPath)) { |
|
2589 |
__BEGIN_INTERRUPTABLE__ |
|
2590 |
do { |
|
2591 |
ret = link((char *) _stringVal(oldPath), (char *) _stringVal(newPath)); |
|
2592 |
} while (ret < 0 && errno == EINTR); |
|
2593 |
__END_INTERRUPTABLE__ |
|
2594 |
RETURN ( (ret >= 0) ? true : false ); |
|
2595 |
} |
|
2596 |
%}. |
|
2597 |
self primitiveFailed |
|
2598 |
||
2599 |
"OperatingSystem linkFile:'foo' to:'bar'" |
|
68 | 2600 |
! |
2601 |
||
616 | 2602 |
linkInfoOf:aPathName |
2603 |
"return a dictionary filled with info for the file 'aPathName', |
|
2604 |
IFF aPathName is a symbolic link. If not, return nil. |
|
2605 |
The contents of the dictionary gives info about the link itself, |
|
2606 |
on contrast to #infoOf:, which returns the info of the pointed to file |
|
2607 |
in case of a symbolic link." |
|
2608 |
||
2609 |
|info type mode uid gid size id atimeLow atimeHi mtimeLow mtimeHi ctimeLow ctimeHi |
|
2610 |
path| |
|
2611 |
||
2612 |
%{ /* STACK: 1200 */ |
|
2613 |
struct stat buf; |
|
2614 |
int ret; |
|
2615 |
char pathBuffer[1024]; |
|
2616 |
||
2617 |
if (__isString(aPathName)) { |
|
2618 |
__BEGIN_INTERRUPTABLE__ |
|
2619 |
do { |
|
2620 |
ret = lstat((char *) _stringVal(aPathName), &buf); |
|
2621 |
} while ((ret < 0) && (errno == EINTR)); |
|
2622 |
__END_INTERRUPTABLE__ |
|
2623 |
||
2624 |
if (ret < 0) { |
|
2625 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2626 |
RETURN ( nil ); |
|
2627 |
} |
|
2628 |
switch (buf.st_mode & S_IFMT) { |
|
2629 |
default: |
|
2630 |
RETURN ( nil ); /* not a symbolic link */ |
|
2631 |
||
2632 |
case S_IFLNK: |
|
2633 |
type = @symbol(symbolicLink); |
|
2634 |
break; |
|
2635 |
} |
|
2636 |
||
2637 |
mode = _MKSMALLINT(buf.st_mode & 0777); |
|
2638 |
uid = _MKSMALLINT(buf.st_uid); |
|
2639 |
gid = _MKSMALLINT(buf.st_gid); |
|
2640 |
size = _MKSMALLINT(buf.st_size); |
|
2641 |
id = _MKSMALLINT(buf.st_ino); |
|
2642 |
atimeLow = _MKSMALLINT(buf.st_atime & 0xFFFF); |
|
2643 |
atimeHi = _MKSMALLINT((buf.st_atime >> 16) & 0xFFFF); |
|
2644 |
mtimeLow = _MKSMALLINT(buf.st_mtime & 0xFFFF); |
|
2645 |
mtimeHi = _MKSMALLINT((buf.st_mtime >> 16) & 0xFFFF); |
|
2646 |
ctimeLow = _MKSMALLINT(buf.st_ctime & 0xFFFF); |
|
2647 |
ctimeHi = _MKSMALLINT((buf.st_ctime >> 16) & 0xFFFF); |
|
2648 |
if ((ret = readlink((char *) _stringVal(aPathName), pathBuffer, sizeof(pathBuffer))) < 0) { |
|
2649 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2650 |
RETURN ( nil ); |
|
2651 |
} |
|
2652 |
pathBuffer[ret] = '\0'; /* readlink does not 0-terminate */ |
|
2653 |
path = _MKSTRING(pathBuffer COMMA_CON); |
|
2654 |
} |
|
2655 |
%}. |
|
2656 |
mode notNil ifTrue:[ |
|
2657 |
info := IdentityDictionary new. |
|
2658 |
info at:#type put:type. |
|
2659 |
info at:#mode put:mode. |
|
2660 |
info at:#uid put:uid. |
|
2661 |
info at:#gid put:gid. |
|
2662 |
info at:#size put:size. |
|
2663 |
info at:#id put:id. |
|
2664 |
info at:#path put:path. |
|
2665 |
info at:#accessed put:(AbsoluteTime fromOSTimeLow:atimeLow and:atimeHi). |
|
2666 |
info at:#modified put:(AbsoluteTime fromOSTimeLow:mtimeLow and:mtimeHi). |
|
2667 |
info at:#statusChanged put:(AbsoluteTime fromOSTimeLow:ctimeLow and:ctimeHi). |
|
2668 |
^ info |
|
2669 |
]. |
|
2670 |
self primitiveFailed |
|
2671 |
||
2672 |
" |
|
2673 |
OperatingSystem infoOf:'Make.proto' |
|
2674 |
OperatingSystem linkInfoOf:'Make.proto' |
|
2675 |
" |
|
2676 |
! |
|
2677 |
||
2678 |
parentDirectoryName |
|
2679 |
"return the name used to refer to parent directories. |
|
2680 |
In MSDOS, Unix and other systems this is '..', but maybe different |
|
2681 |
for other systems. |
|
2682 |
(but those are currently not supported - so this is some |
|
2683 |
preparation for the future)" |
|
2684 |
||
2685 |
^ '..' |
|
68 | 2686 |
! |
2687 |
||
616 | 2688 |
pathNameOf:pathName |
2689 |
"return the pathName of the argument, aPathString, |
|
2690 |
- thats the full pathname of the directory, starting at '/'. |
|
2691 |
This method needs the path to be valid |
|
2692 |
(i.e. all directories must exist, be readable and executable). |
|
2693 |
Notice: if symbolic links are involved, the result may look different |
|
2694 |
from what you expect." |
|
2695 |
||
2696 |
|p path command| |
|
2697 |
||
2698 |
"some systems have a convenient function for this ..." |
|
2699 |
path := self primPathNameOf:pathName. |
|
2700 |
||
2701 |
path isNil ifTrue:[ |
|
2702 |
(self isValidPath:pathName) ifFalse:[^ pathName]. |
|
2703 |
||
2704 |
(SlowFork==true or:[ForkFailed]) ifFalse:[ |
|
2705 |
PipeStream openErrorSignal handle:[:ex | |
|
2706 |
ForkFailed := true. |
|
2707 |
'OS: cannot fork/popen' errorPrintNL. |
|
2708 |
ex return. |
|
2709 |
] do:[ |
|
2710 |
"have to fall back ..." |
|
2711 |
command := 'cd ' , pathName , '; pwd'. |
|
2712 |
p := PipeStream readingFrom:command. |
|
2713 |
]. |
|
2714 |
||
2715 |
(p isNil or:[p atEnd]) ifTrue:[ |
|
2716 |
('OS: PipeStream for <' , command , '> failed') errorPrintNL. |
|
2717 |
] ifFalse:[ |
|
2718 |
path := p nextLine. |
|
2719 |
p close. |
|
2720 |
]. |
|
2721 |
]. |
|
2722 |
path isNil ifTrue:[ |
|
2723 |
path := pathName |
|
2724 |
]. |
|
2725 |
(SlowFork==true or:[ForkFailed]) ifTrue:[ |
|
2726 |
path := self compressPath:path |
|
2727 |
] |
|
2728 |
]. |
|
2729 |
^ path. |
|
2730 |
||
2731 |
" |
|
2732 |
OperatingSystem pathNameOf:'.' |
|
2733 |
OperatingSystem pathNameOf:'../smalltalk/../smalltalk' |
|
2734 |
OperatingSystem pathNameOf:'../../..' |
|
2735 |
OperatingSystem pathNameOf:'..' |
|
2736 |
" |
|
359 | 2737 |
! |
2738 |
||
616 | 2739 |
primPathNameOf:pathName |
2740 |
"return the pathName of the argument, aPathString, |
|
2741 |
- thats the full pathname of the directory, starting at '/'. |
|
2742 |
This method here returns nil, if the OS does not provide a |
|
2743 |
realPath library function. |
|
2744 |
Notice: if symbolic links are involved, the result may look different |
|
2745 |
from what you expect." |
|
2746 |
||
2747 |
|path| |
|
2748 |
||
2749 |
"some systems have a convenient function for this ..." |
|
2750 |
%{ /* STACK: 16000 */ |
|
2751 |
#ifdef HAS_REALPATH |
|
2752 |
char nameBuffer[MAXPATHLEN + 1]; |
|
2753 |
||
2754 |
if (__isString(pathName)) { |
|
2755 |
if (realpath(_stringVal(pathName), nameBuffer)) { |
|
2756 |
RETURN ( _MKSTRING(nameBuffer COMMA_CON) ); |
|
2757 |
} |
|
2758 |
} |
|
2759 |
#endif |
|
2760 |
%}. |
|
2761 |
^ nil |
|
359 | 2762 |
! |
2763 |
||
616 | 2764 |
recursiveCreateDirectory:dirName |
2765 |
"create a directory - with all parent dirs if needed. |
|
2766 |
Return true if successful, false otherwise. If false |
|
2767 |
is returned, a partial created tree may be left, |
|
2768 |
which is not cleaned-up here." |
|
2769 |
||
2770 |
self createDirectory:dirName. |
|
2771 |
(self isDirectory:dirName) ifFalse:[ |
|
2772 |
(self recursiveCreateDirectory:(self directoryNameOf:dirName)) ifFalse:[^ false]. |
|
2773 |
^ self createDirectory:dirName |
|
2774 |
]. |
|
2775 |
^ true |
|
2776 |
||
2777 |
"OperatingSystem recursiveCreateDirectory:'foo/bar/baz'" |
|
359 | 2778 |
! |
2779 |
||
616 | 2780 |
recursiveRemoveDirectory:fullPathName |
2781 |
"remove the directory named 'fullPathName' and all contained files/directories. |
|
2782 |
Return true if successful." |
|
2783 |
||
2784 |
^ self executeCommand:('rm -rf ' , fullPathName) |
|
2785 |
! |
|
2786 |
||
2787 |
removeDirectory:fullPathName |
|
2788 |
"remove the directory named 'fullPathName'. |
|
2789 |
Return true if successful, false if directory is not empty or no permission" |
|
359 | 2790 |
|
2791 |
%{ /* NOCONTEXT */ |
|
616 | 2792 |
int ret; |
2793 |
||
2794 |
if (__isString(fullPathName)) { |
|
2795 |
__BEGIN_INTERRUPTABLE__ |
|
2796 |
do { |
|
2797 |
ret = rmdir((char *) _stringVal(fullPathName)); |
|
2798 |
} while (ret < 0 && errno == EINTR); |
|
2799 |
__END_INTERRUPTABLE__ |
|
2800 |
RETURN ( (ret >= 0) ? true : false ); |
|
2801 |
} |
|
2802 |
%}. |
|
2803 |
self primitiveFailed |
|
359 | 2804 |
! |
2805 |
||
616 | 2806 |
removeFile:fullPathName |
2807 |
"remove the file named 'fullPathName'; return true if successful" |
|
359 | 2808 |
|
2809 |
%{ /* NOCONTEXT */ |
|
616 | 2810 |
int ret; |
2811 |
||
2812 |
if (__isString(fullPathName)) { |
|
2813 |
__BEGIN_INTERRUPTABLE__ |
|
2814 |
do { |
|
2815 |
ret = unlink((char *) _stringVal(fullPathName)); |
|
2816 |
} while (ret < 0 && errno == EINTR); |
|
2817 |
__END_INTERRUPTABLE__ |
|
2818 |
RETURN ( (ret >= 0) ? true : false ); |
|
2819 |
} |
|
2820 |
%}. |
|
2821 |
self primitiveFailed |
|
359 | 2822 |
! |
2823 |
||
616 | 2824 |
renameFile:oldPath to:newPath |
2825 |
"rename the file 'oldPath' to 'newPath'. |
|
670
4d6d0c031711
startProcess: / killProcess: added
Claus Gittinger <cg@exept.de>
parents:
640
diff
changeset
|
2826 |
Return true if successful, false if not" |
359 | 2827 |
|
2828 |
%{ /* NOCONTEXT */ |
|
616 | 2829 |
int ret; |
2830 |
||
2831 |
if (__isString(oldPath) && __isString(newPath)) { |
|
2832 |
#if defined(HAS_RENAME) |
|
2833 |
__BEGIN_INTERRUPTABLE__ |
|
2834 |
do { |
|
2835 |
ret = rename((char *) _stringVal(oldPath), (char *) _stringVal(newPath)); |
|
2836 |
} while (ret < 0 && errno == EINTR); |
|
2837 |
__END_INTERRUPTABLE__ |
|
2838 |
RETURN ( (ret >= 0) ? true : false ); |
|
359 | 2839 |
#else |
616 | 2840 |
if (link((char *) _stringVal(oldPath), (char *) _stringVal(newPath)) >= 0) { |
2841 |
if (unlink((char *) _stringVal(oldPath)) >= 0) { |
|
2842 |
RETURN ( true ); |
|
2843 |
} |
|
2844 |
unlink((char *) _stringVal(newPath)); |
|
2845 |
} |
|
2846 |
#endif |
|
2847 |
RETURN ( false ); |
|
2848 |
} |
|
2849 |
%} |
|
2850 |
. |
|
2851 |
self primitiveFailed |
|
2852 |
||
2853 |
"OperatingSystem renameFile:'foo' to:'bar'" |
|
2854 |
! |
|
2855 |
||
2856 |
timeOfLastAccess:aPathName |
|
2857 |
"return the time, when the file was last accessed. |
|
2858 |
For nonexistent files, nil is returned." |
|
2859 |
||
2860 |
"could be implemented as: |
|
2861 |
(self infoOf:aPathName) at:#accessed |
|
2862 |
" |
|
2863 |
|timeLow timeHi| |
|
2864 |
%{ |
|
2865 |
struct stat buf; |
|
2866 |
time_t mtime; |
|
2867 |
int ret; |
|
2868 |
||
2869 |
if (__isString(aPathName)) { |
|
2870 |
__BEGIN_INTERRUPTABLE__ |
|
2871 |
do { |
|
2872 |
ret = stat((char *) _stringVal(aPathName), &buf); |
|
2873 |
} while (ret < 0 && errno == EINTR); |
|
2874 |
__END_INTERRUPTABLE__ |
|
2875 |
if (ret < 0) { |
|
2876 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2877 |
RETURN (nil); |
|
2878 |
} |
|
2879 |
timeLow = _MKSMALLINT(buf.st_atime & 0xFFFF); |
|
2880 |
timeHi = _MKSMALLINT((buf.st_atime >> 16) & 0xFFFF); |
|
2881 |
} |
|
359 | 2882 |
%} |
616 | 2883 |
. |
2884 |
timeLow notNil ifTrue:[^ AbsoluteTime fromOSTimeLow:timeLow and:timeHi]. |
|
2885 |
self primitiveFailed |
|
2886 |
||
2887 |
" |
|
2888 |
OperatingSystem timeOfLastAccess:'/' |
|
2889 |
" |
|
359 | 2890 |
! |
2891 |
||
616 | 2892 |
timeOfLastChange:aPathName |
2893 |
"return the time, when the file was last changed. |
|
2894 |
For nonexistent files, nil is returned." |
|
2895 |
||
2896 |
"could be implemented as: |
|
2897 |
(self infoOf:aPathName) at:#modified |
|
2898 |
" |
|
2899 |
||
2900 |
|timeLow timeHi| |
|
2901 |
%{ |
|
2902 |
struct stat buf; |
|
2903 |
int ret; |
|
2904 |
time_t mtime; |
|
2905 |
||
2906 |
if (__isString(aPathName)) { |
|
2907 |
__BEGIN_INTERRUPTABLE__ |
|
2908 |
do { |
|
2909 |
ret = stat((char *) _stringVal(aPathName), &buf); |
|
2910 |
} while (ret < 0 && errno == EINTR); |
|
2911 |
__END_INTERRUPTABLE__ |
|
2912 |
if (ret < 0) { |
|
2913 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2914 |
RETURN ( nil ); |
|
2915 |
} |
|
2916 |
timeLow = _MKSMALLINT(buf.st_mtime & 0xFFFF); |
|
2917 |
timeHi = _MKSMALLINT((buf.st_mtime >> 16) & 0xFFFF); |
|
2918 |
} |
|
2919 |
%} |
|
2920 |
. |
|
2921 |
timeLow notNil ifTrue:[^ AbsoluteTime fromOSTimeLow:timeLow and:timeHi]. |
|
2922 |
self primitiveFailed |
|
2923 |
||
2924 |
" |
|
2925 |
OperatingSystem timeOfLastChange:'/' |
|
2926 |
" |
|
2927 |
! |
|
2928 |
||
2929 |
typeOf:aPathName |
|
2930 |
"return the type of a file as a symbol" |
|
2931 |
||
2932 |
" |
|
2933 |
this could have been implemented as: |
|
2934 |
(self infoOf:aPathName) at:#type |
|
2935 |
but for huge directory searches the code below is faster |
|
2936 |
" |
|
359 | 2937 |
|
2938 |
%{ /* NOCONTEXT */ |
|
616 | 2939 |
|
2940 |
struct stat buf; |
|
2941 |
int ret; |
|
2942 |
||
2943 |
if (__isString(aPathName)) { |
|
2944 |
__BEGIN_INTERRUPTABLE__ |
|
2945 |
do { |
|
2946 |
ret = stat((char *) _stringVal(aPathName), &buf); |
|
2947 |
} while (ret < 0 && errno == EINTR); |
|
2948 |
__END_INTERRUPTABLE__ |
|
2949 |
if (ret < 0) { |
|
2950 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
2951 |
RETURN ( nil ); |
|
2952 |
} |
|
2953 |
switch (buf.st_mode & S_IFMT) { |
|
2954 |
case S_IFDIR: |
|
2955 |
RETURN ( @symbol(directory) ); |
|
2956 |
case S_IFREG: |
|
2957 |
RETURN ( @symbol(regular) ); |
|
2958 |
#ifdef S_IFCHR |
|
2959 |
case S_IFCHR: |
|
2960 |
RETURN ( @symbol(characterSpecial) ); |
|
2961 |
#endif |
|
2962 |
#ifdef S_IFBLK |
|
2963 |
case S_IFBLK: |
|
2964 |
RETURN ( @symbol(blockSpecial) ); |
|
2965 |
#endif |
|
2966 |
#ifdef S_IFLNK |
|
2967 |
case S_IFLNK: |
|
2968 |
RETURN ( @symbol(symbolicLink) ); |
|
2969 |
#endif |
|
2970 |
#ifdef S_IFSOCK |
|
2971 |
case S_IFSOCK: |
|
2972 |
RETURN ( @symbol(socket) ); |
|
2973 |
#endif |
|
2974 |
#ifdef S_IFIFO |
|
2975 |
case S_IFIFO: |
|
2976 |
RETURN ( @symbol(fifo) ); |
|
2977 |
#endif |
|
2978 |
default: |
|
2979 |
RETURN ( @symbol(unknown) ); |
|
2980 |
} |
|
2981 |
} |
|
2982 |
%}. |
|
2983 |
self primitiveFailed |
|
2984 |
||
2985 |
" |
|
2986 |
OperatingSystem typeOf:'/' |
|
2987 |
OperatingSystem typeOf:'.' |
|
2988 |
OperatingSystem typeOf:'Make.proto' |
|
2989 |
" |
|
68 | 2990 |
! ! |
2991 |
||
63 | 2992 |
!OperatingSystem class methodsFor:'interrupts & signals'! |
2993 |
||
10 | 2994 |
blockInterrupts |
95 | 2995 |
"disable interrupt processing - if disabled, incoming |
2996 |
interrupts will be registered and handled as soon as |
|
2997 |
interrupts are reenabled by OperatingSystemclass>>unblockInterrupts. |
|
2998 |
Returns the previous blocking status i.e. true if interrupts |
|
2999 |
where already blocked. You need this information for proper |
|
3000 |
unblocking, in case of nested block/unblock calls." |
|
3001 |
||
3002 |
%{ /* NOCONTEXT */ |
|
356 | 3003 |
extern OBJ __BLOCKINTERRUPTS(); |
3004 |
||
710 | 3005 |
RETURN ( __BLOCKINTERRUPTS() ); |
10 | 3006 |
%} |
3007 |
! |
|
3008 |
||
616 | 3009 |
defaultSignal:signalNumber |
3010 |
"revert to the default action on arrival of a (Unix-)signal. |
|
3011 |
Dont confuse Unix signals with smalltalk signals. |
|
3012 |
WARNING: for some signals, it is no good idea to revert to default; |
|
3013 |
for example, the default for SIGINT (i.e. ^C) is to exit; while the |
|
3014 |
default for SIGQUIT (^ \) is to dump core. |
|
3015 |
Also, NOTICE that signal numbers are not portable between unix |
|
3016 |
systems - use OperatingSystem sigXXX to get the numeric value for |
|
3017 |
a signal." |
|
3018 |
||
3019 |
%{ /* NOCONTEXT */ |
|
3020 |
||
3021 |
if (__isSmallInteger(signalNumber)) { |
|
3022 |
signal(_intVal(signalNumber), SIG_DFL); |
|
3023 |
RETURN (self); |
|
3024 |
} |
|
3025 |
%}. |
|
3026 |
" |
|
3027 |
this error is triggered on non-integer argument |
|
3028 |
" |
|
3029 |
self primitiveFailed |
|
3030 |
||
3031 |
"you better save a snapshot image before trying this ..." |
|
3032 |
" |
|
3033 |
'if you hit ^C now, Smalltalk will exit immediately' printNewline. |
|
3034 |
OperatingSystem defaultSignal:(OperatingSystem sigINT). |
|
3035 |
1 to:1000000 do:[:i| ]. |
|
3036 |
OperatingSystem enableSignal:(OperatingSystem sigINT). |
|
3037 |
'normal ^C handling again.' printNewline |
|
3038 |
" |
|
3039 |
! |
|
3040 |
||
3041 |
disableIOInterruptsOn:fd |
|
3042 |
"turn off IO interrupts for a filedescriptor" |
|
3043 |
||
3044 |
%{ /* NOCONTEXT */ |
|
3045 |
||
3046 |
int ret, flags, f; |
|
3047 |
||
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3048 |
#if (defined(F_GETFL) && defined(F_SETFL) && defined(FASYNC)) || defined(SYSV4) |
616 | 3049 |
if (__isSmallInteger(fd)) { |
3050 |
f = _intVal(fd); |
|
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3051 |
# if defined(SYSV4) |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
756
diff
changeset
|
3052 |
ret = ioctl(f, I_SETSIG, 0); |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3053 |
# else /*! SYSV4*/ |
616 | 3054 |
flags = fcntl(f, F_GETFL, 0); |
3055 |
/* |
|
3056 |
* if already clear, there is no need for this syscall ... |
|
3057 |
*/ |
|
3058 |
if (flags & FASYNC) { |
|
3059 |
ret = fcntl(f, F_SETFL, flags & ~FASYNC); |
|
3060 |
if (ret >= 0) ret = flags; |
|
3061 |
} else { |
|
3062 |
ret = flags; |
|
3063 |
} |
|
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3064 |
# endif /* !SYSV4 */ |
616 | 3065 |
RETURN ( _MKSMALLINT(ret) ); |
3066 |
} |
|
3067 |
#endif |
|
3068 |
%}. |
|
3069 |
" |
|
3070 |
this error is triggered on non-integer argument |
|
3071 |
or if the OS does not support IO interrupts. |
|
3072 |
" |
|
3073 |
self primitiveFailed |
|
10 | 3074 |
! |
3075 |
||
63 | 3076 |
disableSignal:signalNumber |
95 | 3077 |
"disable (Unix-) signal processing for signalNumber. |
3078 |
Dont confuse Unix signals with smalltalk signals. |
|
63 | 3079 |
WARNING: for some signals, it is no good idea to disable |
95 | 3080 |
them; for example, disabling the SIGINT signal turns off ^C |
63 | 3081 |
handling. |
68 | 3082 |
Also, NOTICE that signal numbers are not portable between unix |
3083 |
systems - use OperatingSystem sigXXX to get the numeric value for |
|
3084 |
a signal. |
|
63 | 3085 |
Use only for fully debugged stand alone applications." |
3086 |
||
3087 |
%{ /* NOCONTEXT */ |
|
3088 |
||
252 | 3089 |
if (__isSmallInteger(signalNumber)) { |
185 | 3090 |
signal(_intVal(signalNumber), SIG_IGN); |
3091 |
RETURN (self); |
|
63 | 3092 |
} |
68 | 3093 |
%}. |
3094 |
" |
|
3095 |
this error is triggered on non-integer argument |
|
3096 |
" |
|
3097 |
self primitiveFailed |
|
3098 |
||
3099 |
" |
|
3100 |
'now, ^C is totally ignored ...' printNewline. |
|
3101 |
OperatingSystem disableSignal:(OperatingSystem sigINT). |
|
3102 |
1 to:1000000 do:[:i| ]. |
|
3103 |
OperatingSystem enableSignal:(OperatingSystem sigINT). |
|
3104 |
'^C handled again.' printNewline |
|
3105 |
" |
|
3106 |
! |
|
3107 |
||
616 | 3108 |
disableTimer |
3109 |
"disable timer interrupt" |
|
3110 |
||
3111 |
%{ /* NOCONTEXT */ |
|
3112 |
||
3113 |
#if defined(ITIMER_REAL) |
|
3114 |
struct itimerval dt; |
|
3115 |
||
3116 |
dt.it_interval.tv_sec = 0; |
|
3117 |
dt.it_interval.tv_usec = 0; |
|
3118 |
dt.it_value.tv_sec = 0; |
|
3119 |
dt.it_value.tv_usec = 0; |
|
3120 |
setitimer(ITIMER_REAL, &dt, 0); |
|
3121 |
RETURN (true); |
|
3122 |
#endif |
|
3123 |
%} |
|
3124 |
. |
|
3125 |
^ false |
|
3126 |
! |
|
3127 |
||
3128 |
disableUserInterrupts |
|
3129 |
"disable userInterrupt processing; |
|
3130 |
when disabled, no ^C processing takes place. |
|
3131 |
Use this only for debugged stand-alone applications, since |
|
3132 |
no exit to the debugger is possible with user interrupts disabled. |
|
3133 |
Be WARNED." |
|
3134 |
||
3135 |
^ self disableSignal:(self sigINT) |
|
3136 |
! |
|
3137 |
||
3138 |
enableAbortInterrupts |
|
3139 |
"enable abort signalhandling, and make it a regular signalInterrupt. |
|
3140 |
(the default will dump core and exit - which is not a good idea for |
|
3141 |
end-user applications ...). |
|
3142 |
This is especially useful, if linked-in C-libraries call abort() ..." |
|
3143 |
||
3144 |
^ self enableSignal:(self sigABRT) |
|
3145 |
! |
|
3146 |
||
3147 |
enableChildSignalInterrupts |
|
3148 |
"enable childSignal interrupts |
|
3149 |
(SIGCHLD, if the architecture supports it). |
|
3150 |
after enabling, these signals will send the message |
|
3151 |
'childSignalInterrupt' to the ChildSignalInterruptHandler object." |
|
3152 |
||
3153 |
^ self enableSignal:(self sigCHLD) |
|
3154 |
! |
|
3155 |
||
3156 |
enableFpExceptionInterrupts |
|
3157 |
"enable floating point exception interrupts (if the |
|
3158 |
architecture supports it). |
|
3159 |
after enabling, fpu-exceptions will send the message |
|
3160 |
'fpuExceptionInterrupt' to the FPUExceptionInterruptHandler object." |
|
3161 |
||
3162 |
^ self enableSignal:(self sigFP) |
|
3163 |
! |
|
3164 |
||
3165 |
enableHardSignalInterrupts |
|
3166 |
"enable hard signal exception interrupts (trap, buserror & segm. violation). |
|
3167 |
after enabling, these exceptions will send the message |
|
3168 |
'signalInterrupt' to the SignalInterruptHandler object." |
|
68 | 3169 |
|
640
be94dfc60eaa
Anforderung von SA_SIGINFO in sigaction.
Stefan Vogel <sv@exept.de>
parents:
630
diff
changeset
|
3170 |
self enableSignal:(self sigPIPE). |
be94dfc60eaa
Anforderung von SA_SIGINFO in sigaction.
Stefan Vogel <sv@exept.de>
parents:
630
diff
changeset
|
3171 |
self enableSignal:(self sigBUS). |
be94dfc60eaa
Anforderung von SA_SIGINFO in sigaction.
Stefan Vogel <sv@exept.de>
parents:
630
diff
changeset
|
3172 |
self enableSignal:(self sigSEGV) |
616 | 3173 |
! |
3174 |
||
3175 |
enableIOInterruptsOn:fd |
|
3176 |
"turn on IO interrupts for a filedescriptor" |
|
3177 |
||
3178 |
%{ /* NOCONTEXT */ |
|
3179 |
||
3180 |
int ret, flags, f; |
|
3181 |
extern void __signalIoInterrupt(); |
|
3182 |
static int firstCall = 1; |
|
3183 |
||
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3184 |
#if (defined(F_GETFL) && defined(F_SETFL) && defined(FASYNC)) || defined(SYSV4) |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3185 |
/* |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3186 |
* SIGIO/SIGPOLL - data available for I/O |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3187 |
* (used to wake up waiting processes) |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3188 |
*/ |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3189 |
#ifdef SIGIO |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3190 |
# define THESIGNAL SIGIO |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3191 |
#else |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3192 |
# ifdef SIGPOLL |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3193 |
# define THESIGNAL SIGPOLL |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3194 |
# else |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3195 |
# ifdef SIGURG |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3196 |
# define THESIGNAL SIGURG |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3197 |
# endif |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3198 |
# endif |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3199 |
#endif |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3200 |
|
616 | 3201 |
if (__isSmallInteger(fd)) { |
3202 |
if (firstCall) { |
|
762
cea705669628
ok, stefan was right: HAS_SIGACTION works
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
3203 |
#ifdef HAS_SIGACTION |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3204 |
struct sigaction act; |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3205 |
|
763
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
3206 |
act.sa_flags = SA_RESTART | SA_SIGINFO; /* <- if you add more, remember dummys at the top */ |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3207 |
sigemptyset(&act.sa_mask); |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3208 |
act.sa_handler = __signalIoInterrupt; |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3209 |
sigaction(THESIGNAL, &act, 0); |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3210 |
#else |
766
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3211 |
# ifdef HAS_SIGVEC |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3212 |
struct sigvec vec; |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3213 |
|
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3214 |
vec.sv_flags = 0; |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3215 |
sigemptyset(&vec.sv_mask); |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3216 |
vec.sv_handler = __signalIoInterrupt; |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3217 |
sigvec(THESIGNAL, &vec, NULL); |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3218 |
# else |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3219 |
signal(THESIGNAL, __signalIoInterrupt); |
766
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3220 |
# endif |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3221 |
#endif |
616 | 3222 |
firstCall = 0; |
3223 |
} |
|
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3224 |
#undef THESIGNAL |
616 | 3225 |
|
3226 |
f = _intVal(fd); |
|
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3227 |
# if defined(SYSV4) |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
756
diff
changeset
|
3228 |
ret = ioctl(f, I_SETSIG, S_INPUT | S_HIPRI | S_ERROR | S_RDNORM | S_RDBAND | S_MSG | S_HANGUP); |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3229 |
# else /*! SYSV4*/ |
616 | 3230 |
flags = fcntl(f, F_GETFL, 0); |
3231 |
/* |
|
3232 |
* if already set, there is no need for this syscall ... |
|
3233 |
*/ |
|
3234 |
if (flags & FASYNC) { |
|
3235 |
ret = flags; |
|
3236 |
} else { |
|
3237 |
ret = fcntl(f, F_SETFL, flags | FASYNC); |
|
3238 |
if (ret >= 0) ret = flags; |
|
3239 |
} |
|
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3240 |
# endif /*!SYSV4*/ |
616 | 3241 |
RETURN ( _MKSMALLINT(ret) ); |
68 | 3242 |
} |
616 | 3243 |
#endif |
68 | 3244 |
%}. |
3245 |
" |
|
3246 |
this error is triggered on non-integer argument |
|
616 | 3247 |
or if the system does not support SIGIO |
68 | 3248 |
" |
3249 |
self primitiveFailed |
|
616 | 3250 |
! |
3251 |
||
3252 |
enableQuitInterrupts |
|
3253 |
"enable quitInterrupt (usually ^\) handling, and make it a userInterrupt. |
|
3254 |
(the default will dump core and exit - which is not a good idea for |
|
3255 |
end-user applications ...)" |
|
3256 |
||
3257 |
^ self enableSignal:(self sigQUIT) |
|
68 | 3258 |
! |
3259 |
||
3260 |
enableSignal:signalNumber |
|
95 | 3261 |
"enable (Unix-)signal processing for signalNumber. |
3262 |
Dont confuse Unix signals with smalltalk signals. |
|
68 | 3263 |
The signal will be delivered to one of the standard handlers |
3264 |
(SIGINT, SIGQUIT, etc) or to a general handler, which |
|
3265 |
sends #signalInterrupt:. |
|
3266 |
||
3267 |
NOTICE that signal numbers are not portable between unix |
|
3268 |
systems - use OperatingSystem sigXXX to get the numeric value for |
|
3269 |
a signal." |
|
3270 |
||
3271 |
%{ /* NOCONTEXT */ |
|
3272 |
||
3273 |
#ifdef NSIG |
|
3274 |
# define SIG_LIMIT NSIG |
|
3275 |
#else |
|
3276 |
# ifdef SIGUSR2 |
|
3277 |
# define SIG_LIMIT SIGUSR2 |
|
3278 |
# else |
|
3279 |
# ifdef SIGUSR |
|
3280 |
# define SIG_LIMIT SIGUSR |
|
3281 |
# endif |
|
3282 |
# endif |
|
3283 |
#endif |
|
3284 |
||
3285 |
#if defined(SIGPOLL) && !defined(SIGIO) |
|
3286 |
# define SIGIO SIGPOLL |
|
3287 |
#endif |
|
3288 |
||
3289 |
#ifdef SIGCHLD |
|
3290 |
# define CHILD_SIGNAL SIGCHLD |
|
3291 |
#else |
|
3292 |
# ifdef SIGCLD |
|
3293 |
# define CHILD_SIGNAL SIGCLD |
|
3294 |
# endif |
|
3295 |
#endif |
|
3296 |
||
3297 |
int sigNr; |
|
443 | 3298 |
#if defined(SIGINT) || defined(SIGQUIT) |
329 | 3299 |
extern void __signalUserInterrupt(); |
443 | 3300 |
#endif |
3301 |
#ifdef SIGFPE |
|
329 | 3302 |
extern void __signalFpExceptionInterrupt(); |
443 | 3303 |
#endif |
3304 |
#ifdef SIGIO |
|
329 | 3305 |
extern void __signalIoInterrupt(); |
443 | 3306 |
#endif |
68 | 3307 |
#ifdef CHILD_SIGNAL |
329 | 3308 |
extern void __signalChildInterrupt(); |
68 | 3309 |
#endif |
443 | 3310 |
#ifdef SIGPIPE |
329 | 3311 |
extern void __signalPIPEInterrupt(); |
443 | 3312 |
#endif |
3313 |
#ifdef SIGBUS |
|
329 | 3314 |
extern void __signalBUSInterrupt(); |
443 | 3315 |
#endif |
3316 |
#ifdef SIGSEGV |
|
329 | 3317 |
extern void __signalSEGVInterrupt(); |
443 | 3318 |
#endif |
3319 |
#ifdef SIGALRM |
|
329 | 3320 |
extern void __signalTimerInterrupt(); |
443 | 3321 |
#endif |
329 | 3322 |
extern void __signalInterrupt(); |
213 | 3323 |
void (*handler)(); |
68 | 3324 |
|
252 | 3325 |
if (__isSmallInteger(signalNumber) |
68 | 3326 |
&& ((sigNr = _intVal(signalNumber)) > 0) |
3327 |
&& (sigNr <= SIG_LIMIT)) { |
|
185 | 3328 |
/* |
3329 |
* standard signals are forced into standard handlers |
|
3330 |
* - all others go into general signalInterrupt |
|
3331 |
*/ |
|
68 | 3332 |
#if defined(SIGPOLL) && defined(SIGIO) |
185 | 3333 |
if (sigNr == SIGPOLL) |
3334 |
sigNr = SIGIO; |
|
68 | 3335 |
#endif |
185 | 3336 |
switch (sigNr) { |
443 | 3337 |
#ifdef SIGINT |
185 | 3338 |
case SIGINT: |
443 | 3339 |
#endif |
3340 |
#ifdef SIGQUIT |
|
185 | 3341 |
case SIGQUIT: |
443 | 3342 |
#endif |
3343 |
#if defined(SIGINT) || defined(SIGQUIT) |
|
329 | 3344 |
handler = __signalUserInterrupt; |
185 | 3345 |
break; |
443 | 3346 |
#endif |
3347 |
||
3348 |
#ifdef SIGFPE |
|
185 | 3349 |
case SIGFPE: |
329 | 3350 |
handler = __signalFpExceptionInterrupt; |
185 | 3351 |
break; |
443 | 3352 |
#endif |
3353 |
||
3354 |
#ifdef SIGPIPE |
|
185 | 3355 |
case SIGPIPE: |
329 | 3356 |
handler = __signalPIPEInterrupt; |
185 | 3357 |
break; |
443 | 3358 |
#endif |
68 | 3359 |
#ifdef SIGBUS |
185 | 3360 |
case SIGBUS: |
329 | 3361 |
handler = __signalBUSInterrupt; |
185 | 3362 |
break; |
68 | 3363 |
#endif |
443 | 3364 |
#ifdef SIGSEGV |
185 | 3365 |
case SIGSEGV: |
329 | 3366 |
handler = __signalSEGVInterrupt; |
185 | 3367 |
break; |
443 | 3368 |
#endif |
68 | 3369 |
#ifdef SIGIO |
185 | 3370 |
case SIGIO: |
329 | 3371 |
handler = __signalIoInterrupt; |
185 | 3372 |
break; |
68 | 3373 |
#endif |
3374 |
||
3375 |
#ifdef CHILD_SIGNAL |
|
185 | 3376 |
case CHILD_SIGNAL: |
329 | 3377 |
handler = __signalChildInterrupt; |
185 | 3378 |
break; |
68 | 3379 |
#endif |
443 | 3380 |
#ifdef SIGALRM |
185 | 3381 |
case SIGALRM: |
329 | 3382 |
handler = __signalTimerInterrupt; |
185 | 3383 |
break; |
443 | 3384 |
#endif |
185 | 3385 |
|
3386 |
default: |
|
329 | 3387 |
handler = __signalInterrupt; |
185 | 3388 |
break; |
3389 |
} |
|
766
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3390 |
|
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3391 |
{ |
762
cea705669628
ok, stefan was right: HAS_SIGACTION works
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
3392 |
#ifdef HAS_SIGACTION |
766
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3393 |
struct sigaction act; |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3394 |
|
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3395 |
act.sa_flags = SA_RESTART | SA_SIGINFO; /* <- if you add more, remember dummys at the top */ |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3396 |
sigemptyset(&act.sa_mask); |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3397 |
act.sa_handler = handler; |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3398 |
sigaction(sigNr, &act, 0); |
213 | 3399 |
#else |
766
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3400 |
# ifdef HAS_SIGVEC |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3401 |
struct sigvec vec; |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3402 |
|
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3403 |
vec.sv_flags = 0; |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3404 |
sigemptyset(&vec.sv_mask); |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3405 |
vec.sv_handler = handler; |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3406 |
sigvec(sigNr, &vec, NULL); |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3407 |
# else |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3408 |
signal(sigNr, handler); |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3409 |
# endif |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3410 |
#endif |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3411 |
} |
213 | 3412 |
|
185 | 3413 |
/* |
3414 |
* maybe, we should return the old enable-status |
|
3415 |
* as boolean here ... |
|
3416 |
*/ |
|
3417 |
RETURN (self); |
|
68 | 3418 |
} |
3419 |
%}. |
|
3420 |
||
3421 |
" |
|
3422 |
this error is triggered on non-integer argument, or |
|
3423 |
if the signal number is not in the valid range (1..NSIG) |
|
3424 |
" |
|
63 | 3425 |
self primitiveFailed |
3426 |
! |
|
3427 |
||
616 | 3428 |
enableTimer:millis |
3429 |
"trigger a timerInterrupt, to be signalled after some (real) time." |
|
3430 |
||
3431 |
%{ /* NOCONTEXT */ |
|
3432 |
||
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3433 |
#if defined(ITIMER_REAL) |
616 | 3434 |
extern void __signalTimerInterrupt(); |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3435 |
static int firstCall = 1; |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3436 |
|
616 | 3437 |
struct itimerval dt; |
3438 |
||
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3439 |
if (firstCall) { |
762
cea705669628
ok, stefan was right: HAS_SIGACTION works
Claus Gittinger <cg@exept.de>
parents:
761
diff
changeset
|
3440 |
#ifdef HAS_SIGACTION |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3441 |
struct sigaction act; |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3442 |
|
763
7d5e32ed435e
dummy SA_xxx defs for systems which dont have them (HP & ultrix)
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
3443 |
act.sa_flags = SA_RESTART | SA_SIGINFO; /* <- if you add more, remember dummys at the top */ |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3444 |
sigemptyset(&act.sa_mask); |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3445 |
act.sa_handler = __signalTimerInterrupt; |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3446 |
sigaction(SIGALRM, &act, 0); |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3447 |
#else |
766
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3448 |
# ifdef HAS_SIGVEC |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3449 |
struct sigvec vec; |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3450 |
|
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3451 |
vec.sv_flags = 0; |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3452 |
sigemptyset(&vec.sv_mask); |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3453 |
vec.sv_handler = __signalTimerInterrupt; |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3454 |
sigvec(SIGALRM, &vec, NULL); |
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3455 |
# else |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
756
diff
changeset
|
3456 |
signal(SIGALRM, __signalTimerInterrupt); |
766
9d6cc2cc834e
igvec (SIGVEC) stuff added (for ultrix)
Claus Gittinger <cg@exept.de>
parents:
765
diff
changeset
|
3457 |
# endif |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3458 |
#endif |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
3459 |
firstCall = 0; |
640
be94dfc60eaa
Anforderung von SA_SIGINFO in sigaction.
Stefan Vogel <sv@exept.de>
parents:
630
diff
changeset
|
3460 |
} |
616 | 3461 |
|
3462 |
dt.it_interval.tv_sec = 0; |
|
3463 |
dt.it_interval.tv_usec = 0; |
|
3464 |
dt.it_value.tv_sec = _intVal(millis) / 1000; |
|
3465 |
dt.it_value.tv_usec = (_intVal(millis) % 1000) * 1000; |
|
3466 |
setitimer(ITIMER_REAL, &dt, 0); |
|
3467 |
RETURN (true); |
|
3468 |
#endif |
|
3469 |
%} |
|
3470 |
. |
|
3471 |
^ false |
|
3472 |
! |
|
3473 |
||
1 | 3474 |
enableUserInterrupts |
3475 |
"enable userInterrupt (^C) handling; |
|
95 | 3476 |
when enabled, ^C in the terminal window will send the message |
3477 |
'userInterrupt' to the UserInterruptHandler object." |
|
1 | 3478 |
|
68 | 3479 |
^ self enableSignal:(self sigINT) |
63 | 3480 |
! |
3481 |
||
616 | 3482 |
interruptPending |
3483 |
"return true, if an interrupt is pending. The returned value is |
|
3484 |
invalid if interrupts are not currently blocked, since otherwise |
|
3485 |
the interrupt is usually already handled before arriving here, |
|
3486 |
or may be served while returning from here." |
|
3487 |
||
3488 |
%{ /* NOCONTEXT */ |
|
3489 |
extern OBJ __INTERRUPTPENDING(); |
|
3490 |
||
3491 |
RETURN ( __INTERRUPTPENDING() ); |
|
3492 |
%} |
|
1 | 3493 |
! |
3494 |
||
704 | 3495 |
killProcess:processId |
3496 |
"terminate a unix process." |
|
3497 |
||
3498 |
self sendSignal:(self sigKILL) to:processId. |
|
3499 |
! |
|
3500 |
||
616 | 3501 |
nameForSignal:aSignalNumber |
3502 |
"for a given Unix signalnumber, return a descriptive string" |
|
3503 |
||
3504 |
aSignalNumber == self sigHUP ifTrue:[^ 'hangup']. |
|
3505 |
aSignalNumber == self sigINT ifTrue:[^ 'interrupt']. |
|
3506 |
aSignalNumber == self sigKILL ifTrue:[^ 'kill']. |
|
3507 |
aSignalNumber == self sigQUIT ifTrue:[^ 'quit']. |
|
3508 |
aSignalNumber == self sigILL ifTrue:[^ 'illegal instruction']. |
|
3509 |
aSignalNumber == self sigTRAP ifTrue:[^ 'trap']. |
|
3510 |
aSignalNumber == self sigABRT ifTrue:[^ 'abort']. |
|
3511 |
aSignalNumber == self sigIOT ifTrue:[^ 'iot trap']. |
|
3512 |
aSignalNumber == self sigEMT ifTrue:[^ 'emt trap']. |
|
3513 |
aSignalNumber == self sigFP ifTrue:[^ 'fp exception']. |
|
3514 |
aSignalNumber == self sigBUS ifTrue:[^ 'bus error']. |
|
3515 |
aSignalNumber == self sigSEGV ifTrue:[^ 'segmentation violation']. |
|
3516 |
aSignalNumber == self sigSYS ifTrue:[^ 'bad system call']. |
|
3517 |
aSignalNumber == self sigPIPE ifTrue:[^ 'broken pipe']. |
|
3518 |
aSignalNumber == self sigALRM ifTrue:[^ 'alarm timer']. |
|
3519 |
aSignalNumber == self sigTERM ifTrue:[^ 'termination']. |
|
3520 |
aSignalNumber == self sigSTOP ifTrue:[^ 'stop']. |
|
3521 |
aSignalNumber == self sigTSTP ifTrue:[^ 'tty stop']. |
|
3522 |
aSignalNumber == self sigCONT ifTrue:[^ 'continue']. |
|
3523 |
aSignalNumber == self sigCHLD ifTrue:[^ 'child death']. |
|
3524 |
aSignalNumber == self sigTTIN ifTrue:[^ 'background tty input']. |
|
3525 |
aSignalNumber == self sigTTOU ifTrue:[^ 'background tty output']. |
|
3526 |
aSignalNumber == self sigIO ifTrue:[^ 'io available']. |
|
3527 |
aSignalNumber == self sigXCPU ifTrue:[^ 'cpu time expired']. |
|
3528 |
aSignalNumber == self sigXFSZ ifTrue:[^ 'file size limit']. |
|
3529 |
aSignalNumber == self sigVTALRM ifTrue:[^ 'virtual alarm timer']. |
|
3530 |
aSignalNumber == self sigPROF ifTrue:[^ 'profiling timer']. |
|
3531 |
aSignalNumber == self sigWINCH ifTrue:[^ 'winsize changed']. |
|
3532 |
aSignalNumber == self sigLOST ifTrue:[^ 'resource lost']. |
|
3533 |
aSignalNumber == self sigUSR1 ifTrue:[^ 'user signal 1']. |
|
3534 |
aSignalNumber == self sigUSR2 ifTrue:[^ 'user signal 2']. |
|
3535 |
aSignalNumber == self sigMSG ifTrue:[^ 'HFT message']. |
|
3536 |
aSignalNumber == self sigPWR ifTrue:[^ 'power-fail']. |
|
3537 |
aSignalNumber == self sigPRE ifTrue:[^ 'programming exception']. |
|
3538 |
aSignalNumber == self sigGRANT ifTrue:[^ 'HFT access wanted']. |
|
3539 |
aSignalNumber == self sigRETRACT ifTrue:[^ 'HFT access relinquish']. |
|
3540 |
aSignalNumber == self sigSOUND ifTrue:[^ 'HFT sound complete']. |
|
3541 |
aSignalNumber == self sigDANGER ifTrue:[^ 'low on paging space']. |
|
3542 |
||
3543 |
"notice: many systems map SIGPOLL and/or SIGUSR onto SIGIO |
|
3544 |
therefore, keep SIGIO always above the two below" |
|
3545 |
aSignalNumber == self sigPOLL ifTrue:[^ 'io available']. |
|
3546 |
aSignalNumber == self sigURG ifTrue:[^ 'urgent']. |
|
3547 |
||
3548 |
^ 'unknown signal' |
|
3549 |
||
68 | 3550 |
" |
616 | 3551 |
OperatingSystem nameForSignal:9 |
3552 |
OperatingSystem nameForSignal:(OperatingSystem sigPOLL) |
|
68 | 3553 |
" |
616 | 3554 |
! |
3555 |
||
3556 |
operatingSystemSignal:signalNumber |
|
3557 |
"return the signal to be raised when an |
|
3558 |
operatingSystem-signal occurs, or nil" |
|
3559 |
||
3560 |
OSSignals notNil ifTrue:[ |
|
3561 |
^ OSSignals at:signalNumber ifAbsent:[nil] |
|
3562 |
]. |
|
3563 |
^ nil |
|
10 | 3564 |
! |
3565 |
||
616 | 3566 |
operatingSystemSignal:signalNumber install:aSignal |
3567 |
"install a signal to be raised when an operatingSystem-signal occurs" |
|
3568 |
||
3569 |
OSSignals isNil ifTrue:[ |
|
3570 |
OSSignals := Array new:32 |
|
3571 |
]. |
|
3572 |
OSSignals at:signalNumber put:aSignal |
|
3573 |
! |
|
3574 |
||
3575 |
sendSignal:signalNumber to:processId |
|
3576 |
"send a unix signal to some process (maybe myself). |
|
3577 |
Returns false if any error occurred, true otherwise. |
|
3578 |
||
3579 |
Do not confuse UNIX signals with Smalltalk-Signals." |
|
3580 |
%{ |
|
3581 |
if (__bothSmallInteger(signalNumber, processId)) { |
|
3582 |
if (kill(__intVal(processId), __intVal(signalNumber)) < 0) { |
|
3583 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
3584 |
RETURN ( false ); |
|
216 | 3585 |
} |
616 | 3586 |
RETURN ( true ); |
10 | 3587 |
} |
68 | 3588 |
%}. |
10 | 3589 |
self primitiveFailed |
1 | 3590 |
! |
3591 |
||
3592 |
startSpyTimer |
|
63 | 3593 |
"trigger a spyInterrupt, to be signalled after some short (virtual) time. |
359 | 3594 |
This is used by the old MessageTally for profiling. |
63 | 3595 |
Should be changed to use real profiling timer if available. |
68 | 3596 |
On systems, where no virtual timer is available, use the real timer |
359 | 3597 |
(which is of course less correct). |
3598 |
OBSOLETE: the new messageTally runs as a high prio process, not using |
|
3599 |
spy interrupts." |
|
1 | 3600 |
|
3601 |
%{ /* NOCONTEXT */ |
|
3602 |
||
329 | 3603 |
extern void __spyInterrupt(); |
10 | 3604 |
#if defined(ITIMER_VIRTUAL) |
1 | 3605 |
struct itimerval dt; |
3606 |
||
13 | 3607 |
# ifdef SIGVTALRM |
329 | 3608 |
signal(SIGVTALRM, __spyInterrupt); |
13 | 3609 |
# else |
329 | 3610 |
signal(SIGALRM, __spyInterrupt); |
13 | 3611 |
# endif |
3612 |
||
348 | 3613 |
dt.it_interval.tv_sec = 0; |
3614 |
dt.it_interval.tv_usec = 0; |
|
3615 |
dt.it_value.tv_sec = 0; |
|
3616 |
dt.it_value.tv_usec = 1000; /* 1000 Hz */ |
|
3617 |
setitimer(ITIMER_VIRTUAL, &dt, 0); |
|
3618 |
||
13 | 3619 |
RETURN (true); |
1 | 3620 |
#endif |
3621 |
%} |
|
13 | 3622 |
. |
3623 |
^ false |
|
1 | 3624 |
! |
3625 |
||
3626 |
stopSpyTimer |
|
359 | 3627 |
"stop spy timing - disable spy timer. |
3628 |
OBSOLETE: the new messageTally runs as a high prio process, not using |
|
3629 |
spy interrupts." |
|
1 | 3630 |
|
3631 |
%{ /* NOCONTEXT */ |
|
3632 |
||
10 | 3633 |
#if defined(ITIMER_VIRTUAL) |
1 | 3634 |
struct itimerval dt; |
3635 |
||
3636 |
dt.it_interval.tv_sec = 0; |
|
3637 |
dt.it_interval.tv_usec = 0; |
|
3638 |
dt.it_value.tv_sec = 0; |
|
3639 |
dt.it_value.tv_usec = 0; |
|
3640 |
setitimer(ITIMER_VIRTUAL, &dt, 0); |
|
13 | 3641 |
RETURN (true); |
10 | 3642 |
#endif |
3643 |
%} |
|
13 | 3644 |
. |
3645 |
^ false |
|
10 | 3646 |
! |
3647 |
||
616 | 3648 |
unblockInterrupts |
3649 |
"enable interrupt processing - if any interrupts are pending, |
|
3650 |
these will be handled immediately. |
|
3651 |
When unblocking interrupts, take care of nested block/unblock |
|
3652 |
calls - you must only unblock after a blockcall if they where |
|
3653 |
really not blocked before. See OperatingSystemclass>>blockInterrupts." |
|
3654 |
%{ |
|
3655 |
extern void __UNBLOCKINTERRUPTS(); |
|
3656 |
||
3657 |
__UNBLOCKINTERRUPTS(); |
|
3658 |
%} |
|
3659 |
! ! |
|
3660 |
||
3661 |
!OperatingSystem class methodsFor:'misc'! |
|
3662 |
||
3663 |
exit |
|
710 | 3664 |
"shutdown smalltalk immediately - this method does not return. |
3665 |
Return 'good'-status (0) to the parent unix process." |
|
616 | 3666 |
|
3667 |
%{ /* NOCONTEXT */ |
|
3668 |
__mainExit(0); |
|
3669 |
%} |
|
3670 |
"OperatingSystem exit - dont evaluate this" |
|
3671 |
! |
|
3672 |
||
3673 |
exit:exitCode |
|
3674 |
"shutdown smalltalk immediately - |
|
3675 |
returning an exit-code to the parent unix process." |
|
3676 |
||
3677 |
%{ /* NOCONTEXT */ |
|
3678 |
int code = 1; |
|
3679 |
||
3680 |
if (__isSmallInteger(exitCode)) { |
|
3681 |
code = _intVal(exitCode); |
|
3682 |
} |
|
3683 |
__mainExit(code); |
|
3684 |
%} |
|
3685 |
"OperatingSystem exit:1 - dont evaluate this" |
|
3686 |
! |
|
3687 |
||
3688 |
exitWithCoreDump |
|
3689 |
"shutdown smalltalk immediately - dumping core. |
|
3690 |
This always returns 'bad'-status to the parent unix process. |
|
3691 |
Notice, that no cleanup is performed at all - you may have to |
|
3692 |
manually remove any tempfiles. |
|
3693 |
Use this only for debugging ST/X itself" |
|
3694 |
||
3695 |
%{ /* NOCONTEXT */ |
|
3696 |
abort(); |
|
3697 |
%} |
|
3698 |
"OperatingSystem exitWithCoreDump - dont evaluate this" |
|
3699 |
! |
|
3700 |
||
3701 |
slowFork:aBoolean |
|
3702 |
SlowFork := aBoolean |
|
3703 |
! ! |
|
3704 |
||
3705 |
!OperatingSystem class methodsFor:'os queries'! |
|
3706 |
||
3707 |
getCPUDefine |
|
3708 |
"return a string which was used to identify this CPU type when stx was |
|
3709 |
compiled, and which should be passed down when compiling methods. |
|
3710 |
For example, on linux, this may be '-Di386'; on a vax, this would be '-Dvax'." |
|
3711 |
||
3712 |
%{ /* NOCONTEXT */ |
|
3713 |
#ifndef CPU_DEFINE |
|
3714 |
# define CPU_DEFINE "-DunknownCPU" |
|
3715 |
#endif |
|
3716 |
RETURN ( __MKSTRING(CPU_DEFINE COMMA_CON)); |
|
3717 |
%} |
|
3718 |
" |
|
3719 |
OperatingSystem getCPUDefine |
|
3720 |
" |
|
3721 |
! |
|
3722 |
||
3723 |
getCPUType |
|
3724 |
"return a string giving the type of machine we're running on. |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
756
diff
changeset
|
3725 |
This may normally not be of any interest to you ..." |
616 | 3726 |
|
3727 |
|cpu| |
|
3728 |
||
3729 |
%{ /* NOCONTEXT */ |
|
3730 |
||
3731 |
# ifdef vax |
|
3732 |
# define CPU_STRING "vax" |
|
3733 |
# endif |
|
3734 |
# ifdef mips |
|
3735 |
# define CPU_STRING "mips" |
|
3736 |
# endif |
|
3737 |
# ifdef i386 |
|
3738 |
# define CPU_STRING "i386" |
|
3739 |
# endif |
|
3740 |
# ifdef ns32k |
|
3741 |
# define CPU_STRING "ns32k" |
|
3742 |
# endif |
|
3743 |
# ifdef mc68k |
|
3744 |
# define CPU_STRING "mc68k" |
|
3745 |
# endif |
|
3746 |
# ifdef mc88k |
|
3747 |
# define CPU_STRING "mc88k" |
|
3748 |
# endif |
|
3749 |
# ifdef sparc |
|
3750 |
# define CPU_STRING "sparc" |
|
3751 |
# endif |
|
3752 |
# ifdef hppa |
|
3753 |
# define CPU_STRING "hppa" |
|
3754 |
# endif |
|
3755 |
# ifdef rs6000 |
|
3756 |
# define CPU_STRING "rs6000" |
|
3757 |
# endif |
|
3758 |
# ifdef alpha |
|
3759 |
# define CPU_STRING "alpha" |
|
3760 |
# endif |
|
3761 |
# ifdef powerPC |
|
3762 |
# define CPU_STRING "powerPC" |
|
3763 |
# endif |
|
3764 |
# ifdef transputer |
|
3765 |
# define CPU_STRING "transputer" |
|
3766 |
# endif |
|
3767 |
# ifdef ibm370 |
|
3768 |
# define CPU_STRING "ibm370" |
|
3769 |
# endif |
|
3770 |
||
3771 |
# ifndef CPU_STRING |
|
3772 |
# define CPU_STRING "unknown" |
|
3773 |
# endif |
|
3774 |
||
3775 |
cpu = _MKSTRING(CPU_STRING COMMA_CON); |
|
3776 |
# undef CPU_STRING |
|
3777 |
%} |
|
3778 |
. |
|
3779 |
^ cpu |
|
3780 |
||
3781 |
" |
|
3782 |
OperatingSystem getCPUType |
|
3783 |
" |
|
3784 |
||
3785 |
"examples: are we running on a ss-10/solaris ?" |
|
3786 |
" |
|
3787 |
(OperatingSystem getCPUType = 'sparc') |
|
3788 |
and:[OperatingSystem getOSType = 'solaris'] |
|
3789 |
" |
|
3790 |
||
3791 |
"or on a pc/solaris ?" |
|
3792 |
" |
|
3793 |
(OperatingSystem getCPUType = 'i386') |
|
3794 |
and:[OperatingSystem getOSType = 'solaris'] |
|
3795 |
" |
|
3796 |
! |
|
3797 |
||
3798 |
getCommandOutputFrom:aCommand |
|
3799 |
"execute a simple command (such as hostname) and |
|
3800 |
return the commands output as a string" |
|
3801 |
||
3802 |
|p result| |
|
3803 |
||
3804 |
ForkFailed ifFalse:[ |
|
3805 |
PipeStream openErrorSignal handle:[:ex | |
|
3806 |
ForkFailed := true. |
|
3807 |
'OS: cannot fork/popen' errorPrintNL. |
|
3808 |
ex return. |
|
3809 |
] do:[ |
|
3810 |
p := PipeStream readingFrom:aCommand. |
|
3811 |
p notNil ifTrue:[ |
|
3812 |
result := p nextLine. |
|
3813 |
p close |
|
3814 |
] |
|
3815 |
] |
|
3816 |
]. |
|
3817 |
^ result |
|
3818 |
! |
|
3819 |
||
3820 |
getDomainName |
|
3821 |
"return the domain this host is in. |
|
3822 |
Notice: |
|
3823 |
not all systems support this; on some, 'unknown' is returned." |
|
3824 |
||
3825 |
|name| |
|
3826 |
||
3827 |
DomainName notNil ifTrue:[ |
|
3828 |
^ DomainName |
|
3829 |
]. |
|
3830 |
||
3831 |
%{ /* STACK: 2048 */ |
|
3832 |
#if defined(HAS_GETDOMAINNAME) |
|
3833 |
char buffer[128]; |
|
3834 |
||
3835 |
if (getdomainname(buffer, sizeof(buffer)) == 0) { |
|
3836 |
name = _MKSTRING(buffer COMMA_CON); |
|
3837 |
} |
|
3838 |
#else |
|
3839 |
# if defined(HAS_UNAME) && defined(HAS_UTS_DOMAINNAME) |
|
3840 |
struct utsname ubuff; |
|
3841 |
||
3842 |
if (uname(&ubuff) >= 0) { |
|
3843 |
name = _MKSTRING(ubuff.domainname COMMA_CON); |
|
3844 |
} |
|
3845 |
# endif |
|
3846 |
#endif |
|
3847 |
%}. |
|
3848 |
name isNil ifTrue:[ |
|
3849 |
name := self getEnvironment:'DOMAIN'. |
|
3850 |
name isNil ifTrue:[ |
|
3851 |
name := self getCommandOutputFrom:'domainname' |
|
3852 |
] |
|
3853 |
]. |
|
3854 |
name isNil ifTrue:[ |
|
3855 |
'OS: cannot find out domainname' errorPrintNL. |
|
3856 |
name := 'unknown'. |
|
3857 |
]. |
|
3858 |
DomainName := name. |
|
3859 |
^ name |
|
3860 |
||
3861 |
" |
|
3862 |
OperatingSystem getDomainName |
|
3863 |
" |
|
3864 |
! |
|
3865 |
||
3866 |
getEnvironment:aStringOrSymbol |
|
3867 |
"get an environment string" |
|
10 | 3868 |
|
3869 |
%{ /* NOCONTEXT */ |
|
3870 |
||
616 | 3871 |
char *env; |
3872 |
||
3873 |
if (__isString(aStringOrSymbol) || __isSymbol(aStringOrSymbol)) { |
|
3874 |
env = (char *)getenv(_stringVal(aStringOrSymbol)); |
|
3875 |
if (env) { |
|
3876 |
RETURN ( _MKSTRING(env COMMA_CON) ); |
|
3877 |
} |
|
3878 |
} |
|
3879 |
%} |
|
3880 |
. |
|
3881 |
^ nil |
|
3882 |
||
3883 |
" |
|
3884 |
OperatingSystem getEnvironment:'LANG' |
|
3885 |
OperatingSystem getEnvironment:'LOGIN' |
|
3886 |
OperatingSystem getEnvironment:'HOME' |
|
3887 |
OperatingSystem getEnvironment:'NNTPSERVER' |
|
3888 |
OperatingSystem getEnvironment:'MAIL' |
|
3889 |
OperatingSystem getEnvironment:'PATH' |
|
3890 |
" |
|
3891 |
! |
|
3892 |
||
3893 |
getHostName |
|
3894 |
"return the hostname we are running on - if there is |
|
3895 |
a HOST environment variable, we are much faster here ... |
|
3896 |
Notice: |
|
3897 |
not all systems support this; on some, 'unknown' is returned." |
|
3898 |
||
3899 |
|name| |
|
3900 |
||
3901 |
HostName notNil ifTrue:[ |
|
3902 |
^ HostName |
|
3903 |
]. |
|
3904 |
||
3905 |
%{ /* STACK: 2048 */ |
|
3906 |
#if defined(HAS_GETHOSTNAME) |
|
3907 |
char buffer[128]; |
|
3908 |
||
3909 |
if (gethostname(buffer, sizeof(buffer)) == 0) { |
|
3910 |
name = _MKSTRING(buffer COMMA_CON); |
|
3911 |
} |
|
3912 |
#else |
|
3913 |
# if defined(HAS_UNAME) |
|
3914 |
struct utsname ubuff; |
|
3915 |
||
3916 |
if (uname(&ubuff) >= 0) { |
|
3917 |
name = _MKSTRING(ubuff.nodename COMMA_CON); |
|
3918 |
} |
|
1 | 3919 |
# endif |
616 | 3920 |
#endif |
3921 |
%}. |
|
3922 |
name isNil ifTrue:[ |
|
3923 |
name := self getEnvironment:'HOST'. |
|
3924 |
name isNil ifTrue:[ |
|
3925 |
name := self getCommandOutputFrom:'hostname' |
|
3926 |
] |
|
3927 |
]. |
|
3928 |
name isNil ifTrue:[ |
|
3929 |
'OS: cannot find out hostname' errorPrintNL. |
|
3930 |
name := 'unknown'. |
|
3931 |
]. |
|
3932 |
HostName := name. |
|
3933 |
^ name |
|
3934 |
||
3935 |
" |
|
3936 |
OperatingSystem getHostName |
|
3937 |
" |
|
3938 |
! |
|
3939 |
||
3940 |
getOSDefine |
|
3941 |
"return a string which was used to identify this machine when stx was |
|
3942 |
compiled, and which should be passed down when compiling methods. |
|
3943 |
For example, on linux, this is '-DLINUX'." |
|
3944 |
||
3945 |
%{ /* NOCONTEXT */ |
|
3946 |
#ifndef OS_DEFINE |
|
3947 |
# define OS_DEFINE "-DunknownOS" |
|
3948 |
#endif |
|
3949 |
RETURN ( __MKSTRING(OS_DEFINE COMMA_CON)); |
|
3950 |
%} |
|
3951 |
" |
|
3952 |
OperatingSystem getOSDefine |
|
3953 |
" |
|
3954 |
! |
|
3955 |
||
3956 |
getOSType |
|
3957 |
"return a string giving the type of OS we're running on. |
|
3958 |
This can be used to adapt programs to certain environment |
|
3959 |
differences (for example: mail-lock strategy ...)" |
|
3960 |
||
3961 |
|os| |
|
3962 |
||
3963 |
%{ /* NOCONTEXT */ |
|
3964 |
||
3965 |
# ifdef MSDOS |
|
3966 |
# define OS_STRING "msdos" |
|
3967 |
# endif |
|
3968 |
||
3969 |
# ifdef MSWINDOWS |
|
3970 |
# define OS_STRING "mswindows" |
|
3971 |
# endif |
|
3972 |
||
3973 |
# ifdef NT |
|
3974 |
# define OS_STRING "nt" |
|
3975 |
# endif |
|
3976 |
||
3977 |
# ifdef VMS |
|
3978 |
# define OS_STRING "vms" |
|
3979 |
# endif |
|
3980 |
||
3981 |
# ifdef MVS |
|
3982 |
# define OS_STRING "mvs" |
|
3983 |
# endif |
|
3984 |
||
3985 |
# ifdef OS2 |
|
3986 |
# define OS_STRING "os2" |
|
3987 |
# endif |
|
3988 |
||
3989 |
# ifdef sinix |
|
3990 |
# define OS_STRING "sinix" |
|
3991 |
# endif |
|
3992 |
||
3993 |
# ifdef ultrix |
|
3994 |
# define OS_STRING "ultrix" |
|
3995 |
# endif |
|
3996 |
||
3997 |
# ifdef sco |
|
3998 |
# define OS_STRING "sco" |
|
3999 |
# endif |
|
4000 |
||
4001 |
# ifdef hpux |
|
4002 |
# define OS_STRING "hpux" |
|
4003 |
# endif |
|
4004 |
||
4005 |
# ifdef LINUX |
|
4006 |
# define OS_STRING "linux" |
|
4007 |
# endif |
|
4008 |
||
4009 |
# ifdef sunos |
|
4010 |
# define OS_STRING "sunos" |
|
4011 |
# endif |
|
4012 |
||
4013 |
# ifdef solaris |
|
4014 |
# define OS_STRING "solaris" |
|
4015 |
# endif |
|
4016 |
||
4017 |
# ifdef IRIS |
|
4018 |
# define OS_STRING "irix" |
|
4019 |
# endif |
|
4020 |
||
4021 |
# ifdef aix |
|
4022 |
# define OS_STRING "aix" |
|
4023 |
# endif |
|
4024 |
||
4025 |
# ifdef realIX |
|
4026 |
# define OS_STRING "realIX" |
|
4027 |
# endif |
|
4028 |
||
4029 |
/* |
|
4030 |
* no concrete info; become somewhat vague ... |
|
4031 |
*/ |
|
4032 |
# ifndef OS_STRING |
|
4033 |
# ifdef MACH |
|
4034 |
# define OS_STRING "mach" |
|
4035 |
# endif |
|
4036 |
# endif |
|
4037 |
||
4038 |
# ifndef OS_STRING |
|
4039 |
# ifdef BSD |
|
4040 |
# define OS_STRING "bsd" |
|
4041 |
# endif |
|
4042 |
||
4043 |
# ifdef SYSV |
|
4044 |
# ifdef SYSV3 |
|
4045 |
# define OS_STRING "sys5_3" |
|
4046 |
# else |
|
4047 |
# ifdef SYSV4 |
|
4048 |
# define OS_STRING "sys5_4" |
|
4049 |
# else |
|
4050 |
# define OS_STRING "sys5" |
|
4051 |
# endif |
|
4052 |
# endif |
|
4053 |
# endif |
|
4054 |
# endif |
|
4055 |
||
4056 |
/* |
|
4057 |
* become very vague ... |
|
4058 |
*/ |
|
4059 |
# ifndef OS_STRING |
|
4060 |
# ifdef POSIX |
|
4061 |
# define OS_STRING "posix" |
|
4062 |
# endif |
|
4063 |
# endif |
|
4064 |
# ifndef OS_STRING |
|
4065 |
# ifdef UNIX |
|
4066 |
# define OS_STRING "unix" |
|
4067 |
# endif |
|
4068 |
# endif |
|
4069 |
||
4070 |
# ifndef OS_STRING |
|
4071 |
# define OS_STRING "unknown" |
|
4072 |
# endif |
|
4073 |
||
4074 |
os = _MKSTRING(OS_STRING COMMA_CON); |
|
4075 |
# undef OS_STRING |
|
4076 |
%} |
|
4077 |
. |
|
4078 |
^ os |
|
4079 |
||
4080 |
"OperatingSystem getOSType" |
|
4081 |
! |
|
4082 |
||
4083 |
getProcessId |
|
4084 |
"return the (unix-)processId" |
|
4085 |
||
4086 |
%{ /* NOCONTEXT */ |
|
4087 |
||
4088 |
int pid = 0; |
|
4089 |
#ifdef UNIX_LIKE |
|
4090 |
pid = getpid(); |
|
4091 |
#endif |
|
4092 |
RETURN ( _MKSMALLINT(pid) ); |
|
4093 |
%} |
|
4094 |
" |
|
4095 |
OperatingSystem getProcessId |
|
4096 |
" |
|
4097 |
! |
|
4098 |
||
4099 |
getSystemID |
|
4100 |
"if supported by the OS, return the systemID; |
|
4101 |
a unique per machine identification. |
|
4102 |
WARNING: |
|
4103 |
not all systems support this; on some, 'unknown' is returned." |
|
4104 |
||
4105 |
%{ /* NO_CONTEXT */ |
|
4106 |
#if defined(IRIX5) && !defined(HAS_GETHOSTID) |
|
4107 |
char idBuffer[MAXSYSIDSIZE]; |
|
4108 |
int retVal; |
|
4109 |
OBJ arr; |
|
4110 |
extern OBJ __BYTEARRAY_UNINITIALIZED_NEW_INT(); |
|
4111 |
||
4112 |
if ((retVal = syssgi(SGI_SYSID, idBuffer)) == 0) { |
|
4113 |
arr = __BYTEARRAY_UNINITIALIZED_NEW_INT(MAXSYSIDSIZE); |
|
4114 |
bcopy(idBuffer, __ByteArrayInstPtr(arr)->ba_element, MAXSYSIDSIZE); |
|
4115 |
RETURN (arr); |
|
4116 |
} |
|
4117 |
#endif |
|
4118 |
#if defined(HAS_GETHOSTID) |
|
4119 |
int runningId; |
|
4120 |
OBJ arr; |
|
4121 |
extern OBJ __BYTEARRAY_UNINITIALIZED_NEW_INT(); |
|
4122 |
||
4123 |
runningId = gethostid(); |
|
4124 |
arr = __BYTEARRAY_UNINITIALIZED_NEW_INT(4); |
|
4125 |
*(int *)(__ByteArrayInstPtr(arr)->ba_element) = runningId; |
|
4126 |
RETURN (arr); |
|
4127 |
#endif |
|
4128 |
%}. |
|
4129 |
^ 'unknown' |
|
4130 |
||
4131 |
" |
|
4132 |
OperatingSystem getSystemID |
|
4133 |
" |
|
4134 |
! |
|
4135 |
||
4136 |
getSystemInfo |
|
4137 |
"return info on the system weare running on - if the |
|
4138 |
system supports the uname system call, that infor is returned; |
|
4139 |
otherwise, some simulated info is returned. |
|
4140 |
WARNING: |
|
4141 |
Do not depend on the amount of returned information, some |
|
4142 |
systems may return more/less than others. |
|
4143 |
||
4144 |
The returned info may (or may not) contain: |
|
4145 |
#system -> some operating system identification |
|
4146 |
#node -> some host identification |
|
4147 |
#release -> OS release |
|
4148 |
#version -> OS version |
|
4149 |
#machine -> type of machine |
|
4150 |
#domain -> domain name |
|
4151 |
" |
|
4152 |
||
4153 |
|sys node rel ver mach dom mtyp brel info| |
|
4154 |
||
4155 |
%{ /* STACK: 2048 */ |
|
4156 |
#if defined(HAS_UNAME) |
|
4157 |
struct utsname ubuff; |
|
4158 |
||
4159 |
if (uname(&ubuff) >= 0) { |
|
4160 |
sys = _MKSTRING(ubuff.sysname COMMA_CON); |
|
4161 |
node = _MKSTRING(ubuff.nodename COMMA_CON); |
|
4162 |
rel = _MKSTRING(ubuff.release COMMA_CON); |
|
4163 |
ver = _MKSTRING(ubuff.version COMMA_CON); |
|
4164 |
mach = _MKSTRING(ubuff.machine COMMA_CON); |
|
4165 |
# ifdef HAS_UTS_DOMAINNAME |
|
4166 |
dom = _MKSTRING(ubuff.domainname COMMA_CON); |
|
4167 |
# endif |
|
4168 |
} |
|
4169 |
#else |
|
4170 |
# ifdef mswindows |
|
4171 |
/* add corresponding info here */ |
|
4172 |
# endif |
|
4173 |
#endif |
|
4174 |
%}. |
|
4175 |
sys isNil ifTrue:[ |
|
4176 |
sys := self getSystemType. |
|
4177 |
]. |
|
4178 |
node isNil ifTrue:[ |
|
4179 |
node := self getHostName |
|
4180 |
]. |
|
4181 |
dom isNil ifTrue:[ |
|
4182 |
dom := self getDomainName |
|
4183 |
]. |
|
4184 |
||
4185 |
info := IdentityDictionary new. |
|
4186 |
info at:#system put:sys. |
|
4187 |
info at:#node put:node. |
|
4188 |
rel notNil ifTrue:[info at:#release put:rel]. |
|
4189 |
ver notNil ifTrue:[info at:#version put:ver]. |
|
4190 |
mach notNil ifTrue:[info at:#machine put:mach]. |
|
4191 |
dom notNil ifTrue:[info at:#domain put:dom]. |
|
4192 |
^ info |
|
4193 |
||
4194 |
" |
|
4195 |
OperatingSystem getSystemInfo |
|
4196 |
" |
|
4197 |
! |
|
4198 |
||
4199 |
getSystemType |
|
4200 |
"return a string giving the type of system we're running on. |
|
4201 |
This is almost the same as getOSType, but the returned string |
|
4202 |
is slightly different for some systems (i.e. iris vs. irix). |
|
4203 |
Dont depend on this - use getOSType. I dont really see a point |
|
4204 |
here ... (except for slight differences between next/mach and other |
|
4205 |
machs)" |
|
4206 |
||
4207 |
|sys| |
|
4208 |
||
4209 |
%{ |
|
4210 |
# ifdef NEXT |
|
4211 |
# define SYS_STRING "next" |
|
4212 |
# endif |
|
4213 |
||
4214 |
# ifdef IRIS |
|
4215 |
# define SYS_STRING "iris" |
|
4216 |
# endif |
|
4217 |
||
4218 |
# ifdef SYS_STRING |
|
4219 |
sys = _MKSTRING(SYS_STRING COMMA_CON); |
|
4220 |
# undef SYS_STRING |
|
4221 |
# endif |
|
4222 |
%} |
|
4223 |
. |
|
4224 |
sys isNil ifTrue:[ |
|
4225 |
^ self getOSType |
|
4226 |
]. |
|
4227 |
^ sys |
|
4228 |
||
4229 |
" |
|
4230 |
OperatingSystem getSystemType |
|
4231 |
" |
|
4232 |
! |
|
4233 |
||
4234 |
isBSDlike |
|
4235 |
"return true, if the OS we're running on is a 'real' unix." |
|
4236 |
||
4237 |
%{ /* NOCONTEXT */ |
|
4238 |
||
4239 |
#if defined(BSD) || defined(MACH) || defined(SYSV4) |
|
4240 |
RETURN ( true ); |
|
13 | 4241 |
#endif |
10 | 4242 |
%} |
13 | 4243 |
. |
4244 |
^ false |
|
10 | 4245 |
! |
4246 |
||
616 | 4247 |
isMSDOSlike |
4248 |
"return true, if the OS we're running on is dos like |
|
4249 |
(in contrast to unix-like)." |
|
4250 |
||
4251 |
%{ /* NOCONTEXT */ |
|
4252 |
||
4253 |
#if defined(MSDOS_LIKE) |
|
4254 |
RETURN ( true ); |
|
4255 |
#endif |
|
4256 |
%} |
|
4257 |
. |
|
4258 |
^ false |
|
4259 |
! |
|
4260 |
||
4261 |
isUNIXlike |
|
4262 |
"return true, if the OS we're running on is a unix like." |
|
4263 |
||
4264 |
%{ /* NOCONTEXT */ |
|
4265 |
||
4266 |
#if defined(UNIX_LIKE) |
|
4267 |
RETURN ( false ); |
|
4268 |
#endif |
|
4269 |
%} |
|
4270 |
. |
|
4271 |
^ true |
|
4272 |
! |
|
4273 |
||
4274 |
maxFileNameLength |
|
4275 |
"return the max number of characters in a filename. |
|
4276 |
Actually, the following is somewhat wrong - some systems |
|
4277 |
support differnet size depending on the volume. |
|
4278 |
We return a somewhat conservative number here." |
|
10 | 4279 |
|
4280 |
%{ /* NOCONTEXT */ |
|
616 | 4281 |
|
4282 |
/* |
|
4283 |
* XXX: newer systems provide a query function for this ... use it |
|
4284 |
*/ |
|
4285 |
# if defined(BSD) || defined(SYSV4) || defined(LONGFILENAMES) |
|
4286 |
RETURN ( _MKSMALLINT(255) ); |
|
4287 |
# endif |
|
4288 |
||
4289 |
# ifdef realIX |
|
4290 |
RETURN ( _MKSMALLINT(127) ); |
|
4291 |
# endif |
|
4292 |
||
4293 |
# ifdef SYSV |
|
4294 |
RETURN ( _MKSMALLINT(14) ); |
|
4295 |
# endif |
|
4296 |
||
4297 |
# ifdef MSDOS |
|
4298 |
RETURN ( _MKSMALLINT(9) ); |
|
4299 |
# endif |
|
4300 |
||
4301 |
# ifdef NT |
|
4302 |
/* |
|
4303 |
* mhmh - depends on the filesystem type |
|
4304 |
*/ |
|
4305 |
RETURN ( _MKSMALLINT(9) ); |
|
4306 |
# endif |
|
4307 |
%}. |
|
4308 |
"unix default" |
|
4309 |
^ 14 |
|
4310 |
! |
|
4311 |
||
4312 |
supportsIOInterrupts |
|
4313 |
"return true, if the OS supports IO availability interrupts |
|
4314 |
(i.e. SIGPOLL/SIGIO). |
|
4315 |
||
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4316 |
Currently, this mechanism does work for SYSV4 only ..." |
616 | 4317 |
|
4318 |
%{ /* NOCONTEXT */ |
|
765
93bdb4f0e095
no, SIGIO does not work on SGI ...
Claus Gittinger <cg@exept.de>
parents:
764
diff
changeset
|
4319 |
#if defined(SYSV4) && defined(USE_SIGIO) |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4320 |
|
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4321 |
# if defined(SIGPOLL) || defined(SIGIO) |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4322 |
# if (defined(F_GETFL) && defined(F_SETFL) && defined(FASYNC)) || defined(SYSV4) |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4323 |
/* |
765
93bdb4f0e095
no, SIGIO does not work on SGI ...
Claus Gittinger <cg@exept.de>
parents:
764
diff
changeset
|
4324 |
* currently the only system where they work is unixware SYSV4 |
93bdb4f0e095
no, SIGIO does not work on SGI ...
Claus Gittinger <cg@exept.de>
parents:
764
diff
changeset
|
4325 |
* (not even on SGI ...) |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4326 |
*/ |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4327 |
# if !defined(NEXT) |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4328 |
RETURN (true); |
616 | 4329 |
# endif |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4330 |
# endif |
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4331 |
# endif |
616 | 4332 |
|
10 | 4333 |
#endif |
1 | 4334 |
%} |
13 | 4335 |
. |
4336 |
^ false |
|
123 | 4337 |
! |
4338 |
||
616 | 4339 |
supportsNonBlockingIO |
4340 |
"return true, if the OS supports nonblocking IO." |
|
4341 |
||
4342 |
%{ /* NOCONTEXT */ |
|
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4343 |
#if defined(F_GETFL) && defined(F_SETFL) && defined(FNDELAY) |
616 | 4344 |
RETURN (true); |
754
0dcc8af63497
Fix enableIoInterrupts for SYSV4.
Stefan Vogel <sv@exept.de>
parents:
714
diff
changeset
|
4345 |
#endif |
616 | 4346 |
%} |
4347 |
. |
|
4348 |
^ false |
|
123 | 4349 |
! |
4350 |
||
616 | 4351 |
supportsSelect |
4352 |
"return true, if the OS supports selecting on multiple |
|
4353 |
filedescriptors via select." |
|
4354 |
||
4355 |
%{ /* NOCONTEXT */ |
|
4356 |
#if defined(sco) |
|
4357 |
/* |
|
4358 |
* sco has a broken select - always waiting 1 second |
|
4359 |
*/ |
|
4360 |
RETURN(false); |
|
4361 |
#endif |
|
4362 |
%} |
|
4363 |
. |
|
4364 |
^ true |
|
4365 |
! ! |
|
4366 |
||
4367 |
!OperatingSystem class methodsFor:'shared memory access'! |
|
4368 |
||
4369 |
shmAttach:id address:addr flags:flags |
|
4370 |
%{ /* NOCONTEXT */ |
|
4371 |
#ifdef WANT_SHM |
|
4372 |
void *address, *shmaddr; |
|
4373 |
int shmflg, shmid; |
|
4374 |
||
4375 |
if (__isSmallInteger(addr) |
|
4376 |
&& __bothSmallInteger(flags, id)) { |
|
4377 |
shmaddr = (void *) __intVal(addr); |
|
4378 |
shmflg = __intVal(flags); |
|
4379 |
shmid = __intVal(id); |
|
4380 |
||
4381 |
address = shmat(shmid, shmaddr, shmflg); |
|
4382 |
if (address != (void *)-1) { |
|
4383 |
RETURN (__MKEXTERNALBYTES(addr)); |
|
4384 |
} |
|
4385 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
4386 |
RETURN (nil); |
|
4387 |
} |
|
4388 |
#endif |
|
4389 |
%}. |
|
4390 |
self primitiveFailed |
|
370 | 4391 |
! |
4392 |
||
616 | 4393 |
shmDetach:addr |
4394 |
%{ /* NOCONTEXT */ |
|
4395 |
#ifdef WANT_SHM |
|
4396 |
void *shmaddr; |
|
4397 |
int rslt; |
|
4398 |
||
4399 |
if (__isSmallInteger(addr)) { |
|
4400 |
shmaddr = (void *) __intVal(addr); |
|
4401 |
||
4402 |
rslt = shmdt(shmaddr); |
|
4403 |
if (rslt != -1) { |
|
4404 |
RETURN (true); |
|
370 | 4405 |
} |
616 | 4406 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
4407 |
RETURN (false); |
|
370 | 4408 |
} |
616 | 4409 |
#endif |
4410 |
%}. |
|
4411 |
self primitiveFailed |
|
4412 |
! |
|
4413 |
||
4414 |
shmGet:key size:size flags:flags |
|
4415 |
"low level entry to shmget system call. |
|
4416 |
This is not for public use |
|
4417 |
- use the provided wrapper class SharedExternalBytes instead." |
|
4418 |
||
4419 |
%{ /* NOCONTEXT */ |
|
4420 |
#ifdef WANT_SHM |
|
4421 |
if (__bothSmallInteger(key, size) |
|
4422 |
&& __isSmallInteger(flags)) { |
|
4423 |
int rslt; |
|
4424 |
||
4425 |
rslt = shmget(__intVal(key), __intVal(size), __intVal(flags)); |
|
4426 |
if (rslt != -1) { |
|
4427 |
RETURN (__MKSMALLINT(rslt)); |
|
4428 |
} |
|
4429 |
OperatingSystem_LastErrorNumber = _MKSMALLINT(errno); |
|
4430 |
RETURN (nil); |
|
4431 |
} |
|
4432 |
#endif |
|
370 | 4433 |
%}. |
4434 |
self primitiveFailed |
|
1 | 4435 |
! ! |
4436 |
||
4437 |
!OperatingSystem class methodsFor:'time and date'! |
|
4438 |
||
4439 |
computeDatePartsOf:timeLow and:timeHi for:aBlock |
|
4440 |
"compute year, month and day from the time-parts timeLow and |
|
4441 |
timeHi and evaluate the argument, a 3-arg block with these. |
|
241 | 4442 |
Conversion is to localtime including any daylight saving adjustments. |
63 | 4443 |
|
4444 |
This method was added to avoid LargeInteger arithmetic and to be |
|
4445 |
independent of how the OperatingSystem represents time; |
|
4446 |
the time-parts expected are those returned by getTimeParts." |
|
1 | 4447 |
|
4448 |
|year month day| |
|
4449 |
||
4450 |
((timeLow isMemberOf:SmallInteger) and:[timeHi isMemberOf:SmallInteger]) |
|
4451 |
ifFalse:[ |
|
185 | 4452 |
^ self primitiveFailed |
1 | 4453 |
]. |
4454 |
%{ |
|
4455 |
struct tm *tmPtr; |
|
4456 |
long t; |
|
4457 |
||
4458 |
t = (_intVal(timeHi) << 16) | _intVal(timeLow); |
|
4459 |
tmPtr = localtime(&t); |
|
4460 |
year = _MKSMALLINT(tmPtr->tm_year + 1900); |
|
4461 |
month = _MKSMALLINT(tmPtr->tm_mon + 1); |
|
4462 |
day = _MKSMALLINT(tmPtr->tm_mday); |
|
4463 |
%} |
|
4464 |
. |
|
4465 |
aBlock value:year value:month value:day |
|
4466 |
! |
|
4467 |
||
616 | 4468 |
computeDatePartsOf:timeParts for:aBlock |
4469 |
"compute year, month and day from the ostime in timeParts, |
|
4470 |
and evaluate the argument, a 3-arg block with these. |
|
4471 |
Conversion is to localtime including any daylight saving adjustments." |
|
4472 |
||
4473 |
^ self computeDatePartsOf:(timeParts at:1) and:(timeParts at:2) for:aBlock |
|
1 | 4474 |
! |
4475 |
||
63 | 4476 |
computeTimeAndDateFrom:timeParts |
4477 |
"given an Array containing the OS-dependent time, return an Array |
|
241 | 4478 |
containing year, month, day, hour, minute and seconds. |
4479 |
Conversion is to localtime including any daylight saving adjustments." |
|
63 | 4480 |
|
4481 |
|low hi year month day hours minutes seconds ret| |
|
4482 |
||
4483 |
low := timeParts at:1. |
|
4484 |
hi := timeParts at:2. |
|
4485 |
%{ |
|
4486 |
struct tm *tmPtr; |
|
4487 |
long t; |
|
4488 |
||
252 | 4489 |
if (__bothSmallInteger(low, hi)) { |
185 | 4490 |
t = (_intVal(hi) << 16) | _intVal(low); |
4491 |
tmPtr = localtime(&t); |
|
4492 |
hours = _MKSMALLINT(tmPtr->tm_hour); |
|
4493 |
minutes = _MKSMALLINT(tmPtr->tm_min); |
|
4494 |
seconds = _MKSMALLINT(tmPtr->tm_sec); |
|
4495 |
||
4496 |
year = _MKSMALLINT(tmPtr->tm_year + 1900); |
|
4497 |
month = _MKSMALLINT(tmPtr->tm_mon + 1); |
|
4498 |
day = _MKSMALLINT(tmPtr->tm_mday); |
|
63 | 4499 |
} |
241 | 4500 |
%}. |
63 | 4501 |
year notNil ifTrue:[ |
185 | 4502 |
"I would love to have SELF-like inline objects ..." |
4503 |
ret := Array new:6. |
|
4504 |
ret at:1 put:year. |
|
4505 |
ret at:2 put:month. |
|
4506 |
ret at:3 put:day. |
|
4507 |
ret at:4 put:hours. |
|
4508 |
ret at:5 put:minutes. |
|
4509 |
ret at:6 put:seconds. |
|
4510 |
^ ret |
|
63 | 4511 |
]. |
4512 |
^ self primitiveFailed |
|
4513 |
! |
|
4514 |
||
241 | 4515 |
computeTimePartsFromYear:y month:m day:d hour:h minute:min seconds:s |
4516 |
"return an Array containing the OS-dependent time for the given |
|
4517 |
time and day. The arguments are assumed to be in localtime including |
|
4518 |
any daylight saving adjustings." |
|
4519 |
||
4520 |
|low hi| |
|
4521 |
||
4522 |
%{ |
|
4523 |
struct tm tm; |
|
4524 |
long t; |
|
4525 |
||
252 | 4526 |
if (__bothSmallInteger(y, m) |
4527 |
&& __bothSmallInteger(d, h) |
|
4528 |
&& __bothSmallInteger(min, s)) { |
|
4529 |
tm.tm_hour = __intVal(h); |
|
4530 |
tm.tm_min = __intVal(min); |
|
4531 |
tm.tm_sec = __intVal(s); |
|
4532 |
||
4533 |
tm.tm_year = __intVal(y) - 1900; |
|
4534 |
tm.tm_mon = __intVal(m) - 1; |
|
4535 |
tm.tm_mday = __intVal(d); |
|
241 | 4536 |
tm.tm_isdst = -1; |
4537 |
||
4538 |
t = mktime(&tm); |
|
4539 |
low = _MKSMALLINT(t & 0xFFFF); |
|
4540 |
hi = _MKSMALLINT((t >> 16) & 0xFFFF); |
|
4541 |
} |
|
4542 |
%}. |
|
4543 |
low notNil ifTrue:[ |
|
4544 |
^ Array with:low with:hi |
|
4545 |
]. |
|
4546 |
^ self primitiveFailed |
|
4547 |
! |
|
4548 |
||
616 | 4549 |
computeTimePartsOf:timeLow and:timeHi for:aBlock |
4550 |
"compute hours, minutes and seconds from the time-parts timeLow and |
|
4551 |
timeHi and evaluate the argument, a 3-arg block with these. |
|
4552 |
Conversion is to localtime including any daylight saving adjustments. |
|
4553 |
||
4554 |
This method was added to avoid LargeInteger arithmetic and to be |
|
4555 |
independent of how the OperatingSystem represents time; |
|
4556 |
the time-parts expected are those returned by getTimeParts." |
|
4557 |
||
4558 |
|hours minutes seconds| |
|
4559 |
||
4560 |
((timeLow isMemberOf:SmallInteger) and:[timeHi isMemberOf:SmallInteger]) |
|
4561 |
ifFalse:[ |
|
4562 |
^ self primitiveFailed |
|
4563 |
]. |
|
4564 |
%{ |
|
4565 |
struct tm *tmPtr; |
|
4566 |
long t; |
|
4567 |
||
4568 |
t = (_intVal(timeHi) << 16) | _intVal(timeLow); |
|
4569 |
tmPtr = localtime(&t); |
|
4570 |
hours = _MKSMALLINT(tmPtr->tm_hour); |
|
4571 |
minutes = _MKSMALLINT(tmPtr->tm_min); |
|
4572 |
seconds = _MKSMALLINT(tmPtr->tm_sec); |
|
275 | 4573 |
%} |
616 | 4574 |
. |
4575 |
aBlock value:hours value:minutes value:seconds |
|
4576 |
! |
|
4577 |
||
4578 |
computeTimePartsOf:timeParts for:aBlock |
|
4579 |
"compute hour, minute and seconds from the ostime in timeParts, |
|
4580 |
and evaluate the argument, a 3-arg block with these. |
|
4581 |
Conversion is to localtime including any daylight saving adjustments." |
|
4582 |
||
4583 |
^ self computeTimePartsOf:(timeParts at:1) and:(timeParts at:2) for:aBlock |
|
275 | 4584 |
! |
4585 |
||
1 | 4586 |
getMillisecondTime |
185 | 4587 |
"This returns the millisecond timers value. |
4588 |
The range is limited to 0..1fffffff (i.e. the SmallInteger range) to avoid |
|
4589 |
LargeInteger arithmetic when doing timeouts and delays. |
|
4590 |
SInce this value is wrapping around in regular intervals, this can only be used for |
|
4591 |
short relative time deltas. |
|
4592 |
Use the millisecondTimeXXX:-methods to compare and add time deltas - these know about the wrap. |
|
4593 |
||
4594 |
BAD DESIGN: |
|
4595 |
This should be changed to return some instance of RelativeTime, |
|
4596 |
and these computations moved there. |
|
95 | 4597 |
|
4598 |
Dont use this method in application code since it is an internal (private) |
|
4599 |
interface. For compatibility with ST-80, use Time millisecondClockValue. |
|
4600 |
" |
|
1 | 4601 |
|
4602 |
%{ /* NOCONTEXT */ |
|
4603 |
||
4604 |
long t; |
|
185 | 4605 |
#if !defined(HAS_GETTIMEOFDAY) && defined(SYSV) && defined(HZ) |
4606 |
/* |
|
4607 |
* sys5 time |
|
4608 |
*/ |
|
1 | 4609 |
long ticks; |
4610 |
struct tms tb; |
|
4611 |
||
4612 |
ticks = times(&tb); |
|
4613 |
t = (ticks * 1000) / HZ; |
|
185 | 4614 |
#else /* assume HAS_GETTIMEOFDAY */ |
4615 |
/* |
|
4616 |
* bsd time |
|
4617 |
*/ |
|
1 | 4618 |
struct timeval tb; |
4619 |
struct timezone tzb; |
|
4620 |
||
4621 |
gettimeofday(&tb, &tzb); |
|
4622 |
t = tb.tv_sec*1000 + tb.tv_usec/1000; |
|
68 | 4623 |
#endif |
185 | 4624 |
RETURN ( _MKSMALLINT(t & 0x1FFFFFFF) ); |
1 | 4625 |
%} |
4626 |
! |
|
4627 |
||
616 | 4628 |
getTime |
4629 |
"return current Time in some OS dependent representation. |
|
4630 |
(on unix, its the seconds since 1970). |
|
4631 |
||
4632 |
WARNING: this is OperatingSystem dependent - for portable code, |
|
4633 |
use getTimeParts and compute*PartsOf:and:for:. |
|
4634 |
Better yet, use Date>>today or Time>>now for fully ST-80 compatible code." |
|
4635 |
||
4636 |
OperatingSystem getTimeInto:[:low :hi | ^ hi*16r10000 + low] |
|
4637 |
||
4638 |
" |
|
4639 |
OperatingSystem getTime |
|
4640 |
" |
|
4641 |
! |
|
4642 |
||
4643 |
getTimeHi |
|
4644 |
"return hi 16 bits of current time. |
|
4645 |
||
4646 |
OBSOLETE: Dont use this method, use getTimeParts. |
|
4647 |
This method will NOT always return the correct time |
|
4648 |
if used together with getTimeHi, since a wrap between |
|
4649 |
the two getTimeXXX sends could occur. |
|
4650 |
WARNING: this method will vanish - dont use it." |
|
4651 |
||
4652 |
%{ /* NOCONTEXT */ |
|
4653 |
||
4654 |
RETURN ( _MKSMALLINT((time(0) >> 16) & 0xFFFF) ); |
|
4655 |
%} |
|
4656 |
||
4657 |
"OperatingSystem getTimeHi" |
|
4658 |
! |
|
4659 |
||
4660 |
getTimeInto:aBlock |
|
4661 |
"evaluate the argument aBlock, passing the time-parts of |
|
4662 |
the current time as arguments. |
|
4663 |
See comment in 'OperatingSystem>>getTimeParts' on what to |
|
4664 |
do with those parts." |
|
4665 |
||
4666 |
|low hi| |
|
4667 |
%{ |
|
4668 |
int now; |
|
4669 |
||
4670 |
now = time(0); |
|
4671 |
hi = _MKSMALLINT((now >> 16) & 0xFFFF); |
|
4672 |
low = _MKSMALLINT(now & 0xFFFF); |
|
4673 |
%} |
|
4674 |
. |
|
4675 |
aBlock value:low value:hi |
|
4676 |
||
4677 |
"OperatingSystem getTimeInto:[:low :hi | low printNewline. hi printNewline]" |
|
4678 |
! |
|
4679 |
||
4680 |
getTimeLow |
|
4681 |
"return low 16 bits of current time. |
|
4682 |
||
4683 |
OBSOLETE: Dont use this method, use getTimeParts. |
|
4684 |
This method will not always return the correct time |
|
4685 |
if used together with getTimeHi, since a wrap between |
|
4686 |
the two getTimeXXX sends could occur. |
|
4687 |
WARNING: this method will vanish - dont use it." |
|
4688 |
||
4689 |
%{ /* NOCONTEXT */ |
|
4690 |
||
4691 |
RETURN ( _MKSMALLINT(time(0) & 0xFFFF) ); |
|
4692 |
%} |
|
4693 |
||
4694 |
"OperatingSystem getTimeLow" |
|
4695 |
! |
|
4696 |
||
4697 |
getTimeParts |
|
4698 |
"return the current time as an array of 2 integers representing |
|
4699 |
the current time (usually low 16bits / hi 16 bits) in some OS |
|
4700 |
dependent way. |
|
4701 |
||
4702 |
On unix, the values represent the seconds since 1970, on other |
|
4703 |
systems this may be different. |
|
4704 |
WARNING: |
|
4705 |
for portability, never use these values directly, but pass them |
|
4706 |
to #computeTimeParts and/or #computeDatePartsOf:, which know how to |
|
4707 |
interpret them. |
|
4708 |
Better yet, use Date>>today and Time>>now for ST-80 compatibility." |
|
4709 |
||
4710 |
|low hi| |
|
4711 |
%{ |
|
4712 |
int now; |
|
4713 |
||
4714 |
now = time(0); |
|
4715 |
hi = _MKSMALLINT((now >> 16) & 0xFFFF); |
|
4716 |
low = _MKSMALLINT(now & 0xFFFF); |
|
4717 |
%} |
|
4718 |
. |
|
4719 |
^ Array with:low with:hi |
|
4720 |
||
4721 |
"OperatingSystem getTimeParts" |
|
4722 |
! |
|
4723 |
||
4724 |
maximumMillisecondTimeDelta |
|
4725 |
"this returns the maximum delta supported by millisecondCounter |
|
4726 |
based methods. The returned value is half the value at which the |
|
4727 |
timer wraps." |
|
4728 |
||
4729 |
%{ /* NOCONTEXT */ |
|
4730 |
RETURN ( _MKSMALLINT(0x0FFFFFFF) ); |
|
4731 |
%} |
|
4732 |
! |
|
4733 |
||
4734 |
millisecondDelay:millis |
|
4735 |
"delay execution for millis milliseconds or until the next event |
|
4736 |
arrives. |
|
4737 |
All lower priority threads will also sleep for the duration, |
|
4738 |
interrupts (and therefore, higher prio processes) are |
|
4739 |
still handled. |
|
4740 |
Better use a Delay, to only delay the calling thread. |
|
4741 |
(however, a delay cannot be used in the event handler or scheduler)" |
|
4742 |
||
4743 |
|now then delta| |
|
4744 |
||
4745 |
now := OperatingSystem getMillisecondTime. |
|
4746 |
then := OperatingSystem millisecondTimeAdd:now and:millis. |
|
4747 |
||
4748 |
[OperatingSystem millisecondTime:then isAfter:now] whileTrue:[ |
|
4749 |
delta := OperatingSystem millisecondTimeDeltaBetween:then and:now. |
|
4750 |
self selectOnAnyReadable:nil writable:nil exception:nil withTimeOut:delta. |
|
4751 |
now := OperatingSystem getMillisecondTime. |
|
4752 |
] |
|
4753 |
||
4754 |
" |
|
4755 |
OperatingSystem millisecondDelay:2000 |
|
4756 |
" |
|
4757 |
! |
|
4758 |
||
4759 |
millisecondTime:msTime1 isAfter:msTime2 |
|
4760 |
"return true if msTime1 is after msTime2, false if not. |
|
4761 |
The two arguments are supposed to be millisecond times |
|
4762 |
(such as returned getMillisecondTime) which wrap at 16r1FFFFFFF. |
|
4763 |
||
4764 |
This should really be moved to some RelativeTime class." |
|
4765 |
||
4766 |
(msTime1 > msTime2) ifTrue:[ |
|
4767 |
((msTime1 - msTime2) >= 16r10000000) ifTrue:[ |
|
4768 |
^ false |
|
4769 |
]. |
|
4770 |
^ true |
|
4771 |
]. |
|
4772 |
((msTime2 - msTime1) > 16r10000000) ifTrue:[ |
|
4773 |
^ true |
|
4774 |
]. |
|
4775 |
^ false |
|
4776 |
! |
|
4777 |
||
4778 |
millisecondTimeAdd:msTime1 and:msTime2 |
|
4779 |
"Add two millisecond times (such as returned getMillisecondTime). |
|
4780 |
The returned value is msTime1 + msTime2 where a wrap occurs at:16r1FFFFFFF. |
|
4781 |
||
4782 |
This should really be moved to some RelativeTime class." |
|
4783 |
||
4784 |
|sum| |
|
4785 |
||
4786 |
sum := msTime1 + msTime2. |
|
4787 |
(sum > 16r1FFFFFFF) ifTrue:[^ sum - 16r20000000]. |
|
4788 |
(sum < 0) ifTrue:[^ sum + 16r20000000]. |
|
4789 |
^ sum |
|
4790 |
! |
|
4791 |
||
1 | 4792 |
millisecondTimeDeltaBetween:msTime1 and:msTime2 |
95 | 4793 |
"subtract two millisecond times (such as returned getMillisecondTime) |
185 | 4794 |
and return the difference. Since milli-times wrap (at 16r01FFFFFFF), |
95 | 4795 |
some special handling is built-in here. |
185 | 4796 |
The returned value is msTime1 - msTime2. The returned value is invalid |
4797 |
if the delta is >= 0x10000000. |
|
63 | 4798 |
|
4799 |
This should really be moved to some RelativeTime class." |
|
1 | 4800 |
|
4801 |
(msTime1 > msTime2) ifTrue:[ |
|
185 | 4802 |
^ msTime1 - msTime2 |
1 | 4803 |
]. |
4804 |
^ msTime1 + 16r10000000 - msTime2 |
|
95 | 4805 |
|
4806 |
" |
|
4807 |
OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:1 |
|
4808 |
OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:(16 / 3) |
|
4809 |
OperatingSystem millisecondTimeAdd:16r0FFFFFFF and:1000 |
|
4810 |
||
4811 |
OperatingSystem millisecondTimeDeltaBetween:0 and:16r0FFFFFFF |
|
4812 |
OperatingSystem millisecondTimeDeltaBetween:(13/3) and:16r0FFFFFFF |
|
4813 |
OperatingSystem millisecondTimeDeltaBetween:999 and:16r0FFFFFFF |
|
4814 |
||
4815 |
OperatingSystem millisecondTime:0 isAfter:16r0FFFFFFF |
|
4816 |
OperatingSystem millisecondTime:(13/3) isAfter:16r0FFFFFFF |
|
4817 |
OperatingSystem millisecondTime:999 isAfter:16r0FFFFFFF |
|
4818 |
||
4819 |
OperatingSystem millisecondTime:0 isAfter:0 |
|
4820 |
OperatingSystem millisecondTime:(13/3) isAfter:0 |
|
4821 |
OperatingSystem millisecondTime:999 isAfter:0 |
|
4822 |
||
4823 |
OperatingSystem millisecondTime:1 isAfter:0 |
|
4824 |
OperatingSystem millisecondTime:(13/3) isAfter:2 |
|
4825 |
OperatingSystem millisecondTime:999 isAfter:900 |
|
4826 |
||
4827 |
|t1 t2| |
|
4828 |
||
4829 |
t1 := Time millisecondClockValue. |
|
4830 |
(Delay forMilliseconds:1) wait. |
|
4831 |
t2 := Time millisecondClockValue. |
|
4832 |
OperatingSystem millisecondTimeDeltaBetween:t2 and:t1 |
|
4833 |
" |
|
1 | 4834 |
! |
4835 |
||
4836 |
sleep:numberOfSeconds |
|
308 | 4837 |
"cease ANY action for some time. This suspends the whole smalltalk |
4838 |
(unix-) process for some time. |
|
1 | 4839 |
Not really useful since not even low-prio processes and interrupt |
95 | 4840 |
handling will run during the sleep. |
4841 |
Use either OperatingSystem>>millisecondDelay: (which makes all |
|
4842 |
threads sleep, but handles interrupts) or use a Delay (which makes |
|
4843 |
only the calling thread sleep)." |
|
1 | 4844 |
|
4845 |
%{ /* NOCONTEXT */ |
|
4846 |
||
252 | 4847 |
if (__isSmallInteger(numberOfSeconds)) { |
185 | 4848 |
sleep(_intVal(numberOfSeconds)); |
4849 |
RETURN ( self ); |
|
1 | 4850 |
} |
68 | 4851 |
%}. |
4852 |
" |
|
4853 |
argument not integer |
|
4854 |
" |
|
1 | 4855 |
self primitiveFailed |
95 | 4856 |
|
4857 |
" |
|
4858 |
OperatingSystem sleep:2 |
|
4859 |
" |
|
10 | 4860 |
! ! |
4861 |
||
616 | 4862 |
!OperatingSystem class methodsFor:'users & groups'! |
4863 |
||
4864 |
getEffectiveGroupID |
|
4865 |
"return the current users (thats you) effective numeric group id. |
|
4866 |
This is only different from getGroupID, if you have ST/X running |
|
4867 |
as a setuid program (of which you should think about twice)." |
|
4868 |
||
4869 |
%{ /* NOCONTEXT */ |
|
4870 |
||
4871 |
#ifdef UNIX_LIKE |
|
4872 |
int uid; |
|
4873 |
||
4874 |
uid = getegid(); |
|
4875 |
RETURN ( __MKSMALLINT(uid) ); |
|
4876 |
#endif |
|
4877 |
/* --- return same as getGroupID --- */ |
|
4878 |
%}. |
|
4879 |
^ self getGroupID |
|
4880 |
||
4881 |
" |
|
4882 |
OperatingSystem getEffectiveGroupID |
|
4883 |
" |
|
4884 |
! |
|
4885 |
||
4886 |
getEffectiveUserID |
|
4887 |
"return the current users (thats you) effective numeric user id. |
|
4888 |
This is only different from getUserID, if you have ST/X running |
|
4889 |
as a setuid program (of which you should think about twice)." |
|
10 | 4890 |
|
4891 |
%{ /* NOCONTEXT */ |
|
4892 |
||
616 | 4893 |
#ifdef UNIX_LIKE |
4894 |
int uid; |
|
4895 |
||
4896 |
uid = geteuid(); |
|
4897 |
RETURN ( __MKSMALLINT(uid) ); |
|
4898 |
#endif |
|
4899 |
/* --- return same as getUserID --- */ |
|
4900 |
%}. |
|
4901 |
^ self getUserID |
|
4902 |
||
4903 |
" |
|
4904 |
OperatingSystem getEffectiveUserID |
|
4905 |
" |
|
4906 |
! |
|
4907 |
||
4908 |
getGroupID |
|
4909 |
"return the current users (thats you) numeric group id" |
|
4910 |
||
4911 |
%{ /* NOCONTEXT */ |
|
4912 |
||
4913 |
#ifdef UNIX_LIKE |
|
4914 |
int uid; |
|
4915 |
||
4916 |
uid = getgid(); |
|
4917 |
RETURN ( __MKSMALLINT(uid) ); |
|
4918 |
#else |
|
4919 |
# ifdef SYSTEM_HAS_GROUPS |
|
4920 |
/* ... */ |
|
10 | 4921 |
# endif |
4922 |
#endif |
|
68 | 4923 |
%}. |
616 | 4924 |
^ 1 "just a dummy for systems which do not have userIDs" |
4925 |
||
68 | 4926 |
" |
616 | 4927 |
OperatingSystem getGroupID |
4928 |
" |
|
4929 |
! |
|
4930 |
||
4931 |
getGroupNameFromID:aNumber |
|
4932 |
"return the group-name-string for a given numeric group-id" |
|
4933 |
||
4934 |
%{ /* NOCONTEXT */ |
|
4935 |
||
4936 |
#ifdef UNIX_LIKE |
|
4937 |
struct group *g; |
|
4938 |
||
4939 |
if (__isSmallInteger(aNumber)) { |
|
4940 |
g = getgrgid(_intVal(aNumber)); |
|
4941 |
if (g) { |
|
4942 |
RETURN ( _MKSTRING(g->gr_name COMMA_CON) ); |
|
4943 |
} |
|
4944 |
} |
|
4945 |
#endif |
|
4946 |
%}. |
|
4947 |
^ '???' |
|
4948 |
||
4949 |
" |
|
4950 |
OperatingSystem getGroupNameFromID:0 |
|
4951 |
OperatingSystem getGroupNameFromID:10 |
|
4952 |
" |
|
4953 |
! |
|
4954 |
||
4955 |
getHomeDirectory |
|
4956 |
"return the name of the users home directory" |
|
4957 |
||
4958 |
^ OperatingSystem getEnvironment:'HOME' |
|
4959 |
||
4960 |
" |
|
4961 |
OperatingSystem getHomeDirectory |
|
4962 |
" |
|
4963 |
! |
|
4964 |
||
4965 |
getLoginName |
|
4966 |
"return a string with the users name" |
|
4967 |
||
4968 |
%{ /* NOCONTEXT */ |
|
4969 |
static char cachedName[64]; |
|
4970 |
static firstCall = 1; |
|
4971 |
||
4972 |
char *name = "you"; |
|
4973 |
#ifdef UNIX_LIKE |
|
4974 |
if (firstCall) { |
|
4975 |
name = (char *)getlogin(); |
|
4976 |
if (! name || (name[0] == 0)) { |
|
4977 |
name = (char *)getenv("LOGNAME"); |
|
4978 |
} |
|
4979 |
if (strlen(name) < sizeof(cachedName)) { |
|
4980 |
strcpy(cachedName, name); |
|
4981 |
firstCall = 0; |
|
4982 |
} |
|
4983 |
} else { |
|
4984 |
name = cachedName; |
|
4985 |
} |
|
4986 |
#endif |
|
4987 |
RETURN ( _MKSTRING(name COMMA_CON) ); |
|
4988 |
%} |
|
4989 |
" |
|
4990 |
OperatingSystem getLoginName |
|
4991 |
" |
|
4992 |
! |
|
4993 |
||
4994 |
getUserID |
|
4995 |
"return the current users (thats you) numeric user id" |
|
4996 |
||
4997 |
%{ /* NOCONTEXT */ |
|
4998 |
||
4999 |
#ifdef UNIX_LIKE |
|
5000 |
int uid; |
|
5001 |
||
5002 |
uid = getuid(); |
|
5003 |
RETURN ( __MKSMALLINT(uid) ); |
|
5004 |
#else |
|
5005 |
# ifdef SYSTEM_HAS_USERS |
|
5006 |
/* ... */ |
|
5007 |
# endif |
|
5008 |
#endif |
|
5009 |
%}. |
|
5010 |
^ 1 "just a dummy for systems which do not have userIDs" |
|
5011 |
||
5012 |
" |
|
5013 |
OperatingSystem getUserID |
|
68 | 5014 |
" |
616 | 5015 |
! |
5016 |
||
5017 |
getUserNameFromID:aNumber |
|
5018 |
"return the user-name-string for a given numeric user-id" |
|
5019 |
||
5020 |
%{ /* NOCONTEXT */ |
|
5021 |
||
5022 |
#ifdef UNIX_LIKE |
|
5023 |
struct passwd *p; |
|
5024 |
||
5025 |
if (__isSmallInteger(aNumber)) { |
|
5026 |
p = getpwuid(_intVal(aNumber)); |
|
5027 |
if (p) { |
|
5028 |
RETURN ( _MKSTRING(p->pw_name COMMA_CON) ); |
|
5029 |
} |
|
5030 |
} |
|
5031 |
#endif |
|
5032 |
%}. |
|
5033 |
^ '? (' , aNumber printString , ')' |
|
5034 |
||
5035 |
" |
|
5036 |
OperatingSystem getUserNameFromID:0 |
|
5037 |
OperatingSystem getUserNameFromID:100 |
|
5038 |
OperatingSystem getUserNameFromID:9991 |
|
5039 |
" |
|
1 | 5040 |
! |
5041 |
||
616 | 5042 |
userInfoOf:aNameOrID |
5043 |
"return a dictionary filled with userinfo. The argument can be either |
|
5044 |
a string with the users name or its numeric id. |
|
5045 |
Notice, that not all systems provide (all of) this info; |
|
5046 |
DOS systems return nothing; |
|
5047 |
non-SYSV4 systems have no age/comment. |
|
5048 |
Portable applications may want to check the systemType and NOT depend |
|
5049 |
on all keys to be present in the returned dictionary. |
|
5050 |
Another notice: on some systems (SYSV4), the gecos field includes multiple |
|
5051 |
entries (i.e. not just the name), separated by commas. You may want to |
|
5052 |
extract any substring, up to the first comma to get the real life name." |
|
5053 |
||
5054 |
|info name passw uid gid age comment |
|
5055 |
gecos dir shell| |
|
5056 |
||
5057 |
%{ |
|
5058 |
#ifdef UNIX_LIKE |
|
5059 |
struct passwd *buf; |
|
5060 |
int ret; |
|
5061 |
||
5062 |
if (__isString(aNameOrID)) { |
|
5063 |
buf = getpwnam(__stringVal(aNameOrID)); |
|
5064 |
} else if (__isSmallInteger(aNameOrID)) { |
|
5065 |
buf = getpwuid(__intVal(aNameOrID)); |
|
5066 |
} else { |
|
5067 |
buf = (struct passwd *)0; |
|
5068 |
} |
|
5069 |
if (buf) { |
|
5070 |
name = _MKSTRING(buf->pw_name COMMA_CON); |
|
5071 |
passw = _MKSTRING(buf->pw_passwd COMMA_CON); |
|
5072 |
# ifdef SYSV4 |
|
5073 |
age = _MKSTRING(buf->pw_age COMMA_CON); |
|
5074 |
comment = _MKSTRING(buf->pw_comment COMMA_CON); |
|
5075 |
# endif |
|
5076 |
dir = _MKSTRING(buf->pw_dir COMMA_CON); |
|
5077 |
gecos = _MKSTRING(buf->pw_gecos COMMA_CON); |
|
5078 |
shell = _MKSTRING(buf->pw_shell COMMA_CON); |
|
5079 |
||
5080 |
uid = _MKSMALLINT(buf->pw_uid); |
|
5081 |
gid = _MKSMALLINT(buf->pw_gid); |
|
5082 |
} |
|
5083 |
#endif |
|
5084 |
%}. |
|
5085 |
info := IdentityDictionary new. |
|
5086 |
name notNil ifTrue:[ |
|
5087 |
info at:#name put:name. |
|
5088 |
] ifFalse:[ |
|
5089 |
info at:#name put:'unknown' |
|
5090 |
]. |
|
5091 |
passw notNil ifTrue:[info at:#passwd put:passw]. |
|
5092 |
age notNil ifTrue:[info at:#age put:age]. |
|
5093 |
comment notNil ifTrue:[info at:#comment put:comment]. |
|
5094 |
gecos notNil ifTrue:[info at:#gecos put:gecos]. |
|
5095 |
shell notNil ifTrue:[info at:#shell put:shell]. |
|
5096 |
dir notNil ifTrue:[info at:#dir put:dir]. |
|
5097 |
uid notNil ifTrue:[info at:#uid put:uid]. |
|
5098 |
gid notNil ifTrue:[info at:#gid put:gid]. |
|
5099 |
^ info |
|
5100 |
||
5101 |
" |
|
5102 |
OperatingSystem userInfoOf:'root' |
|
5103 |
OperatingSystem userInfoOf:1 |
|
5104 |
OperatingSystem userInfoOf:'claus' |
|
5105 |
OperatingSystem userInfoOf:'fooBar' |
|
5106 |
OperatingSystem userInfoOf:(OperatingSystem getUserID) |
|
5107 |
" |
|
5108 |
! ! |
|
5109 |
||
5110 |
!OperatingSystem class methodsFor:'waiting for events'! |
|
5111 |
||
10 | 5112 |
readCheck:fd |
95 | 5113 |
"return true, if data is available on a filedescriptor (i.e. read |
5114 |
is possible without blocking)" |
|
10 | 5115 |
|
5116 |
(self selectOnAnyReadable:(Array with:fd) |
|
185 | 5117 |
writable:nil |
5118 |
exception:nil |
|
5119 |
withTimeOut:0) == fd |
|
5120 |
ifTrue:[^ true]. |
|
10 | 5121 |
^ false |
5122 |
! |
|
5123 |
||
616 | 5124 |
selectOn:fd1 and:fd2 withTimeOut:millis |
5125 |
"wait for any fd to become ready; timeout after t milliseconds. |
|
5126 |
A zero timeout-time will immediately return (i.e. poll). |
|
5127 |
Return fd if i/o ok, nil if timed-out or interrupted. |
|
5128 |
Obsolete: |
|
5129 |
This is a leftover method and will vanish." |
|
5130 |
||
5131 |
^ self selectOnAnyReadable:(Array with:fd1 with:fd2) |
|
5132 |
writable:(Array with:fd1 with:fd2) |
|
5133 |
exception:nil |
|
5134 |
withTimeOut:millis |
|
10 | 5135 |
! |
5136 |
||
5137 |
selectOn:fd withTimeOut:millis |
|
5138 |
"wait for aFileDesriptor to become ready; timeout after t milliseconds. |
|
1 | 5139 |
Return true, if i/o ok, false if timed-out or interrupted. |
5140 |
With 0 as timeout argument, this can be used to check for availability |
|
5141 |
of read-data. |
|
5142 |
Experimental." |
|
5143 |
||
3 | 5144 |
^ self selectOnAnyReadable:(Array with:fd) |
185 | 5145 |
writable:(Array with:fd) |
5146 |
exception:nil |
|
5147 |
withTimeOut:millis |
|
1 | 5148 |
! |
5149 |
||
616 | 5150 |
selectOnAny:fdArray withTimeOut:millis |
5151 |
"wait for any fd in fdArray (an Array of integers) to become ready; |
|
5152 |
timeout after t milliseconds. An empty set will always wait. |
|
5153 |
Return first ready fd if i/o ok, nil if timed-out or interrupted. |
|
5154 |
Experimental." |
|
5155 |
||
5156 |
^ self selectOnAnyReadable:fdArray |
|
5157 |
writable:fdArray |
|
185 | 5158 |
exception:nil |
5159 |
withTimeOut:millis |
|
1 | 5160 |
! |
5161 |
||
10 | 5162 |
selectOnAnyReadable:fdArray withTimeOut:millis |
95 | 5163 |
"wait for any fd in fdArray (an Array of integers) to become ready for |
5164 |
reading. Timeout after t milliseconds. An empty set will always wait. |
|
5165 |
A zero timeout-time will immediately return (i.e. poll). |
|
3 | 5166 |
Return first ready fd if i/o ok, nil if timed-out or interrupted. |
5167 |
Experimental." |
|
5168 |
||
5169 |
^ self selectOnAnyReadable:fdArray |
|
185 | 5170 |
writable:nil |
5171 |
exception:nil |
|
5172 |
withTimeOut:millis |
|
3 | 5173 |
! |
5174 |
||
95 | 5175 |
selectOnAnyReadable:readFdArray writable:writeFdArray exception:exceptFdArray withTimeOut:millis |
5176 |
"wait for any fd in readFdArray (an Array of integers) to become ready for |
|
5177 |
reading, writeFdArray to become ready for writing, or exceptFdArray to |
|
5178 |
arrive exceptional data (i.e. out-of-band data). |
|
5179 |
Timeout after t milliseconds or, if the timeout time is 0, immediately.. |
|
5180 |
Empty fd-sets will always wait. Zero time can be used to poll file- |
|
5181 |
descriptors (i.e. to check if I/O possible without blocking). |
|
5182 |
Return first ready fd if I/O ok, nil if timed-out or interrupted." |
|
3 | 5183 |
|
1 | 5184 |
%{ |
5185 |
fd_set rset, wset, eset; |
|
5186 |
int t, f, maxF, i, lX, bX; |
|
308 | 5187 |
struct timeval wt, et; |
1 | 5188 |
OBJ fd, retFd; |
95 | 5189 |
int ret; |
300 | 5190 |
int count; |
1 | 5191 |
|
252 | 5192 |
if (__isSmallInteger(millis)) { |
185 | 5193 |
FD_ZERO(&rset); |
5194 |
FD_ZERO(&wset); |
|
5195 |
FD_ZERO(&eset); |
|
5196 |
||
5197 |
maxF = -1; |
|
308 | 5198 |
if (readFdArray != nil) { |
300 | 5199 |
if (! __isArray(readFdArray)) { |
5200 |
goto fail; |
|
5201 |
} |
|
5202 |
count = __arraySize(readFdArray); |
|
308 | 5203 |
|
5204 |
for (i=0; i<count;i++) { |
|
5205 |
fd = _ArrayInstPtr(readFdArray)->a_element[i]; |
|
5206 |
if (fd != nil) { |
|
5207 |
f = _intVal(fd); |
|
5208 |
if ((f >= 0) && (f < FD_SETSIZE)) { |
|
5209 |
FD_SET(f, &rset); |
|
5210 |
if (f > maxF) maxF = f; |
|
5211 |
} |
|
185 | 5212 |
} |
5213 |
} |
|
5214 |
} |
|
300 | 5215 |
|
308 | 5216 |
if (writeFdArray != nil) { |
300 | 5217 |
if (! __isArray(writeFdArray)) { |
5218 |
goto fail; |
|
5219 |
} |
|
5220 |
count = __arraySize(writeFdArray); |
|
308 | 5221 |
for (i=0; i<count;i++) { |
5222 |
fd = _ArrayInstPtr(writeFdArray)->a_element[i]; |
|
5223 |
if (fd != nil) { |
|
5224 |
f = _intVal(fd); |
|
5225 |
if ((f >= 0) && (f < FD_SETSIZE)) { |
|
5226 |
FD_SET(f, &wset); |
|
5227 |
if (f > maxF) maxF = f; |
|
5228 |
} |
|
185 | 5229 |
} |
5230 |
} |
|
5231 |
} |
|
300 | 5232 |
|
308 | 5233 |
if (exceptFdArray != nil) { |
300 | 5234 |
if (! __isArray(exceptFdArray)) { |
5235 |
goto fail; |
|
5236 |
} |
|
5237 |
count = __arraySize(exceptFdArray); |
|
308 | 5238 |
for (i=0; i<count;i++) { |
5239 |
fd = _ArrayInstPtr(exceptFdArray)->a_element[i]; |
|
5240 |
if (fd != nil) { |
|
5241 |
f = _intVal(fd); |
|
5242 |
if ((f >= 0) && (f < FD_SETSIZE)) { |
|
5243 |
FD_SET(f, &eset); |
|
5244 |
if (f > maxF) maxF = f; |
|
5245 |
} |
|
185 | 5246 |
} |
5247 |
} |
|
5248 |
} |
|
308 | 5249 |
|
185 | 5250 |
t = _intVal(millis); |
774
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5251 |
if (t) { |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5252 |
wt.tv_sec = t / 1000; |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5253 |
wt.tv_usec = (t % 1000) * 1000; |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5254 |
} else { |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5255 |
wt.tv_sec = wt.tv_usec = 0; |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5256 |
} |
185 | 5257 |
|
5258 |
/* |
|
5259 |
* make certain, that interrupt gets us out of the select |
|
5260 |
*/ |
|
362 | 5261 |
__BEGIN_INTERRUPTABLE__ |
185 | 5262 |
errno = 0; |
774
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5263 |
|
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5264 |
if (t == 0) { |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5265 |
/* |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5266 |
* if there is no timeout time, we can stay here |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5267 |
* interruptable. |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5268 |
*/ |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5269 |
do { |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5270 |
ret = select(maxF+1, &rset, &wset, &eset, &wt); |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5271 |
} while ((ret < 0) && (errno == EINTR)); |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5272 |
} else { |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5273 |
do { |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5274 |
ret = select(maxF+1, &rset, &wset, &eset, &wt); |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5275 |
/* |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5276 |
* for now: dont loop; if we did, we had to adjust the vt-timeval; |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5277 |
* could otherwise stay in this loop forever ... |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5278 |
* Premature return (before the time expired) must be handled by the caller. |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5279 |
* A good solution is to update the wt-timeval and redo the select. |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5280 |
*/ |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5281 |
} while (0 /* (ret < 0) && (errno == EINTR) */ ); |
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5282 |
} |
362 | 5283 |
__END_INTERRUPTABLE__ |
95 | 5284 |
|
185 | 5285 |
if (ret > 0) { |
5286 |
for (i=0; i <= maxF; i++) { |
|
5287 |
if (FD_ISSET(i, &rset) |
|
5288 |
|| FD_ISSET(i, &wset) |
|
5289 |
|| FD_ISSET(i, &eset)) { |
|
5290 |
RETURN ( _MKSMALLINT(i) ); |
|
5291 |
} |
|
5292 |
} |
|
5293 |
} |
|
308 | 5294 |
|
185 | 5295 |
/* |
5296 |
* return nil (means time expired) |
|
5297 |
*/ |
|
5298 |
RETURN ( nil ); |
|
1 | 5299 |
} |
300 | 5300 |
fail: ; |
68 | 5301 |
%}. |
5302 |
" |
|
300 | 5303 |
timeout argument not integer, |
5304 |
or any fd-array nonNil and not an array |
|
68 | 5305 |
" |
1 | 5306 |
self primitiveFailed |
5307 |
! |
|
5308 |
||
616 | 5309 |
setBlocking:aBoolean on:fd |
5310 |
"set/clear the blocking attribute - if set (which is the default) |
|
5311 |
a read on the fileDescriptor will block until data is available. |
|
5312 |
If cleared, a read operation will immediately return with a value of |
|
5313 |
nil." |
|
10 | 5314 |
|
5315 |
%{ /* NOCONTEXT */ |
|
5316 |
||
616 | 5317 |
int ret, flags; |
5318 |
int savInt; |
|
5319 |
||
5320 |
#if defined(F_GETFL) && defined(F_SETFL) |
|
5321 |
# if defined(FNDELAY) |
|
5322 |
if (__isSmallInteger(fd)) { |
|
5323 |
flags = fcntl(_intVal(fd), F_GETFL, 0); |
|
5324 |
if (aBoolean == true) { |
|
5325 |
ret = fcntl(_intVal(fd), F_SETFL, flags & ~FNDELAY); |
|
5326 |
} else { |
|
5327 |
ret = fcntl(_intVal(fd), F_SETFL, flags | FNDELAY); |
|
185 | 5328 |
} |
616 | 5329 |
if (ret >= 0) ret = flags; |
5330 |
RETURN ( _MKSMALLINT(ret) ); |
|
77 | 5331 |
} |
616 | 5332 |
# endif |
77 | 5333 |
#endif |
308 | 5334 |
%}. |
77 | 5335 |
" |
616 | 5336 |
fd argument not integer |
185 | 5337 |
" |
1 | 5338 |
self primitiveFailed |
5339 |
! |
|
5340 |
||
616 | 5341 |
writeCheck:fd |
5342 |
"return true, if filedescriptor can be written without blocking" |
|
5343 |
||
5344 |
(self selectOnAnyReadable:nil |
|
5345 |
writable:(Array with:fd) |
|
5346 |
exception:nil |
|
5347 |
withTimeOut:0) == fd |
|
5348 |
ifTrue:[^ true]. |
|
5349 |
^ false |
|
1 | 5350 |
! ! |
434 | 5351 |
|
630 | 5352 |
!OperatingSystem class methodsFor:'documentation'! |
5353 |
||
5354 |
version |
|
774
e0ee05157570
selectOnAny with timeout vs. no timeout
Claus Gittinger <cg@exept.de>
parents:
771
diff
changeset
|
5355 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/Unix.st,v 1.98 1995-12-16 12:29:09 cg Exp $' |
630 | 5356 |
! ! |
616 | 5357 |
OperatingSystem initialize! |