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