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