(file) Return to FileHandle.c CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Executor

 1 kumpf 1.1 /*
 2           //%2006////////////////////////////////////////////////////////////////////////
 3           //
 4           // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 5           // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
 6           // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
 7           // IBM Corp.; EMC Corporation, The Open Group.
 8           // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
 9           // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
10           // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
11           // EMC Corporation; VERITAS Software Corporation; The Open Group.
12           // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
13           // EMC Corporation; Symantec Corporation; The Open Group.
14           //
15           // Permission is hereby granted, free of charge, to any person obtaining a copy
16           // of this software and associated documentation files (the "Software"), to
17           // deal in the Software without restriction, including without limitation the
18           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
19           // sell copies of the Software, and to permit persons to whom the Software is
20           // furnished to do so, subject to the following conditions:
21           // 
22 kumpf 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
23           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
24           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
25           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
26           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30           //
31           //%/////////////////////////////////////////////////////////////////////////////
32           */
33           #include <stdlib.h>
34           #include <sys/types.h>
35           #include <sys/stat.h>
36           #include <fcntl.h>
37           #include <unistd.h>
38           #include <sys/time.h>
39           #include <sys/resource.h>
40           #include "FileHandle.h"
41           
42           /*
43 kumpf 1.1 **==============================================================================
44           **
45           ** RedirectTerminalIO()
46           **
47           **     Redirect stdin, stdout, and stderr to /dev/null.
48           **
49           **==============================================================================
50           */
51           
52           void RedirectTerminalIO(void)
53           {
54               /* Close these file descriptors (stdin, stdout, stderr). */
55           
56               close(0);
57               close(1);
58               close(2);
59           
60               /* Direct standard input, output, and error to /dev/null: */
61           
62               open("/dev/null", O_RDONLY);
63               open("/dev/null", O_RDWR);
64 kumpf 1.1     open("/dev/null", O_RDWR);
65           }
66           
67           /*
68           **==============================================================================
69           **
70           ** CloseUnusedDescriptors()
71           **
72           **     Close all file descriptors except stdin, stdout, stderr, and the two
73           **     specified file descriptors.
74           **
75           **==============================================================================
76           */
77           
78           void CloseUnusedDescriptors(int fd1, int fd2)
79           {
80               struct rlimit rlim;
81           
82               if (getrlimit(RLIMIT_NOFILE, &rlim) == 0)
83               {
84                   int i;
85 kumpf 1.1 
86                   for (i = 3; i < (int)rlim.rlim_cur; i++)
87                   {
88                       if (i != fd1 && i != fd2)
89                       {
90                           close(i);
91                       }
92                   }
93               }
94           }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2