Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9238
Modified Files:
Tag: desiredata
s_main.c s_inter.c
Log Message:
cleanup
Index: s_inter.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_inter.c,v
retrieving revision 1.5.4.10.2.25.2.2
retrieving revision 1.5.4.10.2.25.2.3
diff -C2 -d -r1.5.4.10.2.25.2.2 -r1.5.4.10.2.25.2.3
*** s_inter.c 30 Nov 2006 18:10:51 -0000 1.5.4.10.2.25.2.2
--- s_inter.c 1 Dec 2006 19:27:19 -0000 1.5.4.10.2.25.2.3
***************
*** 270,273 ****
--- 270,274 ----
}
+ /* what is this for?? */
static void sys_huphandler(int n)
{
***************
*** 907,911 ****
}
! int sys_startgui(const char *guidir)
{
pid_t childpid;
--- 908,914 ----
}
! void sys_setpriority(void);
!
! int sys_startgui(void)
{
pid_t childpid;
***************
*** 924,933 ****
int stdinpipe[2];
#endif
-
/* create an empty FD poll list */
sys_fdpoll = (t_fdpoll *)t_getbytes(0);
sys_nfdpoll = 0;
inbinbuf = binbuf_new();
-
#ifdef UNISTD
signal(SIGHUP, sys_huphandler);
--- 927,934 ----
***************
*** 937,992 ****
signal(SIGIOT, sys_exithandler);
signal(SIGFPE, SIG_IGN);
! /* signal(SIGILL, sys_exithandler);
signal(SIGBUS, sys_exithandler);
! signal(SIGSEGV, sys_exithandler); */
signal(SIGPIPE, SIG_IGN);
signal(SIGALRM, SIG_IGN);
! #if 0 /* GG says: don't use that */
! signal(SIGSTKFLT, sys_exithandler);
! #endif
#endif
#ifdef _WIN32
if (WSAStartup(version, &nobby)) sys_sockerror("WSAstartup");
#endif /* _WIN32 */
!
! if (sys_nogui)
! {
! sys_callback((t_int(*)(t_int*))fake_initfromgui,0,0);
! }
! else if (sys_guisetportnumber) /* GUI exists and sent us a port number */
! {
struct sockaddr_in server;
struct hostent *hp;
/* create a socket */
sys_guisock = socket(AF_INET, SOCK_STREAM, 0);
! if (sys_guisock < 0)
! sys_sockerror("socket");
!
/* connect socket using hostname provided in command line */
server.sin_family = AF_INET;
-
hp = gethostbyname(LOCALHOST);
!
! if (hp == 0)
! {
! fprintf(stderr,
! "localhost not found (inet protocol not installed?)\n");
exit(1);
}
memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
-
/* assign client port number */
server.sin_port = htons((unsigned short)sys_guisetportnumber);
!
! /* try to connect */
! if (connect(sys_guisock, (struct sockaddr *) &server, sizeof (server))
! < 0)
! {
sys_sockerror("connecting stream socket");
exit(1);
}
! }
! else /* default behavior: start up the GUI ourselves. */
! {
fprintf(stderr,
"PureData in DesireData mode does not currently support starting without\n"
--- 938,975 ----
signal(SIGIOT, sys_exithandler);
signal(SIGFPE, SIG_IGN);
! /* signal(SIGILL, sys_exithandler);
signal(SIGBUS, sys_exithandler);
! signal(SIGSEGV, sys_exithandler); */
signal(SIGPIPE, SIG_IGN);
signal(SIGALRM, SIG_IGN);
! /* GG says: don't set SIGSTKFLT */
#endif
#ifdef _WIN32
if (WSAStartup(version, &nobby)) sys_sockerror("WSAstartup");
#endif /* _WIN32 */
! if (sys_nogui) {
! sys_callback((t_int(*)(t_int*))fake_initfromgui,0,0);
! } else if (sys_guisetportnumber) { /* GUI exists and sent us a port number */
struct sockaddr_in server;
struct hostent *hp;
/* create a socket */
sys_guisock = socket(AF_INET, SOCK_STREAM, 0);
! if (sys_guisock < 0) sys_sockerror("socket");
/* connect socket using hostname provided in command line */
server.sin_family = AF_INET;
hp = gethostbyname(LOCALHOST);
! if (hp == 0) {
! fprintf(stderr, "localhost not found (inet protocol not installed?)\n");
exit(1);
}
memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
/* assign client port number */
server.sin_port = htons((unsigned short)sys_guisetportnumber);
! /* try to connect */
! if (connect(sys_guisock, (struct sockaddr *) &server, sizeof (server)) < 0) {
sys_sockerror("connecting stream socket");
exit(1);
}
! } else {
fprintf(stderr,
"PureData in DesireData mode does not currently support starting without\n"
***************
*** 996,1072 ****
#if defined(__linux__) || defined(IRIX)
! /* now that we've spun off the child process we can promote
! our process's priority, if we can and want to. If not specfied
! (-1), we check root status. This misses the case where we might
! have permission from a "security module" (linux 2.6) -- I don't
! know how to test for that. The "-rt" flag must b eset in that
! case. */
! if (sys_hipriority == -1)
! sys_hipriority = (!getuid() || !geteuid());
!
! if (sys_hipriority)
! {
! #ifndef WATCHDOGTHREAD
! /* To prevent lockup, we fork off a watchdog process with
! higher real-time priority than ours. The GUI has to send
! a stream of ping messages to the watchdog THROUGH the Pd
! process which has to pick them up from the GUI and forward
! them. If any of these things aren't happening the watchdog
! starts sending "stop" and "cont" signals to the Pd process
! to make it timeshare with the rest of the system. (Version
! 0.33P2 : if there's no GUI, the watchdog pinging is done
! from the scheduler idle routine in this process instead.) */
!
! int pipe9[2], watchpid;
! if (pipe(pipe9) < 0)
! {
! setuid(getuid()); /* lose setuid priveliges */
! sys_sockerror("pipe");
! return (1);
! }
! watchpid = fork();
! if (watchpid < 0)
! {
! setuid(getuid()); /* lose setuid priveliges */
! if (errno)
! perror("sys_startgui");
! else fprintf(stderr, "sys_startgui failed\n");
! return (1);
! }
! else if (!watchpid) /* we're the child */
! {
! sys_set_priority(1);
! setuid(getuid()); /* lose setuid priveliges */
! if (pipe9[1] != 0)
! {
! dup2(pipe9[0], 0);
! close(pipe9[0]);
! }
! close(pipe9[1]);
! sprintf(cmdbuf, "%s/pd-watchdog\n", guidir);
! if (sys_verbose) fprintf(stderr, "%s", cmdbuf);
! execl("/bin/sh", "sh", "-c", cmdbuf, (char*)0);
! perror("pd: exec");
! _exit(1);
! }
! else /* we're the parent */
! {
! sys_set_priority(0);
! setuid(getuid()); /* lose setuid priveliges */
close(pipe9[0]);
- sys_watchfd = pipe9[1];
- /* We also have to start the ping loop in the GUI;
- this is done later when the socket is open. */
}
#else
! sys_start_watchdog_thread();
! sys_set_priority(0);
#endif
- }
-
- setuid(getuid()); /* lose setuid priveliges */
#endif /* __linux__ */
-
#ifdef MSW
if (!SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS))
--- 979,1050 ----
#if defined(__linux__) || defined(IRIX)
! /* now that we've spun off the child process we can promote our process's
! priority, if we can and want to. If not specfied (-1), we check root
! status. This misses the case where we might have permission from a
! "security module" (linux 2.6) -- I don't know how to test for that.
! The "-rt" flag must be set in that case. */
! if (sys_hipriority == -1) sys_hipriority = !getuid() || !geteuid();
! #endif
! if (sys_hipriority) sys_setpriority();
! setuid(getuid());
! if (!sys_nogui) {
! char buf[256], buf2[256];
! sys_socketreceiver = socketreceiver_new(0,0,0,0);
! sys_addpollfn(sys_guisock, (t_fdpollfn)socketreceiver_read, sys_socketreceiver);
! sys_get_audio_apis(buf);
! sys_get_midi_apis(buf2);
! sys_vgui("pdtk_pd_startup {%s} %s %s\n", pd_version, buf, buf2);
! }
! return 0;
! }
! /* To prevent lockup, we fork off a watchdog process with higher real-time
! priority than ours. The GUI has to send a stream of ping messages to the
! watchdog THROUGH the Pd process which has to pick them up from the GUI
! and forward them. If any of these things aren't happening the watchdog
! starts sending "stop" and "cont" signals to the Pd process to make it
! timeshare with the rest of the system. (Version 0.33P2 : if there's no
! GUI, the watchdog pinging is done from the scheduler idle routine in this
! process instead.) */
! void sys_setpriority(void) {
! #if defined(__linux__) || defined(IRIX)
! #ifndef WATCHDOGTHREAD
! int pipe9[2], watchpid;
! if (pipe(pipe9) < 0) {
! setuid(getuid());
! sys_sockerror("pipe");
! return 1;
! }
! watchpid = fork();
! if (watchpid < 0) {
! setuid(getuid());
! if (errno) perror("sys_startgui"); else fprintf(stderr, "sys_startgui failed\n");
! return 1;
! } else if (!watchpid) { /* we're the child */
! sys_set_priority(1);
! setuid(getuid());
! if (pipe9[1]) {
! dup2(pipe9[0], 0);
close(pipe9[0]);
}
+ close(pipe9[1]);
+ sprintf(cmdbuf, "%s/pd-watchdog\n", guidir);
+ if (sys_verbose) fprintf(stderr, "%s", cmdbuf);
+ execl("/bin/sh", "sh", "-c", cmdbuf, (char*)0);
+ perror("pd: exec");
+ _exit(1);
+ } else { /* we're the parent */
+ sys_set_priority(0);
+ setuid(getuid());
+ close(pipe9[0]);
+ sys_watchfd = pipe9[1];
+ /* We also have to start the ping loop in the GUI;
+ this is done later when the socket is open. */
+ }
#else
! sys_start_watchdog_thread();
! sys_set_priority(0);
#endif
#endif /* __linux__ */
#ifdef MSW
if (!SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS))
***************
*** 1074,1112 ****
#endif
#ifdef __APPLE__
! if (sys_hipriority)
! {
struct sched_param param;
int policy = SCHED_RR;
int err;
param.sched_priority = 80; /* adjust 0 : 100 */
-
err = pthread_setschedparam(pthread_self(), policy, ¶m);
! if (err)
! post("warning: high priority scheduling failed\n");
}
#endif /* __APPLE__ */
! if (!sys_nogui && !sys_guisetportnumber)
! {
! if (sys_verbose)
! fprintf(stderr, "Waiting for connection request... \n");
if (listen(xsock, 5) < 0) sys_sockerror("listen");
!
! sys_guisock = accept(xsock, (struct sockaddr *) &server,
! (socklen_t *)&len);
! #ifdef OOPS
! close(xsock);
! #endif
if (sys_guisock < 0) sys_sockerror("accept");
! if (sys_verbose)
! fprintf(stderr, "... connected\n");
}
if (!sys_nogui)
{
- char buf[256], buf2[256];
- sys_socketreceiver = socketreceiver_new(0, 0, 0, 0);
- sys_addpollfn(sys_guisock, (t_fdpollfn)socketreceiver_read,
- sys_socketreceiver);
-
/* here is where we start the pinging. */
#if defined(__linux__) || defined(IRIX)
--- 1052,1078 ----
#endif
#ifdef __APPLE__
! if (sys_hipriority) {
struct sched_param param;
int policy = SCHED_RR;
int err;
param.sched_priority = 80; /* adjust 0 : 100 */
err = pthread_setschedparam(pthread_self(), policy, ¶m);
! if (err) post("warning: high priority scheduling failed\n");
}
#endif /* __APPLE__ */
! #if 0
! if (!sys_nogui && !sys_guisetportnumber) {
! if (sys_verbose) fprintf(stderr, "Waiting for connection request... \n");
if (listen(xsock, 5) < 0) sys_sockerror("listen");
! sys_guisock = accept(xsock, (struct sockaddr *) &server, (socklen_t *)&len);
! close(xsock); //OOPS
if (sys_guisock < 0) sys_sockerror("accept");
! if (sys_verbose) fprintf(stderr, "... connected\n");
}
+ #endif
+
if (!sys_nogui)
{
/* here is where we start the pinging. */
#if defined(__linux__) || defined(IRIX)
***************
*** 1116,1128 ****
#endif
#endif
- sys_get_audio_apis(buf);
- sys_get_midi_apis(buf2);
- sys_vgui("pdtk_pd_startup {%s} %s %s {%s}\n", pd_version, buf, buf2, 666);
}
- return (0);
-
}
-
/* This is called when something bad has happened, like a segfault.
Call glob_quit() below to exit cleanly.
--- 1082,1088 ----
Index: s_main.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_main.c,v
retrieving revision 1.7.4.17.2.22.2.6
retrieving revision 1.7.4.17.2.22.2.7
diff -C2 -d -r1.7.4.17.2.22.2.6 -r1.7.4.17.2.22.2.7
*** s_main.c 1 Dec 2006 18:07:38 -0000 1.7.4.17.2.22.2.6
--- s_main.c 1 Dec 2006 19:27:19 -0000 1.7.4.17.2.22.2.7
***************
*** 43,47 ****
int sys_argparse(int argc, char **argv);
void sys_findprogdir(char *progname);
! int sys_startgui(const char *guipath);
void sys_init_idle_callbacks(void);
int sys_rcfile(void);
--- 43,47 ----
int sys_argparse(int argc, char **argv);
void sys_findprogdir(char *progname);
! int sys_startgui(void);
void sys_init_idle_callbacks(void);
int sys_rcfile(void);
***************
*** 63,67 ****
char *sys_guicmd;
t_symbol *sys_libdir;
- static t_symbol *sys_guidir;
t_namelist *sys_externlist;
static t_namelist *sys_openlist=NULL;
--- 63,66 ----
***************
*** 205,210 ****
return (0);
! if (sys_startgui(sys_guidir->s_name)) /* start the gui */
! return(1);
/* tb: { *
--- 204,208 ----
return (0);
! if (sys_startgui()) return 1; /* start the gui */
/* tb: { *
***************
*** 448,475 ****
#ifdef MSW
sys_libdir = gensym(sbuf2);
- sys_guidir = &s_; /* in MSW the guipath just depends on the libdir */
#else
strncpy(sbuf, sbuf2, MAXPDSTRING-30);
sbuf[MAXPDSTRING-30] = 0;
strcat(sbuf, "/lib/pd");
! if (stat(sbuf, &statbuf) >= 0)
! {
! /* complicated layout: lib dir is the one we just stat-ed above */
sys_libdir = gensym(sbuf);
! /* gui lives in .../lib/pd/bin */
! strncpy(sbuf, sbuf2, MAXPDSTRING-30);
! sbuf[MAXPDSTRING-30] = 0;
! strcat(sbuf, "/lib/pd/bin");
! sys_guidir = gensym(sbuf);
! }
! else
! {
! /* simple layout: lib dir is the parent */
sys_libdir = gensym(sbuf2);
- /* gui lives in .../bin */
- strncpy(sbuf, sbuf2, MAXPDSTRING-30);
- sbuf[MAXPDSTRING-30] = 0;
- strcat(sbuf, "/bin");
- sys_guidir = gensym(sbuf);
}
#endif
--- 446,457 ----
#ifdef MSW
sys_libdir = gensym(sbuf2);
#else
strncpy(sbuf, sbuf2, MAXPDSTRING-30);
sbuf[MAXPDSTRING-30] = 0;
strcat(sbuf, "/lib/pd");
! if (stat(sbuf, &statbuf) >= 0) {
sys_libdir = gensym(sbuf);
! } else {
sys_libdir = gensym(sbuf2);
}
#endif