mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 00:00:48 +00:00
Close file descriptors
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@17514 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b2c5c9c8d2
commit
d0649ee7c9
2 changed files with 101 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2003-08-22 Adam Fedor <fedor@gnu.org>
|
||||||
|
|
||||||
|
* Tools/gsnd/gsnd.m (main): Close any open file descriptors so
|
||||||
|
we can be a proper daemon.
|
||||||
|
|
||||||
2003-08-22 Gregory John Casamento <greg_casamento@yahoo.com>
|
2003-08-22 Gregory John Casamento <greg_casamento@yahoo.com>
|
||||||
|
|
||||||
* Source/GSNibTemplates.[hm]: Added new template classes to a new file
|
* Source/GSNibTemplates.[hm]: Added new template classes to a new file
|
||||||
|
|
|
@ -24,11 +24,16 @@
|
||||||
#include "portaudio/pa_common/portaudio.h"
|
#include "portaudio/pa_common/portaudio.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#ifdef __MINGW__
|
#ifdef __MINGW__
|
||||||
#include "process.h"
|
#include "process.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_SYSLOG_H
|
||||||
|
#include <syslog.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define GSNDNAME @"GNUstepGSSoundServer"
|
#define GSNDNAME @"GNUstepGSSoundServer"
|
||||||
#define FRAME_SIZE 4
|
#define FRAME_SIZE 4
|
||||||
#define BUFFER_SIZE_IN_FRAMES (1024 * FRAME_SIZE)
|
#define BUFFER_SIZE_IN_FRAMES (1024 * FRAME_SIZE)
|
||||||
|
@ -60,6 +65,8 @@
|
||||||
#define CLAMP(x, low, high) \
|
#define CLAMP(x, low, high) \
|
||||||
(((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
|
(((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
|
||||||
|
|
||||||
|
static int is_daemon = 0; /* Currently running as daemon. */
|
||||||
|
|
||||||
short **_X;
|
short **_X;
|
||||||
short **_Y;
|
short **_Y;
|
||||||
unsigned int _Time;
|
unsigned int _Time;
|
||||||
|
@ -77,6 +84,66 @@ int resamplerReadData(int inCount, short inArray[], short *outPtr[],
|
||||||
int dataArraySize, int Xoff, BOOL init_count);
|
int dataArraySize, int Xoff, BOOL init_count);
|
||||||
int resampleError(char *s);
|
int resampleError(char *s);
|
||||||
|
|
||||||
|
static char ebuf[2048];
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_SYSLOG
|
||||||
|
|
||||||
|
static int log_priority;
|
||||||
|
|
||||||
|
static void
|
||||||
|
gsnd_log (int prio)
|
||||||
|
{
|
||||||
|
if (is_daemon)
|
||||||
|
{
|
||||||
|
syslog (log_priority | prio, ebuf);
|
||||||
|
}
|
||||||
|
else if (prio == LOG_INFO)
|
||||||
|
{
|
||||||
|
write (1, ebuf, strlen (ebuf));
|
||||||
|
write (1, "\n", 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
write (2, ebuf, strlen (ebuf));
|
||||||
|
write (2, "\n", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prio == LOG_CRIT)
|
||||||
|
{
|
||||||
|
if (is_daemon)
|
||||||
|
{
|
||||||
|
syslog (LOG_CRIT, "exiting.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf (stderr, "exiting.\n");
|
||||||
|
fflush (stderr);
|
||||||
|
}
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define LOG_CRIT 2
|
||||||
|
#define LOG_DEBUG 0
|
||||||
|
#define LOG_ERR 1
|
||||||
|
#define LOG_INFO 0
|
||||||
|
#define LOG_WARNING 0
|
||||||
|
void
|
||||||
|
gsnd_log (int prio)
|
||||||
|
{
|
||||||
|
write (2, ebuf, strlen (ebuf));
|
||||||
|
write (2, "\n", 1);
|
||||||
|
if (prio == LOG_CRIT)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "exiting.\n");
|
||||||
|
fflush (stderr);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
@protocol GSSndObj
|
@protocol GSSndObj
|
||||||
|
|
||||||
- (void)setIdentifier:(NSString *)identifier;
|
- (void)setIdentifier:(NSString *)identifier;
|
||||||
|
@ -969,6 +1036,7 @@ static int paCallback(void *inputBuffer,
|
||||||
|
|
||||||
int main(int argc, char** argv, char **env)
|
int main(int argc, char** argv, char **env)
|
||||||
{
|
{
|
||||||
|
int c;
|
||||||
CREATE_AUTORELEASE_POOL(pool);
|
CREATE_AUTORELEASE_POOL(pool);
|
||||||
|
|
||||||
#ifdef GS_PASS_ARGUMENTS
|
#ifdef GS_PASS_ARGUMENTS
|
||||||
|
@ -1007,6 +1075,34 @@ int main(int argc, char** argv, char **env)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Ensure we don't have any open file descriptors which may refer
|
||||||
|
* to sockets bound to ports we may try to use.
|
||||||
|
*
|
||||||
|
* Use '/dev/null' for stdin and stdout. Assume stderr is ok.
|
||||||
|
*/
|
||||||
|
for (c = 0; c < FD_SETSIZE; c++)
|
||||||
|
{
|
||||||
|
if (is_daemon || (c != 2))
|
||||||
|
{
|
||||||
|
(void)close(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (open("/dev/null", O_RDONLY) != 0)
|
||||||
|
{
|
||||||
|
sprintf(ebuf, "failed to open stdin from /dev/null (%s)\n",
|
||||||
|
strerror(errno));
|
||||||
|
gsnd_log(LOG_CRIT);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (open("/dev/null", O_WRONLY) != 1)
|
||||||
|
{
|
||||||
|
sprintf(ebuf, "failed to open stdout from /dev/null (%s)\n",
|
||||||
|
strerror(errno));
|
||||||
|
gsnd_log(LOG_CRIT);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
gsnd = [[SoundServer alloc] init];
|
gsnd = [[SoundServer alloc] init];
|
||||||
|
|
||||||
if (gsnd == nil) {
|
if (gsnd == nil) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue