Exemplo n.º 1
0
/*======================================
 *	CORE : MAINROUTINE
 *--------------------------------------*/
int main (int argc, char **argv)
{
	{// initialize program arguments
		char *p1 = SERVER_NAME = argv[0];
		char *p2 = p1;
		while ((p1 = strchr(p2, '/')) != NULL || (p1 = strchr(p2, '\\')) != NULL)
		{
			SERVER_NAME = ++p1;
			p2 = p1;
		}
		arg_c = argc;
		arg_v = argv;
	}

	malloc_init();// needed for Show* in display_title() [FlavioJS]

#ifdef MINICORE // minimalist Core
	display_title();
	usercheck();
	do_init(argc,argv);
	do_final();
#else// not MINICORE
	set_server_type();
	display_title();
	usercheck();

	db_init();
	signals_init();
	
#ifdef _WIN32 
	cevents_init(); 
#endif

	timer_init();
	socket_init();
	plugins_init();

	do_init(argc,argv);
	plugin_event_trigger(EVENT_ATHENA_INIT);

	{// Main runtime cycle
		int next;
		while (runflag != CORE_ST_STOP) {
			next = do_timer(gettick_nocache());
			do_sockets(next);
		}
	}

	plugin_event_trigger(EVENT_ATHENA_FINAL);
	do_final();

	timer_final();
	plugins_final();
	socket_final();
	db_final();
#endif

	malloc_final();

	return 0;
}
Exemplo n.º 2
0
/*
 * Main routine.  Parse the arguments, open the remctl connection, send the
 * command, and then call process_response.
 */
int
main(int argc, char *argv[])
{
    int option, status;
    char *server_host;
    struct addrinfo hints, *ai;
    const char *source = NULL;
    const char *service_name = NULL;
    char *end;
    long tmp_port;
    unsigned short port = 0;
    struct remctl *r;
    int errorcode = 0;

    /* Set up logging and identity. */
    message_program_name = "remctl";
    if (!socket_init())
        die("failed to initialize socket library");

    /*
     * Parse options.  The + tells GNU getopt to stop option parsing at the
     * first non-argument rather than proceeding on to find options anywhere.
     * Without this, it's hard to call remote programs that take options.
     * Non-GNU getopt will treat the + as a supported option, which is handled
     * below.
     */
    while ((option = getopt(argc, argv, "+b:dhp:s:v")) != EOF) {
        switch (option) {
        case 'b':
            source = optarg;
            break;
        case 'd':
            message_handlers_debug(1, message_log_stderr);
            break;
        case 'h':
            usage(0);
        case 'p':
            tmp_port = strtol(optarg, &end, 10);
            if (*end != '\0' || tmp_port < 1 || tmp_port > (1L << 16) - 1)
                die("invalid port number %ld", tmp_port);
            port = (unsigned short) tmp_port;
            break;
        case 's':
            service_name = optarg;
            break;
        case 'v':
            printf("%s\n", PACKAGE_STRING);
            exit(0);
        case '+':
            fprintf(stderr, "%s: invalid option -- +\n", argv[0]);
            usage(1);
        default:
            usage(1);
        }
    }
    argc -= optind;
    argv += optind;
    if (argc < 2)
        usage(1);
    server_host = *argv++;

    /*
     * If service_name isn't set, the remctl library uses host/<server>
     * (host@<server> in GSS-API parlance).  However, if the server to which
     * we're connecting is a DNS-load-balanced name, we have to be careful
     * what principal name we use.
     *
     * Ideally, we would let the GSS-API library handle this and choose
     * whether to canonicalize the <server> in the principal name based on the
     * krb5.conf rdns setting and similar configuration.  However, with DNS
     * load balancing, this still may fail.  At the time of network
     * connection, we will connect to whatever the name resolves to then.
     * After we connect, we authenticate, and the GSS-API library will then
     * separately canonicalize the hostname.  It could get a different answer
     * than we got for our network connection, leading to an authentication
     * failure.
     *
     * Therefore, if the principal isn't specified, we canonicalize the
     * hostname to which we're connecting before we connect.  Then, the
     * additional canonicalization possibly done by the GSS-API library should
     * return the same results and be consistent.
     *
     * Note that this opens the possibility of a subtle attack through DNS
     * spoofing, since both the principal used and the host to which we're
     * connecting can be changed by varying the DNS response.
     *
     * If the principal is specified explicitly, assume the user knows what
     * they're doing and don't do any of this.
     */
    if (service_name == NULL) {
        memset(&hints, 0, sizeof(hints));
        hints.ai_flags = AI_CANONNAME;
        status = getaddrinfo(server_host, NULL, &hints, &ai);
        if (status != 0)
            die("cannot resolve host %s: %s", server_host,
                gai_strerror(status));
        server_host = xstrdup(ai->ai_canonname);
        freeaddrinfo(ai);
    }

    /* Open connection. */
    r = remctl_new();
    if (r == NULL)
        sysdie("cannot initialize remctl connection");
    if (source != NULL)
        if (!remctl_set_source_ip(r, source))
            die("%s", remctl_error(r));
    if (!remctl_open(r, server_host, port, service_name))
        die("%s", remctl_error(r));

    /* Do the work. */
    if (!remctl_command(r, (const char **) argv))
        die("%s", remctl_error(r));
    if (!process_response(r, &errorcode))
        die("%s", remctl_error(r));

    /* Shut down cleanly. */
    remctl_close(r);
    socket_shutdown();
    return errorcode;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
    char   tmp[MAX_PATH];
    char*  tmpend = tmp + sizeof(tmp);
    char*  args[128];
    int    n;
    char*  opt;
    /* The emulator always uses the first serial port for kernel messages
     * and the second one for qemud. So start at the third if we need one
     * for logcat or 'shell'
     */
    int    serial = 2;
    int    shell_serial = 0;

    int    forceArmv7 = 0;

    AndroidHwConfig*  hw;
    AvdInfo*          avd;
    AConfig*          skinConfig;
    char*             skinPath;
    int               inAndroidBuild;
    uint64_t          defaultPartitionSize = convertMBToBytes(66);

    AndroidOptions  opts[1];
    /* net.shared_net_ip boot property value. */
    char boot_prop_ip[64];
    boot_prop_ip[0] = '\0';

    args[0] = argv[0];

    if ( android_parse_options( &argc, &argv, opts ) < 0 ) {
        exit(1);
    }

#ifdef _WIN32
    socket_init();
#endif

    handle_ui_options(opts);

    while (argc-- > 1) {
        opt = (++argv)[0];

        if(!strcmp(opt, "-qemu")) {
            argc--;
            argv++;
            break;
        }

        if (!strcmp(opt, "-help")) {
            emulator_help();
        }

        if (!strncmp(opt, "-help-",6)) {
            STRALLOC_DEFINE(out);
            opt += 6;

            if (!strcmp(opt, "all")) {
                android_help_all(out);
            }
            else if (android_help_for_option(opt, out) == 0) {
                /* ok */
            }
            else if (android_help_for_topic(opt, out) == 0) {
                /* ok */
            }
            if (out->n > 0) {
                printf("\n%.*s", out->n, out->s);
                exit(0);
            }

            fprintf(stderr, "unknown option: -help-%s\n", opt);
            fprintf(stderr, "please use -help for a list of valid topics\n");
            exit(1);
        }

        if (opt[0] == '-') {
            fprintf(stderr, "unknown option: %s\n", opt);
            fprintf(stderr, "please use -help for a list of valid options\n");
            exit(1);
        }

        fprintf(stderr, "invalid command-line parameter: %s.\n", opt);
        fprintf(stderr, "Hint: use '@foo' to launch a virtual device named 'foo'.\n");
        fprintf(stderr, "please use -help for more information\n");
        exit(1);
    }

    if (opts->version) {
        printf("Android emulator version %s\n"
               "Copyright (C) 2006-2011 The Android Open Source Project and many others.\n"
               "This program is a derivative of the QEMU CPU emulator (www.qemu.org).\n\n",
#if defined ANDROID_BUILD_ID
               VERSION_STRING " (build_id " STRINGIFY(ANDROID_BUILD_ID) ")" );
#else
               VERSION_STRING);
#endif
        printf("  This software is licensed under the terms of the GNU General Public\n"
               "  License version 2, as published by the Free Software Foundation, and\n"
               "  may be copied, distributed, and modified under those terms.\n\n"
               "  This program is distributed in the hope that it will be useful,\n"
               "  but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
               "  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
               "  GNU General Public License for more details.\n\n");

        exit(0);
    }
Exemplo n.º 4
0
int main(int argc, char**argv, char**envp)
{
	int s;
	int flag;
	int l, len, sz, nm;
	uint8_t *p, *buf = NULL;
	int ec = 0;
	struct statistics {
		size_t sent;
		size_t intr;
		size_t again;
		int min, max, avg;
		int a, b;
	} stats;
	const char *iptype = "ip\0\0";
    char *address = NULL;
    short port = -1;

	if( argc<3 ) usage(argv[0]);
    if( argc>1 ) {
	    char *svc;
        address = strdup(argv[1]);
	    svc = strtok(address,":");
	    if( svc ) svc = strtok(NULL,":");
        if( svc ) port = (short)atoi(svc);
        // address contains IP, port holds port number
    }
	sz = (argc>2)?atoi(argv[2]):4;	// length of I/O is arg2 (default=4)
	if( (sz<4) || (sz%4) ) { errno = EINVAL; perror("bytes"); exit(1); }
	nm = (argc>3)?atoi(argv[3]):-1;	// num messages is arg3 (default=-1)
	if( argc>4 && stristr(argv[4],"ipv4",4) ) iptype = "ipv4";
	if( argc>4 && stristr(argv[4],"ipv6",4) ) iptype = "ipv6";

	// platform independence (see socket.h)
    socket_init();

	// buffers and statistics
	buf = (uint8_t *)malloc(sz);
	if( !buf) { perror("malloc"); exit(1); }

	memset(&stats, 0, sizeof(struct statistics));
	stats.min = INT_MAX;
	stats.max = INT_MIN;
    stats.avg = 0;
	stats.a   = (int)(ALPHA * FACTOR);
	stats.b   = (int)(FACTOR - stats.a);

    flag = SOCKET_VERBOSE;
    if( iptype[3]=='6') flag |= SOCKET_IPV6;
    if( argc>4 && stristr(argv[4],"bsd",3)) flag |= SOCKET_BSD;

    // platform-independent socket (see socket.h)
    s = socket_open_and_connect(address, port, flag);
    if (s>0) {

	    fprintf(stderr,"%s: connected to %s,%hu ...\n", argv[0], address, port);
	    fprintf(stderr,"%s: using %d block size\n", argv[0], sz);

        l=socket_send(s,&sz,sizeof(sz),0);
        if( l==sizeof(sz) ) {
	        stats.avg = sz;

	        // transmit buffers continuously
	        p = buf; len=0;
	        do {
                l=socket_send(s,p,sz-len,0);
                if( l<=0 ) { ec = 1; break; }

			    stats.sent++;
		        if(l < stats.min) stats.min=l;
		        if(l > stats.max) stats.max=l;
		        stats.avg = ((stats.a*stats.avg) + (stats.b*l))>>LOG2FACTOR;	// autoregressive

		        len += l; p += l;
		        if( len == sz ) {
			        p=buf;
			        len=0;
	            }
	        } while( (nm==-1) || ((int)stats.sent < nm) );
        }
Exemplo n.º 5
0
void
data_loop(int from, int tcp, char *host, int port)
{
    unsigned char b[2];
    int n;
    int prevhighbit = -1;
#if OUT_OF_BAND_SOMEDAY
    int prevwaszero;
#endif
    int highbit;
    static int to = -1;

    while (1) {

	/* leave extra space in buf for extra bytes we may read below */
	if ((n = read(from, b, 2)) < 0)
	    die("read");

	/* in my experience, this results from a USB serial
	 * device being unplugged */
	if (n == 0)
	    return;

	if (n == 1) { /* short read -- force it even */
	    if (read(from, &b[1], 1) <= 0)
		die("read");
	    n++;
	}

	if (debug) {
	    int pulse;
	    pulse = (b[1] << 8) + b[0];
	    pulse &= 0xffff;
	    fprintf(stderr, "%s 0x%04x (%d)\n",
		(pulse & 0x8000) ? "pulse":"space", pulse, pulse & 0x7fff);
	}

#if OUT_OF_BAND_SOMEDAY
	if (oob) {  // these bytes are out-of-band
	    process_oob(from, b);
	    prevhighbit = -1;
	    prevwaszero = 0;
	    oob = 0;
	    continue;
	}

	//if (debug)
	//    debug_buffer("", buf, n);

	if (b[0] == 0 && b[1] == 0) {
	    // then we're definitely in phase
	    oob = 1;
	    prevwaszero = 0;
	    continue;
	} 

	oob = 0;

	if (prevwaszero && b[0] == 0) {
	    // then we're definitely out of phase
	    report("phase correction");
	    b[0] = b[1];
	    if (read(from, &b[1], 1) <= 0)
		die("read");
	    process_oob(from, b);
	    prevhighbit = -1;
	    prevwaszero = 0;
	    continue;
	}
#endif
	
	highbit = (b[1] & 0x80);
	if (highbit == prevhighbit) {
	    report("phase correction");
	    b[0] = b[1];
	    if (read(from, &b[1], 1) <= 0)
		die("read");
	    highbit = (b[1] & 0x80);
	}
	prevhighbit = highbit;
#if OUT_OF_BAND_SOMEDAY
	prevwaszero = (b[1] == 0);
#endif

	if (debug != DEBUG_ONLY)  { // sending to host
	    if (to < 0)
		to = socket_init(tcp, host, port);
	    if (to >= 0) {
		if (write(to, b, 2) < 0) {
		    if (errno != ECONNREFUSED)
			die("write");
		}
	    }
	}

    }
}
Exemplo n.º 6
0
/*======================================
 *	CORE : MAINROUTINE
 *--------------------------------------*/
int main (int argc, char **argv)
{
	{// initialize program arguments
		char *p1;
		if((p1 = strrchr(argv[0], '/')) != NULL ||  (p1 = strrchr(argv[0], '\\')) != NULL ){
			char *pwd = NULL; //path working directory
			int n=0;
			SERVER_NAME = ++p1;
			n = p1-argv[0]; //calc dir name len
			pwd = safestrncpy((char*)malloc(n + 1), argv[0], n);
			if(chdir(pwd) != 0)
				ShowError("Couldn't change working directory to %s for %s, runtime will probably fail",pwd,SERVER_NAME);
			free(pwd);
		}else{
			// On Windows the .bat files have the executeable names as parameters without any path seperator [Lemongrass]
			SERVER_NAME = argv[0];
		}
	}

	malloc_init();// needed for Show* in display_title() [FlavioJS]

#ifdef MINICORE // minimalist Core
	display_title();
	usercheck();
	do_init(argc,argv);
	do_final();
#else// not MINICORE
	set_server_type();
	display_title();
	usercheck();

	Sql_Init();
	rathread_init();
	mempool_init();
	db_init();
	signals_init();

#ifdef _WIN32
	cevents_init();
#endif

	timer_init();
	socket_init();

	do_init(argc,argv);

	// Main runtime cycle
	while (runflag != CORE_ST_STOP) { 
		int next = do_timer(gettick_nocache());
		do_sockets(next);
	}

	do_final();

	timer_final();
	socket_final();
	db_final();
	mempool_final();
	rathread_final();
	ers_final();
#endif

	malloc_final();

	return 0;
}
Exemplo n.º 7
0
/* main loop */
int main (void) {
	uint8_t string[SCANDALLONGSTRINGSIZE];
	/* can packet parameters */
	sion_entry entry;
	char dbfilename[MAX_LINE_LENGTH];
	struct timeval tstamp;

	/* set up signals */
	signal(SIGINT, shutdown_cleanly);
	signal(SIGINT, shutdown_cleanly);
	
	/* set up sqlite db */
	makedbfile(dbfilename, ACCURACY_DAY);
	FILE *textlog = fopen("../canlog/scandal.log", "a");


	if (checkdbfile(dbfilename)){
		init_sqlite3(&db, dbfilename, OLDDB);
		init_sqlite3(&dbsync, dbfilename, OLDDB);
		printf("CIEL: opening previous database....\n");
	}
	else {
		init_sqlite3(&db, dbfilename, NEWDB);
		init_sqlite3(&dbsync, dbfilename, OLDDB);
		printf("CIEL: creating new database...\n");
	}

	/* Set up sockets */
	int numbytes;
	int loopcounter;
	char receivequeue[MAX_SOCKET_BLOCK_LENGTH];

	//select() stuff
	fd_set master;
	fd_set read_fds;
	int fdmax;
	int fdcount;
	FD_ZERO(&master);
	FD_ZERO(&read_fds);

	//socket for receiving SION data
	socket_init(&sockfd_sion, &sioninfo,
				CIELIN_SION_HOST, CIELIN_SION_PORT, SIONOUTHOST, SIONOUTPORT) ;
	//socket for sending sync requests and receiving their reply
	socket_init(&sockfd_sync, &syncinfo,
				CIELOUT_SYNC_HOST, CIELOUT_SYNC_PORT, SIONIN_SYNC_HOST, SIONIN_SYNC_PORT);
	//socket for receiving Seven data.
	socket_init(&sockfd_seven, &seveninfo, 
				CIELIN_SEVEN_HOST, CIELIN_SEVEN_PORT, SEVENOUTHOST, SEVENOUTPORT);
	//socket for sending these to something else eg scanalysis
	socket_init(&sockfd_telemout, &telemoutinfo,
				CIELOUT_OPEN_HOST, CIELOUT_OPEN_PORT, TELEM_TARGET_HOST , TELEM_TARGET_PORT) ;
	//socket for sending packed telemetry to something else eg sunswift live
	socket_init(&sockfd_telemout2, &telemoutinfo2,
				CIELOUT_OPEN_HOST2, CIELOUT_OPEN_PORT2, TELEM_TARGET_HOST2 , TELEM_TARGET_PORT2) ;


	//more select() stuff
	FD_SET(sockfd_sion, &master);
	FD_SET(sockfd_seven, &master);
	FD_SET(sockfd_sync, &master);
	fdmax = sockfd_sync;
	if (fdmax < sockfd_seven) //checking to make sure fdmax is the largest
		fdmax = sockfd_seven;
	if (fdmax < sockfd_sion)
		fdmax = sockfd_sion;
	fdmax++; //+1 as required by select()

	/* Set up threads */

	printf("CIEL: Setting up threads...\n ");
	pthread_t out_thread,  sync_thread_handler;
	int rc;
	rc = pthread_create(&out_thread, NULL, output_thread, NULL);
	if (rc) {
		printf("CIEL: ERROR: Return code from pthread_create for output thread is %d\n", rc);
		exit(-1);
	}
	/*
	rc = pthread_create(&sync_thread_handler, NULL, sync_thread, NULL);
	if (rc) {
		printf("CIEL: ERROR: Return code from pthread_create for sync thread is %d\n", rc);
		exit(-1);
	}
	*/


	//FIXME 
	/*
	int date_is_set=0;
	int number_of_seconds_since_epoch = 0;
	int delay = 0;
	*/

	printf("CIEL: Entering main receiver loop..\n");
	while ( loop ) {
		read_fds = master;
		if (select(fdmax, &read_fds, NULL, NULL, NULL) == -1) {
			perror("select");
			exit(4);
		}

		for(fdcount = 0; fdcount <=fdmax; fdcount++ ) { //for all the socket descriptors....
			if(FD_ISSET(fdcount, &read_fds)) {
				if (fdcount == sockfd_sion ) {
					/* Receiving live telemetry stream */
					numbytes = socket_recv(&sockfd_sion, receivequeue, 
						SCANDALLONGSTRINGSIZE * SOCKET_BLOCK_LENGTH);
					gettimeofday(&tstamp, NULL); //hurry, grab the timestamp!
				}
				else if (fdcount == sockfd_seven) {
					/* Receiving live control car stream */
					numbytes = socket_recv(&sockfd_seven, receivequeue,
						SCANDALLONGSTRINGSIZE * SOCKET_BLOCK_LENGTH);
					gettimeofday(&tstamp, NULL); //hurry, grab the timestamp!
				}
				else if (fdcount == sockfd_sync) {
					/* Receiving solar car retransmission */
					numbytes = socket_recv(&sockfd_sync, receivequeue, 
						SCANDALLONGSTRINGSIZE * SOCKET_BLOCK_LENGTH);
					gettimeofday(&tstamp, NULL); //hurry, grab the timestamp!
				}
			}
		}

		/* Send packed frames to something else. Used in 2011 for sunswift live */
		socket_send(&sockfd_telemout2, receivequeue, SCANDALLONGSTRINGSIZE * SOCKET_BLOCK_LENGTH, telemoutinfo2);


		/*
		Since each ethernet packet contains multiple CAN packets, we unpack them
		one by one and process them individually.
		*/
		for (loopcounter=0; loopcounter < SOCKET_BLOCK_LENGTH; loopcounter++) {
			//extract an individual packet
			memmove(string, &receivequeue[(SCANDALLONGSTRINGSIZE*loopcounter)], SCANDALLONGSTRINGSIZE);

			//TODO: Fix the Scandal Channel messages etc timestamps to full 64-bit.

			
			longstringtoentry(string, &entry);
			entry.ciel_timestamp = (((uint64_t) tstamp.tv_sec) * 1000) +
				( (uint64_t) lrintf( ((float) tstamp.tv_usec) / 1000 ) ); 

			entrytostring(&entry, string); //we don't send everything to scanalysis
			socket_send(&sockfd_telemout, string, SCANDALSTRINGSIZE, telemoutinfo); //to scanalysis
			//FIXME: plaintext log, not needed
			
			fprintf(textlog,"%d\t%d\t%d\t%d\t%d\t%llu\t%llu\t%u\n\r", 
			entry.priority, 
			entry.message_type, 
			entry.source_address, 
			entry.specifics, 
			entry.value,
			entry.scandal_timestamp,
			entry.ciel_timestamp,
			entry.pkt_id);
			

			queue_can_packet(db, &entry, SQLITE_BLOCKLEN); //duplicate packets are ignored by sqlite

			/* Debug function. Do not print too much UART or you'll slow everything down. */
			#define SION_DEBUG
			#ifdef SION_DEBUG
				//printf_sion_entry(&entry);
				printf("%llu\t%u\n\r", entry.scandal_timestamp, entry.pkt_id); 
			#endif
		} //end processing individual packets
	}// end infinite loop
	
	shutdown_sqlite3(db);//why is this even here
	return 0; //makes compiler happy
}
Exemplo n.º 8
0
/*
   applies and consumes the following options: 
   PH_PASTSOCKET, PH_FD, PH_PREBIND, PH_BIND, PH_PASTBIND, PH_CONNECTED, PH_LATE
   OFUNC_OFFSET
   OPT_PROTOCOL_FAMILY, OPT_BIND, OPT_SO_TYPE, OPT_SO_PROTOTYPE, OPT_USER,
   OPT_GROUP, OPT_CLOEXEC
 */
static
int _xioopen_rawip_sendto(const char *hostname, const char *protname,
			  struct opt *opts, int xioflags, xiofile_t *xxfd,
			  unsigned groups, int *pf) {
   char *garbage;
   xiosingle_t *xfd = &xxfd->stream;
   int rw = (xioflags&XIO_ACCMODE);
   union sockaddr_union us;
   socklen_t uslen;
   int feats = 1;	/* option bind supports only address, not port */
   int socktype = SOCK_RAW;
   int ipproto;
   bool needbind = false;
   int result;

   if ((ipproto = strtoul(protname, &garbage, 0)) >= 256) {
      Error3("xioopen_rawip_sendto(\"%s:%s\",,): protocol number exceeds 255 (%u)",
	     hostname, protname, ipproto);
      return STAT_NORETRY;
   } else if (*garbage) {
      Warn2("xioopen_rawip_sendto(\"%s:%s\",,): trailing garbage in protocol specification",
	     hostname, protname);
      /*return STAT_NORETRY;*/
   }

   retropt_int(opts, OPT_PROTOCOL_FAMILY, pf);

   /* ...res_opts[] */
   if (applyopts_single(xfd, opts, PH_INIT) < 0)  return -1;
   applyopts(-1, opts, PH_INIT);

   xfd->salen = sizeof(xfd->peersa);
   if ((result =
	xiogetaddrinfo(hostname, NULL, *pf, socktype, ipproto,
		       &xfd->peersa, &xfd->salen,
		       xfd->para.socket.ip.res_opts[0],
		       xfd->para.socket.ip.res_opts[1]))
       != STAT_OK) {
      return result;
   }
   if (*pf == PF_UNSPEC) {
      *pf = xfd->peersa.soa.sa_family;
   }

   uslen = socket_init(*pf, &us);

   xfd->dtype = XIODATA_RECVFROM_SKIPIP;

   if (retropt_bind(opts, *pf, socktype, ipproto, &us.soa, &uslen, feats,
		    xfd->para.socket.ip.res_opts[0],
		    xfd->para.socket.ip.res_opts[1]) != STAT_NOACTION) {
      needbind = true;
   }
   if ((result =
	_xioopen_dgram_sendto(needbind?&us:NULL, uslen,
			      opts, xioflags, xfd, groups, *pf, socktype,
			      ipproto)) != STAT_OK) {
      return result;
   }
   if (XIOWITHWR(rw))   xfd->wfd = xfd->rfd;
   if (!XIOWITHRD(rw))  xfd->rfd = -1;
   return STAT_OK;
}
Exemplo n.º 9
0
static void
start_server (void) {
    int                 client_sd;
    int                 daemon_sd;
    int                 connected_sd;
    struct sockaddr_in  client_sa;
    struct sockaddr_in  daemon_sa;
    struct sockaddr_in  connected_sa;
    socklen_t           size;
    fd_set              socket_set;
    int                 nfds;
    struct ifreq        if_info;
    struct sockaddr_in  *if_addr;
    char                addr[INET_ADDRSTRLEN];
    struct client       *c;
    struct daemon       *d;
    struct parsed_cmd   *pcmd = NULL;
    char                *ident_msg;
    int                 port;
    char                *colon;


    /* Prepare all the threads */
    slow_pool = NULL;
    fast_pool = NULL;
    clients_pool = NULL;
    daemons_pool = NULL;

    ABORT_IF (!(slow_pool = pool_create (prefs->nb_proc)),
        "Unable to create slow_pool")

    ABORT_IF (!(fast_pool = pool_create (prefs->nb_proc)),
        "Unable to create fast_pool")

    ABORT_IF (!(clients_pool = pool_create (prefs->max_clients)),
        "Unable to create clients_pool")

    ABORT_IF (!(daemons_pool = pool_create (prefs->max_daemons)),
        "Unable to create daemons_pool")

    nb_clients.count = 0;
    ABORT_IF (sem_init (&nb_clients.lock, 0, 1) < 0,
        "Unable to create nb_clients lock")

    nb_daemons.count = 0;
    ABORT_IF (sem_init (&nb_daemons.lock, 0, 1) < 0,
        "Unable to create nb_daemons lock")

    /* Create the shared directory if it does not exist already */
    ABORT_IF (create_dir (prefs->shared_folder, (mode_t)0755) < 0,
                "Unable to create shared directory")

    /* Initialize global pointers and their semaphores */
    clients = NULL;
    ABORT_IF (sem_init (&clients_lock, 0, 1) < 0,
        "Unable to sem_init clients_lock")

    daemons = NULL;
    ABORT_IF (sem_init (&daemons_lock, 0, 1) < 0,
        "Unable to sem_init daemons_lock")

    file_cache = NULL;
    ABORT_IF (sem_init (&file_cache_lock, 0, 1) < 0,
        "Unable to sem_init file_cache_lock")

    list_client = NULL;
    ABORT_IF (sem_init (&list_lock, 0, 1) < 0,
        "Unable to sem_init list_lock")

    downloads = NULL;
    ABORT_IF (sem_init (&downloads_lock, 0, 1) < 0,
        "Unable to sem_init download_queue_lock")

    client_sa.sin_family        = AF_INET;
    client_sa.sin_addr.s_addr   = INADDR_ANY;
    client_sa.sin_port          = htons (prefs->client_port);
    client_sd = socket_init (&client_sa);
    ABORT_IF (client_sd < 0,
        "Unable to socket_init client_sd")

    daemon_sa.sin_family        = AF_INET;
    daemon_sa.sin_addr.s_addr   = INADDR_ANY;
    daemon_sa.sin_port          = htons (prefs->daemon_port);
    daemon_sd = socket_init (&daemon_sa);
    ABORT_IF (daemon_sd < 0,
        "Unable to socket_init daemon_sd")

#if 1
    /* We get our ip */
    memcpy (if_info.ifr_name, prefs->interface, strlen (prefs->interface) + 1);
    if (ioctl (daemon_sd, SIOCGIFADDR, &if_info) == -1) {
        log_failure (log_file, "Can't get my ip from interface");
        log_failure (log_file, "LOL ERRNO : %s\n", strerror (errno));
        goto abort;
    }
    if_addr = (struct sockaddr_in *)&if_info.ifr_addr;
    inet_ntop (AF_INET, &if_addr->sin_addr, my_ip, INET_ADDRSTRLEN);
    log_success (log_file, "Found my IP : %s", my_ip);
#endif

    /* socket_set contains both client_sd and daemon_sd */
    FD_ZERO (&socket_set);
    size = sizeof (connected_sa);
    nfds = NFDS (client_sd, daemon_sd);
    for (;;) {
        /*
         * It is VERY important to FD_SET at each loop, because select
         * will FD_UNSET the socket descriptors
         */
        FD_SET (client_sd, &socket_set);
        FD_SET (daemon_sd, &socket_set);

        /* Block until a socket is ready to accept */
        if (select (nfds, &socket_set, NULL, NULL, NULL) < 0) {
            log_failure (log_file, "main () : select failed");
        }

        if (FD_ISSET (client_sd, &socket_set)) {
            if ((connected_sd = (accept (client_sd,
                                        (struct sockaddr *) &connected_sa,
                                        &size))) < 0) {
                log_failure (log_file, "Failed to accept incoming connection.");
                break;
            }

            /* Can we handle this client? */
            sem_wait (&nb_clients.lock);
            if (nb_clients.count < prefs->max_clients) {
                nb_clients.count++;
                sem_post (&nb_clients.lock);
            }
            else {
                sem_post (&nb_clients.lock);
                socket_sendline (connected_sd, " < Too many clients\n");
                goto close_socket;
            }

            /* Then, let's handle him */
            if (!inet_ntop (AF_INET, &connected_sa.sin_addr,
                            addr, INET_ADDRSTRLEN)) {
                socket_sendline (connected_sd, " < Oops\n");
                goto failed_handling_client;
            }
            if (!(c = client_new (connected_sd, addr))) {
                socket_sendline (connected_sd, " < Sorry pal :(\n");
            }

            pool_queue (clients_pool, handle_client, c);
        }
        else if (FD_ISSET (daemon_sd, &socket_set)) {
            if ((connected_sd = (accept (daemon_sd,
                                        (struct sockaddr *) &connected_sa,
                                        &size))) < 0) {
                log_failure (log_file, "Failed to accept incoming connection.");
                break;
            }

            /* Can we handle this daemon? */
            sem_wait (&nb_daemons.lock);
            if (nb_daemons.count < prefs->max_daemons) {
                /* Remember client_request_connect is also creating daemons, so
                    we increment the counter even if we have to decrement it
                    on a possible following failure */
                nb_daemons.count++;
                sem_post (&nb_daemons.lock);
            }
            else {
                sem_post (&nb_daemons.lock);
                socket_sendline (connected_sd, " < Too many daemons\n");
                goto close_socket;
            }

            /* Let's identify him first */
            ident_msg = socket_try_getline (connected_sd,
                                            IDENTIFICATION_TIMEOUT);
            if (!ident_msg) {
                socket_sendline (connected_sd,
                                "error: identification timed out\n");
                goto failed_handling_daemon;
            }
            if (cmd_parse_failed ((pcmd = cmd_parse (ident_msg, NULL)))) {
                pcmd = NULL;
                goto failed_handling_daemon;
            }
            if (pcmd->argc < 2)
                goto failed_handling_daemon;
            if (strcmp (pcmd->argv[0], "neighbour") != 0)
                goto failed_handling_daemon;
            if (!(colon = strchr (pcmd->argv[1], ':')))
                goto failed_handling_daemon;
            port = atoi (colon + 1);

            free (ident_msg);
            cmd_parse_free (pcmd);
            pcmd = NULL;

            if (!inet_ntop (AF_INET, &connected_sa.sin_addr,
                            addr, INET_ADDRSTRLEN)) {
                socket_sendline (connected_sd, " < Oops\n");
                goto failed_handling_daemon;
            }

            /* Now we've got his port, let him go in */
            if (!(d = daemon_new (connected_sd, addr, port))) {
                socket_sendline (connected_sd, " < Sorry pal :(\n");
                goto failed_handling_daemon;
            }

            pool_queue (daemons_pool, handle_daemon, d);
        }
        else {
            /* This should never happen : neither client nor daemon!? */
            log_failure (log_file, "Unknown connection");
        }

        continue;

failed_handling_client:
        sem_wait (&nb_clients.lock);
        --nb_clients.count;
        sem_post (&nb_clients.lock);
        goto close_socket;

/* We jump here if we reserved a slot for a daemon, but failed to create it */
failed_handling_daemon:
        sem_wait (&nb_daemons.lock);
        --nb_daemons.count;
        sem_post (&nb_daemons.lock);
        /* goto close_socket; */

close_socket:
        if (pcmd) {
            cmd_parse_free (pcmd);
            pcmd = NULL;
        }
        close (connected_sd);
    }

abort:
    if (slow_pool)
        pool_destroy (slow_pool);
    if (fast_pool)
        pool_destroy (fast_pool);
    if (clients_pool)
        pool_destroy (clients_pool);
    if (daemons_pool)
        pool_destroy (daemons_pool);
    conf_free (prefs);
    exit (EXIT_FAILURE);
}
Exemplo n.º 10
0
/*
功能:	程序开始时初始化各个模块,启动相关的线程,instruction线程用于处理具体指令,timing线程管理定时器
返回:	0——成功;-1——失败
*/
int global_init()
{
	int ret = -1;

	if(-1==dir_exist_ensure(WORKSPACE_SURFIX))
		return -1;
	
	setting_init();
	
	if(-1==dir_exist_ensure(FIFO_DIR))
		return -1;
	if(-1==socket_init()){
		DEBUG("socket module init failed\n");
		return -1;
	}
	if(-1==sqlite_init()){
		DEBUG("sqlite module init failed\n");
		return -1;
	}
	if(-1==timing_init()){
		DEBUG("timer module init failed\n");
		return -1;
	}
	if(-1==equipment_init()){
		DEBUG("equipment array init failed\n");
		return -1;
	}
	if(-1==instruction_init()){
		DEBUG("instruction module init failed\n");
		return -1;
	}
	if(-1==serial_int()){
		DEBUG("serial module init failed\n");
		return -1;
	}

// only for database testing
	//DEBUG("getGlobalPara(version)=%d\n", getGlobalPara("version"));
	
	//~~~~~~~~~~create  thread~~~~~~~~~~//
	typedef void*(*format)(void *);													///define function pointer of "void*(name)(void*)"
	pthread_t l_socketlinkthread;													/// the file description of thread
#if 0
	pthread_attr_t l_attrthread;													///the attribute of thread
	size_t l_stacksize=1048576*1;													///set thread stack size
	///start thread.
	pthread_attr_init(&l_attrthread);												///initialize attribute
	pthread_attr_setscope(&l_attrthread,PTHREAD_SCOPE_SYSTEM);						///set attribute binding
	pthread_attr_setdetachstate(&l_attrthread,PTHREAD_CREATE_DETACHED);				///set attribute detached
	pthread_attr_setstacksize(&l_attrthread,l_stacksize);
	ret=pthread_create(&l_socketlinkthread,&l_attrthread,(format)socketHandler,NULL);
#else	/* use default attr */
	ret = pthread_create(&l_socketlinkthread,NULL,(format)instruction_mainloop,NULL);
#endif
	if(0!=ret)
	{
		ERROROUT("thread instruction_mainloop create failed!");
		return -1;
	}

	pthread_t timing_thread_id;
	ret = pthread_create(&timing_thread_id, NULL, (void *)timing_mainloop, NULL);
	if(0!=ret){
		ERROROUT("thread timing_mainloop create failed\n");
	}
	
	return 0;
}
Exemplo n.º 11
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int impl(int argc, char *argv[])
{
    char   *cfgfile;                        /* -> Configuration filename */
    int     c;                              /* Work area for getopt      */
    int     arg_error = 0;                  /* 1=Invalid arguments       */
    char   *msgbuf;                         /*                           */
    int     msgnum;                         /*                           */
    int     msgcnt;                         /*                           */
    TID     rctid;                          /* RC file thread identifier */
    TID     logcbtid;                       /* RC file thread identifier */

    SET_THREAD_NAME("impl");

    /* Initialize 'hostinfo' BEFORE display_version is called */
    init_hostinfo( &hostinfo );

#ifdef _MSVC_
    /* Initialize sockets package */
    VERIFY( socket_init() == 0 );
#endif

    /* Ensure hdl_shut is called in case of shutdown
       hdl_shut will ensure entries are only called once */
    atexit(hdl_shut);

    set_codepage(NULL);

    /* Clear the system configuration block */
    memset (&sysblk, 0, sizeof(SYSBLK));

    /* Save thread ID of main program */
    sysblk.impltid = thread_id();

    /* Save TOD of when we were first IMPL'ed */
    time( &sysblk.impltime );

#ifdef OPTION_MSGHLD
    /* Set the default timeout value */
    sysblk.keep_timeout_secs = 120;
#endif

    /* Initialize thread creation attributes so all of hercules
       can use them at any time when they need to create_thread
    */
    initialize_detach_attr (DETACHED);
    initialize_join_attr   (JOINABLE);

    /* Copy length for regs */
    sysblk.regs_copy_len = (int)((uintptr_t)&sysblk.dummyregs.regs_copy_end
                                 - (uintptr_t)&sysblk.dummyregs);

    /* Set the daemon_mode flag indicating whether we running in
       background/daemon mode or not (meaning both stdout/stderr
       are redirected to a non-tty device). Note that this flag
       needs to be set before logger_init gets called since the
       logger_logfile_write function relies on its setting.
    */
    sysblk.daemon_mode = !isatty(STDERR_FILENO) && !isatty(STDOUT_FILENO);

    /* Initialize the logmsg pipe and associated logger thread.
       This causes all subsequent logmsg's to be redirected to
       the logger facility for handling by virtue of stdout/stderr
       being redirected to the logger facility.
    */
    logger_init();

    /* Now display the version information again after logger_init
       has been called so that either the panel display thread or the
       external gui can see the version which was previously possibly
       only displayed to the actual physical screen the first time we
       did it further above (depending on whether we're running in
       daemon_mode (external gui mode) or not). This it the call that
       the panel thread or the one the external gui actually "sees".
       The first call further above wasn't seen by either since it
       was issued before logger_init was called and thus got written
       directly to the physical screen whereas this one will be inter-
       cepted and handled by the logger facility thereby allowing the
       panel thread or external gui to "see" it and thus display it.
    */
    display_version (stdout, "Hercules ", TRUE);

#if defined(OPTION_DYNAMIC_LOAD)
    /* Initialize the hercules dynamic loader */
    hdl_main();
#endif /* defined(OPTION_DYNAMIC_LOAD) */

#ifdef EXTERNALGUI
    /* Set GUI flag if specified as final argument */
    if (argc >= 1 && strncmp(argv[argc-1],"EXTERNALGUI",11) == 0)
    {
#if defined(OPTION_DYNAMIC_LOAD)
        if (hdl_load("dyngui",HDL_LOAD_DEFAULT) != 0)
        {
            usleep(10000); /* (give logger thread time to issue
                               preceding HHCHD007E message) */
            logmsg(_("HHCIN008S DYNGUI.DLL load failed; Hercules terminated.\n"));
            delayed_exit(1);
        }
#endif /* defined(OPTION_DYNAMIC_LOAD) */
        argc--;
    }
#endif /*EXTERNALGUI*/

#if !defined(WIN32) && !defined(HAVE_STRERROR_R)
    strerror_r_init();
#endif

#if defined(OPTION_SCSI_TAPE)
    initialize_lock (&sysblk.stape_lock);
    initialize_condition (&sysblk.stape_getstat_cond);
    InitializeListHead (&sysblk.stape_mount_link);
    InitializeListHead (&sysblk.stape_status_link);
#endif /* defined(OPTION_SCSI_TAPE) */

    /* Get name of configuration file or default to hercules.cnf */
    if(!(cfgfile = getenv("HERCULES_CNF")))
        cfgfile = "hercules.cnf";

    /* Process the command line options */
    while ((c = getopt(argc, argv, "f:p:l:db:")) != EOF)
    {

        switch (c) {
        case 'f':
            cfgfile = optarg;
            break;
#if defined(OPTION_DYNAMIC_LOAD)
        case 'p':
            if(optarg)
                hdl_setpath(strdup(optarg));
            break;
        case 'l':
        {
            char *dllname, *strtok_str;
            for(dllname = strtok_r(optarg,", ",&strtok_str);
                    dllname;
                    dllname = strtok_r(NULL,", ",&strtok_str))
                hdl_load(dllname, HDL_LOAD_DEFAULT);
        }
        break;
#endif /* defined(OPTION_DYNAMIC_LOAD) */
        case 'b':
            sysblk.logofile=optarg;
            break;
        case 'd':
            sysblk.daemon_mode = 1;
            break;
        default:
            arg_error = 1;

        } /* end switch(c) */
    } /* end while */

    if (optind < argc)
        arg_error = 1;

    /* Terminate if invalid arguments were detected */
    if (arg_error)
    {
        logmsg("usage: %s [-f config-filename] [-d] [-b logo-filename]"
#if defined(OPTION_DYNAMIC_LOAD)
               " [-p dyn-load-dir] [[-l dynmod-to-load]...]"
#endif /* defined(OPTION_DYNAMIC_LOAD) */
               " [> logfile]\n",
               argv[0]);
        delayed_exit(1);
    }

    /* Register the SIGINT handler */
    if ( signal (SIGINT, sigint_handler) == SIG_ERR )
    {
        logmsg(_("HHCIN001S Cannot register SIGINT handler: %s\n"),
               strerror(errno));
        delayed_exit(1);
    }

    /* Register the SIGTERM handler */
    if ( signal (SIGTERM, sigterm_handler) == SIG_ERR )
    {
        logmsg(_("HHCIN009S Cannot register SIGTERM handler: %s\n"),
               strerror(errno));
        delayed_exit(1);
    }

#if defined( _MSVC_ )
    /* Register the Window console ctrl handlers */
    if (SetConsoleCtrlHandler(console_ctrl_handler, TRUE) == FALSE)
    {
        logmsg(_("HHCIN010S Cannot register ConsoleCtrl handler: %s\n"),
               strerror(errno));
        delayed_exit(1);
    }
#endif

#if defined(HAVE_DECL_SIGPIPE) && HAVE_DECL_SIGPIPE
    /* Ignore the SIGPIPE signal, otherwise Hercules may terminate with
       Broken Pipe error if the printer driver writes to a closed pipe */
    if ( signal (SIGPIPE, SIG_IGN) == SIG_ERR )
    {
        logmsg(_("HHCIN002E Cannot suppress SIGPIPE signal: %s\n"),
               strerror(errno));
    }
#endif

#if defined( OPTION_WAKEUP_SELECT_VIA_PIPE )
    {
        int fds[2];
        initialize_lock(&sysblk.cnslpipe_lock);
        initialize_lock(&sysblk.sockpipe_lock);
        sysblk.cnslpipe_flag=0;
        sysblk.sockpipe_flag=0;
        VERIFY( create_pipe(fds) >= 0 );
        sysblk.cnslwpipe=fds[1];
        sysblk.cnslrpipe=fds[0];
        VERIFY( create_pipe(fds) >= 0 );
        sysblk.sockwpipe=fds[1];
        sysblk.sockrpipe=fds[0];
    }
#endif // defined( OPTION_WAKEUP_SELECT_VIA_PIPE )

#if !defined(NO_SIGABEND_HANDLER)
    {
        struct sigaction sa;
        sa.sa_sigaction = (void*)&sigabend_handler;
#ifdef SA_NODEFER
        sa.sa_flags = SA_NODEFER;
#else
        sa.sa_flags = 0;
#endif

        /* Explictily initialize sa_mask to its default.        @PJJ */
        sigemptyset(&sa.sa_mask);

        if( sigaction(SIGILL, &sa, NULL)
                || sigaction(SIGFPE, &sa, NULL)
                || sigaction(SIGSEGV, &sa, NULL)
                || sigaction(SIGBUS, &sa, NULL)
                || sigaction(SIGUSR1, &sa, NULL)
                || sigaction(SIGUSR2, &sa, NULL) )
        {
            logmsg(_("HHCIN003S Cannot register SIGILL/FPE/SEGV/BUS/USR "
                     "handler: %s\n"),
                   strerror(errno));
            delayed_exit(1);
        }
    }
#endif /*!defined(NO_SIGABEND_HANDLER)*/

    /* Build system configuration */
    build_config (cfgfile);

    /* System initialisation time */
    sysblk.todstart = hw_clock() << 8;

#ifdef OPTION_MIPS_COUNTING
    /* Initialize "maxrates" command reporting intervals */
    curr_int_start_time = time( NULL );
    prev_int_start_time = curr_int_start_time;
#endif

#if !defined(NO_SIGABEND_HANDLER)
    /* Start the watchdog */
    if ( create_thread (&sysblk.wdtid, DETACHED,
                        watchdog_thread, NULL, "watchdog_thread") )
    {
        logmsg(_("HHCIN004S Cannot create watchdog thread: %s\n"),
               strerror(errno));
        delayed_exit(1);
    }
#endif /*!defined(NO_SIGABEND_HANDLER)*/

#ifdef OPTION_SHARED_DEVICES
    /* Start the shared server */
    if (sysblk.shrdport)
        if ( create_thread (&sysblk.shrdtid, DETACHED,
                            shared_server, NULL, "shared_server") )
        {
            logmsg(_("HHCIN006S Cannot create shared_server thread: %s\n"),
                   strerror(errno));
            delayed_exit(1);
        }

    /* Retry pending connections */
    {
        DEVBLK *dev;
        TID     tid;

        for (dev = sysblk.firstdev; dev != NULL; dev = dev->nextdev)
            if (dev->connecting)
                if ( create_thread (&tid, DETACHED,
                                    *dev->hnd->init, dev, "device connecting thread")
                   )
                {
                    logmsg(_("HHCIN007S Cannot create %4.4X connection thread: %s\n"),
                           dev->devnum, strerror(errno));
                    delayed_exit(1);
                }
    }
#endif

    /* Start up the RC file processing thread */
    create_thread(&rctid,DETACHED,
                  process_rc_file,NULL,"process_rc_file");

    if(log_callback)
    {
        // 'herclin' called us. IT'S in charge. Create its requested
        // logmsg intercept callback function and return back to it.
        create_thread(&logcbtid,DETACHED,
                      log_do_callback,NULL,"log_do_callback");
        return(0);
    }

    //---------------------------------------------------------------
    // The below functions will not return until Hercules is shutdown
    //---------------------------------------------------------------

    /* Activate the control panel */
    if(!sysblk.daemon_mode)
        panel_display ();
    else
    {
#if defined(OPTION_DYNAMIC_LOAD)
        if(daemon_task)
            daemon_task ();
        else
#endif /* defined(OPTION_DYNAMIC_LOAD) */
        {
            /* Tell RC file and HAO threads they may now proceed */
            sysblk.panel_init = 1;

            /* Retrieve messages from logger and write to stderr */
            while (1)
                if((msgcnt = log_read(&msgbuf, &msgnum, LOG_BLOCK)))
                    if(isatty(STDERR_FILENO))
                        fwrite(msgbuf,msgcnt,1,stderr);
        }
    }

    //  -----------------------------------------------------
    //      *** Hercules has been shutdown (PAST tense) ***
    //  -----------------------------------------------------

    ASSERT( sysblk.shutdown );  // (why else would we be here?!)

#ifdef _MSVC_
    SetConsoleCtrlHandler(console_ctrl_handler, FALSE);
    socket_deinit();
#endif
#ifdef DEBUG
    fprintf(stdout, _("IMPL EXIT\n"));
#endif
    fprintf(stdout, _("HHCIN099I Hercules terminated\n"));
    fflush(stdout);
    usleep(10000);
    return 0;
} /* end function main */
int main()
{

   socket_init();

   fp1 = fopen("raw_recv_data.txt","w");
   fp2 = fopen("increase_bit.txt","w");

   printf("my:hello fedora!\n");
if((testfd = ML605Open())<0)
   printf("open ml605 failed");

if(ML605StartEthernet(testfd, SFP_TX_START)<0) {
    printf("PCIe:Start ethernet failure\n");
	  ML605Close(testfd);
    exit(-1);
  }

/* pthread_t writethread;
  if (pthread_create(&writethread, NULL, mywrite, NULL)) 
  {
    perror("writethread process thread creation failed");
  }  
  sleep(1);
*/  

/*
  pthread_t readthread;
  if (pthread_create(&readthread, NULL, GetRate, NULL)) 
  {
    perror("readthread process thread creation failed");
  }  
  sleep(1);
*/  
  pthread_t ratathread;
/*

  if (pthread_create(&ratathread, NULL, myread2, NULL)) 
  {
    perror("readthread process thread creation failed");
  }
  pthread_t readthread2;
  if (pthread_create(&ratathread, NULL, myread, NULL)) 
  {
    perror("readthread process thread creation failed");
  }  
*/
  pthread_t readthread3;
  if (pthread_create(&ratathread, NULL, myread3, NULL)) 
  {
    perror("readthread process thread creation failed");
  }  
  sleep(1);


  char ch_input;
  scanf("%c", &ch_input);
  isclose=0;
  ML605Close(testfd);
  fclose(fp1);
  fclose(fp2);
}
Exemplo n.º 13
0
static void power_init(struct power_module *module)
{
    ALOGI("%s", __func__);
    socket_init();
}