/* signals usr1 & usr2 are sent by the spnav_x11 script to start/stop the * daemon's connection to the X server. */ static void sig_handler(int s) { int tmp; switch(s) { case SIGHUP: tmp = cfg.led; read_cfg("/etc/spnavrc", &cfg); if(cfg.led != tmp) { set_led(cfg.led); } break; case SIGSEGV: fprintf(stderr, "Segmentation fault caught, trying to exit gracefully\n"); case SIGINT: case SIGTERM: exit(0); #ifdef USE_X11 case SIGUSR1: init_x11(); break; case SIGUSR2: close_x11(); break; #endif default: break; } }
void ps_end(void) { ps_write("stroke"); ps_write("grestore"); ps_write("end"); ps_write("showpage"); ps_write_pars(psfile); fclose(psfile); PltFmtFlag = 0; if (Xup) init_x11(); }
Bool window_subsystem_init( char * error_buf) { bzero( &guts, sizeof( guts)); guts. debug = do_debug; guts. icccm_only = do_icccm_only; Mdebug("init x11:%d, debug:%x, sync:%d, display:%s\n", do_x11, guts.debug, do_sync, do_display ? do_display : "(default)"); if ( do_x11) { Bool ret = init_x11( error_buf ); if ( !ret && DISP) { XCloseDisplay(DISP); DISP = nil; } return ret; } return true; }
/* signals usr1 & usr2 are sent by the spnav_x11 script to start/stop the * daemon's connection to the X server. */ void sig_handler(int s) { int tmp; switch(s) { case SIGHUP: tmp = cfg.led; read_cfg("/etc/spnavrc", &cfg); if(cfg.led != tmp) { set_led(cfg.led); } break; case SIGSEGV: fprintf(stderr, "Segmentation fault caught, trying to exit gracefully\n"); case SIGINT: case SIGTERM: close_x11(); /* call to avoid leaving garbage in the X server's root windows */ close_dev(); remove(PIDFILE); exit(0); #ifdef USE_X11 case SIGUSR1: init_x11(); break; case SIGUSR2: close_x11(); break; #endif default: break; } }
/* * Simple "main" function for multiple platforms. * * Note the special "--" option which terminates the processing of * standard options. All non-standard options (if any) are passed * directly to the "init_xxx()" function. */ int main(int argc, char *argv[]) { int i; bool done = FALSE; bool new_game = FALSE; int show_score = 0; cptr mstr = NULL; bool args = TRUE; /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; #ifdef USE_286 /* Attempt to use XMS (or EMS) memory for swap space */ if (_OvrInitExt(0L, 0L)) { _OvrInitEms(0, 0, 64); } #endif #ifdef SET_UID /* Default permissions on files */ (void)umask(022); # ifdef SECURE /* Authenticate */ Authenticate(); # endif #endif /* Get the file paths */ init_stuff(); #ifdef SET_UID /* Get the user id (?) */ player_uid = getuid(); #ifdef VMS /* Mega-Hack -- Factor group id */ player_uid += (getgid() * 1000); #endif # ifdef SAFE_SETUID # ifdef _POSIX_SAVED_IDS /* Save some info for later */ player_euid = geteuid(); player_egid = getegid(); # endif # if 0 /* XXX XXX XXX */ /* Redundant setting necessary in case root is running the game */ /* If not root or game not setuid the following two calls do nothing */ if (setgid(getegid()) != 0) { quit("setgid(): cannot set permissions correctly!"); } if (setuid(geteuid()) != 0) { quit("setuid(): cannot set permissions correctly!"); } # endif # endif #endif #ifdef SET_UID /* Initialize the "time" checker */ if (check_time_init() || check_time()) { quit("The gates to Angband are closed (bad time)."); } /* Initialize the "load" checker */ if (check_load_init() || check_load()) { quit("The gates to Angband are closed (bad load)."); } /* Acquire the "user name" as a default player name */ #ifdef ANGBAND_2_8_1 user_name(player_name, player_uid); #else /* ANGBAND_2_8_1 */ user_name(op_ptr->full_name, player_uid); #endif /* ANGBAND_2_8_1 */ #ifdef PRIVATE_USER_PATH /* Create a directory for the users files. */ create_user_dir(); #endif /* PRIVATE_USER_PATH */ #endif /* SET_UID */ /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { /* Require proper options */ if (argv[i][0] != '-') game_usage(); /* Analyze option */ switch (argv[i][1]) { case 'N': case 'n': { new_game = TRUE; break; } case 'F': case 'f': { arg_fiddle = TRUE; break; } case 'W': case 'w': { arg_wizard = TRUE; break; } case 'V': case 'v': { arg_sound = TRUE; break; } case 'G': case 'g': { /* HACK - Graphics mode switches on the original tiles */ arg_graphics = GRAPHICS_ORIGINAL; break; } case 'R': case 'r': { arg_force_roguelike = TRUE; break; } case 'O': case 'o': { arg_force_original = TRUE; break; } case 'S': case 's': { show_score = atoi(&argv[i][2]); if (show_score <= 0) show_score = 10; break; } case 'u': case 'U': { if (!argv[i][2]) game_usage(); #ifdef ANGBAND_2_8_1 strncpy(player_name, &argv[i][2], 32); player_name[31] = '\0'; #else /* ANGBAND_2_8_1 */ strncpy(op_ptr->full_name, &argv[i][2], 32); op_ptr->full_name[31] = '\0'; #endif /* ANGBAND_2_8_1 */ break; } case 'm': { if (!argv[i][2]) game_usage(); mstr = &argv[i][2]; break; } case 'M': { arg_monochrome = TRUE; break; } case 'd': case 'D': { change_path(&argv[i][2]); break; } case '-': { argv[i] = argv[0]; argc = argc - i; argv = argv + i; args = FALSE; break; } default: { /* Default usage-help */ game_usage(); } } } /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Process the player name */ process_player_name(TRUE); /* Install "quit" hook */ quit_aux = quit_hook; /* * Drop privs (so X11 will work correctly) * unless we are running the Linux-SVGALib version. * * (In which case we initialize after safe_setuid_grab() * is called.) */ safe_setuid_drop(); #ifdef USE_XAW /* Attempt to use the "main-xaw.c" support */ if (!done && (!mstr || (streq(mstr, "xaw")))) { if (0 == init_xaw(argc, argv)) { ANGBAND_SYS = "xaw"; done = TRUE; } } #endif #ifdef USE_X11 /* Attempt to use the "main-x11.c" support */ if (!done && (!mstr || (streq(mstr, "x11")))) { if (0 == init_x11(argc, argv)) { ANGBAND_SYS = "x11"; done = TRUE; } } #endif #ifdef USE_XPJ /* Attempt to use the "main-xpj.c" support */ if (!done && (!mstr || (streq(mstr, "xpj")))) { if (0 == init_xpj(argc, argv)) { ANGBAND_SYS = "xpj"; done = TRUE; } } #endif #ifdef USE_GTK /* Attempt to use the "main-gtk.c" support */ if (!done && (!mstr || (streq(mstr, "gtk")))) { if (0 == init_gtk((unsigned char*) &new_game, argc, argv)) { done = TRUE; } } #endif #ifdef USE_GCU /* Attempt to use the "main-gcu.c" support */ if (!done && (!mstr || (streq(mstr, "gcu")))) { if (0 == init_gcu()) { ANGBAND_SYS = "gcu"; done = TRUE; } } #endif #ifdef USE_CAP /* Attempt to use the "main-cap.c" support */ if (!done && (!mstr || (streq(mstr, "cap")))) { if (0 == init_cap(argc, argv)) { ANGBAND_SYS = "cap"; done = TRUE; } } #endif #ifdef USE_DOS /* Attempt to use the "main-dos.c" support */ if (!done && (!mstr || (streq(mstr, "dos")))) { if (0 == init_dos()) { ANGBAND_SYS = "dos"; done = TRUE; } } #endif #ifdef USE_IBM /* Attempt to use the "main-ibm.c" support */ if (!done && (!mstr || (streq(mstr, "ibm")))) { if (0 == init_ibm()) { ANGBAND_SYS = "ibm"; done = TRUE; } } #endif #ifdef USE_EMX /* Attempt to use the "main-emx.c" support */ if (!done && (!mstr || (streq(mstr, "emx")))) { if (0 == init_emx()) { ANGBAND_SYS = "emx"; done = TRUE; } } #endif #ifdef USE_SLA /* Attempt to use the "main-sla.c" support */ if (!done && (!mstr || (streq(mstr, "sla")))) { if (0 == init_sla()) { ANGBAND_SYS = "sla"; done = TRUE; } } #endif #ifdef USE_AMI /* Attempt to use the "main-ami.c" support */ if (!done && (!mstr || (streq(mstr, "ami")))) { if (0 == init_ami()) { ANGBAND_SYS = "ami"; done = TRUE; } } #endif #ifdef USE_VME /* Attempt to use the "main-vme.c" support */ if (!done && (!mstr || (streq(mstr, "vme")))) { if (0 == init_vme()) { ANGBAND_SYS = "vme"; done = TRUE; } } #endif #ifdef USE_VCS /* Attempt to use the "main-vcs.c" support */ if (!done && (!mstr || (streq(mstr, "vcs")))) { if (0 == init_vcs(argc, argv)) { ANGBAND_SYS = "vcs"; done = TRUE; } } #endif /* USE_VCS */ /* Grab privs (dropped above for X11) */ safe_setuid_grab(); #ifdef USE_LSL /* Attempt to use the "main-lsl.c" support */ if (!done && (!mstr || (streq(mstr, "lsl")))) { if (0 == init_lsl()) { ANGBAND_SYS = "lsl"; done = TRUE; } } #endif /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); /* Hack -- If requested, display scores and quit */ if (show_score > 0) display_scores(0, show_score); /* Gtk initializes earlier */ if (!streq(ANGBAND_SYS, "gtk")) { /* Catch nasty signals */ signals_init(); /* Initialize */ init_angband(); } /* Wait for response */ pause_line(23); /* Play the game */ play_game(new_game); /* Quit */ quit(NULL); /* Exit */ return (0); }
int main(int argc, char **argv) { int i, ret, become_daemon = 1; for(i=1; i<argc; i++) { if(argv[i][0] == '-' && argv[i][2] == 0) { switch(argv[i][1]) { case 'd': become_daemon = !become_daemon; break; case 'v': verbose = 1; break; case 'h': printf("usage: %s [options]\n", argv[0]); printf("options:\n"); printf(" -d\tdo not daemonize\n"); printf(" -v\tverbose output\n"); printf(" -h\tprint this usage information\n"); return 0; default: fprintf(stderr, "unrecognized argument: %s\n", argv[i]); return 1; } } else { fprintf(stderr, "unexpected argument: %s\n", argv[i]); return 1; } } if(become_daemon) { daemonize(); } write_pid_file(); puts("Spacenav daemon " VERSION); read_cfg("/etc/spnavrc", &cfg); if(init_clients() == -1) { return 1; } signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); signal(SIGSEGV, sig_handler); signal(SIGHUP, sig_handler); signal(SIGUSR1, sig_handler); signal(SIGUSR2, sig_handler); if(init_dev() == -1) { init_hotplug(); } init_unix(); #ifdef USE_X11 init_x11(); #endif atexit(cleanup); for(;;) { fd_set rset; int fd, max_fd = 0; struct client *c; FD_ZERO(&rset); /* set the device fd if it's open, otherwise set the hotplug fd */ if((fd = get_dev_fd()) != -1 || (fd = get_hotplug_fd()) != -1) { FD_SET(fd, &rset); if(fd > max_fd) max_fd = fd; } /* the UNIX domain socket listening for connections */ if((fd = get_unix_socket()) != -1) { FD_SET(fd, &rset); if(fd > max_fd) max_fd = fd; } /* all the UNIX socket clients */ c = first_client(); while(c) { if(get_client_type(c) == CLIENT_UNIX) { int s = get_client_socket(c); assert(s >= 0); FD_SET(s, &rset); if(s > max_fd) max_fd = s; } c = next_client(); } /* and the X server socket */ #ifdef USE_X11 if((fd = get_x11_socket()) != -1) { FD_SET(fd, &rset); if(fd > max_fd) max_fd = fd; } #endif do { ret = select(max_fd + 1, &rset, 0, 0, 0); } while(ret == -1 && errno == EINTR); if(ret > 0) { handle_events(&rset); } } return 0; /* unreachable */ }
/* * Simple "main" function for multiple platforms. * * Note the special "--" option which terminates the processing of * standard options. All non-standard options (if any) are passed * directly to the "init_xxx()" function. */ int main(int argc, char *argv[]) { int i; bool done = FALSE; bool new_game = FALSE; int show_score = 0; cptr mstr = NULL; bool args = TRUE; /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; #ifdef USE_286 /* Attempt to use XMS (or EMS) memory for swap space */ if (_OvrInitExt(0L, 0L)) { _OvrInitEms(0, 0, 64); } #endif #ifdef SET_UID /* Default permissions on files */ (void)umask(022); # ifdef SECURE /* Authenticate */ Authenticate(); # endif #endif /* Get the file paths */ init_stuff(); #ifdef SET_UID /* Get the user id (?) */ player_uid = getuid(); #ifdef VMS /* Mega-Hack -- Factor group id */ player_uid += (getgid() * 1000); #endif # ifdef SAFE_SETUID # ifdef _POSIX_SAVED_IDS /* Save some info for later */ player_euid = geteuid(); player_egid = getegid(); # endif # if 0 /* XXX XXX XXX */ /* Redundant setting necessary in case root is running the game */ /* If not root or game not setuid the following two calls do nothing */ if (setgid(getegid()) != 0) { quit("setgid(): cannot set permissions correctly!"); } if (setuid(geteuid()) != 0) { quit("setuid(): cannot set permissions correctly!"); } # endif # endif #endif /* Drop permissions */ safe_setuid_drop(); #ifdef SET_UID /* Initialize the "time" checker */ if (check_time_init() || check_time()) { quit("The gates to Angband are closed (bad time)."); } /* Initialize the "load" checker */ if (check_load_init() || check_load()) { quit("The gates to Angband are closed (bad load)."); } /* Acquire the "user name" as a default player name */ user_name(player_name, player_uid); #ifdef PRIVATE_USER_PATH /* Create a directory for the users files. */ create_user_dir(); #endif /* PRIVATE_USER_PATH */ #endif /* SET_UID */ /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { /* Require proper options */ if (argv[i][0] != '-') goto usage; /* Analyze option */ switch (argv[i][1]) { case 'N': case 'n': { new_game = TRUE; break; } case 'F': case 'f': { arg_fiddle = TRUE; break; } case 'W': case 'w': { arg_wizard = TRUE; break; } case 'V': case 'v': { arg_sound = TRUE; break; } case 'G': case 'g': { /* HACK - Graphics mode switches on the original tiles */ arg_graphics = GRAPHICS_ORIGINAL; break; } case 'R': case 'r': { arg_force_roguelike = TRUE; break; } case 'O': case 'o': { arg_force_original = TRUE; break; } case 'S': case 's': { show_score = atoi(&argv[i][2]); if (show_score <= 0) show_score = 10; break; } case 'u': case 'U': { if (!argv[i][2]) goto usage; strcpy(player_name, &argv[i][2]); break; } case 'm': { if (!argv[i][2]) goto usage; mstr = &argv[i][2]; break; } case 'M': { arg_monochrome = TRUE; break; } case 'd': case 'D': { change_path(&argv[i][2]); break; } case '-': { argv[i] = argv[0]; argc = argc - i; argv = argv + i; args = FALSE; break; } default: usage: { /* Dump usage information */ puts("Usage: angband [options] [-- subopts]"); puts(" -n Start a new character"); puts(" -f Request fiddle mode"); puts(" -w Request wizard mode"); puts(" -v Request sound mode"); puts(" -g Request graphics mode"); puts(" -o Request original keyset"); puts(" -r Request rogue-like keyset"); puts(" -M Request monochrome mode"); puts(" -s<num> Show <num> high scores"); puts(" -u<who> Use your <who> savefile"); puts(" -m<sys> Force 'main-<sys>.c' usage"); puts(" -d<def> Define a 'lib' dir sub-path"); puts(""); #ifdef USE_SDL puts(" -msdl To use SDL"); #endif /* USE_SDL */ #ifdef USE_X11 puts(" -mx11 To use X11"); puts(" -- Sub options"); puts(" -- -d Set display name"); puts(" -- -o Request old 8x8 tile graphics"); puts(" -- -a Request Adam Bolt 16x16 tile graphics"); puts(" -- -b Request Bigtile graphics mode"); puts(" -- -s Turn off smoothscaling graphics"); puts(" -- -n# Number of terms to use"); puts(""); #endif /* USE_X11 */ #ifdef USE_GCU puts(" -mgcu To use GCU (GNU Curses)"); #endif /* USE_GCU */ #ifdef USE_CAP puts(" -mcap To use CAP (\"Termcap\" calls)"); #endif /* USE_CAP */ #ifdef USE_DOS puts(" -mdos To use DOS (Graphics)"); #endif /* USE_DOS */ #ifdef USE_IBM puts(" -mibm To use IBM (BIOS text mode)"); #endif /* USE_IBM */ #ifdef USE_SLA puts(" -msla To use SLA (SLANG)"); #endif /* USE_SLA */ #ifdef USE_LSL puts(" -mlsl To use LSL (Linux-SVGALIB)"); #endif /* USE_LSL */ #ifdef USE_AMI puts(" -mami To use AMI (Amiga)"); #endif /* USE_AMI */ #ifdef USE_VME puts(" -mvme To use VME (VAX/ESA)"); #endif /* USE_VME */ /* Actually abort the process */ quit(NULL); } } } /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Process the player name */ process_player_name(TRUE); /* Create any missing directories */ create_needed_dirs(); /* Install "quit" hook */ quit_aux = quit_hook; #ifdef USE_XAW /* Attempt to use the "main-xaw.c" support */ if (!done && (!mstr || (streq(mstr, "xaw")))) { extern errr init_xaw(int, char**); if (0 == init_xaw(argc, argv)) { ANGBAND_SYS = "xaw"; done = TRUE; } } #endif #ifdef USE_SDL /* Attempt to use the "main-sdl.c" support */ if (!done && (!mstr || (streq(mstr, "sdl")))) { extern errr init_sdl(int, char**); if (0 == init_sdl(argc, argv)) { ANGBAND_SYS = "sdl"; done = TRUE; } } #endif #ifdef USE_X11 /* Attempt to use the "main-x11.c" support */ if (!done && (!mstr || (streq(mstr, "x11")))) { extern errr init_x11(int, char**); if (0 == init_x11(argc, argv)) { ANGBAND_SYS = "x11"; done = TRUE; } } #endif #ifdef USE_GCU /* Attempt to use the "main-gcu.c" support */ if (!done && (!mstr || (streq(mstr, "gcu")))) { extern errr init_gcu(int, char**); if (0 == init_gcu(argc, argv)) { ANGBAND_SYS = "gcu"; done = TRUE; } } #endif #ifdef USE_CAP /* Attempt to use the "main-cap.c" support */ if (!done && (!mstr || (streq(mstr, "cap")))) { extern errr init_cap(int, char**); if (0 == init_cap(argc, argv)) { ANGBAND_SYS = "cap"; done = TRUE; } } #endif #ifdef USE_DOS /* Attempt to use the "main-dos.c" support */ if (!done && (!mstr || (streq(mstr, "dos")))) { extern errr init_dos(void); if (0 == init_dos()) { ANGBAND_SYS = "dos"; done = TRUE; } } #endif #ifdef USE_IBM /* Attempt to use the "main-ibm.c" support */ if (!done && (!mstr || (streq(mstr, "ibm")))) { extern errr init_ibm(void); if (0 == init_ibm()) { ANGBAND_SYS = "ibm"; done = TRUE; } } #endif #ifdef USE_EMX /* Attempt to use the "main-emx.c" support */ if (!done && (!mstr || (streq(mstr, "emx")))) { extern errr init_emx(void); if (0 == init_emx()) { ANGBAND_SYS = "emx"; done = TRUE; } } #endif #ifdef USE_SLA /* Attempt to use the "main-sla.c" support */ if (!done && (!mstr || (streq(mstr, "sla")))) { extern errr init_sla(void); if (0 == init_sla()) { ANGBAND_SYS = "sla"; done = TRUE; } } #endif #ifdef USE_LSL /* Attempt to use the "main-lsl.c" support */ if (!done && (!mstr || (streq(mstr, "lsl")))) { extern errr init_lsl(void); if (0 == init_lsl()) { ANGBAND_SYS = "lsl"; done = TRUE; } } #endif #ifdef USE_AMI /* Attempt to use the "main-ami.c" support */ if (!done && (!mstr || (streq(mstr, "ami")))) { extern errr init_ami(void); if (0 == init_ami()) { ANGBAND_SYS = "ami"; done = TRUE; } } #endif #ifdef USE_VME /* Attempt to use the "main-vme.c" support */ if (!done && (!mstr || (streq(mstr, "vme")))) { extern errr init_vme(void); if (0 == init_vme()) { ANGBAND_SYS = "vme"; done = TRUE; } } #endif /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); /* Hack -- If requested, display scores and quit */ if (show_score > 0) display_scores(0, show_score); /* Catch nasty signals */ signals_init(); /* Initialize */ init_angband(); /* Wait for response */ pause_line(23); /* Play the game */ play_game(new_game); /* Quit */ quit(NULL); /* Exit */ return (0); }
int main(void) { int nthr = 4; //get_nprocs_conf(); int ndx; int delta = HEIGHT / nthr; int ofs = 0; struct mandelthr *args; pthread_t *thrtab = calloc(nthr, sizeof(pthread_t)); pthread_t **thrptrtab = calloc(nthr, sizeof(pthread_t *)); fprintf(stderr, "mandel launching %d threads\n", nthr); /* Make a window! */ init_x11(WIDTH); init_colours(); g_mandel.nthr = nthr; for (ndx = 0 ; ndx < nthr ; ndx++) { args = calloc(1, sizeof(struct mandelthr)); args->yofs = ofs; args->ylim = ofs + delta; pthread_create(&thrtab[ndx], NULL, mandel_start, args); ofs += delta; } for (ndx = 0 ; ndx < nthr ; ndx++) { pthread_join(thrtab[ndx], (void **)&thrptrtab[ndx]); } do { // pthread_yield(); // m_waitspin(); usleep(50000); pthread_yield(); } while (g_mandel.nthr); XPutImage(g_x11.dpy, g_x11.win, g_x11.gc, g_x11.bitmap, 0, 0, 0, 0, WIDTH, HEIGHT); XFlush(g_x11.dpy); // display_double(ASIZE, xmin, xmax, ymin, ymax); #ifdef WAIT_EXIT while(1) { XEvent event; KeySym key; char text[255]; XNextEvent(g_x11.dpy, &event); /* Just redraw everything on expose */ if ((event.type == Expose) && !event.xexpose.count) { XPutImage(g_x11.dpy, g_x11.win, g_x11.gc, g_x11.bitmap, 0, 0, 0, 0, WIDTH, HEIGHT); } /* Press 'q' to quit */ if ((event.type == KeyPress) && XLookupString(&event.xkey, text, 255, &key, 0) == 1) { if (text[0] == 'q') break; } /* Or simply close the window */ if ((event.type == ClientMessage) && ((Atom) event.xclient.data.l[0] == g_x11.wmdelmsg)) { break; } } #endif sleep(5); /* Done! */ exit_x11(); return 0; }
int handle_xdet_events(fd_set *rset) { struct kevent kev; struct timespec ts = {0, 0}; if(kq == -1 || !FD_ISSET(kq, rset)) { return -1; } if(kevent(kq, 0, 0, &kev, 1, &ts) <= 0) { return -1; } if(kev.ident == fd_tmp) { assert(fd_x11 == -1); /* try to open the socket dir, see if that was what was added to /tmp */ if((fd_x11 = open("/tmp/.X11-unix", O_RDONLY)) == -1) { return -1; } EV_SET(&kev, fd_x11, EVFILT_VNODE, EV_ADD | EV_CLEAR, NOTE_WRITE, 0, 0); if(kevent(kq, &kev, 1, 0, 0, &ts) == -1) { perror("failed to register kqueue event notification for /tmp/.X11-unix"); close(fd_x11); fd_x11 = -1; return -1; } /* successfully added the notification for /tmp/.X11-unix, now we * don't need the /tmp notification anymore. by closing the fd it's * automatically removed from the kqueue. */ close(fd_tmp); fd_tmp = -1; } else if(kev.ident == fd_x11) { int i; if(verbose) { printf("found X socket, will now attempt to connect to the X server\n"); } /* poll for approximately 30 seconds (well a bit more than that) */ for(i=0; i<30; i++) { sleep(1); if(init_x11() != -1) { /* done, we don't need the X socket notification any more */ close(fd_x11); fd_x11 = -1; return 0; /* success */ } } fprintf(stderr, "found X socket yet failed to connect\n"); } return -1; }
int main(int argc, char **argv) { int i, become_daemon = 1; for(i=1; i<argc; i++) { if(argv[i][0] == '-' && argv[i][2] == 0) { switch(argv[i][1]) { case 'd': become_daemon = !become_daemon; break; case 'v': verbose = 1; break; case 'h': printf("usage: %s [options]\n", argv[0]); printf("options:\n"); printf(" -d\tdo not daemonize\n"); printf(" -v\tverbose output\n"); printf(" -h\tprint this usage information\n"); return 0; default: fprintf(stderr, "unrecognized argument: %s\n", argv[i]); return 1; } } else { fprintf(stderr, "unexpected argument: %s\n", argv[i]); return 1; } } if(become_daemon) { daemonize(); } write_pid_file(); read_cfg("/etc/spnavrc", &cfg); if(!(client_list = malloc(sizeof *client_list))) { perror("failed to allocate client list"); return 1; } client_list->next = 0; signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); signal(SIGSEGV, sig_handler); signal(SIGHUP, sig_handler); signal(SIGUSR1, sig_handler); signal(SIGUSR2, sig_handler); init_dev(); init_unix(); #ifdef USE_X11 init_x11(); #endif /* event handling loop */ while(1) { fd_set rd_set; if(dev_fd == -1) { if(init_dev() == -1) { sleep(30); continue; } } if(select_all(&rd_set) >= 0) { handle_events(&rd_set); } } /* just for the sense of symmetry, execution can't reach this :) */ #ifdef USE_X11 close_x11(); #endif close_dev(); return 0; }
void init_game() { struct array_mem_small *msmall; struct array_mem_mid *mmid; struct array_mem_norm *mlarge; struct Process *proc; struct instruction_node *in; struct process_thread *pthread; struct process_task *ptask; int next_offs,proc_offs,pos; double xx,lato_x,lato_y; if(arena_mem_type==MEM_TYPE_ONE) { msmall=(struct array_mem_small*)malloc(sizeof(struct array_mem_small)*size_arena); if(msmall==NULL) die("error malloking small array mem"); bzero(msmall,sizeof(struct array_mem_small)*size_arena); arena=msmall; } if(arena_mem_type==MEM_TYPE_TWO) { mmid=(struct array_mem_mid*)malloc(sizeof(struct array_mem_mid)*size_arena); if(mmid==NULL) die("error malloking mid array mem"); bzero(mmid,sizeof(struct array_mem_mid)*size_arena); arena=mmid; } if(arena_mem_type==MEM_TYPE_FOUR) { mlarge=(struct array_mem_norm*)malloc(sizeof(struct array_mem_norm)*size_arena); if(mlarge==NULL) die("error malloking large array mem"); bzero(mlarge,sizeof(struct array_mem_norm)*size_arena); arena=mlarge; } next_offs=0; for(proc=proc_primo;proc;proc=proc->next) { //calc offset in mem proc_offs=(next_offs+(rand()%min_distance))%size_arena; //put in mem pos=proc_offs; for(in=proc->pc->first;in;in=in->next) { putcode(pos++,proc->processID,in->code); } //create pt pthread=(struct process_thread*)malloc(sizeof(struct process_thread)); if(pthread==NULL) die("error alloking new thread"); pthread->IP=proc_offs+(atoi(proc->pc->org)); pthread->communication_in_a=0; pthread->communication_out_a=0; pthread->communication_in_b=0; pthread->communication_out_b=0; pthread->prev=NULL; pthread->next=NULL; pthread->ptask=NULL; ptask=(struct process_task*)malloc(sizeof(struct process_task)); if(ptask==NULL) die("error alloking new task"); ptask->ID=proc->processID; ptask->n_threads=1; ptask->prev=NULL; ptask->next=NULL; ptask->primo_thread=NULL; ptask->ultimo_thread=NULL; ptask->cur_thread=pthread; ptask->communication_in_a=0; ptask->communication_out_a=0; ptask->communication_in_b=0; ptask->communication_out_b=0; get_symbols(&ptask->out_symbol,&ptask->out_color); //add pt add_thread(pthread,ptask); add_task(ptask); //recalc next_offs next_offs+=proc_offs+proc->pc->len; //free proc&pc in=proc->pc->first; do{ if(in->left) free_expr(in->left); if(in->right) free_expr(in->right); if(in->code) free(in->code); if(in->next) {in=in->next;free(in->prev);} else {free(in);in=NULL;} }while(in!=NULL); } xx=sqrt(size_arena); lato_y=rint(xx); lato_x=ceil(xx); max_x=(int)lato_x; max_y=(int)lato_y; if(output_mode>=OUTPUT_DEBUG) { sprintf(out_str,"max_x=%d max_y=%d\n",max_x,max_y); fputs(out_str,fpout); } //init_graph if(vo_mode==VO_FRAMEBUFFER) init_txt(); if(vo_mode==VO_X11) init_x11(); }
int main(void) { int nthr = get_nprocs_conf(); int ndx; int delta = ASIZE / nthr; int ofs = 0; struct mandelthr *args; pthread_t *thrtab = calloc(nthr, sizeof(pthread_t)); pthread_t **thrptrtab = calloc(nthr, sizeof(pthread_t *)); /* Make a window! */ init_x11(ASIZE); init_colours(); g_nthr = nthr; for (ndx = 0 ; ndx < nthr ; ndx++) { args = calloc(1, sizeof(struct mandelthr)); args->yofs = ofs; args->ylim = ofs + delta; pthread_create(&thrtab[ndx], NULL, mandel_start, args); ofs += delta; } for (ndx = 0 ; ndx < nthr ; ndx++) { pthread_join(thrtab[ndx], (void **)&thrptrtab[ndx]); } do { pthread_yield(); } while (g_nthr); XPutImage(dpy, win, gc, bitmap, 0, 0, 0, 0, ASIZE, ASIZE); XFlush(dpy); // display_double(ASIZE, xmin, xmax, ymin, ymax); #ifdef WAIT_EXIT while(1) { XEvent event; KeySym key; char text[255]; XNextEvent(dpy, &event); /* Just redraw everything on expose */ if ((event.type == Expose) && !event.xexpose.count) { XPutImage(dpy, win, gc, bitmap, 0, 0, 0, 0, ASIZE, ASIZE); } /* Press 'q' to quit */ if ((event.type == KeyPress) && XLookupString(&event.xkey, text, 255, &key, 0) == 1) { if (text[0] == 'q') break; } /* Or simply close the window */ if ((event.type == ClientMessage) && ((Atom) event.xclient.data.l[0] == wmDeleteMessage)) { break; } } #endif /* Done! */ exit_x11(); return 0; }
/* * Simple "main" function for multiple platforms. * * Note the special "--" option which terminates the processing of * standard options. All non-standard options (if any) are passed * directly to the "init_xxx()" function. */ int main(int argc, char *argv[]) { int i; bool done = FALSE; bool new_game = FALSE; int show_score = 0; const char * mstr = NULL; bool args = TRUE; /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; #ifdef SET_UID /* Default permissions on files */ (void)umask(022); #endif /* Get the file paths */ init_stuff(); #ifdef SET_UID /* Get the user id */ player_uid = getuid(); /* Save the effective GID for later recall */ player_egid = getegid(); # if 0 /* XXX XXX XXX */ /* Redundant setting necessary in case root is running the game */ /* If not root or game not setuid the following two calls do nothing */ if (setgid(getegid()) != 0) { quit("setgid(): cannot set permissions correctly!"); } if (setuid(geteuid()) != 0) { quit("setuid(): cannot set permissions correctly!"); } # endif #endif /* SET_UID */ #ifdef SET_UID #ifdef PRIVATE_USER_PATH /* Create directories for the users files */ create_user_dirs(); #endif /* PRIVATE_USER_PATH */ /* Acquire the "user name" as a default player name */ user_name(op_ptr->full_name, player_uid); #endif /* SET_UID */ /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { /* Require proper options */ if (argv[i][0] != '-') goto usage; /* Analyze option */ switch (argv[i][1]) { case 'N': case 'n': { new_game = TRUE; break; } case 'F': case 'f': { arg_fiddle = TRUE; break; } case 'W': case 'w': { arg_wizard = TRUE; break; } case 'V': case 'v': { arg_sound = TRUE; break; } case 'R': case 'r': { arg_force_roguelike = TRUE; break; } case 'O': case 'o': { arg_force_original = TRUE; break; } case 'S': case 's': { show_score = atoi(&argv[i][2]); if (show_score <= 0) show_score = 10; break; } case 'u': case 'U': { if (!argv[i][2]) goto usage; strncpy(op_ptr->base_name, &argv[i][2], 32); op_ptr->base_name[31] = '\0'; break; } case 'm': { if (!argv[i][2]) goto usage; mstr = &argv[i][2]; break; } case 'M': { arg_monochrome = TRUE; break; } case 'd': case 'D': { change_path(&argv[i][2]); break; } case '-': { argv[i] = argv[0]; argc = argc - i; argv = argv + i; args = FALSE; break; } default: usage: { /* Dump usage information */ puts("Usage: angband [options] [-- subopts]"); puts(" -n Start a new character"); puts(" -f Request fiddle mode"); puts(" -w Request wizard mode"); puts(" -v Request sound mode"); puts(" -g Request graphics mode"); puts(" -o Request original keyset"); puts(" -r Request rogue-like keyset"); puts(" -M Request monochrome mode"); puts(" -s<num> Show <num> high scores"); puts(" -u<who> Use your <who> savefile"); puts(" -d<path> Store pref files and screendumps in <path>"); #ifdef USE_X11 puts(" -mx11 To use X11"); puts(" -- Sub options"); puts(" -- -d Set display name"); puts(" -- -s Turn off smoothscaling graphics"); puts(" -- -n# Number of terms to use"); #endif /* USE_X11 */ #ifdef USE_GCU puts(" -mgcu To use GCU (GNU Curses)"); puts(" -- Sub options"); puts(" -- -x No extra sub-windows"); #endif /* USE_GCU */ #ifdef USE_SLA puts(" -msla To use SLA (SLANG)"); #endif /* USE_SLA */ /* Actually abort the process */ quit(NULL); } } } /* Process the player name (but only if one is specified) */ if (strlen(op_ptr->base_name)) process_player_name(FALSE); /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Install "quit" hook */ quit_aux = quit_hook; /* Drop privs (so X11 will work correctly) */ safe_setuid_drop(); #ifdef USE_X11 /* Attempt to use the "main-x11.c" support */ if (!done && (!mstr || (streq(mstr, "x11")))) { extern errr init_x11(int, char**); if (0 == init_x11(argc, argv)) { ANGBAND_SYS = "x11"; done = TRUE; } } #endif #ifdef USE_GCU /* Attempt to use the "main-gcu.c" support */ if (!done && (!mstr || (streq(mstr, "gcu")))) { extern errr init_gcu(int, char**); if (0 == init_gcu(argc, argv)) { ANGBAND_SYS = "gcu"; done = TRUE; } } #endif #ifdef USE_SLA /* Attempt to use the "main-sla.c" support */ if (!done && (!mstr || (streq(mstr, "sla")))) { extern errr init_sla(void); if (0 == init_sla()) { ANGBAND_SYS = "sla"; done = TRUE; } } #endif /* Grab privs (dropped above for X11) */ safe_setuid_grab(); /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); /* Catch nasty signals */ signals_init(); /* Initialize */ init_angband(); /* Hack -- If requested, display scores and quit */ if (show_score > 0) { show_scores(); quit(NULL); } /* Wait for response */ pause_line(23); /* Play the game */ play_game(new_game); /* Quit */ quit(NULL); /* Exit */ return (0); }