00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026
00027 #include <cerrno>
00028
00029 #include <string.h>
00030
00031 #ifdef HAVE_SYS_TYPES_H
00032 #include <sys/types.h>
00033 #endif
00034
00035 #ifdef HAVE_UNISTD_H
00036 #include <unistd.h>
00037 #endif
00038
00039 #ifdef HAVE_FCNTL_H
00040 #include <fcntl.h>
00041 #endif
00042
00043
00044
00045
00046 #include <signal.h>
00047
00048 #include "oct-syscalls.h"
00049 #include "str-vec.h"
00050 #include "syswait.h"
00051
00052 #define NOT_SUPPORTED(nm) \
00053 nm ": not supported on this system"
00054
00055 int
00056 octave_syscalls::dup2 (int old_fd, int new_fd)
00057 {
00058 std::string msg;
00059 return dup2 (old_fd, new_fd, msg);
00060 }
00061
00062 int
00063 octave_syscalls::dup2 (int old_fd, int new_fd, std::string& msg)
00064 {
00065 msg = std::string ();
00066
00067 int status = -1;
00068
00069 #if defined (HAVE_DUP2)
00070 status = ::dup2 (old_fd, new_fd);
00071
00072 if (status < 0)
00073 {
00074 using namespace std;
00075 msg = ::strerror (errno);
00076 }
00077 #else
00078 msg = NOT_SUPPORTED ("dup2");
00079 #endif
00080
00081 return status;
00082 }
00083
00084 int
00085 octave_syscalls::execvp (const std::string& file, const string_vector& argv)
00086 {
00087 std::string msg;
00088 return execvp (file, argv, msg);
00089 }
00090
00091 int
00092 octave_syscalls::execvp (const std::string& file, const string_vector& args,
00093 std::string& msg)
00094 {
00095 msg = std::string ();
00096
00097 int status = -1;
00098
00099 #if defined (HAVE_EXECVP)
00100 char **argv = args.c_str_vec ();
00101
00102 status = ::execvp (file.c_str (), argv);
00103
00104 string_vector::delete_c_str_vec (argv);
00105
00106 if (status < 0)
00107 {
00108 using namespace std;
00109 msg = ::strerror (errno);
00110 }
00111 #else
00112 msg = NOT_SUPPORTED ("execvp");
00113 #endif
00114
00115 return status;
00116 }
00117
00118 int
00119 octave_syscalls::fcntl (int fd, int cmd, long arg)
00120 {
00121 std::string msg;
00122 return fcntl (fd, cmd, arg, msg);
00123 }
00124
00125 int
00126 octave_syscalls::fcntl (int fd, int cmd, long arg, std::string& msg)
00127 {
00128 msg = std::string ();
00129
00130 int status = -1;
00131
00132 #if defined (HAVE_FCNTL)
00133 status = ::fcntl (fd, cmd, arg);
00134
00135 if (status < 0)
00136 {
00137 using namespace std;
00138 msg = ::strerror (errno);
00139 }
00140 #else
00141 msg = NOT_SUPPORTED ("fcntl");
00142 #endif
00143
00144 return status;
00145 }
00146
00147 pid_t
00148 octave_syscalls::fork (std::string& msg)
00149 {
00150 pid_t status = -1;
00151
00152 #if defined (HAVE_FORK)
00153 status = ::fork ();
00154
00155 if (status < 0)
00156 {
00157 using namespace std;
00158 msg = ::strerror (errno);
00159 }
00160 #else
00161 msg = NOT_SUPPORTED ("fork");
00162 #endif
00163
00164 return status;
00165 }
00166
00167 pid_t
00168 octave_syscalls::vfork (std::string& msg)
00169 {
00170 pid_t status = -1;
00171
00172 #if defined (HAVE_VFORK) || defined (HAVE_FORK)
00173 #if defined (HAVE_VFORK)
00174 status = ::vfork ();
00175 #else
00176 status = ::fork ();
00177 #endif
00178
00179 if (status < 0)
00180 {
00181 using namespace std;
00182 msg = ::strerror (errno);
00183 }
00184 #else
00185 msg = NOT_SUPPORTED ("vfork");
00186 #endif
00187
00188 return status;
00189 }
00190
00191 pid_t
00192 octave_syscalls::getpgrp (std::string& msg)
00193 {
00194 pid_t status = -1;
00195
00196 #if defined (HAVE_GETPGRP)
00197 status = ::getpgrp ();
00198
00199 if (status < 0)
00200 {
00201 using namespace std;
00202 msg = ::strerror (errno);
00203 }
00204 #else
00205 msg = NOT_SUPPORTED ("getpgrp");
00206 #endif
00207
00208 return status;
00209 }
00210
00211 pid_t
00212 octave_syscalls::getpid (void)
00213 {
00214 #if defined (HAVE_GETPID)
00215 return ::getpid ();
00216 #else
00217 return 0;
00218 #endif
00219 }
00220
00221 pid_t
00222 octave_syscalls::getppid (void)
00223 {
00224 #if defined (HAVE_GETPPID)
00225 return ::getppid ();
00226 #else
00227 return 0;
00228 #endif
00229 }
00230
00231 gid_t
00232 octave_syscalls::getgid (void)
00233 {
00234 #if defined (HAVE_GETGID)
00235 return ::getgid ();
00236 #else
00237 return 0;
00238 #endif
00239 }
00240
00241 gid_t
00242 octave_syscalls::getegid (void)
00243 {
00244 #if defined (HAVE_GETEGID)
00245 return ::getegid ();
00246 #else
00247 return 0;
00248 #endif
00249 }
00250
00251 uid_t
00252 octave_syscalls::getuid (void)
00253 {
00254 #if defined (HAVE_GETUID)
00255 return ::getuid ();
00256 #else
00257 return 0;
00258 #endif
00259 }
00260
00261 uid_t
00262 octave_syscalls::geteuid (void)
00263 {
00264 #if defined (HAVE_GETEUID)
00265 return ::geteuid ();
00266 #else
00267 return 0;
00268 #endif
00269 }
00270
00271 int
00272 octave_syscalls::pipe (int *fildes)
00273 {
00274 std::string msg;
00275 return pipe (fildes);
00276 }
00277
00278 int
00279 octave_syscalls::pipe (int *fildes, std::string& msg)
00280 {
00281 msg = std::string ();
00282
00283 int status = -1;
00284
00285 #if defined (HAVE_PIPE)
00286 status = ::pipe (fildes);
00287
00288 if (status < 0)
00289 {
00290 using namespace std;
00291 msg = ::strerror (errno);
00292 }
00293 #else
00294 msg = NOT_SUPPORTED ("pipe");
00295 #endif
00296
00297 return status;
00298 }
00299
00300 pid_t
00301 octave_syscalls::waitpid (pid_t pid, int options)
00302 {
00303 std::string msg;
00304 return waitpid (pid, options, msg);
00305 }
00306
00307 pid_t
00308 octave_syscalls::waitpid (pid_t pid, int options, std::string& msg)
00309 {
00310 msg = std::string ();
00311
00312 int status = -1;
00313
00314 #if defined (HAVE_WAITPID)
00315 status = ::waitpid (pid, 0, options);
00316
00317 if (status < 0)
00318 {
00319 using namespace std;
00320 msg = ::strerror (errno);
00321 }
00322 #else
00323 msg = NOT_SUPPORTED ("waitpid");
00324 #endif
00325
00326 return status;
00327 }
00328
00329 int
00330 octave_syscalls::kill (pid_t pid, int sig)
00331 {
00332 std::string msg;
00333 return kill (pid, sig, msg);
00334 }
00335
00336 int
00337 octave_syscalls::kill (pid_t pid, int sig, std::string& msg)
00338 {
00339 msg = std::string ();
00340
00341 int status = -1;
00342
00343 #if defined (HAVE_KILL)
00344 status = ::kill (pid, sig);
00345
00346 if (status < 0)
00347 {
00348 using namespace std;
00349 msg = ::strerror (errno);
00350 }
00351 #else
00352 msg = NOT_SUPPORTED ("kill");
00353 #endif
00354
00355 return status;
00356 }
00357
00358
00359
00360
00361
00362