From 21c068f1916330e90f814bed461fe0821d1665ec Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sun, 9 Oct 2011 16:36:37 +0000 Subject: checked in pd-0.43-0.src.tar.gz svn path=/trunk/; revision=15557 --- pd/src/s_inter.c | 124 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 65 insertions(+), 59 deletions(-) (limited to 'pd/src/s_inter.c') diff --git a/pd/src/s_inter.c b/pd/src/s_inter.c index 1549f9de..6efa098c 100644 --- a/pd/src/s_inter.c +++ b/pd/src/s_inter.c @@ -9,7 +9,7 @@ that didn't really belong anywhere. */ #include "s_stuff.h" #include "m_imp.h" #include "g_canvas.h" /* for GUI queueing stuff */ -#ifndef MSW +#ifndef _WIN32 #include #include #include @@ -59,15 +59,15 @@ typedef int socklen_t; #define PDBINDIR "bin/" #endif -#ifndef PDTCLDIR -#define PDTCLDIR "tcl/" +#ifndef PDGUIDIR +#define PDGUIDIR "tcl/" #endif #ifndef WISHAPP #define WISHAPP "wish84.exe" #endif -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__GNU__) #define LOCALHOST "127.0.0.1" #else #define LOCALHOST "localhost" @@ -93,7 +93,6 @@ struct _socketreceiver t_socketreceivefn sr_socketreceivefn; }; -extern char *pd_version; extern int sys_guisetportnumber; static int sys_nfdpoll; @@ -104,10 +103,13 @@ static int sys_guisock; static t_binbuf *inbinbuf; static t_socketreceiver *sys_socketreceiver; extern int sys_addhist(int phase); +void sys_set_searchpath(void); +void sys_set_extrapath(void); +void sys_set_startup(void); /* ----------- functions for timing, signals, priorities, etc --------- */ -#ifdef MSW +#ifdef _WIN32 static LARGE_INTEGER nt_inittime; static double nt_freq = 0; @@ -136,13 +138,13 @@ double nt_tixtotime(LARGE_INTEGER *dumbass) return (((double)(dumbass->QuadPart - nt_inittime.QuadPart)) / nt_freq); } #endif -#endif /* MSW */ +#endif /* _WIN32 */ /* get "real time" in seconds; take the first time we get called as a reference time of zero. */ double sys_getrealtime(void) { -#ifndef MSW +#ifndef _WIN32 static struct timeval then; struct timeval now; gettimeofday(&now, 0); @@ -174,7 +176,7 @@ static int sys_domicrosleep(int microsec, int pollem) FD_ZERO(&exceptset); for (fp = sys_fdpoll, i = sys_nfdpoll; i--; fp++) FD_SET(fp->fdp_fd, &readset); -#ifdef MSW +#ifdef _WIN32 if (sys_maxfd == 0) Sleep(microsec/1000); else @@ -196,7 +198,7 @@ static int sys_domicrosleep(int microsec, int pollem) } else { -#ifdef MSW +#ifdef _WIN32 if (sys_maxfd == 0) Sleep(microsec/1000); else @@ -211,10 +213,8 @@ void sys_microsleep(int microsec) sys_domicrosleep(microsec, 1); } -#ifdef HAVE_UNISTD_H -typedef void (*sighandler_t)(int); - -static void sys_signal(int signo, sighandler_t sigfun) +#if !defined(_WIN32) && !defined(__CYGWIN__) +static void sys_signal(int signo, sig_t sigfun) { struct sigaction action; action.sa_flags = 0; @@ -270,9 +270,9 @@ void sys_setalarm(int microsec) setitimer(ITIMER_REAL, &gonzo, 0); } -#endif +#endif /* NOT _WIN32 && NOT __CYGWIN__ */ -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__GNU__) #if defined(_POSIX_PRIORITY_SCHEDULING) || defined(_POSIX_MEMLOCK) #include @@ -346,7 +346,7 @@ void sys_set_priority(int higher) void sys_sockerror(char *s) { -#ifdef MSW +#ifdef _WIN32 int err = WSAGetLastError(); if (err == 10054) return; else if (err == 10044) @@ -562,7 +562,7 @@ void sys_closesocket(int fd) #ifdef HAVE_UNISTD_H close(fd); #endif -#ifdef MSW +#ifdef _WIN32 closesocket(fd); #endif } @@ -844,7 +844,7 @@ int sys_pollgui(void) static int sys_watchfd; -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__GNU__) void glob_watchdog(t_pd *dummy) { if (write(sys_watchfd, "\n", 1) < 1) @@ -873,24 +873,25 @@ int sys_startgui(const char *libdir) int len = sizeof(server); int ntry = 0, portno = FIRSTPORTNUM; int xsock = -1; -#ifdef MSW +#ifdef _WIN32 short version = MAKEWORD(2, 0); WSADATA nobby; -#endif -#ifdef HAVE_UNISTD_H +#else int stdinpipe[2]; -#endif +#endif /* _WIN32 */ /* create an empty FD poll list */ sys_fdpoll = (t_fdpoll *)t_getbytes(0); sys_nfdpoll = 0; inbinbuf = binbuf_new(); -#ifdef HAVE_UNISTD_H +#if !defined(_WIN32) && !defined(__CYGWIN__) signal(SIGHUP, sys_huphandler); signal(SIGINT, sys_exithandler); signal(SIGQUIT, sys_exithandler); signal(SIGILL, sys_exithandler); +# ifdef SIGIOT signal(SIGIOT, sys_exithandler); +# endif signal(SIGFPE, SIG_IGN); /* signal(SIGILL, sys_exithandler); signal(SIGBUS, sys_exithandler); @@ -900,10 +901,11 @@ int sys_startgui(const char *libdir) #if 0 /* GG says: don't use that */ signal(SIGSTKFLT, sys_exithandler); #endif -#endif -#ifdef MSW +#endif /* NOT _WIN32 && NOT __CYGWIN__ */ + +#ifdef _WIN32 if (WSAStartup(version, &nobby)) sys_sockerror("WSAstartup"); -#endif +#endif /* _WIN32 */ if (sys_nogui) { @@ -911,11 +913,10 @@ int sys_startgui(const char *libdir) skip starting the GUI up. */ t_atom zz[NDEFAULTFONT+2]; int i; -#ifdef MSW +#ifdef _WIN32 if (GetCurrentDirectory(MAXPDSTRING, cmdbuf) == 0) strcpy(cmdbuf, "."); -#endif -#ifdef HAVE_UNISTD_H +#else if (!getcwd(cmdbuf, MAXPDSTRING)) strcpy(cmdbuf, "."); @@ -961,12 +962,9 @@ int sys_startgui(const char *libdir) } else /* default behavior: start up the GUI ourselves. */ { -#ifdef MSW +#ifdef _WIN32 char scriptbuf[MAXPDSTRING+30], wishbuf[MAXPDSTRING+30], portbuf[80]; int spawnret; - -#endif -#ifdef MSW char intarg; #else int intarg; @@ -988,7 +986,7 @@ int sys_startgui(const char *libdir) intarg = 1; if (setsockopt(xsock, IPPROTO_TCP, TCP_NODELAY, &intarg, sizeof(intarg)) < 0) -#ifndef MSW +#ifndef _WIN32 post("setsockopt (TCP_NODELAY) failed\n") #endif ; @@ -1003,7 +1001,7 @@ int sys_startgui(const char *libdir) /* name the socket */ while (bind(xsock, (struct sockaddr *)&server, sizeof(server)) < 0) { -#ifdef MSW +#ifdef _WIN32 int err = WSAGetLastError(); #else int err = errno; @@ -1024,7 +1022,7 @@ int sys_startgui(const char *libdir) if (sys_verbose) fprintf(stderr, "port %d\n", portno); -#ifdef HAVE_UNISTD_H +#ifndef _WIN32 if (!sys_guicmd) { #ifdef __APPLE__ @@ -1063,14 +1061,13 @@ int sys_startgui(const char *libdir) if (stat(wish_paths[i], &statbuf) >= 0) break; } - sprintf(cmdbuf,"\"%s\" %s/tcl/pd-gui.tcl %d\n", wish_paths[i], - libdir, portno); -#else + sprintf(cmdbuf,"\"%s\" %d\n", wish_paths[i], portno); +#else /* __APPLE__ */ sprintf(cmdbuf, "TCL_LIBRARY=\"%s/lib/tcl/library\" TK_LIBRARY=\"%s/lib/tk/library\" \ - wish \"%s/tcl/pd-gui.tcl\" %d\n", + wish \"%s/" PDGUIDIR "/pd-gui.tcl\" %d\n", libdir, libdir, libdir, portno); -#endif +#endif /* __APPLE__ */ sys_guicmd = cmdbuf; } @@ -1104,19 +1101,17 @@ int sys_startgui(const char *libdir) close(stdinpipe[0]); } } -#endif +#endif /* NOT __APPLE__ */ execl("/bin/sh", "sh", "-c", sys_guicmd, (char*)0); perror("pd: exec"); _exit(1); } -#endif /* UNISTD */ - -#ifdef MSW +#else /* NOT _WIN32 */ /* fprintf(stderr, "%s\n", libdir); */ strcpy(scriptbuf, "\""); strcat(scriptbuf, libdir); - strcat(scriptbuf, "/" PDTCLDIR "pd-gui.tcl\""); + strcat(scriptbuf, "/" PDGUIDIR "pd-gui.tcl\""); sys_bashfilename(scriptbuf, scriptbuf); sprintf(portbuf, "%d", portno); @@ -1133,18 +1128,23 @@ int sys_startgui(const char *libdir) exit(1); } -#endif /* MSW */ +#endif /* NOT _WIN32 */ } -#if defined(__linux__) || defined(IRIX) +#if defined(__linux__) || defined(IRIX) || defined(__FreeBSD_kernel__) /* 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. */ + (-1), we assume real-time was wanted. Afterward, just in case + someone made Pd setuid in order to get permission to do this, + unset setuid and lose root priveliges after doing this. Starting + in Linux 2.6 this is accomplished by putting lines like: + @audio - rtprio 99 + @audio - memlock unlimited + in the system limits file, perhaps /etc/limits.conf or + /etc/security/limits.conf */ + fprintf(stderr, "was... %d\n", sys_hipriority); if (sys_hipriority == -1) - sys_hipriority = (!getuid() || !geteuid()); + sys_hipriority = 1; if (sys_hipriority) { @@ -1205,7 +1205,7 @@ int sys_startgui(const char *libdir) setuid(getuid()); /* lose setuid priveliges */ #endif /* __linux__ */ -#ifdef MSW +#ifdef _WIN32 if (!SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS)) fprintf(stderr, "pd: couldn't set high priority class\n"); #endif @@ -1246,14 +1246,20 @@ int sys_startgui(const char *libdir) sys_socketreceiver); /* here is where we start the pinging. */ -#if defined(__linux__) || defined(IRIX) +#if defined(__linux__) || defined(IRIX) || defined(__FreeBSD_kernel__) if (sys_hipriority) sys_gui("pdtk_watchdog\n"); #endif sys_get_audio_apis(buf); sys_get_midi_apis(buf2); - sys_vgui("pdtk_pd_startup {%s} %s %s {%s} %s\n", pd_version, buf, buf2, - sys_font, sys_fontweight); + sys_set_searchpath(); /* tell GUI about path and startup flags */ + sys_set_extrapath(); + sys_set_startup(); + /* ... and about font, medio APIS, etc */ + sys_vgui("pdtk_pd_startup %d %d %d {%s} %s %s {%s} %s\n", + PD_MAJOR_VERSION, PD_MINOR_VERSION, + PD_BUGFIX_VERSION, PD_TEST_VERSION, + buf, buf2, sys_font, sys_fontweight); } return (0); @@ -1270,7 +1276,7 @@ void sys_bail(int n) if (!reentered) { reentered = 1; -#ifndef __linux__ /* sys_close_audio() hangs if you're in a signal? */ +#if !defined(__linux__) && !defined(__FreeBSD_kernel__) && !defined(__GNU__) /* sys_close_audio() hangs if you're in a signal? */ fprintf(stderr, "closing audio...\n"); sys_close_audio(); fprintf(stderr, "closing MIDI...\n"); -- cgit v1.2.1