Ejemplo n.º 1
0
Archivo: client.c Proyecto: rsenn/tichu
/* -------------------------------------------------------------------------- *
 * Client Shutdown                                                            *
 * -------------------------------------------------------------------------- */
void client_shutdown(void)
{
  if(client_ini)
    ini_close(client_ini);
  
  /* Bilder freigeben */
  client_free(client_buffer);  
/*  client_free_image(client_background);*/
  
  /* Client-Module herunterfahren */
  sound_shutdown();
  card_shutdown();
  net_shutdown();
  
  /* Bibliotheken herunterfahren */
  SDL_Quit();
  sgQuit();
  
#if MDEBUG_ENABLE
  mdebug_shutdown();
#endif /* MDEBUG_ENABLE */
  
  client_log(STATUS, "Baba! *Winke-Wink*");
  exit(0);
}
Ejemplo n.º 2
0
Archivo: app.c Proyecto: rzel/dim3
void app_end(void)
{
	if (server.map_open) map_end();
	if (server.game_open) game_end();
	
		// shut down app
		
	console_add_system("Closing App");
	
		// shutdown view
		
	if (!app.dedicated_host) view_shutdown();
	
		// physics ray tracing
		
	ray_trace_shutdown();

		// shutdown server
		
	server_shutdown();
	
		// OS network shutdown
		
	net_shutdown();
}
Ejemplo n.º 3
0
void client_run( void )
{
#ifdef NETWORK_ENABLED
	/* init UDP socket */
	sys_printf = client_printf_info;
	net_init( atoi(config.local_port) );
	sys_printf = printf;
	client_add_chatter( _("Press 'Connect' to connect to a game server."), 1 );

	client_state = CLIENT_NONE;
	client_recv_limit = config.recv_limit;

	gui_enable_event_filter();
	gui_widget_show( dlg_chatroom );
	stk_display_fade( STK_FADE_IN, STK_FADE_DEFAULT_TIME );
	gui_run( dlg_chatroom );
	stk_display_fade( STK_FADE_OUT, STK_FADE_DEFAULT_TIME );
	gui_disable_event_filter();

	if ( client_is_connected ) {
		/* tell server we are off */
		client_disconnect();
		/* finalize UDP socket */
		socket_print_stats( &client );
	}
	net_shutdown();
#endif
}
Ejemplo n.º 4
0
/* Close the network connection */
static int apcups_shutdown (void)
{
	if (global_sockfd < 0)
		return (0);

	net_shutdown (&global_sockfd);
	return (0);
} /* int apcups_shutdown */
Ejemplo n.º 5
0
arg_t _shutdown(void)
{
	struct socket *s = sock_get(fd, NULL);

	if (s == NULL)
		return -1;
	if (how > 2) {
		udata.u_error = EINVAL;
		return -1;
	}
	return net_shutdown(s, how + 1);
}
Ejemplo n.º 6
0
Archivo: main.c Proyecto: kmeaw/bootos
void shutdown_and_launch(void)
{
#ifdef NETRPC_ENABLE
	netrpc_shutdown();
#endif
	if (tftp)
		tftp_remove(tftp);

	net_shutdown();
	mm_shutdown();
	kernel_launch();
}
Ejemplo n.º 7
0
void sploit_shutdown(void)
{
  ssl_shutdown();
  net_shutdown();
  str_shutdown();
  io_shutdown();
  dlink_shutdown();
  queue_shutdown();
  log_shutdown();
  timer_shutdown();
  mem_shutdown();
  
  syscall_exit(1);
}
Ejemplo n.º 8
0
void arch_auto_shutdown() {
	irq_disable();
	timer_shutdown();
#if 0
	snd_shutdown();
	hardware_shutdown();
	net_shutdown();
	pvr_shutdown();
	fs_dcload_shutdown();
	fs_vmu_shutdown();
	fs_iso9660_shutdown();
#endif
	fs_ramdisk_shutdown();
	fs_romdisk_shutdown();
	fs_shutdown();
	thd_shutdown();
}
Ejemplo n.º 9
0
int main (void) 
{
	NET_DRIVERNAME *drivers;
	int i, j, class;
  	char buf[1024];

	net_init();
  
	puts ("Defined network classes:");

	for (j = 0; j < NET_CLASS_MAX; j++)
		if (net_classes[j].name)
			printf ("%d\t%s\n", j, net_classes[j].name);

	puts ("Choose one:");
	fgets (buf, sizeof buf, stdin);
	j = atoi (buf);
	printf ("\n\n%d: ", j);
	if (!net_classes[j].name) {
		puts ("no such class");
		return 1;
	}

	puts (net_classes[j].name);

	printf ("Address format information: ");
	if (!net_classes[j].addrhelp)
		puts ("None");
	else
		puts (net_classes[j].addrhelp);

	puts ("Drivers in this class:");

	drivers = net_getdrivernames (net_classes[j].drivers);

	for (i = 0; drivers[i].name; i++)
		printf ("%d\t%s\n", drivers[i].num, drivers[i].name);

	free (drivers);
	net_shutdown();

	return 0;
}
Ejemplo n.º 10
0
static int lua_net_shutdown(lua_State * L)
{
  int n;

  if (!init) {
    goto ok;
  }

  if (lwipinit) {
    httpfs_shutdown();
    tcpfs_shutdown();

    lwip_shutdown_all();
    lwipinit = 0;
  }

  if (netinit) {
    fs_shutdown();

    net_input_set_target(0);

    net_shutdown();

    net_driver_close();

    netinit = 0;
  }

  dma_test(-1);

  init = 0;
  printf("net_driver LUA shutdown.\n");
 ok:
  lua_settop(L,0);
  lua_pushnumber(L,1);
  return 1;
}
Ejemplo n.º 11
0
/* Get and print status from apcupsd NIS server */
static int apc_query_server (char *host, int port,
		struct apc_detail_s *apcups_detail)
{
	int     n;
	char    recvline[1024];
	char   *tokptr;
	char   *toksaveptr;
	char   *key;
	double  value;
	_Bool retry = 1;
	int status;

#if APCMAIN
# define PRINT_VALUE(name, val) printf("  Found property: name = %s; value = %f;\n", name, val)
#else
# define PRINT_VALUE(name, val) /**/
#endif

	while (retry)
	{
		if (global_sockfd < 0)
		{
			global_sockfd = net_open (host, port);
			if (global_sockfd < 0)
			{
				ERROR ("apcups plugin: Connecting to the "
						"apcupsd failed.");
				return (-1);
			}
		}


		status = net_send (&global_sockfd, "status", strlen ("status"));
		if (status != 0)
		{
			/* net_send is closing the socket on error. */
			assert (global_sockfd < 0);
			if (retry)
			{
				retry = 0;
				count_retries++;
				continue;
			}

			ERROR ("apcups plugin: Writing to the socket failed.");
			return (-1);
		}

		break;
	} /* while (retry) */

        /* When collectd's collection interval is larger than apcupsd's
         * timeout, we would have to retry / re-connect each iteration. Try to
         * detect this situation and shut down the socket gracefully in that
         * case. Otherwise, keep the socket open to avoid overhead. */
	count_iterations++;
	if ((count_iterations == 10) && (count_retries > 2))
	{
		NOTICE ("apcups plugin: There have been %i retries in the "
				"first %i iterations. Will close the socket "
				"in future iterations.",
				count_retries, count_iterations);
		close_socket = 1;
	}

	while ((n = net_recv (&global_sockfd, recvline, sizeof (recvline) - 1)) > 0)
	{
		assert ((unsigned int)n < sizeof (recvline));
		recvline[n] = '\0';
#if APCMAIN
		printf ("net_recv = `%s';\n", recvline);
#endif /* if APCMAIN */

		toksaveptr = NULL;
		tokptr = strtok_r (recvline, " :\t", &toksaveptr);
		while (tokptr != NULL)
		{
			key = tokptr;
			if ((tokptr = strtok_r (NULL, " :\t", &toksaveptr)) == NULL)
				continue;
			value = atof (tokptr);

			PRINT_VALUE (key, value);

			if (strcmp ("LINEV", key) == 0)
				apcups_detail->linev = value;
			else if (strcmp ("BATTV", key) == 0)
				apcups_detail->battv = value;
			else if (strcmp ("ITEMP", key) == 0)
				apcups_detail->itemp = value;
			else if (strcmp ("LOADPCT", key) == 0)
				apcups_detail->loadpct = value;
			else if (strcmp ("BCHARGE", key) == 0)
				apcups_detail->bcharge = value;
			else if (strcmp ("OUTPUTV", key) == 0)
				apcups_detail->outputv = value;
			else if (strcmp ("LINEFREQ", key) == 0)
				apcups_detail->linefreq = value;
			else if (strcmp ("TIMELEFT", key) == 0)
			{
				/* Convert minutes to seconds if requested by
				 * the user. */
				if (conf_report_seconds)
					value *= 60.0;
				apcups_detail->timeleft = value;
			}

			tokptr = strtok_r (NULL, ":", &toksaveptr);
		} /* while (tokptr != NULL) */
	}
	status = errno; /* save errno, net_shutdown() may re-set it. */

	if (close_socket)
		net_shutdown (&global_sockfd);

	if (n < 0)
	{
		char errbuf[1024];
		ERROR ("apcups plugin: Reading from socket failed: %s",
				sstrerror (status, errbuf, sizeof (errbuf)));
		return (-1);
	}

	return (0);
}
Ejemplo n.º 12
0
int main (int argc, const char **argv)
{
#ifdef WIN32
	{
		// set the console to accept escape sequences (Win10+)
		HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);

		if (console != INVALID_HANDLE_VALUE)
		{
			DWORD consoleMode = 0;
			GetConsoleMode(console, &consoleMode);

			consoleMode |= 4; // ENABLE_VIRTUAL_TERMINAL_PROCESSING; but that isn't available in our current SDK target

			SetConsoleMode(console, consoleMode);
		}
	}
#endif

    int exit_code = EXIT_SUCCESS;

    try {

        // Experiment with floating point masks.
        // #ifdef FE_NOMASK_ENV
        // feenableexcept(FE_INVALID);
        // feenableexcept(FE_DIVBYZERO | FE_INVALID);
        // #endif

        bgl = new BackgroundLoader();

        size_t winid = gfx_init(cb);

        debug_drawer = new BulletDebugDrawer(ogre_sm); // FIXME: hack

        #ifdef WIN32
        mouse = new MouseDirectInput8(winid);
        bool use_dinput = getenv("GRIT_DINPUT")!=NULL;
        keyboard = use_dinput ? (Keyboard *)new KeyboardDirectInput8(winid)
                      : (Keyboard *)new KeyboardWinAPI(winid);
        #else
        mouse = new MouseX11(winid);
        keyboard = new KeyboardX11(winid);
        #endif
        clipboard_init();

        physics_init();

        net_init();

        core_option_init();
        streamer_init();

        navigation_init();

        // audio_init(getenv("GRIT_AUDIO_DEV"));
        audio_init(NULL);

        std::vector<std::string> args;
        for (int i=0 ; i<argc ; i++) {
            args.push_back(argv[i]);
        }

        try {
            const char *init_file = getenv("GRIT_INIT");
            if (init_file == nullptr) init_file = "/system/init.lua";
            init_lua(init_file, args, core_L);
        } catch (Exception &e) {
            CERR << "Fatal error: " << e << std::endl;
            exit_code = EXIT_FAILURE;
        }

        // Lua returns - we quit.
        
        CVERB << "Shutting down Lua net subsystem..." << std::endl;

        net_shutdown(core_L);

        navigation_shutdown();

        object_all_del(core_L);  // Will remove all demands from background loader.

        CVERB << "Shutting down Lua graphics subsystem..." << std::endl;

        gfx_shutdown_lua(core_L);

        CVERB << "Shutting down Background Loader..." << std::endl;

        bgl->shutdown();

        CVERB << "Shutting down Mouse & Keyboard..." << std::endl;

        if (mouse) delete mouse;
        if (keyboard) delete keyboard;

        CVERB << "Shutting down clipboard..." << std::endl;
        clipboard_shutdown();

        CVERB << "Shutting down Lua VM..." << std::endl;
        if (core_L) shutdown_lua(core_L);

        CVERB << "Shutting down audio subsystem..." << std::endl;
        audio_shutdown(); //close AL device

        CVERB << "Shutting down physics subsystem..." << std::endl;
        physics_shutdown();

        CVERB << "Shutting down the physics debug drawer..." << std::endl;
        if (debug_drawer) delete debug_drawer;

        CVERB << "Shutting down the Graphics subsystem..." << std::endl;
        gfx_shutdown();

        delete bgl;

    } catch (Exception &e) {
        std::cerr << "TOP LEVEL ERROR: " << e << std::endl;
        return EXIT_FAILURE;
    }

    return exit_code;
}
Ejemplo n.º 13
0
int
main(int argc, char **argv)
{
	extern char	*__progname;
	char		*cfgfile = 0;
	int		 ch;

	if (geteuid() != 0) {
		/* No point in continuing. */
		fprintf(stderr, "%s: This daemon needs to be run as root.\n",
		    __progname);
		return 1;
	}

	while ((ch = getopt(argc, argv, "c:dv")) != -1) {
		switch (ch) {
		case 'c':
			if (cfgfile)
				usage();
			cfgfile = optarg;
			break;
		case 'd':
			cfgstate.debug++;
			break;
		case 'v':
			cfgstate.verboselevel++;
			break;
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (argc > 0)
		usage();

	log_init(__progname);
	timer_init();

	cfgstate.runstate = INIT;
	LIST_INIT(&cfgstate.peerlist);

	cfgstate.listen_port = SASYNCD_DEFAULT_PORT;
	cfgstate.flags |= CTL_DEFAULT;

	if (!cfgfile)
		cfgfile = SASYNCD_CFGFILE;

	if (conf_parse_file(cfgfile) == 0 ) {
		if (!cfgstate.sharedkey) {
			fprintf(stderr, "config: "
			    "no shared key specified, cannot continue");
			exit(1);
		}
	} else {
		exit(1);
	}

	carp_demote(CARP_INC, 0);

	if (carp_init())
		return 1;
	if (pfkey_init(0))
		return 1;
	if (net_init())
		return 1;

	if (!cfgstate.debug)
		if (daemon(1, 0)) {
			perror("daemon()");
			exit(1);
		}

	if (monitor_init()) {
		/* Parent, with privileges. */
		monitor_loop();
		exit(0);
	}

	/* Child, no privileges left. Run main loop. */
	sasyncd_run(getppid());

	/* Shutdown. */
	log_msg(0, "shutting down...");

	net_shutdown();
	pfkey_shutdown();
	return 0;
}
Ejemplo n.º 14
0
int main(int argc, char** argv) {
    WINDOW *lic = NULL;
    int x, y, mr;
    int opt = 0, cnt = 0;
    char remname[256];
    char *licpath = NULL;
    FILE *fout = NULL;
    char *version = NULL;
    if (am_bin_path(instance_path, sizeof (instance_path)) == -1) {
        return 0;
    } else {
        if (am_whitespace(instance_path) > 0) {
            fprintf(stderr, "Whitespace in path: %s \n", instance_path);
            return 0;
        }

        snprintf(log_path, sizeof (log_path), "%s/../logs/install_%s.log", instance_path, TIMESTAMPLONG);
        snprintf(lic_path, sizeof (lic_path), "%s/../legal-notices/license.txt", instance_path);

        fout = fopen(log_path, "a");
        if (fout != NULL) {
            fprintf(fout, "\n\n===================================================");
            print_version(fout, NULL);
            fprintf(fout, "\r\n");
            fclose(fout);
        }

        strcat(instance_path, "../instances");
        snprintf(int_conf_path, sizeof (int_conf_path), "%s/.agents", instance_path);
    }

    net_initialize();

    /* cli mode */
    if (argc > 1) {
        while ((opt = opts(argc, argv, "e:vlxr:o:a:i:p:c:")) != -1)
            switch (opt) {
                case 'e':
                {
                    char encryptpasswd[1024] = "";
                    char origpasswd[1024] = "";
                    char *keystr;
                    char bkeystr[1024] = "";
                    strcpy(origpasswd, oarg);
                    am_trim(origpasswd);
                    keystr = am_random_key();
                    memset(bkeystr, 0, 1024);
                    am_b64encode(keystr, bkeystr);
                    encrypt_base64(origpasswd, encryptpasswd, bkeystr);
                    fprintf(stderr, "\nEncrypted password:\n%s\n\nKey:\n%s\n\n", encryptpasswd, bkeystr);
                    net_shutdown();
                    return (EXIT_SUCCESS);
                }
                    break;
                case 'l':
                {
                    fprintf(stderr, "Agent instances:\n");
                    int n;
                    am_conf_p inst = NULL, temp;
                    if ((n = am_read_instances(instance_path, &inst)) > 0) {
                        temp = inst;
                        while (temp != NULL) {
                            fprintf(stderr, "%s\n", temp->name);
                            temp = temp->next;
                        }
                        am_free(inst);
                    } else
                        fprintf(stderr, "There are no agent instances registered.\n");
                    net_shutdown();
                    return (EXIT_SUCCESS);
                }
                    break;
                case 'v':
                {
                    print_version(stdout, NULL);
                    net_shutdown();
                    return (EXIT_SUCCESS);
                }
                    break;
                case 'r':
                {
                    fprintf(stderr, "Removing \"%s\" instance...\n", oarg);
                    if (remove_instance(oarg)) {
                        fprintf(stderr, "Instance \"%s\" removed.\n", oarg);
                    } else
                        fprintf(stderr, "Error removing \"%s\" instance.\n", oarg);
                    net_shutdown();
                    return (EXIT_SUCCESS);
                }
                    break;
                case 'o':
                    sprintf(openam_url, oarg);
                    cnt = 1;
                    break;
                case 'a':
                    sprintf(agent_url, oarg);
                    cnt = 1;
                    break;
                case 'i':
                    sprintf(agent_id, oarg);
                    cnt = 1;
                    break;
                case 'p':
                    sprintf(agent_pass_file, oarg);
                    cnt = 1;
                    break;
                case 'c':
                    sprintf(web_conf_path, oarg);
                    cnt = 1;
                    break;
                case 'x':
                {
                    asprintf(&licpath, "%s/.license", instance_path);
                    if (licpath) {
                        am_setup_conf(licpath, NULL);
                        free(licpath);
                        licpath = NULL;
                    }
                    net_shutdown();
                    return (EXIT_SUCCESS);
                }
                    break;
                case '?':
                    if (oopt == 'e' || oopt == 'r' || oopt == 'o' || oopt == 'a' || oopt == 'i' || oopt == 'p' || oopt == 'c')
                        fprintf(stderr, "\nError: option -%c requires an argument.\n", oopt);
                    else if (isprint(oopt))
                        fprintf(stderr, "\nError: unknown option `-%c'.\n", oopt);
                    else
                        fprintf(stderr, "\nnError: unknown option character `\\x%x'.\n", oopt);
                    opt = -1;
                default:
                    opt = -1;
            }

        if (cnt == 1) {
            asprintf(&licpath, "%s/.license", instance_path);
            if (licpath && am_file_exists(licpath) == 0) {
                am_free(licpath);
                fprintf(stderr, "\nYou have to accept ForgeRock Web Policy Agent license terms to continue.\n"
                        "Please run agentadmin with -x option or interactively to view and accept the license.\n\n");
                net_shutdown();
                return (EXIT_FAILURE);
            }
            am_free(licpath);
            licpath = NULL;
        }

        if (cnt == 1) {
            url_t u, ua;
            am_trim(openam_url);
            u = URL(openam_url);
            if (u.error == 0) {
                if (validate_am_host(&u) != 0) {
                    fprintf(stderr, "Error validating OpenAM URL\n");
                    net_shutdown();
                    return (EXIT_FAILURE);
                }
            } else {
                fprintf(stderr, "Invalid OpenAM URL value\n");
                net_shutdown();
                return (EXIT_FAILURE);
            }
            am_trim(agent_url);
            ua = URL(agent_url);
            if (ua.error != 0) {
                fprintf(stderr, "Invalid Agent URL value\n");
                net_shutdown();
                return (EXIT_FAILURE);
            } else {
                am_trim(agent_id);
                am_trim(agent_pass_file);
                if (am_read_password(agent_pass_file, agent_pass) == 0) {
                    fprintf(stderr, "Error reading password file\n");
                    net_shutdown();
                    return (EXIT_FAILURE);
                }
                if (validate_agent(&u, agent_id, agent_pass) != 0) {
                    fprintf(stderr, "%s\n", PROFILE_NOT_FOUND);
                    net_shutdown();
                    return (EXIT_FAILURE);
                }
            }
            am_trim(web_conf_path);
            if (web_conf_path == NULL || web_conf_path[0] == '\0') {
                fprintf(stderr, "Varnish vmod directory must not be empty\n");
                net_shutdown();
                return (EXIT_FAILURE);
            } else {
                char *t = NULL;
                asprintf(&t, "%s/libvmod_am.so", web_conf_path);
                if (am_whitespace(web_conf_path) > 0) {
                    fprintf(stderr, "Path to Varnish modules directory must not contain spaces\n");
                    am_free(t);
                    net_shutdown();
                    return (EXIT_FAILURE);
                } else if (am_file_writeable(web_conf_path) == 0) {
                    fprintf(stderr, "Error opening Varnish modules directory\n");
                    am_free(t);
                    net_shutdown();
                    return (EXIT_FAILURE);
                } else if (am_file_exists(t) == 1) {
                    fprintf(stderr, "This Varnish instance is already configured\n");
                    am_free(t);
                    net_shutdown();
                    return (EXIT_FAILURE);
                }
                am_free(t);
            }
            create_varnish_instance(ua);
            fprintf(stderr, "\nVarnish and agent configuration files are here:\n%s\nCheck installation log %s for any errors.\n\n", web_conf_path_out, log_path);
        } else {
            display_usage();
        }
        net_shutdown();
        return (EXIT_SUCCESS);
    }

    print_version(NULL, &version);
    if (version != NULL) {
        snprintf(vers, sizeof (vers), "Version: %s", version);
        free(version);
    }

    initscr();
    cbreak();
    noecho();
    keypad(stdscr, TRUE);
    start_color();
    init_pair(1, COLOR_RED, COLOR_BLACK);
    getmaxyx(stdscr, y, x);

    asprintf(&licpath, "%s/.license", instance_path);
    if (am_file_exists(licpath) == 0) {
        lic = license(y, x, &mr);
        wrefresh(lic);
        delwin(lic);
        lic = NULL;
        if (mr == KEY_F(4)) {
            goto all_done;
        } else {
            am_setup_conf(licpath, NULL);
        }
    }

ret_to_menu:

    refresh();

    mr = mainmenu(y, x);

    if (mr == 0) {
        int cr = configure_step(y, x);
        if (cr == KEY_F(4)) {
            goto ret_to_menu;
        }
    } else if (mr >= 2 && mr < menu_size - 1) {
        memset(remname, 0, sizeof (remname));
        if (sscanf(menu_values[mr], "Remove '%[^''']' instance", remname) == 1) {
            if (remove_step(remname, y, x) == KEY_F(4))
                goto ret_to_menu;
        }
        goto ret_to_menu;
    } else if (mr == 1) {
        encrypt_step(y, x);
        goto ret_to_menu;
    }

all_done:

    am_free(licpath);
    clean_main_menu();
    move(0, 0);
    clrtoeol();
    refresh();
    endwin();
    net_shutdown();
    return (EXIT_SUCCESS);
}
Ejemplo n.º 15
0
/* exitfunc:  (internal)
 *  Calls net_shutdown.  net_init installs this as an atexit
 *  function.
 */
static void exitfunc (void) { net_shutdown(); }