Ejemplo n.º 1
0
     static void
 gui_do_fork()
 {
-#ifdef __QNXNTO__
+#if 0
     procmgr_daemon(0, PROCMGR_DAEMON_KEEPUMASK | PROCMGR_DAEMON_NOCHDIR |
 	    PROCMGR_DAEMON_NOCLOSE | PROCMGR_DAEMON_NODEVNULL);
     gui_attempt_start();
Ejemplo n.º 2
0
Archivo: main.c Proyecto: vocho/openqnx
int main(int argc, char *argv[]) {
	dispatch_t				*dpp;
	resmgr_context_t		*ctp;
	resmgr_attr_t			res_attr;
	resmgr_connect_funcs_t	connect_funcs1;
	resmgr_connect_funcs_t	connect_funcs2;
	resmgr_io_funcs_t		io_funcs1;
	resmgr_io_funcs_t		io_funcs2;
	struct slogdev			*trp;
	int				daemon_flag = 0;

	// Parse any options.
	options(argc, argv);

	//	
	// Buffer allocation.
	// The design puts all the data structures in one big contiguious
	// chunk of memory. Makes it easy to analyze if it was in a memory
	// mapped SRAM card which survives a crash or power failure.
	//
	trp = &SlogDev;
	trp->beg = malloc(NumInts*sizeof(int));
	trp->end = trp->beg + NumInts;
	if(trp->beg == NULL) {
		fprintf(stderr, "%s: Insufficient memory to allocate buffers.\n", __progname);
		exit(EXIT_FAILURE);
	}
	slogger_init(trp);

	// Create a dispatch context to receive messages.
	if((dpp = dispatch_create()) == NULL) {
		fprintf(stderr, "%s: Unable to allocate dispatch context\n", __progname);
		exit(EXIT_FAILURE);
	}

	// Init resmgr attributes
	memset(&res_attr, 0, sizeof res_attr);
	res_attr.nparts_max = 2;
	// All slogf/slogb calls should fit in the intial receive
	res_attr.msg_max_size = _SLOG_MAXSIZE + _SLOG_HDRINTS + sizeof(io_msg_t);

	// Init funcs for handling /dev/slog messages
	iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs1, _RESMGR_IO_NFUNCS, &io_funcs1);
	connect_funcs1.unlink = io_unlink;
	io_funcs1.read        = io_read;
	io_funcs1.write       = io_write;
	io_funcs1.unblock     = io_unblock;

	// Create /dev/slog in the pathname space. At this point we can get opens.
	iofunc_attr_init(&trp->attr, S_IFCHR | 0666, 0, 0);
	if((trp->id = resmgr_attach(dpp, &res_attr, "/dev/slog", _FTYPE_ANY, _RESMGR_FLAG_SELF,
		&connect_funcs1, &io_funcs1, &trp->attr)) == -1) {
		fprintf(stderr, "%s: Unable to allocate device %s (%s)\n", __progname, "/dev/slog", strerror(errno));
		exit(EXIT_FAILURE);
	}

	// Init funcs for handling /dev/slog messages
	iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs2, _RESMGR_IO_NFUNCS, &io_funcs2);
	io_funcs2.write       = io_console_write;

	// Create /dev/console in the pathname space. At this point we can get opens.
	if(resmgr_attach(dpp, &res_attr, "/dev/console", _FTYPE_ANY, 0,
		&connect_funcs2, &io_funcs2, &trp->attr) == -1) {
		fprintf(stderr, "%s: Unable to allocate device %s (%s)\n", __progname, "/dev/console", strerror(errno));
		exit(EXIT_FAILURE);
	}

	// If a logfile was specified then create a thread to write it
	if(LogFname) {
		sigset_t	signalset;

		if(pthread_create(0, NULL, &logger, NULL) != 0) {
			fprintf(stderr, "%s: Unable to create logger thread.\n", __progname);
			exit(EXIT_FAILURE);
		}

	// We want the logger thread to catch signals. Not us!
	sigemptyset(&signalset);
	sigfillset(&signalset);
	pthread_sigmask(SIG_BLOCK, &signalset, NULL);
	}

	// Run in backgound
	if(Verbose) {
		daemon_flag = PROCMGR_DAEMON_NODEVNULL;
	}
	if (procmgr_daemon(EXIT_SUCCESS, daemon_flag) == -1) {
		fprintf(stderr, "%s: Couldn't become daemon.\n", argv[0]);
	}

	// Slogger is single-threaded
	ctp = resmgr_context_alloc(dpp);

	for(;;) {
		if((ctp = resmgr_block(ctp)) == NULL)
			exit(EXIT_FAILURE);

		resmgr_handler(ctp);
	}

	exit(EXIT_SUCCESS);
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	int 				c;
	char				*size_suffix;
	pid_t 				process = 0;
	dispatch_t			*dpp;
	resmgr_attr_t		resmgr_attr;
	resmgr_context_t	*ctp;

	umask(0222);

	/* We want some pshysical memory reserved for dumper process. */
	init_memory();

	/* We also want some physical memory for our stack.  */
	init_stack();
	
	while ( (c = getopt( argc, argv, "Dd:p:ns:vmPwtz:" )) != -1 ) {
		switch(c) {
		case 'd':
			dump_dir = optarg;
			break;
		case 'n':
			sequential_dumps = 1;
			break;
		case 'p':
			process = atoi(optarg);
			break;
		case 's':
			max_core_size = strtol(optarg, &size_suffix, 10);
			switch(*size_suffix){
				case 'g':
				case 'G':
					max_core_size *= 1024;
				case 'm':
				case 'M':
					max_core_size *= 1024;
				case 'k':
				case 'K':
					max_core_size *= 1024;
					break;
				case 0:
					break;
				default:
					fprintf(stderr, "Warning: suffix '%c' unrecognized\n", *size_suffix);
			}
			break;
		case 'v':
			verbose = 1;
			break;
		case 'm':
			nodumpmem = 1;
			break;
		case 'P':
			nodumpphys = 0;
			break;
		case 't':
			cur_tid_only = 1;
			break;
		case 'w':
			world_readable = 1;
			break;
	    case 'z':
			gzlevel = strtol(optarg, &size_suffix, 10);
			if (gzlevel < 1 || gzlevel > 9) {
				fprintf(stderr, "Compress level must between 1 and 9.\n");
				exit(EXIT_FAILURE);
			}
			break;
		}
	}

	if ( process ) {
		requested = 1;
		return dump( ND_LOCAL_NODE, process, max_core_size );
	}

	if((dpp = dispatch_create()) == NULL) {
		fprintf(stderr, "%s: Unable to allocate dispatch handle.\n",argv[0]);
		exit(EXIT_FAILURE);
	}

	memset(&resmgr_attr, 0, sizeof resmgr_attr);
	resmgr_attr.nparts_max = 1;
	resmgr_attr.msg_max_size = 2048;

	iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect, _RESMGR_IO_NFUNCS, &io);
	io.write = dumper_write;
	io.devctl = dumper_devctl; 
	io.close_ocb = dumper_close_ocb; 

	iofunc_attr_init(&attr, S_IFNAM | 0600, 0, 0);

	if ( -1 == resmgr_attach(dpp, &resmgr_attr, "/proc/dumper", _FTYPE_DUMPER, 0, &connect, &io, &attr)) {
		fprintf( stderr, "%s: Couldn't attach as /proc/dumper: %s\n", argv[0], strerror(errno) );
		exit(EXIT_FAILURE);
	}

	if((ctp = resmgr_context_alloc(dpp)) == NULL) {
		fprintf(stderr, "%s: Unable to allocate dispatch handle.\n",argv[0]);
		exit(EXIT_FAILURE);
	}

	if ( -1 == procmgr_daemon(EXIT_SUCCESS, verbose ? 
		PROCMGR_DAEMON_NODEVNULL | PROCMGR_DAEMON_KEEPUMASK :
		PROCMGR_DAEMON_KEEPUMASK) ) {
		fprintf(stderr, "%s: Couldn't become daemon.\n",argv[0]);
		exit(EXIT_FAILURE);
	}

	while(1) {
		if((ctp = resmgr_block(ctp)) == NULL) {
			fprintf(stderr, "block error\n");
			exit(EXIT_FAILURE);
		}
		resmgr_handler(ctp);
	}
	return EXIT_SUCCESS;
}
Ejemplo n.º 4
0
int 
begin(int argc, char *argv[])
{
        int                   	i, j;
	uint32_t		ph_flags = 0;
        thread_pool_attr_t	tp_attr;
	static void 		*tpp;
        dispatch_t              *dpp;

        dpp = dispatch_create();
        if (dpp == NULL) {
               char * pMsgTxt = "Error: cannot create dispatch interface\n";
               fprintf(stderr, pMsgTxt);
               slogf(_SLOG_SETCODE(_SLOGC_INPUT, 0), _SLOG_ERROR, pMsgTxt);
                return (EXIT_FAILURE);
        }
        devi_set_dispatch_handle(dpp);
        /* set up the module table */
        if (modules != NULL) {

                for (i = 0; i < MODULE_TABLE_SIZE && ModuleTable[i] != NULL; 
		     i++)
                        ;
                /* add extra modules to end of ModuleTable */
                
                for (j = 0; j < (MODULE_TABLE_SIZE - i) && modules[j] != NULL; 
		     j++, i++) 
                        ModuleTable[i] = modules[j];
        }
        
        if(ThreadCtl(_NTO_TCTL_IO, 0) == -1) {
                errno_print("ThreadCtl");
                return (EXIT_FAILURE);
        }
        // Call global callback if it was specified        
        if(commonCallbacks.pre_init && commonCallbacks.pre_init())
		return (EXIT_FAILURE);
        if (options(argc, argv, &ph_flags, &OptFlags) < 0)
		return (EXIT_FAILURE);
        // Call global callback if it was specified        
        if(commonCallbacks.post_init && commonCallbacks.post_init())
		return (EXIT_FAILURE);
        sig_install(signal_table, termination_hndlr);

	if (procmgr_daemon(0, PROCMGR_DAEMON_NODEVNULL | 
			   PROCMGR_DAEMON_NOCLOSE) < 0) {
		errno_print("procmgr_daemon");
		return (EXIT_FAILURE);
	}


        if (!(OptFlags & OPT_NO_PHOTON))  {
                if (start_photon_interface(ph_flags) < 0) {
                        errno_print("unable to start photon interface");
                        return (EXIT_FAILURE);
                }
        }

	memset(&tp_attr, 0, sizeof(tp_attr));
        tp_attr.handle = devi_get_dispatch_handle();
        tp_attr.context_alloc = dispatch_context_alloc;
        tp_attr.block_func = dispatch_block;
        tp_attr.handler_func = dispatch_handler;
        tp_attr.context_free = dispatch_context_free;
    /* We'd rather not to use thread pool for device driver - it could 
       cause desynchronizing and data losing                       */
	tp_attr.lo_water  = 1;   /* min amount threads waiting blocked */
	tp_attr.hi_water  = 1;   /* max amount threads waiting blocked */
	tp_attr.increment = 1;  
	tp_attr.maximum   = 1;    

	tpp = thread_pool_create(&tp_attr, POOL_FLAG_USE_SELF);
	if (tpp == NULL) {
                errno_print("thread_pool_create");
                return (EXIT_FAILURE);
        }

	thread_pool_start(tpp);

        return (EOK);
}