void shutdown(int sig) {
  ROS_INFO("Disabling motors");
  send_vel(0, 0);
  port_close(0);
  port_close(1);
  exit(0);
}
Пример #2
0
void* handle_gps(int *arg)
{
	char one_line[512] = {0};
//	int ret = 0;
//	unsigned int count = 0;
	char *p = one_line;
	char ch = 0;
	int valid_flag = 0;
	
	NOTE("GPS Thread start...\n");
	int fd = open_gps_com("/dev/ttyS0");
	while(!exit_flag) {
		ch = get_char(fd);
		if(ch <=0)
			goto RECONN;
		if(ch == '$') {
			memset(one_line,0,512);
			p = one_line;
			*p = ch;
			valid_flag = 1;
		} else if(ch == '\r' || ch == '\n') {
			if(valid_flag) {
				//valid data is between '$' to '\r' or '\n'
				//tail add ','
				*p = ',';
				p++;
				*p = '\0';
// 				DEBUG("[%d][%s]\n",++count,one_line);
				parse_var(one_line,"/tmp/gps_info"); 
				//the all gps info,can not sleep here
			}
			valid_flag = 0;
		}
		if(valid_flag) {
			*p = ch;
			p++;
		}
		continue;
	RECONN:
		ERROR("Read GPS Com Error!%d:%s\n",errno,strerror(errno));
		if(fd >= 0) port_close(fd);
		sleep_seconds_intr(10);
		fd = open_gps_com("/dev/ttyS0");
	}
	NOTE("GPS Thread exit!\n");
	if(fd >= 0) port_close(fd);
	system("/bin/echo GPS_thread_EXIT > /tmp/gps_status");
	return NULL;
}
Пример #3
0
obj_ptr global_env(void)
{
    static obj_ptr _global = 0;
    if (!_global)
    {
        obj_ptr o;
        _global = CONS(obj_alloc_map(), NIL);
        gc_protect(_global);

        _env_add_primitive(_global, "+", _add);
        _env_add_primitive(_global, "*", _mul);
        _env_add_primitive(_global, "-", _sub);
        _env_add_primitive(_global, "/", _div);
        _env_add_primitive1(_global, "floor", _floor);
        _env_add_primitive1(_global, "++", _increment);
        _env_add_primitive1(_global, "--", _decrement);
        _env_add_primitive2(_global, "%", _mod);

        _env_add_primitive(_global, "<", _lt);
        _env_add_primitive(_global, "<=", _lte);
        _env_add_primitive(_global, ">", _gt);
        _env_add_primitive(_global, ">=", _gte);
        _env_add_primitive(_global, "=", _e);

        _env_add_primitive2(_global, "cons", _cons);
        _env_add_primitive1(_global, "car", _car);
        _env_add_primitive1(_global, "cdr", _cdr);
        _env_add_primitive1(_global, "null?", _nullp);

        _env_add_primitive0(_global, "gc", _gc);
        _env_add_primitive1(_global, "load", _load);
        _env_add_primitive0(_global, "quit", _quit);

        _env_add_primitive(_global, "vec-alloc", _vec_alloc);
        _env_add_primitive(_global, "vec-add", _vec_add);
        _env_add_primitive1(_global, "vec-length", _vec_length);
        _env_add_primitive1(_global, "vec-clear", _vec_clear);
        _env_add_primitive2(_global, "vec-get", _vec_get);
        _env_add_primitive3(_global, "vec-set", _vec_set);

        _env_add_primitive0(_global, "map-alloc", _map_alloc);
        _env_add_primitive3(_global, "map-add", _map_add);
        _env_add_primitive1(_global, "map-clear", _map_clear);
        _env_add_primitive1(_global, "map-size", _map_size);
        _env_add_primitive(_global, "map-find", _map_find);
        _env_add_primitive2(_global, "map-delete", _map_delete);
        _env_add_primitive1(_global, "map-keys", _map_keys);

        _env_add_primitive1(_global, "display", _display);

        o = _load_imp("prelude.ang", _global);
        if (ERRORP(o)) /* TODO */
        {
            port_ptr p = port_open_stdout();
            obj_print(o, p);
            port_close(p);
        }
    }
    return _global;    
}
Пример #4
0
void
renounce(void* obj, int size, void* refcon)
{
    if (PAIRP(obj)) return;
    int tc = HDR_TC(HDR(obj));
    assert(tc >= 0);
    assert(tc <= TC_MASKBITS);
    switch (tc) {
        case TC_HASHTABLE: {
            scm_hashtable_t ht = (scm_hashtable_t)obj;
            ht->lock.destroy();
            break;
        }
        case TC_WEAKHASHTABLE: {
            scm_weakhashtable_t ht = (scm_weakhashtable_t)obj;
            ht->lock.destroy();
            break;
        }
        case TC_PORT: {
            scm_port_t port = (scm_port_t)obj;
            {
                scoped_lock lock(port->lock);
                if (port->type != SCM_PORT_TYPE_CUSTOM) port_close(port);
            }
            port->lock.destroy();
            break;
        }
        case TC_SOCKET: {
            scm_socket_t socket = (scm_socket_t)obj;
            socket_close(socket);
            break;
        }
        case TC_SHAREDQUEUE: {
            scm_sharedqueue_t queue = (scm_sharedqueue_t)obj;
            queue->buf.destroy();
            queue->queue.destroy();
            break;
        }
        case TC_SHAREDBAG: {
            scm_sharedbag_t bag = (scm_sharedbag_t)obj;
            for (int i = 0; i < bag->capacity; i++) {
                bag->datum[i]->buf.destroy();
                bag->datum[i]->queue.destroy();
                free(bag->datum[i]->key);
                free(bag->datum[i]);
            }
            free(bag->datum);
            bag->lock.destroy();
            break;
        }
    }
}
Пример #5
0
int do_test_userland(const char *test_parm)
{
    (void) test_parm;

    char testdata[5];
    int res;
    int32_t code;


    strcpy(testdata, "abcd");

    SHOW_INFO0( 0, "port_create()");
    uland_port = port_create(1,    "__regress_test_port");

    test_check_ge(uland_port,0);


    SHOW_INFO0( 0, "port_write()");
    res = port_write(uland_port, 1, &testdata, sizeof(testdata));
    test_check_eq(res,0);

    testdata[0] = 0;

    SHOW_INFO0( 0, "port_read()");
    res = port_read_etc(uland_port, &code, &testdata, sizeof(testdata), PORT_FLAG_TIMEOUT, 1000000);
    test_check_eq(res,5);
    test_check_eq(code,0xAA);

    test_check_eq( strcmp(testdata, "abcd"), 0);


    SHOW_INFO0( 0, "port_read() - wait for userland to finish");
    res = port_read_etc(uland_port, &code, &testdata, sizeof(testdata), PORT_FLAG_TIMEOUT, 1000000);
    test_check_ge(res,0);
    test_check_eq(code,0x55);


    SHOW_INFO0( 0, "close port");
    res = port_close(uland_port);
    test_check_ne(res,0);

#if 0
    SHOW_INFO0( 0, "delete port");
    res = port_delete(test_p2);
    test_check_eq(res,0);
#endif
    SHOW_INFO0( 0, "end test");

    return 0;
}
Пример #6
0
void sig_interrupt(void)
{
	int i=3;
	int rval;

/*	We first set this variable to 1. Other threads know to stop their operation. TCP server does not
 *	accept new connections and serial server stops polling the serial port.
 */
	haltsystem = 1;

/*	Because if the nRoute is running as a daemon we can not receive keyboard interrupt we know that STDOUT is available for printf. */
	printf("Trying to close all threads and exit decently. Please wait 3 seconds...");
	while(i>0)
	{
		printf("\b\b\b\b\b\b\b\b\b\b\b\b%d seconds...", i);
		fflush(stdout);
		sleep(1);
		i--;
	}
	printf("\b\b\b\b\b\b\b\b\b\b\b\b0 seconds...\n");
	fflush(stdout);
	
/*	Close all open TCP connections. the tcp_conn_handler() should take care of all this when it exits but just to make things sure we check the
 *	connection table here also. 
 */

/*	for(i=0;i<nRdconf.tcpmaxconn;i++)
	{
		if(nRd_conn_table[i].active == 1)
			close(nRd_conn_table[i].fd);
	}
*/

/*	Close the serial port. */
	port_close();

/*	Remove the lock file but leave the LOCK_DIR intact. */

	if((rval = remove(nRouted_lockfile)) != 0)
	{
		logger(0, "Failed to remove lock file (%s), this might cause trouble when nRouted is started next time (stale lock file).\n", nRouted_lockfile);
	}
	
	printf("All done.\n");
	
	exit(1);
}
Пример #7
0
static obj_ptr _display(obj_ptr arg, obj_ptr env)
{
    port_ptr p = port_open_stdout();
    switch (TYPE(arg))
    {
    case TYPE_STRING:
        port_write_string(p, &STRING(arg));
        break;
    case TYPE_SYMBOL:
        port_write_cptr(p, SYMBOL(arg));
        break;
    default:
        obj_print(arg, p);
    }
    port_close(p);
    return NIL;
}
Пример #8
0
/***************************************************************
 Load
 ***************************************************************/
static obj_ptr _load_imp(cptr file, obj_ptr env)
{
    port_ptr p;
    obj_ptr  o = NIL;

    p = port_open_input_file(file);
    while (!port_eof(p))
    {
        o = obj_read(p);
        if (ERRORP(o)) break;
        o = obj_eval(o, env);
        if (ERRORP(o)) break;
        port_skip_while(p, isspace);
    }

    if (ERRORP(o))
        error_add_file_info(o, port_name(p), port_line(p));

    port_close(p);
    return o;
}
Пример #9
0
void port_test()
{
	char testdata[5];
	thread_id t;
	int res;
	int32 dummy;
	int32 dummy2;

	strcpy(testdata, "abcd");

	dprintf("porttest: port_create()\n");
	test_p1 = port_create(1,    "test port #1");
	test_p2 = port_create(10,   "test port #2");
	test_p3 = port_create(1024, "test port #3");
	test_p4 = port_create(1024, "test port #4");

	dprintf("porttest: port_find()\n");
	dprintf("'test port #1' has id %d (should be %d)\n", port_find("test port #1"), test_p1);

	dprintf("porttest: port_write() on 1, 2 and 3\n");
	port_write(test_p1, 1, &testdata, sizeof(testdata));
	port_write(test_p2, 666, &testdata, sizeof(testdata));
	port_write(test_p3, 999, &testdata, sizeof(testdata));
	dprintf("porttest: port_count(test_p1) = %d\n", port_count(test_p1));

	dprintf("porttest: port_write() on 1 with timeout of 1 sec (blocks 1 sec)\n");
	port_write_etc(test_p1, 1, &testdata, sizeof(testdata), PORT_FLAG_TIMEOUT, 1000000);
	dprintf("porttest: port_write() on 2 with timeout of 1 sec (wont block)\n");
	res = port_write_etc(test_p2, 777, &testdata, sizeof(testdata), PORT_FLAG_TIMEOUT, 1000000);
	dprintf("porttest: res=%d, %s\n", res, res == 0 ? "ok" : "BAD");

	dprintf("porttest: port_read() on empty port 4 with timeout of 1 sec (blocks 1 sec)\n");
	res = port_read_etc(test_p4, &dummy, &dummy2, sizeof(dummy2), PORT_FLAG_TIMEOUT, 1000000);
	dprintf("porttest: res=%d, %s\n", res, res == ERR_PORT_TIMED_OUT ? "ok" : "BAD");

	dprintf("porttest: spawning thread for port 1\n");
	t = thread_create_kernel_thread("port_test", port_test_thread_func, NULL);
	// resume thread
	thread_resume_thread(t);

	dprintf("porttest: write\n");
	port_write(test_p1, 1, &testdata, sizeof(testdata));

	// now we can write more (no blocking)
	dprintf("porttest: write #2\n");
	port_write(test_p1, 2, &testdata, sizeof(testdata));
	dprintf("porttest: write #3\n");
	port_write(test_p1, 3, &testdata, sizeof(testdata));

	dprintf("porttest: waiting on spawned thread\n");
	thread_wait_on_thread(t, NULL);

	dprintf("porttest: close p1\n");
	port_close(test_p2);
	dprintf("porttest: attempt write p1 after close\n");
	res = port_write(test_p2, 4, &testdata, sizeof(testdata));
	dprintf("porttest: port_write ret %d\n", res);

	dprintf("porttest: testing delete p2\n");
	port_delete(test_p2);

	dprintf("porttest: end test main thread\n");

}
Пример #10
0
int	user_port_close(port_id id)
{
	return port_close(id);
}
Пример #11
0
int main(int argc, char** argv) {
  int i, ret;

  struct sockaddr_in cliaddr;  // used by accept()
  int clilen;

  int conn_fd;  // fd for a new connection with client
  int file_fd;  // fd for file that we open for reading
  char buf[512];
  int buf_len;

  // Parse args.
  if (argc != 2) {
    fprintf(stderr, "usage: %s [port]\n", argv[0]);
    exit(1);
  }

  // Initialize server
  init_server((unsigned short) atoi(argv[1]));

  // Get file descripter table size and initize request table
  maxfd = getdtablesize();
  requestP = (request*) malloc(sizeof(request) * maxfd);
  if (requestP == NULL) {
    ERR_EXIT("out of memory allocating all requests");
  }
  for (i = 0; i < maxfd; i++) {
    init_request(&requestP[i]);
  }
  requestP[svr.listen_fd].conn_fd = svr.listen_fd;
  strcpy(requestP[svr.listen_fd].host, svr.hostname);

  // Loop for handling connections
  fprintf(stderr, "\nstarting on %.80s, port %d, fd %d, maxconn %d...\n", svr.hostname, svr.port, svr.listen_fd, maxfd);

  // my own variable
  fd_set rset, allset;
  FD_ZERO(&allset);
  FD_SET(svr.listen_fd, &allset);
  int monitor_fd = svr.listen_fd;
  int socket_fd;
  Porter* porter = port_init();
  int id, amount, price;

  while (1) {
    // TODO: Add IO multiplexing

    rset = allset;
    select(monitor_fd + 1, &rset, NULL, NULL, NULL);

    // new client connection
    if (FD_ISSET(svr.listen_fd, &rset)) {
      clilen = sizeof(cliaddr);
      conn_fd = accept(svr.listen_fd, (struct sockaddr*)&cliaddr, (socklen_t*)&clilen);
      if (conn_fd < 0) {
        if (errno == EINTR || errno == EAGAIN) continue;  // try again
        if (errno == ENFILE) {
          (void) fprintf(stderr, "out of file descriptor table ... (maxconn %d)\n", maxfd);
          continue;
        }
        ERR_EXIT("accept");
      }
      requestP[conn_fd].conn_fd = conn_fd;
      strcpy(requestP[conn_fd].host, inet_ntoa(cliaddr.sin_addr));
      fprintf(stderr, "getting a new request... fd %d from %s\n", conn_fd, requestP[conn_fd].host);

      // add new descriptor to set
      FD_SET(conn_fd, &allset);

      // extend the select() range
      if (conn_fd > monitor_fd) {
        monitor_fd = conn_fd;
      }
    }

    // check all client if data is ready
    for (i = svr.listen_fd+1; i <= monitor_fd; ++i) {
      socket_fd = requestP[i].conn_fd;
      if (FD_ISSET(socket_fd, &rset)) {
        ret = handle_read(&requestP[i]); // parse data from client to requestP[conn_fd].buf
        if (ret < 0) {
          fprintf(stderr, "bad request from %s\n", requestP[i].host);
          continue;
        }

#ifdef READ_SERVER
        id = atoi(requestP[i].buf);
        // sprintf(buf, "%s : %s\n",accept_read_header,requestP[i].buf);
        if (id <= 0 || id > 20) {
          sprintf(buf, "Operation failed.\n");
        }
        else if (port_read(porter, id, &amount, &price) == -1) {
          sprintf(buf, "This item is locked.\n");
        }
        else {
          sprintf(buf, "item%d $%d remain: %d\n", id, price, amount);
        }
        write(requestP[i].conn_fd, buf, strlen(buf));
#else
        if (requestP[i].wait_for_write != 1) {
          // wait_for_write is 1 means this socket is bidding to an item for changing
          id = atoi(requestP[i].buf);
          if (id <= 0 || id > 20) {
            sprintf(buf, "Operation failed.\n");
            write(requestP[i].conn_fd, buf, strlen(buf));
          }
          else if (port_write(porter, id) != 1) {
            sprintf(buf, "This item is locked.\n");
            write(requestP[i].conn_fd, buf, strlen(buf));
          }
          else {
            // This item is not locked by other process
            int j;
            for (j = svr.listen_fd+1; j <= monitor_fd; ++j) {
              if (j != i && requestP[j].wait_for_write == 1 && requestP[j].item == id) {
                sprintf(buf, "This item is locked.\n");
                write(requestP[i].conn_fd, buf, strlen(buf));
                break;
              }
            }
            if (j > monitor_fd) {
              // This item is not locked by other file descriptor
              sprintf(buf, "This item is modifiable.\n");
              write(requestP[i].conn_fd, buf, strlen(buf));
              requestP[i].wait_for_write = 1;
              requestP[i].item = id;
              continue;
            }
          }
        }
        else {
          // This socket is waiting for command such as buy, sell, price
          if (port_operate(porter, requestP[i].buf, buf, requestP[i].item) == 0)
            write(requestP[i].conn_fd, buf, strlen(buf));
          port_unlock(porter, requestP[i].item);
        }
#endif

        close(requestP[i].conn_fd);
        // clear socket descriptor from the set
        FD_CLR(socket_fd, &allset);
        free_request(&requestP[i]);
      }
    }
  }

  free(requestP);
  port_close(porter);
  return 0;
}
Пример #12
0
void
finalize(object_heap_t* heap, void* obj)
{
    // do not access shared object during finalize, it may collected.
    assert(heap->is_collectible(obj));
    if (PAIRP(obj)) {
        assert(false);
    }
    if (FLONUMP(obj)) {
        assert(false);
    }

    int tc = HDR_TC(HDR(obj));
    assert(tc >= 0);
    assert(tc <= TC_MASKBITS);
    switch (tc) {
        case TC_BIGNUM: {
            scm_bignum_t bignum = (scm_bignum_t)obj;
            if (bignum->elts != (digit_t*)((uintptr_t)bignum + sizeof(scm_bignum_rec_t))) {
                heap->deallocate_private(bignum->elts);
            }
            break;
        }
        case TC_SYMBOL: {
            scm_symbol_t symbol = (scm_symbol_t)obj;
            if (symbol->name != (char*)((uintptr_t)symbol + sizeof(scm_symbol_rec_t))) {
                heap->deallocate_private(symbol->name);
            }
            break;
        }
        case TC_STRING: {
            scm_string_t string = (scm_string_t)obj;
            if (string->name != (char*)((uintptr_t)string + sizeof(scm_string_rec_t))) {
                heap->deallocate_private(string->name);
            }
            break;
        }
        case TC_VECTOR: {
            scm_vector_t vector = (scm_vector_t)obj;
            if (vector->elts != (scm_obj_t*)((uintptr_t)vector + sizeof(scm_vector_rec_t))) {
                heap->deallocate_private(vector->elts);
            }
            break;
        }
        case TC_BVECTOR: {
            scm_bvector_t bvector = (scm_bvector_t)obj;
            if (HDR_BVECTOR_MAPPING(bvector->hdr) == 0) heap->deallocate_private(bvector->elts);
            break;
        }
        case TC_TUPLE: {
            scm_tuple_t tuple = (scm_tuple_t)obj;
            if (tuple->elts != (scm_obj_t*)((uintptr_t)tuple + sizeof(scm_tuple_rec_t))) {
                heap->deallocate_private(tuple->elts);
            }
            break;
        }
        case TC_VALUES: {
            scm_values_t values = (scm_values_t)obj;
            if (values->elts != (scm_obj_t*)((uintptr_t)values + sizeof(scm_values_rec_t))) {
                heap->deallocate_private(values->elts);
            }
            break;
        }
        case TC_HASHTABLE: {
            scm_hashtable_t ht = (scm_hashtable_t)obj;
            heap->deallocate_private(ht->datum);
            ht->lock.destroy();
            break;
        }
        case TC_WEAKHASHTABLE: {
            scm_weakhashtable_t ht = (scm_weakhashtable_t)obj;
            heap->deallocate_private(ht->datum);
            ht->lock.destroy();
            break;
        }
        case TC_PORT: {
            scm_port_t port = (scm_port_t)obj;
            {
                scoped_lock lock(port->lock);
                if (port->type != SCM_PORT_TYPE_CUSTOM) port_close(port);
                // todo: finalizer for custom port
            }
            port->lock.destroy();
            break;
        }
        case TC_SOCKET: {
            scm_socket_t socket = (scm_socket_t)obj;
            socket_close(socket);
            break;
        }
        case TC_SHAREDQUEUE: {
            scm_sharedqueue_t queue = (scm_sharedqueue_t)obj;
            queue->buf.destroy();
            queue->queue.destroy();
            break;
        }
        case TC_SHAREDBAG: {
            scm_sharedbag_t bag = (scm_sharedbag_t)obj;
            for (int i = 0; i < bag->capacity; i++) {
                bag->datum[i]->buf.destroy();
                bag->datum[i]->queue.destroy();
                free(bag->datum[i]->key);
                free(bag->datum[i]);
            }
            free(bag->datum);
            bag->lock.destroy();
            break;
        }
    }
}
Пример #13
0
int main(int argc, char *argv[])
{
    struct termios ter, oldter;
    int portfd, status;

    portfd = port_open("/dev/ttyS0");
    if(portfd < 0) {
        exit(EXIT_FAILURE);
    }

    /* Save current port settings for restore it later. */
    tcgetattr(portfd, &oldter);

    /* Avoid all bits in new structure. */
    memset(&ter, 0, sizeof(ter));
    port_init(portfd, &ter);

    /* Set high level signal on DTR line. */
    ioctl(portfd, TIOCMGET, &status);    
    status |= TIOCM_DTR;
    status |= TIOCM_RTS;
    ioctl(portfd, TIOCMSET, &status);
    
    /* Flush input/output buffers of the port. */
    tcflush(portfd, TCIOFLUSH);
    
    /* Interactive I/O loop. */
    while("All humans alive") {
        char buf[256];
        int buflen;
        
        printf("for quit, type 'q'(for help, type '?') "
               "else send string to port:\n");
        printf("> ");
        
        fgets(buf, 256, stdin);
        buflen = strlen(buf);
        /* Skip newline character. */
        buf[buflen - 1] = '\0';
        
        if(!strcmp(buf, "q")) {
            break;
        } else if(!strcmp(buf, "?")) {
            printf("some help.\n");
        } else {
            if(port_write(portfd, buf, buflen) < 0) {
                printf("Some error occured when send data to device.\n");
            } else {
                usleep(500000);
                buflen = port_read(portfd, buf, 256);
                if(buflen < 0) {
                    printf("Some error occered when read data from device.\n");
                }
                printf("Read %d bytes: %s\n", buflen, buf);
            }
        }
    }

    exit:
    /* Restore old port settings. */
    tcsetattr(portfd, TCSANOW, &oldter);
    status &= ~TIOCM_DTR;
    status &= ~TIOCM_RTS;
    ioctl(portfd, TIOCMSET, &status);
    
    /* Close port. */
    port_close(portfd);
    
    return 0;
}
Пример #14
0
static void do_syscall_sw( uuprocess_t *u, struct trap_state *st)
{
#if HAVE_UNIX
    int callno = st->eax;

    /*
    unsigned int mina = 0, maxa = 0;
    {
        extern struct real_descriptor 	ldt[];

        struct real_descriptor  dsd = ldt[ st->ds/8 ];
        mina = dsd.base_low | (dsd.base_med << 16) | (dsd.base_high << 24);
        maxa = (dsd.limit_low | dsd.limit_high << 16);
        if( dsd.granularity & SZ_G)
            maxa *= PAGE_SIZE;
        maxa += mina;
        }
    */


    //phantom_thread_t *t = GET_CURRENT_THREAD();
    //uuprocess_t *u = t->u;

    /*
    tid_t tid = get_current_tid();
    pid_t pid;
    assert( !t_get_pid( tid, &pid ));
    uuprocess_t *u = proc_by_pid(pid);
    */

    assert( u != 0 );

    unsigned int mina = (int)u->mem_start, maxa = (int)u->mem_end;

    // trap state is good for interrupt.
    // call gate does not push eflags
    int user_esp = st->eflags;

#ifndef ARCH_ia32
#  warning machdep ia32 arg pass convention
#endif
    // list of user syscsall arguments
    int *uarg = adjustin( user_esp, st );
    uarg++; // syscall func return addr

    //SHOW_FLOW( 10, "Syscall pid %2d tid %2d, our esp %p, user esp %p, t kstack %p", u->pid, t->tid, &st, user_esp, t->kstack_top );
    SHOW_FLOW( 8, "Syscall %d args %x, %x, %x", callno, uarg[0], uarg[1],uarg[2] );

    int ret = 0;
    int err = 0;


    switch(callno)
    {
    case SYS__exit:
        // TODO housekeeping?
        SHOW_FLOW( 2, "exit %d", uarg[0] );
        hal_exit_kernel_thread();
        err = ENOSYS;
        break;

    case SYS_ssyslog:
        syslog( uarg[0], "%s", (const char *)adjustin( uarg[1], st ) );
        SHOW_FLOW( 2, "syslog %d %s", uarg[0], (const char *)adjustin( uarg[1], st ) );
        //SHOW_ERROR0( 0, "syslog not impl" );
        break;





    case SYS_sleepmsec:
        //SHOW_FLOW( 2, "sleepmsec %d", uarg[0] );
        hal_sleep_msec(uarg[0]);
        break;



    case SYS_getpagesize:       ret = PAGE_SIZE; break;

    case SYS_personality:
        if( ((unsigned) uarg[0]) == 0xffffffff)
        {
            ret = 0; // Say we're Linux... well...to some extent.
            break;
        }
        err = EINVAL;
        break;

    case SYS_uname:
        err = copyout(uarg[0], mina, maxa, &phantom_uname, sizeof(phantom_uname) );
        if( err ) ret = -1;
        break;


    case SYS_getuid:            ret = u->uid; break;
    case SYS_getuid32:          ret = u->uid;; break;
    case SYS_getegid:           ret = u->egid; break;
    case SYS_getegid32:         ret = u->egid; break;
    case SYS_geteuid:           ret = u->euid; break;
    case SYS_geteuid32:         ret = u->euid; break;
    case SYS_getgid:            ret = u->gid; break;
    case SYS_getgid32:          ret = u->gid; break;

    case SYS_gettid:            ret = get_current_tid(); break;
    case SYS_getpid:            ret = u->pid; break;
    case SYS_getpgrp:           ret = u->pgrp_pid; break;
    case SYS_getppid:           ret = u->ppid; break;

    case SYS_getpgid:
        goto unimpl;

    case SYS_time:
        {
            time_t t = time(0);

            AARG(time_t *, tp, 0, sizeof(time_t));

            *tp = t;
            ret = t;
            break;
        }
    case SYS_nanosleep:
        // todo check for POSIX compliance, make it interruptible by signals
        //int nanosleep(const struct timespec *, struct timespec *);
        {
            goto unimpl;
            //AARG(struct timespec *,  req_time, 0, sizeof(struct timespec));
            //AARG(struct timespec *, rest_time, 1, sizeof(struct timespec));
            //ret = usys_nanosleep( &err, u, req_time, rest_time );
            //break;
        }


    case SYS_sync:
    case SYS_sysinfo:
    case SYS_sysfs:
    case SYS_klogctl:

    case SYS_shutdown:
    case SYS_reboot:



    case SYS_getitimer:
    case SYS_setitimer:
    case SYS_gettimeofday:


    case SYS_setuid:
    case SYS_setuid32:          CHECK_CAP(CAP_SETUID); u->euid = uarg[0]; break;

    case SYS_setgid:            
    case SYS_setgid32:          CHECK_CAP(CAP_SETGID); u->egid = uarg[0]; break;

    case SYS_setgroups:
    case SYS_setgroups32:
        goto unimpl;

    case SYS_setpgid:
    case SYS_setregid:
    case SYS_setregid32:
    case SYS_setresgid:
    case SYS_setresgid32:
    case SYS_setresuid:
    case SYS_setresuid32:
    case SYS_setreuid:
    case SYS_setreuid32:
        goto unimpl;

    case SYS_open:              ret = usys_open(&err, u, adjustin( uarg[0], st ), uarg[1], uarg[2] ); break;
    case SYS_close:             ret = usys_close(&err, u, uarg[0] ); break;
    case SYS_read:
        {
            int count = uarg[2];
            void *addr = adjustin( uarg[1], st );
            CHECKA(addr,count);
            ret = usys_read(&err, u, uarg[0], addr, count );
            break;
        }
    case SYS_write:
        {
            int count = uarg[2];
            void *addr = adjustin( uarg[1], st );
            CHECKA(addr,count);
            ret = usys_write(&err, u, uarg[0], addr, count );
            break;
        }
    case SYS_lseek: ret = usys_lseek(&err, u, uarg[0], uarg[1], uarg[2] ); break;
    case SYS_creat: ret = usys_creat(&err, u, adjustin( uarg[0], st ), uarg[1] ); break;
    case SYS_chdir:
        {
            AARG(const char *, path, 0, 0);
            ret = usys_chdir(&err, u, path );
            break;
        }

    case SYS_pipe:
        {
            AARG(int *, fds, 0, sizeof(int) * 2);
            ret = usys_pipe( &err, u, fds );
            break;
        }

    case SYS_rmdir:
    case SYS_unlink:
        {
            AARG(const char *, name, 0, 1);
            ret = usys_rm( &err, u, name );
            break;
        }


    case SYS_dup:
        ret = usys_dup( &err, u, uarg[0] );
        break;

    case SYS_dup2:
        ret = usys_dup2( &err, u, uarg[0], uarg[1] );
        break;

    case SYS_symlink:
        {
            AARG(const char *, n1, 0, 1);
            AARG(const char *, n2, 1, 1);
            ret = usys_symlink( &err, u, n1, n2 );
            break;
        }

    case SYS_getcwd:
        {
            AARG(char *, buf, 0, uarg[1]);
            ret = usys_getcwd( &err, u, buf, uarg[1] );
            break;
        }

    case SYS_mkdir:
        {
            AARG(const char *, path, 0, 2);
            ret = usys_mkdir( &err, u, path );
            break;
        }

    case SYS_link:
    case SYS__llseek:
    case SYS_chroot:
    case SYS_lstat64:
    case SYS_mknod:
        goto unimpl;

    case SYS_mount:
        {
            const char *source = adjustin( uarg[0], st );
            CHECKA(source,0);
            const char *target = adjustin( uarg[1], st );
            CHECKA(target,0);
            const char *fstype = adjustin( uarg[2], st );
            CHECKA(target,0);
            const void *data = adjustin( uarg[4], st );
            CHECKA(data,0);

            ret = usys_mount(&err, u, source, target, fstype, uarg[3], data );
            break;
        }
    case SYS_umount:
        {
            const char *target = adjustin( uarg[0], st );
            CHECKA(target,0);
            ret = usys_umount(&err, u, target, 0 );
            break;
        }

    /*
    case SYS_umount2:
        {
            const char *target = adjustin( uarg[0], st );
            CHECKA(target);
            ret = usys_umount(&err, u, target, uarg[1] );
            break;
        }
    */

    case SYS_truncate:
        {
            AARG(const char *, path, 0, 0);
            ret = usys_truncate(&err, u, path, uarg[1] );
            break;
        }
    case SYS_ftruncate:
        {
            ret = usys_ftruncate(&err, u, uarg[0], uarg[1] );
            break;
        }

    case SYS_truncate64:
    case SYS_ftruncate64:
        goto unimpl;

    case SYS_fchdir:
        ret = usys_fchdir( &err, u, uarg[0] );
        break;

    case SYS_readdir:
        {
            AARG(struct dirent *, ent, 1, sizeof(struct dirent));
            ret = usys_readdir( &err, u, uarg[0], ent );
            break;
        }
    case SYS_fchmod:
        ret = usys_fchmod( &err, u, uarg[0], uarg[1] );
        break;

    case SYS_fchown:
    case SYS_fchown32:
        ret = usys_fchown( &err, u, uarg[0], uarg[1], uarg[2] );
        break;

    case SYS_fcntl:
        {
            //AARG(void *, str, 2, sizeof(int)); // FIXME size of arg?
            ret = usys_fcntl( &err, u, uarg[0], uarg[1], uarg[0] );
        }
        break;

    case SYS_fcntl64:
    case SYS_fdatasync:
    case SYS_flock:

    case SYS_fstat64:
    case SYS_fstatfs:
    case SYS_fsync:

    case SYS_utime:
    case SYS_chmod:
    case SYS_chown:
    case SYS_chown32:
    case SYS_access:
    case SYS_lchown:
    case SYS_lchown32:
    case SYS_pread:
    case SYS_pwrite:
        goto unimpl;

    case SYS_readv:
        {
            int fd = uarg[0];
            int iovcnt = uarg[2];
            AARG(struct iovec *, list, 1, sizeof(struct iovec) * iovcnt);

            unsigned int onerc;
            int lp;

            for( lp = 0; lp < iovcnt; lp++ )
            {
                void *addr = adjustin( list[lp].iov_base, st );
                CHECKA(addr,list[lp].iov_len);
                onerc = usys_read(&err, u, fd, addr, list[lp].iov_len );

                /*
                if( onerc < 0 )
                {
                    ret = -1;
                    goto err_ret;
                }
                */
                ret += onerc;
                if( onerc < list[lp].iov_len )
                    break;
            }
            break;
        }

    case SYS_writev:
        {
            int fd = uarg[0];
            int iovcnt = uarg[2];
            AARG(struct iovec *, list, 1, sizeof(struct iovec) * iovcnt);

            unsigned int onerc;
            int lp;

            for( lp = 0; lp < iovcnt; lp++ )
            {
                void *addr = adjustin( list[lp].iov_base, st );
                CHECKA(addr,list[lp].iov_len);
                onerc = usys_write(&err, u, fd, addr, list[lp].iov_len );

                /*
                if( onerc < 0 )
                {
                    ret = -1;
                    goto err_ret;
                }
                */
                ret += onerc;
                if( onerc < list[lp].iov_len )
                    break;
            }
            break;
        }

    case SYS_readlink:
        goto unimpl;


    case SYS_gethostname:
        {
            int len = uarg[1];
            char *target = adjustin( uarg[0], st );
            CHECKA(target,len);
            ret = usys_gethostname(&err, u, target, len );
            break;
        }
    case SYS_sethostname:
        {
            int len = uarg[1];
            const char *target = adjustin( uarg[0], st );
            CHECKA(target,len);
            ret = usys_sethostname(&err, u, target, len );
            break;
        }



    case SYS_socket:
        ret = usys_socket( &err, u, uarg[0], uarg[1], uarg[2] );
        break;

    case SYS_setsockopt:
        {
            socklen_t optlen = uarg[4];
            AARG(const void *, optval, 3, optlen);
            ret = usys_setsockopt( &err, u, uarg[0], uarg[1], uarg[2], optval, optlen);
            break;
        }
    case SYS_getsockopt:
        {
            AARG(socklen_t *, optlen, 4, sizeof(socklen_t));
            AARG(void *, optval, 3, *optlen);
            ret = usys_getsockopt( &err, u, uarg[0], uarg[1], uarg[2], optval, optlen);
            break;
        }

    case SYS_getpeername:
        {
            AARG(socklen_t *, namelen, 2, sizeof(socklen_t));
            AARG(struct sockaddr *, name, 1, *namelen);
            ret = usys_getpeername( &err, u, uarg[0], name, namelen);
            break;
        }
    case SYS_getsockname:
        {
            AARG(socklen_t *, namelen, 2, sizeof(socklen_t));
            AARG(struct sockaddr *, name, 1, *namelen);
            ret = usys_getsockname( &err, u, uarg[0], name, namelen);
            break;
        }

    case SYS_bind:
        {
            AARG(const struct sockaddr *, addr, 1, sizeof(struct sockaddr));
            ret = usys_bind( &err, u, uarg[0], addr, uarg[2] );
            break;
        }

    case SYS_listen:
        ret = usys_listen( &err, u, uarg[0], uarg[1] );
        break;

    case SYS_accept:
        {
            AARG( socklen_t *, len, 2, sizeof(socklen_t));
            AARG( struct sockaddr *, acc_addr, 1, *len );
            ret = usys_accept( &err, u, uarg[0], acc_addr, len );
            break;
        }

    case SYS_recv:
        {
            int len = uarg[2];
            AARG( void *, buf, 0, len );
            ret =  usys_recv( &err, u, uarg[0], buf, len, uarg[3] );
            break;
        }

    case SYS_recvmsg:
        {
            AARG( struct msghdr *, msg, 0, sizeof(struct msghdr) );
            ret = usys_recvmsg( &err, u, uarg[0], msg, uarg[2] );
            break;
        }

    case SYS_send:
        {
            int len = uarg[2];
            AARG( const void *, buf, 0, len );
            ret =  usys_send( &err, u, uarg[0], buf, len, uarg[3] );
            break;
        }

    case SYS_sendmsg:
        {
            AARG( const struct msghdr *, msg, 0, sizeof(struct msghdr) );
            ret = usys_sendmsg( &err, u, uarg[0], msg, uarg[2] );
            break;
        }

    case SYS_sendto:
        {
            socklen_t tolen = uarg[5];
            AARG( const struct sockaddr *, to, 4, tolen );
            int len = uarg[2];
            AARG( const void *, buf, 0, len );
            ret =  usys_sendto( &err, u, uarg[0], buf, len, uarg[3], to, tolen );
            break;
        }

    case SYS_recvfrom:
        {
            AARG( socklen_t *, fromlen, 5, sizeof(socklen_t) );
            AARG( struct sockaddr *, from, 4, *fromlen );
            int len = uarg[2];
            AARG( void *, buf, 0, len );
            ret =  usys_recvfrom( &err, u, uarg[0], buf, len, uarg[3], from, fromlen );
            break;
        }



    case SYS_connect:
        // int connect(int socket, const struct sockaddr *address, socklen_t address_len);
        {
            int len = uarg[2];
            AARG( struct sockaddr *, acc_addr, 1, len );
            ret = usys_connect( &err, u, uarg[0], acc_addr, len );
            break;
        }

    case SYS_socketpair:
        {
            AARG( int *, sv, 3, sizeof(int) * 2 );
            ret = usys_socketpair( &err, u, uarg[0], uarg[1], uarg[2], sv );
            break;
        }




    case SYS_sendfile:
    case SYS_socketcall:
        goto unimpl;

    case SYS_nice:
        {
            // int nice = uarg[0];
            // set thr prio
            // break;
            goto unimpl;
        }

    case SYS_brk:
        goto unimpl;
        /*{
            ret = usys_sbrk( &err, u, uarg[0] );
            break;
        }*/

    case SYS_fork:
    case SYS_vfork:
        goto unimpl;

    case SYS_ioctl:
        {
            void *data = adjustin( uarg[2], st );
            CHECKA(data,0);
            ret = usys_ioctl( &err, u, uarg[0], uarg[1], data, uarg[3] );
            break;
        }

        int statlink;
    case SYS_lstat: statlink = 1; goto dostat;
    case SYS_stat: statlink = 0; goto dostat;

    dostat:
        {
            const char *path = adjustin( uarg[0], st );
            CHECKA(path,0);
            struct stat *data = adjustin( uarg[1], st );
            CHECKA(data,sizeof(struct stat));
            ret = usys_stat( &err, u, path, data, statlink );
            break;
        }

    case SYS_fstat:
        {
            struct stat *data = adjustin( uarg[1], st );
            CHECKA(data,sizeof(struct stat));
            ret = usys_fstat( &err, u, uarg[0], data, 0 );
            break;
        }

    case SYS_umask:
        {
            ret = u->umask;
            u->umask = uarg[0];
            break;
        }

    case SYS_kill:
        {
            ret = usys_kill( &err, u, uarg[0], uarg[1] );
            break;
        }

    case SYS_waitpid:
        {
            AARG(int *, addr, 1, sizeof(int));
            ret = usys_waitpid( &err, u, uarg[0], addr, uarg[2] );
            break;
        }

    case SYS_wait:
        {
            AARG(int *, addr, 0, sizeof(int));
            ret = usys_waitpid( &err, u, -1, addr, 0 );
            break;
        }


    case SYS_clone:
        goto unimpl;


    case SYS_madvise:
    case SYS_mincore:
    case SYS_mlock:
    case SYS_mlockall:
    case SYS_mmap:
    case SYS_mprotect:
    case SYS_mremap:
    case SYS_msync:
    case SYS_munlock:
    case SYS_munlockall:
    case SYS_munmap:
        goto unimpl;


        // NewOS/BeOS/Haiku
    case SYS_create_port:
        {
            // TODO check string length and final addr to be valid
            AARG(const char *, name, 1, 0);
            ret = port_create( uarg[0], name );
            break;
        }
    case SYS_close_port:
        ret = port_close( uarg[0] );
        break;
    case SYS_delete_port:
        ret = port_delete( uarg[0] );
        break;
    case SYS_find_port:
        {
            // TODO check string length and final addr to be valid
            AARG(const char *, name, 0, 0);
            ret = port_find(name);
            break;
        }
    case SYS_get_port_info:
        {
            AARG(struct port_info *, info, 1, sizeof(struct port_info));
            ret = port_get_info( uarg[0], info);
        }
    case SYS_get_port_bufsize:
        ret = port_buffer_size( uarg[0] );
        break;
    case SYS_get_port_bufsize_etc:
        ret = port_buffer_size_etc( uarg[0], uarg[1], uarg[2] );
        break;
    case SYS_get_port_count:
        ret = port_count( uarg[0] );
        break;
    case SYS_read_port:
        {
            AARG(int32_t *, msg_code, 1, sizeof(int32_t));
            AARG(void  *, msg_buffer, 2, uarg[3]);
            ret = port_read( uarg[0],
                             msg_code,
                             msg_buffer,
                             uarg[3]);
            break;
        }
    case SYS_write_port:
        {
            //AARG(int32_t *, msg_code, 1, sizeof(int32_t));
            //AARG(int32_t, msg_code, 1, sizeof(int32_t));
            AARG(void  *, msg_buffer, 2, uarg[3]);
            ret = port_write( uarg[0],
                             uarg[1],
                             msg_buffer,
                             uarg[3]);
            break;
        }
    case SYS_read_port_etc:
    case SYS_write_port_etc:
    case SYS_set_port_owner:
    case SYS_get_next_port_info:
        goto unimpl;

    case SYS_phantom_run:
        {
            // extern int phantom_run(const char *fname, const char **argv, const char **envp, int flags);
            AARG(const char  *, fname, 0, 1);

            AARG(const char **, uav,   1, 4);
            AARG(const char **, uep,   2, 4);

            if( 0 == uarg[1] ) uav = 0;
            if( 0 == uarg[2] ) uep = 0;

            SHOW_FLOW( 2, "run %s flags 0x%b", fname, uarg[3], "\020\1<WAIT>\2<NEWWIN>\3<NEWPGRP>" );

            char *a[1024];
            char *e[1024];

            SHOW_FLOW( 2, "run %s load args", fname );

            if(
               user_args_load( mina, maxa, a, 1024, uav ) ||
               user_args_load( mina, maxa, e, 1024, uep )
              )
            {
                ret = -1;
                err = EFAULT;
                SHOW_ERROR( 0, "fault reading args for %s", fname );
                goto err_ret;
            }

            ret = usys_run( &err, u, fname, (const char**)a, (const char**)e, uarg[3] );
            break;
        }

    case SYS_phantom_method:
        // AARG(const char *, m_name, 0, 1);
        // int nfd = aarg[1];
        // AARG(int *, fds, 0, sizeof(int)*nfd);

        // ret = usys_pmethod( &err, u, m_name, int nfd, int fds[] );

    case SYS_phantom_toobject:
    case SYS_phantom_fromobject:
    case SYS_phantom_intmethod:
    case SYS_phantom_strmethod:
        goto unimpl;

        // extern int phantom_runclass(const char *cname, int nmethod, int flags);
    case SYS_phantom_runclass:
        {
            AARG(const char  *, cname, 0, 1);
            unsigned flags = uarg[2];

            if(flags)
                SHOW_ERROR( 0, "SYS_phantom_runclass: unknown flags %x" , flags );

            usys_phantom_runclass( &err, u, cname, uarg[1] );
            ret = err;
        }
        break;

    case SYS_setproperty:
        {
            AARG(const char *, pName, 1, 1); // TODO check zero term string!
            AARG(const char *, pValue, 2, 1);

            usys_setproperty( &err, u, uarg[0], pName, pValue );
            ret = err;
        }
        break;

    case SYS_getproperty:
        {
            AARG(const char *, pName, 1, 1); // TODO check zero term string!
            AARG(char *, pValue, 2, uarg[3]);

            usys_getproperty( &err, u, uarg[0], pName, pValue, uarg[3] );
            ret = err;
        }
        break;

    case SYS_listproperties:
        {
            AARG(char *, buf, 2, uarg[3]);
            usys_listproperties( &err, u, uarg[0], uarg[1], buf, uarg[3] );
            ret = err;
        }
        break;


    case SYS_name2ip:
        {
            AARG(in_addr_t *, out, 0, sizeof(in_addr_t));
            AARG(const char *, name, 1, 1);

            ret = name2ip( out, name, uarg[2] );
            if( ret != 0 ) err = ret;
        }
        break;


    case SYS_sigpending:
        {
            AARG(sigset_t *, set, 0, sizeof(sigset_t *));
            ret = usys_sigpending( &err, u, set);
            break;
        }

    case SYS_signal:
        {
#if 0
            AARG(sighandler_t, hand, 1, sizeof(sighandler_t));
            hand = usys_signal( &err, u, uarg[0], hand);
            // FIXME 64 bit error
            ret = ((int)hand) - mina; // Convert pointer back
#else
            // We do not use pointer (ret and uarg 1), so we don't have to convert it
            ret = (int)usys_signal( &err, u, uarg[0], (void *)uarg[1]);
#endif
            break;
        }

    case SYS_sigprocmask:
    //case raise:
    case SYS_sigaction:
    case SYS_siginterrupt:
    case SYS_sigsuspend:
        goto unimpl;


    unimpl:
        SHOW_ERROR( 0, "Unimplemented syscall %d called", callno );
        err = ENOSYS;
        break;

    default:
        SHOW_ERROR( 0, "Unknown syscall %d called", callno );
        err = ENOSYS;
        break;
    }

#else // HAVE_UNIX
    int err = ENOSYS;
    int ret = -1;
    goto err_ret; // to clear warning
#endif // HAVE_UNIX

err_ret:

#ifdef ARCH_ia32
#define _RET_OK
    st->eax = ret;
    st->edx = err;
#endif

#ifdef ARCH_mips
#define _RET_OK
    st->r2 = ret; // v0 (normal ret register, low)
    st->r3 = err; // v1 (normal ret register, hi)
#endif

#ifdef ARCH_arm
#define _RET_OK
    st->r0 = ret; // normal ret register
    st->r1 = err; // arg1 reg, we can safely use for return of errno
#endif

#ifndef _RET_OK
#error arch ret
#endif

}
Пример #15
0
BinMode::~BinMode()
{
	port_close();
}
Пример #16
0
void* handle_agps(int *arg)
{
	char ttydev[32] = {0};
	char atcfgfile[64] = {0};
	char one_line[512] = {0};
	char *p = one_line;
	char ch = 0;
	int valid_flag = 0;
    int count = 0;
	int fd = -1;
	
	NOTE("AGPS Thread start...\n");
WAIT_TYPE:
	read_file("/tmp/modem_type",one_line,64);
	if(strstr(one_line,"EC20")) {
		strcpy(ttydev,"/dev/ttyUSB1");
		strcpy(atcfgfile,"/etc/gcom/longsangagps.gcom");
	} else if(strstr(one_line,"LONGSUNG")) {
		strcpy(ttydev,"/dev/ttyUSB3");
		strcpy(atcfgfile,"/etc/gcom/ec20agps.gcom");
	} else {
		NOTE("AGPS Thread wait modem_type [%s]\n",one_line);
		sleep_seconds_intr(3);
		memset(one_line,0,sizeof(one_line));
		goto WAIT_TYPE;
	}
	
	if(access(ttydev,F_OK) == 0) {
		NOTE("send AGPS Start AT CMD\n");
		sprintf(one_line,"/usr/bin/gcom -d %s -s %s > /tmp/agps_status",ttydev,atcfgfile);
		//system(one_line); // exec at 3g.sh
	}
	
	NOTE("AGPS dev is %s\n",ttydev);
	NOTE("AGPS AT cmd is %s\n",atcfgfile);
	while(!exit_flag) {
		if(access(ttydev,F_OK) != 0) {
			ERROR("APGS:DEV %s is not exist!\n",ttydev);
			if(fd > 0) port_close(fd);
			fd = -1;
			sleep_seconds_intr(120);
			continue;
		}
		
		if(fd < 0) {
			NOTE("APGS: Reopen GPS dev %s\n",ttydev);
			fd = open_gps_com(ttydev);
			if(fd < 0)
				goto RECONN;
		}
		ch = get_agps_char(fd);
		if(ch < 0)
			goto RECONN;
		if(ch == '$') {
			memset(one_line,0,512);
			p = one_line;
			*p = ch;
			valid_flag = 1;
			count = 0;
		} else if(ch == '\r' || ch == '\n' || count >510) {
			if(valid_flag) {
				//valid data is between '$' to '\r' or '\n'
				//add ',' tail
				*p = ',';
				p++;
				*p = '\0';
 				//printf("[%d][%s]\n",++count,one_line);
				parse_var(one_line,"/tmp/agps_info"); 
				//the all gps info,can not sleep here
			}
			valid_flag = 0;
			count = 0;
		}
		if(valid_flag) {
			*p = ch;
			p++;
			count++;
		}
		continue;
	RECONN:
		ERROR("Read AGPS Com Error!%d:%s\n",errno,strerror(errno));
		if(fd > 0) port_close(fd);
		fd = -1;
		sleep_seconds_intr(60);
	}
	NOTE("AGPS Thread exit! need to close AT ?\n");
	if(fd >0) port_close(fd);
	system("/bin/echo AGPS_thread_EXIT > /tmp/agps_status");
	return NULL;
}
Пример #17
0
void
VM::boot()
{
    try {
#if USE_DEBUG_BOOT
        {
            char load_path[] = "heap/debug-boot.vmi";
            m_bootport = make_file_port(m_heap, make_string_literal(m_heap, load_path), SCM_PORT_DIRECTION_IN, 0, SCM_PORT_BUFFER_MODE_BLOCK, scm_true);
            printf(";; loading \"%s\"\n", load_path);
            fflush(stdout);
            scoped_lock lock_port(m_bootport->lock);
            while (true) {
                reset();
                scm_obj_t obj = reader_t(this, m_bootport).read(NULL);
                if (obj == scm_eof) break;
                m_pc = obj;
                prebind(m_pc);
                run(false);
            }
            port_close(m_bootport);
        }
#else
        {
            scm_bvector_t bv = make_bvector_mapping(m_heap, (void*)s_bootimage, sizeof(s_bootimage));
            m_bootport = make_bytevector_port(m_heap, make_symbol(m_heap, "bootimage"), SCM_PORT_DIRECTION_IN, bv, scm_true);
            scoped_lock lock_port(m_bootport->lock);
            while (true) {
                reset();
                scm_obj_t obj = reader_t(this, m_bootport).read(NULL);
                if (obj == scm_eof) break;
                m_pc = obj;
                prebind(m_pc);
                run(false);
            }
            port_close(m_bootport);
        }
#endif
        m_bootport = (scm_port_t)scm_unspecified;
        m_current_environment = m_heap->m_interaction_environment;
#if USE_DEBUG_CORE
        {
            char load_path[] = "heap/debug-core.vmi";
            m_bootport = make_file_port(m_heap, make_string_literal(m_heap, load_path), SCM_PORT_DIRECTION_IN, 0, SCM_PORT_BUFFER_MODE_BLOCK, scm_true);
            printf(";; loading \"%s\"\n", load_path);
            fflush(stdout);
            scoped_lock lock_port(m_bootport->lock);
            while (true) {
                reset();
                scm_obj_t obj = reader_t(this, m_bootport).read(NULL);
                if (obj == scm_eof) break;
                m_pc = obj;
                prebind(m_pc);
                run(false);
            }
            port_close(m_bootport);
        }
#elif USE_INTERNED_CORE
        {
            scm_bvector_t bv = make_bvector_mapping(m_heap, (void*)s_coreimage, sizeof(s_coreimage));
            m_bootport = make_bytevector_port(m_heap, make_symbol(m_heap, "bootimage"), SCM_PORT_DIRECTION_IN, bv, scm_true);
            scoped_lock lock_port(m_bootport->lock);
            while (true) {
                reset();
                scm_obj_t obj = reader_t(this, m_bootport).read(NULL);
                if (obj == scm_eof) break;
                m_pc = obj;
                prebind(m_pc);
                run(false);
            }
            port_close(m_bootport);
        }
#endif
        m_bootport = (scm_port_t)scm_unspecified;
    } catch (vm_exception_t& e) {
        fatal("fatal in boot: unexpected vm_exception_t");
    } catch (reader_exception_t& e) {
        fatal("fatal in boot: unexpected reader_expecption_t(%s)", e.m_message);
    } catch (io_exception_t& e) {
        fatal("fatal in boot: unexpected io_expecption_t(%d, %s)", e.m_err, e.m_message);
    } catch (io_codec_exception_t& e) {
        fatal("fatal in boot: unexpected io_codec_exception_t(%d, %s)", e.m_operation, e.m_message);
    } catch (vm_escape_t& e) {
        fatal("fatal in boot: unexpected vm_escape_t, maybe <#subr escape> in bad context");
    } catch (vm_continue_t& e) {
        fatal("fatal in boot: unexpected vm_continue_t, maybe <#subr escape> in bad context");
    } catch (int code) {
        fatal("fatal in boot: unexpected system error (errno %d, %s)", code, strerror(code));
    } catch (...) {
        fatal("fatal in boot: unknown exception");
    }
  #if PROFILE_OPCODE
    memset(m_opcode_profile, 0, sizeof(m_opcode_profile));
  #endif
}
Пример #18
0
rs232_port::~rs232_port()
{
    port_close();
}