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