Exemplo n.º 1
0
static int load_image(at_bitmap *image, FILE *stream, at_input_opts_type * opts, at_exception_type * exp) 
{
	png_structp png;
	png_infop info, end_info;
	png_bytep *rows;
	unsigned short width, height, row;
	int pixel_size;
	int result = 1;
	
	if (!init_structs(&png, &info, &end_info, exp)) 
	  return 0;

	png_init_io(png, stream);
	CHECK_ERROR();
	
	rows = read_png(png, info, opts);

	width = (unsigned short)png_get_image_width(png, info);
	height = (unsigned short)png_get_image_height(png, info);
	if ( png_get_color_type(png, info) == PNG_COLOR_TYPE_GRAY ) {
		pixel_size = 1;
	} else {
		pixel_size = 3;
	}

	*image = at_bitmap_init(NULL, width, height, pixel_size);
	for ( row = 0 ; row < height ; row++, rows++ ) {
		memcpy(AT_BITMAP_PIXEL(image, row, 0), *rows,
		       width * pixel_size * sizeof(unsigned char));
	}
 cleanup:
	finalize_structs(png, info, end_info);
	return result;
}
Exemplo n.º 2
0
int main(int argc, char* argv[]){
  parse_args(argc, argv);
  
  init_ui();
  init_structs();
  init_plotter();

  start_debug();
  
  int x;
  while (!options.quit) {
    clear();
    set_terminal_size();    
    draw_axis();
    replot_functions();

    x = input();
    if(x == -1) break;

    refresh(); 
  } 

  clean_plotter();
  clean_ui();
  return 0;
}
Exemplo n.º 3
0
    static int
Python_Init(void)
{
    if (!initialised)
    {
#ifdef DYNAMIC_PYTHON
	if (!python_enabled(TRUE))
	{
	    EMSG(_("E263: Sorry, this command is disabled, the Python library could not be loaded."));
	    goto fail;
	}
#endif

#ifdef PYTHON_HOME
	Py_SetPythonHome(PYTHON_HOME);
#endif

	init_structs();

#if !defined(MACOS) || defined(MACOS_X_UNIX)
	Py_Initialize();
#else
	PyMac_Initialize();
#endif
	/* initialise threads */
	PyEval_InitThreads();

#ifdef DYNAMIC_PYTHON
	get_exceptions();
#endif

	if (PythonIO_Init())
	    goto fail;

	if (PythonMod_Init())
	    goto fail;

	/* Remove the element from sys.path that was added because of our
	 * argv[0] value in PythonMod_Init().  Previously we used an empty
	 * string, but dependinding on the OS we then get an empty entry or
	 * the current directory in sys.path. */
	PyRun_SimpleString("import sys; sys.path = filter(lambda x: x != '/must>not&exist', sys.path)");

	/* the first python thread is vim's, release the lock */
	Python_SaveThread();

	initialised = 1;
    }

    return 0;

fail:
    /* We call PythonIO_Flush() here to print any Python errors.
     * This is OK, as it is possible to call this function even
     * if PythonIO_Init() has not completed successfully (it will
     * not do anything in this case).
     */
    PythonIO_Flush();
    return -1;
}
Exemplo n.º 4
0
Arquivo: t_cc.c Projeto: Baalmart/krb5
int
main(void)
{
    krb5_context context;
    krb5_error_code     kret;

    if ((kret = krb5_init_context(&context))) {
        printf("Couldn't initialize krb5 library: %s\n",
               error_message(kret));
        exit(1);
    }

    kret = krb5_cc_register(context, &krb5_mcc_ops,0);
    if(kret && kret != KRB5_CC_TYPE_EXISTS) {
        CHECK(kret, "register_mem");
    }

    kret = krb5_cc_register(context, &krb5_fcc_ops,0);
    if(kret && kret != KRB5_CC_TYPE_EXISTS) {
        CHECK(kret, "register_mem");
    }

    /* Registering a second time tests for error return */
    kret = krb5_cc_register(context, &krb5_fcc_ops,0);
    if(kret != KRB5_CC_TYPE_EXISTS) {
        CHECK(kret, "register_mem");
    }

    /* Registering with override should work */
    kret = krb5_cc_register(context, &krb5_fcc_ops,1);
    CHECK(kret, "register_mem override");

    init_structs();

    test_misc(context);
    do_test(context, "");

    if(check_registered(context, "KEYRING:"))
        do_test(context, "KEYRING:");
    else
        printf("Skiping KEYRING: test - unregistered type\n");

    do_test(context, "MEMORY:");
    do_test(context, "FILE:");

    krb5_free_context(context);
    return 0;
}
Exemplo n.º 5
0
    static int
Python3_Init(void)
{
    if (!py3initialised)
    {
#ifdef DYNAMIC_PYTHON3
	if (!python3_enabled(TRUE))
	{
	    EMSG(_("E263: Sorry, this command is disabled, the Python library could not be loaded."));
	    goto fail;
	}
#endif

	init_structs();

	/* initialise threads */
	PyEval_InitThreads();

#if !defined(MACOS) || defined(MACOS_X_UNIX)
	Py_Initialize();
#else
	PyMac_Initialize();
#endif

#ifdef DYNAMIC_PYTHON3
	get_py3_exceptions();
#endif

	if (PythonIO_Init())
	    goto fail;

	PyImport_AppendInittab("vim", Py3Init_vim);

	/* Remove the element from sys.path that was added because of our
	 * argv[0] value in Py3Init_vim().  Previously we used an empty
	 * string, but dependinding on the OS we then get an empty entry or
	 * the current directory in sys.path. */
	PyRun_SimpleString("import sys; sys.path = list(filter(lambda x: x != '/must>not&exist', sys.path))");

	// lock is created and acquired in PyEval_InitThreads() and thread
	// state is created in Py_Initialize()
	// there _PyGILState_NoteThreadState() also sets gilcounter to 1
	// (python must have threads enabled!)
	// so the following does both: unlock GIL and save thread state in TLS
	// without deleting thread state
	PyGILState_Release(pygilstate);

	py3initialised = 1;
    }

    return 0;

fail:
    /* We call PythonIO_Flush() here to print any Python errors.
     * This is OK, as it is possible to call this function even
     * if PythonIO_Init() has not completed successfully (it will
     * not do anything in this case).
     */
    PythonIO_Flush();
    return -1;
}
Exemplo n.º 6
0
    static int
Python_Init(void)
{
    if (!initialised)
    {
#if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
	PyObject *site;
#endif

#ifdef DYNAMIC_PYTHON
	if (!python_enabled(TRUE))
	{
	    EMSG(_("E263: Sorry, this command is disabled, the Python library could not be loaded."));
	    goto fail;
	}
#endif

#ifdef PYTHON_HOME
# ifdef DYNAMIC_PYTHON
	if (mch_getenv((char_u *)"PYTHONHOME") == NULL)
# endif
	    Py_SetPythonHome(PYTHON_HOME);
#endif

	init_structs();

#if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
	/* Disable implicit 'import site', because it may cause Vim to exit
	 * when it can't be found. */
	Py_NoSiteFlag++;
#endif

#if !defined(MACOS) || defined(MACOS_X_UNIX)
	Py_Initialize();
#else
	PyMac_Initialize();
#endif

#if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
	/* 'import site' explicitly. */
	site = PyImport_ImportModule("site");
	if (site == NULL)
	{
	    EMSG(_("E887: Sorry, this command is disabled, the Python's site module could not be loaded."));
	    goto fail;
	}
	Py_DECREF(site);
#endif

	/* Initialise threads, and below save the state using
	 * PyEval_SaveThread.  Without the call to PyEval_SaveThread, thread
	 * specific state (such as the system trace hook), will be lost
	 * between invocations of Python code. */
	PyEval_InitThreads();
#ifdef DYNAMIC_PYTHON
	get_exceptions();
#endif

	if (PythonIO_Init_io())
	    goto fail;

	if (PythonMod_Init())
	    goto fail;

	globals = PyModule_GetDict(PyImport_AddModule("__main__"));

	/* Remove the element from sys.path that was added because of our
	 * argv[0] value in PythonMod_Init().  Previously we used an empty
	 * string, but depending on the OS we then get an empty entry or
	 * the current directory in sys.path. */
	PyRun_SimpleString("import sys; sys.path = filter(lambda x: x != '/must>not&exist', sys.path)");

	/* lock is created and acquired in PyEval_InitThreads() and thread
	 * state is created in Py_Initialize()
	 * there _PyGILState_NoteThreadState() also sets gilcounter to 1
	 * (python must have threads enabled!)
	 * so the following does both: unlock GIL and save thread state in TLS
	 * without deleting thread state
	 */
#ifndef PY_CAN_RECURSE
	saved_python_thread =
#endif
	    PyEval_SaveThread();

	initialised = 1;
    }

    return 0;

fail:
    /* We call PythonIO_Flush() here to print any Python errors.
     * This is OK, as it is possible to call this function even
     * if PythonIO_Init_io() has not completed successfully (it will
     * not do anything in this case).
     */
    PythonIO_Flush();
    return -1;
}
Exemplo n.º 7
0
 int main(int argc,const char *argv[])
{
	/* shall I run as a daemon */
	bool is_daemon = false;
	bool interactive = false;
	bool Fork = true;
	bool no_process_group = false;
	bool log_stdout = false;
	char *ports = NULL;
	char *profile_level = NULL;
	int opt;
	poptContext pc;
	bool print_build_options = False;
        enum {
		OPT_DAEMON = 1000,
		OPT_INTERACTIVE,
		OPT_FORK,
		OPT_NO_PROCESS_GROUP,
		OPT_LOG_STDOUT
	};
	struct poptOption long_options[] = {
	POPT_AUTOHELP
	{"daemon", 'D', POPT_ARG_NONE, NULL, OPT_DAEMON, "Become a daemon (default)" },
	{"interactive", 'i', POPT_ARG_NONE, NULL, OPT_INTERACTIVE, "Run interactive (not a daemon)"},
	{"foreground", 'F', POPT_ARG_NONE, NULL, OPT_FORK, "Run daemon in foreground (for daemontools, etc.)" },
	{"no-process-group", '\0', POPT_ARG_NONE, NULL, OPT_NO_PROCESS_GROUP, "Don't create a new process group" },
	{"log-stdout", 'S', POPT_ARG_NONE, NULL, OPT_LOG_STDOUT, "Log to stdout" },
	{"build-options", 'b', POPT_ARG_NONE, NULL, 'b', "Print build options" },
	{"port", 'p', POPT_ARG_STRING, &ports, 0, "Listen on the specified ports"},
	{"profiling-level", 'P', POPT_ARG_STRING, &profile_level, 0, "Set profiling level","PROFILE_LEVEL"},
	POPT_COMMON_SAMBA
	POPT_COMMON_DYNCONFIG
	POPT_TABLEEND
	};
	struct smbd_parent_context *parent = NULL;
	TALLOC_CTX *frame;
	NTSTATUS status;
	uint64_t unique_id;
	struct tevent_context *ev_ctx;
	struct messaging_context *msg_ctx;

	/*
	 * Do this before any other talloc operation
	 */
	talloc_enable_null_tracking();
	frame = talloc_stackframe();

	setup_logging(argv[0], DEBUG_DEFAULT_STDOUT);

	load_case_tables();

	smbd_init_globals();

	TimeInit();

#ifdef HAVE_SET_AUTH_PARAMETERS
	set_auth_parameters(argc,argv);
#endif

	pc = poptGetContext("smbd", argc, argv, long_options, 0);
	while((opt = poptGetNextOpt(pc)) != -1) {
		switch (opt)  {
		case OPT_DAEMON:
			is_daemon = true;
			break;
		case OPT_INTERACTIVE:
			interactive = true;
			break;
		case OPT_FORK:
			Fork = false;
			break;
		case OPT_NO_PROCESS_GROUP:
			no_process_group = true;
			break;
		case OPT_LOG_STDOUT:
			log_stdout = true;
			break;
		case 'b':
			print_build_options = True;
			break;
		default:
			d_fprintf(stderr, "\nInvalid option %s: %s\n\n",
				  poptBadOption(pc, 0), poptStrerror(opt));
			poptPrintUsage(pc, stderr, 0);
			exit(1);
		}
	}
	poptFreeContext(pc);

	if (interactive) {
		Fork = False;
		log_stdout = True;
	}

	if (log_stdout) {
		setup_logging(argv[0], DEBUG_STDOUT);
	} else {
		setup_logging(argv[0], DEBUG_FILE);
	}

	if (print_build_options) {
		build_options(True); /* Display output to screen as well as debug */
		exit(0);
	}

#ifdef HAVE_SETLUID
	/* needed for SecureWare on SCO */
	setluid(0);
#endif

	set_remote_machine_name("smbd", False);

	if (interactive && (DEBUGLEVEL >= 9)) {
		talloc_enable_leak_report();
	}

	if (log_stdout && Fork) {
		DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"));
		exit(1);
	}

	/* we want to re-seed early to prevent time delays causing
           client problems at a later date. (tridge) */
	generate_random_buffer(NULL, 0);

	/* get initial effective uid and gid */
	sec_init();

	/* make absolutely sure we run as root - to handle cases where people
	   are crazy enough to have it setuid */
	gain_root_privilege();
	gain_root_group_privilege();

	fault_setup();
	dump_core_setup("smbd", lp_logfile());

	/* we are never interested in SIGPIPE */
	BlockSignals(True,SIGPIPE);

#if defined(SIGFPE)
	/* we are never interested in SIGFPE */
	BlockSignals(True,SIGFPE);
#endif

#if defined(SIGUSR2)
	/* We are no longer interested in USR2 */
	BlockSignals(True,SIGUSR2);
#endif

	/* POSIX demands that signals are inherited. If the invoking process has
	 * these signals masked, we will have problems, as we won't recieve them. */
	BlockSignals(False, SIGHUP);
	BlockSignals(False, SIGUSR1);
	BlockSignals(False, SIGTERM);

	/* Ensure we leave no zombies until we
	 * correctly set up child handling below. */

	CatchChild();

	/* we want total control over the permissions on created files,
	   so set our umask to 0 */
	umask(0);

	reopen_logs();

	DEBUG(0,("smbd version %s started.\n", samba_version_string()));
	DEBUGADD(0,("%s\n", COPYRIGHT_STARTUP_MESSAGE));

	DEBUG(2,("uid=%d gid=%d euid=%d egid=%d\n",
		 (int)getuid(),(int)getgid(),(int)geteuid(),(int)getegid()));

	/* Output the build options to the debug log */ 
	build_options(False);

	if (sizeof(uint16) < 2 || sizeof(uint32) < 4) {
		DEBUG(0,("ERROR: Samba is not configured correctly for the word size on your machine\n"));
		exit(1);
	}

	if (!lp_load_initial_only(get_dyn_CONFIGFILE())) {
		DEBUG(0, ("error opening config file '%s'\n", get_dyn_CONFIGFILE()));
		exit(1);
	}

	/* Init the security context and global current_user */
	init_sec_ctx();

	/*
	 * Initialize the event context. The event context needs to be
	 * initialized before the messaging context, cause the messaging
	 * context holds an event context.
	 * FIXME: This should be s3_tevent_context_init()
	 */
	ev_ctx = server_event_context();
	if (ev_ctx == NULL) {
		exit(1);
	}

	/*
	 * Init the messaging context
	 * FIXME: This should only call messaging_init()
	 */
	msg_ctx = server_messaging_context();
	if (msg_ctx == NULL) {
		exit(1);
	}

	/*
	 * Reloading of the printers will not work here as we don't have a
	 * server info and rpc services set up. It will be called later.
	 */
	if (!reload_services(NULL, -1, False)) {
		exit(1);
	}

	/* ...NOTE... Log files are working from this point! */

	DEBUG(3,("loaded services\n"));

	init_structs();

#ifdef WITH_PROFILE
	if (!profile_setup(msg_ctx, False)) {
		DEBUG(0,("ERROR: failed to setup profiling\n"));
		return -1;
	}
	if (profile_level != NULL) {
		int pl = atoi(profile_level);
		struct server_id src;

		DEBUG(1, ("setting profiling level: %s\n",profile_level));
		src.pid = getpid();
		set_profile_level(pl, src);
	}
#endif

	if (!is_daemon && !is_a_socket(0)) {
		if (!interactive)
			DEBUG(0,("standard input is not a socket, assuming -D option\n"));

		/*
		 * Setting is_daemon here prevents us from eventually calling
		 * the open_sockets_inetd()
		 */

		is_daemon = True;
	}

	if (is_daemon && !interactive) {
		DEBUG( 3, ( "Becoming a daemon.\n" ) );
		become_daemon(Fork, no_process_group, log_stdout);
	}

        generate_random_buffer((uint8_t *)&unique_id, sizeof(unique_id));
        set_my_unique_id(unique_id);

#if HAVE_SETPGID
	/*
	 * If we're interactive we want to set our own process group for
	 * signal management.
	 */
	if (interactive && !no_process_group)
		setpgid( (pid_t)0, (pid_t)0);
#endif

	if (!directory_exist(lp_lockdir()))
		mkdir(lp_lockdir(), 0755);

	if (is_daemon)
		pidfile_create("smbd");

	status = reinit_after_fork(msg_ctx,
				   ev_ctx,
				   procid_self(), false);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(0,("reinit_after_fork() failed\n"));
		exit(1);
	}

	smbd_server_conn->msg_ctx = msg_ctx;

	smbd_setup_sig_term_handler();
	smbd_setup_sig_hup_handler(ev_ctx,
				   msg_ctx);

	/* Setup all the TDB's - including CLEAR_IF_FIRST tdb's. */

	if (smbd_memcache() == NULL) {
		exit(1);
	}

	memcache_set_global(smbd_memcache());

	/* Initialise the password backed before the global_sam_sid
	   to ensure that we fetch from ldap before we make a domain sid up */

	if(!initialize_password_db(false, ev_ctx))
		exit(1);

	if (!secrets_init()) {
		DEBUG(0, ("ERROR: smbd can not open secrets.tdb\n"));
		exit(1);
	}

	if (lp_server_role() == ROLE_DOMAIN_BDC || lp_server_role() == ROLE_DOMAIN_PDC) {
		struct loadparm_context *lp_ctx = loadparm_init_s3(NULL, loadparm_s3_context());
		if (!open_schannel_session_store(NULL, lp_ctx)) {
			DEBUG(0,("ERROR: Samba cannot open schannel store for secured NETLOGON operations.\n"));
			exit(1);
		}
		TALLOC_FREE(lp_ctx);
	}

	if(!get_global_sam_sid()) {
		DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
		exit(1);
	}

	if (!sessionid_init()) {
		exit(1);
	}

	if (!connections_init(True))
		exit(1);

	if (!locking_init())
		exit(1);

	if (!messaging_tdb_parent_init(ev_ctx)) {
		exit(1);
	}

	if (!notify_internal_parent_init(ev_ctx)) {
		exit(1);
	}

	if (!serverid_parent_init(ev_ctx)) {
		exit(1);
	}

	if (!W_ERROR_IS_OK(registry_init_full()))
		exit(1);

	/* Open the share_info.tdb here, so we don't have to open
	   after the fork on every single connection.  This is a small
	   performance improvment and reduces the total number of system
	   fds used. */
	if (!share_info_db_init()) {
		DEBUG(0,("ERROR: failed to load share info db.\n"));
		exit(1);
	}

	status = init_system_info();
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(1, ("ERROR: failed to setup system user info: %s.\n",
			  nt_errstr(status)));
		return -1;
	}

	if (!init_guest_info()) {
		DEBUG(0,("ERROR: failed to setup guest info.\n"));
		return -1;
	}

	if (!file_init(smbd_server_conn)) {
		DEBUG(0, ("ERROR: file_init failed\n"));
		return -1;
	}

	/* This MUST be done before start_epmd() because otherwise
	 * start_epmd() forks and races against dcesrv_ep_setup() to
	 * call directory_create_or_exist() */
	if (!directory_create_or_exist(lp_ncalrpc_dir(), geteuid(), 0755)) {
		DEBUG(0, ("Failed to create pipe directory %s - %s\n",
			  lp_ncalrpc_dir(), strerror(errno)));
		return -1;
	}

	if (is_daemon && !interactive) {
		if (rpc_epmapper_daemon() == RPC_DAEMON_FORK) {
			start_epmd(ev_ctx, msg_ctx);
		}
	}

	if (!dcesrv_ep_setup(ev_ctx, msg_ctx)) {
		exit(1);
	}

	/* only start other daemons if we are running as a daemon
	 * -- bad things will happen if smbd is launched via inetd
	 *  and we fork a copy of ourselves here */
	if (is_daemon && !interactive) {

		if (rpc_lsasd_daemon() == RPC_DAEMON_FORK) {
			start_lsasd(ev_ctx, msg_ctx);
		}

		if (!_lp_disable_spoolss() &&
		    (rpc_spoolss_daemon() != RPC_DAEMON_DISABLED)) {
			bool bgq = lp_parm_bool(-1, "smbd", "backgroundqueue", true);

			if (!printing_subsystem_init(ev_ctx, msg_ctx, true, bgq)) {
				exit(1);
			}
		}
	} else if (!_lp_disable_spoolss() &&
		   (rpc_spoolss_daemon() != RPC_DAEMON_DISABLED)) {
		if (!printing_subsystem_init(ev_ctx, msg_ctx, false, false)) {
			exit(1);
		}
	}

	if (!is_daemon) {
		/* inetd mode */
		TALLOC_FREE(frame);

		/* Started from inetd. fd 0 is the socket. */
		/* We will abort gracefully when the client or remote system
		   goes away */
		smbd_server_conn->sock = dup(0);

		/* close our standard file descriptors */
		if (!debug_get_output_is_stdout()) {
			close_low_fds(False); /* Don't close stderr */
		}

#ifdef HAVE_ATEXIT
		atexit(killkids);
#endif

	        /* Stop zombies */
		smbd_setup_sig_chld_handler(ev_ctx);

		smbd_process(ev_ctx, smbd_server_conn);

		exit_server_cleanly(NULL);
		return(0);
	}

	parent = talloc_zero(ev_ctx, struct smbd_parent_context);
	if (!parent) {
		exit_server("talloc(struct smbd_parent_context) failed");
	}
	parent->interactive = interactive;

	if (!open_sockets_smbd(parent, ev_ctx, msg_ctx, ports))
		exit_server("open_sockets_smbd() failed");

	/* do a printer update now that all messaging has been set up,
	 * before we allow clients to start connecting */
	printing_subsystem_update(ev_ctx, msg_ctx, false);

	TALLOC_FREE(frame);
	/* make sure we always have a valid stackframe */
	frame = talloc_stackframe();

	smbd_parent_loop(ev_ctx, parent);

	exit_server_cleanly(NULL);
	TALLOC_FREE(frame);
	return(0);
}
Exemplo n.º 8
0
static int
Python3_Init(void)
{
	if (!py3initialised) {
#ifdef DYNAMIC_PYTHON3
		if (!python3_enabled(TRUE)) {
			EMSG(_("E263: Sorry, this command is disabled, the Python library could not be loaded."));
			goto fail;
		}
#endif

		init_structs();


#ifdef PYTHON3_HOME
		Py_SetPythonHome(PYTHON3_HOME);
#endif

		PyImport_AppendInittab("vim", Py3Init_vim);

#if !defined(MACOS) || defined(MACOS_X_UNIX)
		Py_Initialize();
#else
		PyMac_Initialize();
#endif
		/* Initialise threads, and below save the state using
		 * PyEval_SaveThread.  Without the call to PyEval_SaveThread, thread
		 * specific state (such as the system trace hook), will be lost
		 * between invocations of Python code. */
		PyEval_InitThreads();
#ifdef DYNAMIC_PYTHON3
		get_py3_exceptions();
#endif

		if (PythonIO_Init_io())
			goto fail;

		globals = PyModule_GetDict(PyImport_AddModule("__main__"));

		/* Remove the element from sys.path that was added because of our
		 * argv[0] value in Py3Init_vim().  Previously we used an empty
		 * string, but depending on the OS we then get an empty entry or
		 * the current directory in sys.path.
		 * Only after vim has been imported, the element does exist in
		 * sys.path.
		 */
		PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))");

		/* lock is created and acquired in PyEval_InitThreads() and thread
		 * state is created in Py_Initialize()
		 * there _PyGILState_NoteThreadState() also sets gilcounter to 1
		 * (python must have threads enabled!)
		 * so the following does both: unlock GIL and save thread state in TLS
		 * without deleting thread state
		 */
		PyEval_SaveThread();

		py3initialised = 1;
	}

	return 0;

fail:
	/* We call PythonIO_Flush() here to print any Python errors.
	 * This is OK, as it is possible to call this function even
	 * if PythonIO_Init_io() has not completed successfully (it will
	 * not do anything in this case).
	 */
	PythonIO_Flush();
	return -1;
}
Exemplo n.º 9
0
Arquivo: main.c Projeto: NX-Andro/x3
int main(int argc, char *argv[])
{
    int run_as_daemon;
    int debug;
    pid_t pid = 0;
    FILE *file_out;
    struct sigaction sv;

#if WITH_MALLOC_BOEHM_GC
    GC_find_leak = 1;
    GC_set_warn_proc(gc_warn_proc);
    GC_enable_incremental();
#endif

    run_as_daemon = 1;
    debug = 0;
    tools_init();

    /* set up some signal handlers */
    memset(&sv, 0, sizeof(sv));
    sigemptyset(&sv.sa_mask);
    sv.sa_handler = SIG_IGN;
    sigaction(SIGPIPE, &sv, NULL);
    sv.sa_handler = sigaction_rehash;
    sigaction(SIGHUP, &sv, NULL);
    sv.sa_handler = sigaction_writedb;
    sigaction(SIGINT, &sv, NULL);
    sv.sa_handler = sigaction_exit;
    sigaction(SIGQUIT, &sv, NULL);
    sv.sa_handler = sigaction_wait;
    sigaction(SIGCHLD, &sv, NULL);

    if (argc > 1) { /* parse command line, if any */
        int c;
        struct option options[] =
        {
            {"config", 1, 0, 'c'},
            {"debug", 0, 0, 'd'},
            {"foreground", 0, 0, 'f'},
            {"help", 0, 0, 'h'},
            {"check", 0, 0, 'k'},
            {"replay", 1, 0, 'r'},
            {"version", 0, 0, 'v'},
            {0, 0, 0, 0}
        };

        while ((c = getopt_long(argc, argv, "c:dfhkr:v", options, NULL)) != -1) {
            switch (c) {
            case 'c':
                services_config = optarg;
                break;
            case 'k':
                if (conf_read(services_config)) {
                    printf("%s appears to be a valid configuration file.\n", services_config);
                } else {
                    printf("%s is an invalid configuration file.\n", services_config);
                }
                exit(0);
            case 'r':
                replay_file = fopen(optarg, "r");
                if (!replay_file) {
                    fprintf(stderr, "Could not open %s for reading: %s (%d)\n",
                            optarg, strerror(errno), errno);
                    exit(0);
                }
                break;
            case 'd':
                debug = 1;
                break;
            case 'f':
                run_as_daemon = 0;
                break;
            case 'v':
                version();
                license();
                exit(0);
            case 'h':
            default:
                usage(argv[0]);
                exit(0);
            }
        }
    }

    version();

    if (replay_file) {
        /* We read a line here to "prime" the replay file parser, but
         * mostly to get the right value of "now" for when we do the
         * irc_introduce. */
        replay_read_line();
    } else {
        now = time(NULL);
    }
    boot_time = now;

    fprintf(stdout, "Initializing daemon...\n");
    if (!conf_read(services_config)) {
        fprintf(stderr, "Unable to read %s.\n", services_config);
        exit(1);
    }

    conf_register_reload(uplink_compile);

    if (run_as_daemon) {
        /* Attempt to fork into the background if daemon mode is on. */
        pid = fork();
        if (pid < 0) {
            fprintf(stderr, "Unable to fork: %s\n", strerror(errno));
        } else if (pid > 0) {
            fprintf(stdout, "Forking into the background (pid: %d)...\n", pid);
            exit(0);
        }
        setsid();
    }

    file_out = fopen(PID_FILE, "w");
    if (file_out == NULL) {
        /* Create the main process' pid file */
        fprintf(stderr, "Unable to create PID file: %s", strerror(errno));
    } else {
        fprintf(file_out, "%i\n", (int)getpid());
        fclose(file_out);
    }

    if (run_as_daemon) {
        /* Close these since we should not use them from now on. */
        fclose(stdin);
        fclose(stdout);
        fclose(stderr);
    }

    services_argc = argc;
    services_argv = argv;

    atexit(call_exit_funcs);
    reg_exit_func(main_shutdown, NULL);

    log_init();
    MAIN_LOG = log_register_type("x3", "file:main.log");
    if (debug)
        log_debug();
    ioset_init();
    init_structs();
    init_parse();
    modcmd_init();
    saxdb_init();
    sar_init();
    gline_init();
    shun_init();
    mail_init();
    helpfile_init();
    conf_globals(); /* initializes the core services */
    conf_rlimits();
    modules_init();
    message_register_table(msgtab);
    modcmd_finalize();
    saxdb_finalize();
    helpfile_finalize();
    modules_finalize();

    /* The first exit func to be called *should* be saxdb_write_all(). */
    reg_exit_func(saxdb_write_all, NULL);
    if (replay_file) {
        char *msg;
        log_module(MAIN_LOG, LOG_INFO, "Beginning replay...");
        srand(now);
        replay_event_loop();
        if ((msg = dict_sanity_check(clients))) {
            log_module(MAIN_LOG, LOG_ERROR, "Clients insanity: %s", msg);
            free(msg);
        }
        if ((msg = dict_sanity_check(channels))) {
            log_module(MAIN_LOG, LOG_ERROR, "Channels insanity: %s", msg);
            free(msg);
        }
        if ((msg = dict_sanity_check(servers))) {
            log_module(MAIN_LOG, LOG_ERROR, "Servers insanity: %s", msg);
            free(msg);
        }
    } else {
        now = time(NULL);
        srand(now);
        ioset_run();
    }
    return 0;
}
Exemplo n.º 10
0
int get_options(optiondata *opt, motparm * mp, port_list * plist,
                int argc, char *argv[])
{
    char * prog = argv[0];
    int    ac;

    init_structs(opt, mp, plist);

    if ( argc < 2 )
        return usage(prog, SH_USE_SHORT);

    for ( ac = 1; ac < argc; ac++ )   /* help, hist first, rest alphabetical */
    {
        if ( !strncmp(argv[ac], "-help", 5) )
            return usage(prog, SH_USE_LONG);
        if ( !strncmp(argv[ac], "-hist", 5) )
            return usage(prog, SH_USE_HIST);
        else if ( !strncmp(argv[ac], "-debug", 6) )
        {
            CHECK_ARG_COUNT(ac, "opt use: -debug DEBUG_LEVEL\n");
            opt->debug = atoi(argv[++ac]);
        }
        else if ( !strncmp(argv[ac], "-disp_all", 9) )
        {
            CHECK_ARG_COUNT(ac, "opt use: -disp_all NVOXELS\n");
            if( opt->num_extra > 0 ) {
                fprintf(stderr,"** cannot use both -num_extra and -disp_all\n");
                return -1;
            }
            opt->num_extra = atoi(argv[++ac]) * 8;
            opt->disp_all = 1;
        }
        else if ( !strncmp(argv[ac], "-mp_max", 6) )
        {
            CHECK_ARG_COUNT(ac, "opt use: -mp_max MAX_MP_VAL\n");
            opt->mp_max = atof(argv[++ac]);
        }
        else if ( !strncmp(argv[ac], "-mp_min", 6) )
        {
            CHECK_ARG_COUNT(ac, "opt use: -mp_min MIN_MP_VAL\n");
            opt->mp_min = atof(argv[++ac]);
        }
        else if ( !strncmp(argv[ac], "-no_serial", 7) )
            opt->no_serial = 1;
        else if ( !strncmp(argv[ac], "-num_extra", 7) )
        {
            if( opt->disp_all ) {
                fprintf(stderr,"** cannot use both -num_extra and -disp_all\n");
                return -1;
            }
            CHECK_ARG_COUNT(ac, "opt use: -num_extra NVALS\n");
            opt->num_extra = atoi(argv[++ac]);
        }
        else if ( !strncmp(argv[ac], "-serial_port", 7) )
        {
            CHECK_ARG_COUNT(ac, "opt use: -serial_port SERIAL_FILENAME\n");
            opt->serial_port = argv[++ac];
        }
        else if ( !strncmp(argv[ac], "-show_times", 5) )
            opt->show_times = 1;
        else if ( !strncmp(argv[ac], "-sock_num", 7) )
        {
            CHECK_ARG_COUNT(ac, "opt use: -sock_num SOCKET_NUMBER\n");
            opt->sock_num = atoi(argv[++ac]);
        }
        else if ( !strncmp(argv[ac], "-swap", 5) )
            opt->swap = 1;
        else if ( !strncmp(argv[ac], "-ver", 4) )
            return usage(prog, SH_USE_VERSION);
        else
        {
            fprintf(stderr,"** invalid option '%s', exiting...\n", argv[ac]);
            return -1;
        }
    }

    /* check basic options */
    if ( opt->sock_num <= 0 || opt->sock_num > 65536 )
    {
        fprintf(stderr,"** socket number %d is out of range\n", opt->sock_num);
        return -1;
    }
    if ( ! opt->serial_port && opt->no_serial == 0 )
    {
        fprintf(stderr,"** missing option '-serial_port'\n");
        return -1;
    }

    if ( opt->num_extra < 0 || opt->num_extra > 1000 )
    {
        fprintf(stderr,"** -num_extra %d is out of range [0,1000]\n",
                opt->num_extra);
        return -1;
    }

    if( opt->num_extra > 0 ) alloc_extras(mp, opt->num_extra);

    if ( opt->debug > 1 )
        disp_optiondata( "options read: ", opt );

    plist->debug = opt->debug;          /* for clean_n_exit() */
    mp->nvals    = 6;

    return 0;
}
Exemplo n.º 11
0
int main(int argc, char **argv) {
  struct sockaddr_un addr;
  pid_t pid, sid;
  int pipefd[2];
  int clfd;
  char deamonize;
  
  if(argc==2 && !strncmp(argv[1], "-f", 3)) {
    deamonize=0;
  } else {
    deamonize=1;
  }
  
  if(deamonize) {
    if(pipe2(pipefd, O_CLOEXEC)) {
      print( FATAL, "pipe2: %s", strerror(errno) );
      return EXIT_FAILURE;
    }
    
    pid = fork();
    
    if(pid<0) {
      print( FATAL, "fork: %s", strerror(errno) );
      return EXIT_FAILURE;
    } else if(pid) {
      close(pipefd[1]);
      if(!read(pipefd[0], &clfd, 1))
        return EXIT_FAILURE;
      return EXIT_SUCCESS;
    }
    close(pipefd[0]);
  
    umask(0);

    if(open_logfile(LOG_PATH)) {
      print( FATAL, "cannot open logfile");
      return EXIT_FAILURE;
    }

    close(STDIN_FILENO);
    close(STDOUT_FILENO);
    close(STDERR_FILENO);

    set_logger(file_logger);

    sid = setsid();
    if(sid<0) {
      print( FATAL, "setsid: %s", strerror(errno) );
      return EXIT_FAILURE;
    }
  }
  
  if(init_structs())
    return EXIT_FAILURE;
  
  if(load_handlers())
    return EXIT_FAILURE;
  
  if(load_users())
    return EXIT_FAILURE;
  
  if(remove_old_socket())
    return EXIT_FAILURE;
  
  sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
  
  if(sockfd < 0) {
    print( FATAL, "socket: %s", strerror(errno) );
    return EXIT_FAILURE;
  }
  
  if(register_signal_handlers()) {
    close(sockfd);
    return EXIT_FAILURE;
  }
  
  memset(&addr, 0, sizeof(struct sockaddr_un));
  addr.sun_family = AF_UNIX;
  strncpy(addr.sun_path, SOCKET_PATH, sizeof(addr.sun_path)-1);
  if(bind(sockfd, (struct sockaddr*)&addr, sizeof(addr))) {
    print( FATAL, "bind: %s", strerror(errno) );
    close(sockfd);
    unlink(SOCKET_PATH);
    return EXIT_FAILURE;
  }
  
  if(listen(sockfd, 5)) {
    print( FATAL, "listen: %s", strerror(errno) );
    close(sockfd);
    unlink(SOCKET_PATH);
    return EXIT_FAILURE;
  }
  
  if(start_reaper()) {
    close(sockfd);
    unlink(SOCKET_PATH);
    return EXIT_FAILURE;
  }
  
#ifndef NDEBUG
  chmod(SOCKET_PATH, 0666);
#endif
  
  if(deamonize) {
    if(write(pipefd[1], "!", 1) != 1) {
      print( FATAL, "cannot notify that daemon started" );
      return EXIT_FAILURE;
    }
    close(pipefd[1]);
  }
  
  while(1) {
    if((clfd=accept(sockfd, NULL, NULL)) < 0) {
      if(errno == EINVAL) {
#ifndef NDEBUG
        print( DEBUG, "socket closed" );
#endif
      }
      print( ERROR, "accept: %s", strerror(errno) );
      break;
    }
    
    if(serve_new_client(clfd)) {
      print( WARNING, "cannot serve new connection" );
      close(clfd);
    }
  }
  
  unlink(SOCKET_PATH);
  
  close_connections();
  
  stop_reaper();
  
  destroy_structs();
  
  unload_users();
  unload_handlers();
  
  return EXIT_SUCCESS;
}
Exemplo n.º 12
0
int main(int argc, char *argv[])
{
  int flags;

  /* register at exit handler */
  if (atexit(exit_nice) < 0) {
    fprintf(stderr, "atexit failed\n");
    exit(1);
  }

  /* reg sig handlers */
  (void) signal(SIGHUP, sig_catch);
  (void) signal(SIGINT, sig_catch);
  (void) signal(SIGQUIT, sig_catch);
  (void) signal(SIGTERM, sig_catch);
  (void) signal(SIGPIPE, sig_pipe);
  
  /* init the global structs and arrays */
  init_structs();

  /* Create socket */
  if((accept_sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("Socket open failed");
    exit(1);
  }
  FD_SET(accept_sock, &sock_read);
  FD_SET(accept_sock, &sock_except);

  /* Bind to given port */
  if(bind(accept_sock, (struct sockaddr *) &uart_addr, sizeof(uart_addr)) < 0) {
    perror("Bind failed");
    exit(1);
  }
  listen(accept_sock, 5);
  flags = fcntl (accept_sock, F_GETFL); 
  flags |= O_NONBLOCK; 
  fcntl (accept_sock, F_SETFL, flags); 

  sock_max = accept_sock;

  /* Now the uart_sock is in the listen state, we can monitor it
   * for incomming connections. when a connection is accepted, the new
   * socket is added to the array */

  while (1) {
    int nevents;
    int i;

    nevents = select(sock_max + 1, &sock_read, &sock_write,
		     &sock_except, NULL);
    if (nevents <= 0) {
      perror("select");
      goto FD_READD;
    }
    
    /* see if this is a new connection on accept_sock */
    if (FD_ISSET(accept_sock, &sock_read)) {
      nevents--;
      accept_connect(accept_sock);
    }

    /* see if any other socket is ready for reading */
    while (nevents-- > 0) {
      int sock_index;
      int read_fd, write_fd;
      
      sock_index = get_next_fd(&read_fd, &write_fd);
      if (sock_index < 0) {
	printf ("Error for event %d\n", nevents + 1);
	goto FD_READD;
      }

      if (read_write(read_fd, write_fd) < 0) {
	/* close connection */
	del_sockindex(sock_index);
	goto FD_READD;
      }
    }

    /* add fds to fd set */
  FD_READD: {
      int count = 0;
      int *uart = sock_pair.uart;
      int *client = sock_pair.client;
	
      FD_ZERO(&sock_read);
      FD_SET(accept_sock, &sock_read);
      sock_max = accept_sock;
      for (i=0; i <MAX_CONN && count <= sock_pair.len; i++) {
	if (uart[i] != -1 && client[i] != -1) {
	  FD_SET(uart[i], &sock_read);
	  FD_SET(client[i], &sock_read);
	  
	  /* set the max sock count */
	  if (uart[i] > client[i] && uart[i] > sock_max) sock_max = uart[i];
	  else if (client[i] > uart[i] && client[i] > sock_max) sock_max = client[i];
	  count++;
	}
      }
      //printf ("Added total of %d FDs\n", 2*count+1);

    }
  }
}
Exemplo n.º 13
0
 int main2(int argc,const char *argv[])
{
	/* shall I run as a daemon */
	static BOOL is_daemon = False;
	static BOOL interactive = False;
	static BOOL Fork = True;
	static BOOL no_process_group = False;
	static BOOL log_stdout = False;
	static char *ports = NULL;
	int opt;
#ifndef _XBOX
	poptContext pc;

	struct poptOption long_options[] = {
	POPT_AUTOHELP
	{"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon (default)" },
	{"interactive", 'i', POPT_ARG_VAL, &interactive, True, "Run interactive (not a daemon)"},
	{"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools, etc.)" },
	{"no-process-group", '\0', POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" },
	{"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" },
	{"build-options", 'b', POPT_ARG_NONE, NULL, 'b', "Print build options" },
	{"port", 'p', POPT_ARG_STRING, &ports, 0, "Listen on the specified ports"},
	POPT_COMMON_SAMBA
	POPT_COMMON_DYNCONFIG
	POPT_TABLEEND
	};
#else
	interactive = True;
	log_stdout = True;
#endif

	load_case_tables();

#ifdef HAVE_SET_AUTH_PARAMETERS
	set_auth_parameters(argc,argv);
#endif

#ifndef _XBOX
	pc = poptGetContext("smbd", argc, argv, long_options, 0);
	
	while((opt = poptGetNextOpt(pc)) != -1) {
		switch (opt)  {
		case 'b':
			build_options(True); /* Display output to screen as well as debug */ 
			exit(0);
			break;
		}
	}

	poptFreeContext(pc);
#endif

#ifdef HAVE_SETLUID
	/* needed for SecureWare on SCO */
	setluid(0);
#endif

	sec_init();

	set_remote_machine_name("smbd", False);

	if (interactive) {
		Fork = False;
		log_stdout = True;
	}

	if (interactive && (DEBUGLEVEL >= 9)) {
		talloc_enable_leak_report();
	}

	if (log_stdout && Fork) {
		DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"));
		exit(1);
	}

	setup_logging(argv[0],log_stdout);

	/* we want to re-seed early to prevent time delays causing
           client problems at a later date. (tridge) */
	generate_random_buffer(NULL, 0);

	/* make absolutely sure we run as root - to handle cases where people
	   are crazy enough to have it setuid */

	gain_root_privilege();
	gain_root_group_privilege();

#ifndef _XBOX
	fault_setup((void (*)(void *))exit_server_fault);
	dump_core_setup("smbd");
#endif

	CatchSignal(SIGTERM , SIGNAL_CAST sig_term);
#ifndef _XBOX
	CatchSignal(SIGHUP,SIGNAL_CAST sig_hup);
	
	/* we are never interested in SIGPIPE */
	BlockSignals(True,SIGPIPE);
#endif

#if defined(SIGFPE)
	/* we are never interested in SIGFPE */
	BlockSignals(True,SIGFPE);
#endif

#if defined(SIGUSR2)
	/* We are no longer interested in USR2 */
	BlockSignals(True,SIGUSR2);
#endif

	/* POSIX demands that signals are inherited. If the invoking process has
	 * these signals masked, we will have problems, as we won't recieve them. */
#ifndef _XBOX
	BlockSignals(False, SIGHUP);
#endif
	BlockSignals(False, SIGUSR1);
	BlockSignals(False, SIGTERM);

	/* we want total control over the permissions on created files,
	   so set our umask to 0 */
	umask(0);

	init_sec_ctx();

	reopen_logs();

	DEBUG(0,( "smbd version %s started.\n", SAMBA_VERSION_STRING));
	DEBUGADD( 0, ( "%s\n", COPYRIGHT_STARTUP_MESSAGE ) );

	DEBUG(2,("uid=%d gid=%d euid=%d egid=%d\n",
		 (int)getuid(),(int)getgid(),(int)geteuid(),(int)getegid()));

	/* Output the build options to the debug log */ 
	build_options(False);

	if (sizeof(uint16) < 2 || sizeof(uint32) < 4) {
		DEBUG(0,("ERROR: Samba is not configured correctly for the word size on your machine\n"));
		exit(1);
	}

	/*
	 * Do this before reload_services.
	 */

	if (!reload_services(False))
		return(-1);	

	init_structs();

#ifdef WITH_PROFILE
	if (!profile_setup(False)) {
		DEBUG(0,("ERROR: failed to setup profiling\n"));
		return -1;
	}
#endif

	DEBUG(3,( "loaded services\n"));

	if (!is_daemon && !is_a_socket(0)) {
		if (!interactive)
			DEBUG(0,("standard input is not a socket, assuming -D option\n"));

		/*
		 * Setting is_daemon here prevents us from eventually calling
		 * the open_sockets_inetd()
		 */

		is_daemon = True;
	}

	if (is_daemon && !interactive) {
		DEBUG( 3, ( "Becoming a daemon.\n" ) );
		become_daemon(Fork, no_process_group);
	}

#if HAVE_SETPGID
	/*
	 * If we're interactive we want to set our own process group for
	 * signal management.
	 */
	if (interactive && !no_process_group)
		setpgid( (pid_t)0, (pid_t)0);
#endif

	if (!directory_exist(lp_lockdir(), NULL))
		mkdir(lp_lockdir(), 0755);

#ifndef _XBOX
	if (is_daemon)
		pidfile_create("smbd");
#endif

	/* Setup all the TDB's - including CLEAR_IF_FIRST tdb's. */
	if (!message_init())
		exit(1);

	/* Initialize our global sam sid first -- quite a lot of the other
	 * initialization routines further down depend on it.
	 */

	/* Initialise the password backed before the global_sam_sid
	   to ensure that we fetch from ldap before we make a domain sid up */

	if(!initialize_password_db(False))
		exit(1);

	/* Fail gracefully if we can't open secrets.tdb */

	if (!secrets_init()) {
		DEBUG(0, ("ERROR: smbd can not open secrets.tdb\n"));
		exit(1);
	}

	if(!get_global_sam_sid()) {
		DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
		exit(1);
	}

	if (!session_init())
		exit(1);

	if (conn_tdb_ctx() == NULL)
		exit(1);

	if (!locking_init(0))
		exit(1);

	namecache_enable();

	if (!init_registry())
		exit(1);

#if 0
	if (!init_svcctl_db())
                exit(1);
#endif

#ifndef _XBOX
	if (!print_backend_init())
		exit(1);
#endif

	if (!init_guest_info()) {
		DEBUG(0,("ERROR: failed to setup guest info.\n"));
		return -1;
	}

	/* Setup the main smbd so that we can get messages. */
	/* don't worry about general printing messages here */

	claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD);

	/* only start the background queue daemon if we are 
	   running as a daemon -- bad things will happen if
	   smbd is launched via inetd and we fork a copy of 
	   ourselves here */
#ifndef _XBOX
	if ( is_daemon && !interactive )
		start_background_queue(); 
#endif
	/* Always attempt to initialize DMAPI. We will only use it later if
	 * lp_dmapi_support is set on the share, but we need a single global
	 * session to work with.
	 */
	dmapi_init_session();

	if (!open_sockets_smbd(is_daemon, interactive, ports))
		exit(1);

	/*
	 * everything after this point is run after the fork()
	 */ 

	static_init_rpc;

	init_modules();

	/* possibly reload the services file. */
	reload_services(True);

	if (!init_account_policy()) {
		DEBUG(0,("Could not open account policy tdb.\n"));
		exit(1);
	}

	if (*lp_rootdir()) {
		if (sys_chroot(lp_rootdir()) == 0)
			DEBUG(2,("Changed root to %s\n", lp_rootdir()));
	}

	/* Setup oplocks */
	if (!init_oplocks())
		exit(1);
	
	/* Setup change notify */
	if (!init_change_notify())
		exit(1);

	/* Setup aio signal handler. */
	initialize_async_io_handler();

	/* re-initialise the timezone */
	TimeInit();

	/* register our message handlers */
	message_register(MSG_SMB_FORCE_TDIS, msg_force_tdis);

	smbd_process();

#ifdef _XBOX
	xb_DecClientCount();
#endif

	namecache_shutdown();

	exit_server_cleanly(NULL);
	return(0);
}