コード例 #1
0
static void handle_uevent(const char* udata)
{
    const char *str = udata;
    char path[PATH_MAX];
    char usb[2], ac[2];
    int type = NO_CHARGER;

    memset(usb, 0, 2);
    memset(ac, 0, 2);

        ALOGE("Type: %d", type);
        write_path(type);
        (!strncmp(str, USB, strlen(USB))) ;
        snprintf(path, sizeof(path), "%s/usb/online", POWER_SUPPLY_PATH);
        read_path(path, usb, 1);

        snprintf(path, sizeof(path), "%s/pm8921-dc/online", POWER_SUPPLY_PATH);
        read_path(path, ac, 1);

        if (!strncmp(usb, "1", 1)) {
            type = CHARGER_USB;
        } else if (!strncmp(ac, "1", 1)) {
            type = CHARGER_AC;
        }

        ALOGE("Type: %d", type);
        write_path(type);
    }
コード例 #2
0
static void command_open(char * token, Channel * c) {
    char path[FILE_PATH_SIZE];
    unsigned long flags = 0;
    FileAttrs attrs;
    int file = -1;
    int err = 0;
    OpenFileInfo * handle = NULL;

    read_path(&c->inp, path, sizeof(path));
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    flags = json_read_ulong(&c->inp);
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    memset(&attrs, 0, sizeof(FileAttrs));
    json_read_struct(&c->inp, read_file_attrs, &attrs);
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);

    if ((attrs.flags & ATTR_PERMISSIONS) == 0) {
        attrs.permissions = 0775;
    }
    file = open(path, to_local_open_flags(flags), attrs.permissions);

    if (file < 0) {
        err = errno;
    }
    else {
        handle = create_open_file_info(c, path, file, NULL);
    }

    write_stringz(&c->out, "R");
    write_stringz(&c->out, token);
    write_fs_errno(&c->out, err);
    write_file_handle(&c->out, handle);
    write_stream(&c->out, MARKER_EOM);
}
コード例 #3
0
static void command_mkdir(char * token, Channel * c) {
    char path[FILE_PATH_SIZE];
    FileAttrs attrs;
    int err = 0;
    int mode = 0777;

    read_path(&c->inp, path, sizeof(path));
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    memset(&attrs, 0, sizeof(FileAttrs));
    json_read_struct(&c->inp, read_file_attrs, &attrs);
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);

    if (attrs.flags & ATTR_PERMISSIONS) {
        mode = attrs.permissions;
    }
#if defined(_WRS_KERNEL)
    if (mkdir(path) < 0) err = errno;
#else
    if (mkdir(path, mode) < 0) err = errno;
#endif

    write_stringz(&c->out, "R");
    write_stringz(&c->out, token);
    write_fs_errno(&c->out, err);
    write_stream(&c->out, MARKER_EOM);
}
コード例 #4
0
ファイル: main.c プロジェクト: TRex22/DDS_Group_Work
int main(void){

	char c;
	int i=0, j=0, k=0;
	
	PQueue *min = pq_init();	
	char array[MAX_UNIQUE_CHARS];
	char freq[MAX_UNIQUE_CHARS];
	char path[MAX_LENGTH];
	
	gets(array);
	gets(freq);
	gets(path);
	
	int r=0;
	while(array[r]!=NULL){
		Tree *node= tree_init(freq[r]-'0', array[r]);
		pq_enqueue(min, node, freq[r]-'0');
		r+=2;		
	}
	
	while(min->size > 1){
		Tree *left=pq_dequeue(min);
		Tree *right=pq_dequeue(min);
		Tree *node=tree_merge(left, right);	
		pq_enqueue(min, node, node->root->freq);		
	}

	List *l=init_list(9);
	Stack *s=init_stack();
	
	l=recursive_Encoding(min->data[0]->root, s, l);
	
	read_path(min->data[0]->root, path);
}
コード例 #5
0
ファイル: ReaderWriterPaths.cpp プロジェクト: yueying/osg
osgDB::ReaderWriter::ReadResult ReaderWriterPaths::readObject(std::istream& fin, const osgDB::Options* options) const
{
    OSG_INFO<<"ReaderWriterPaths::readObject(std::istream& fin"<<std::endl;

    if (!options) return ReadResult::FILE_NOT_HANDLED;
    if (!fin) return ReadResult::ERROR_IN_READING_FILE;


    std::string filename = options->getPluginStringData("filename");

    std::string ext = osgDB::getLowerCaseFileExtension(filename);

    OSG_INFO<<"   filename found in options: "<<filename<<"  extension="<<ext<<std::endl;


    if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;


    if      (ext=="path") return read_path(fin, options);
    else if (ext=="material") return read_material(fin, options);
    else if (ext=="pivot_path") return read_pivot_path(fin, options);
    else if (ext=="rotation_path") return read_rotation_path(fin, options);

    return ReadResult::FILE_NOT_HANDLED;
}
コード例 #6
0
static void command_setstat(char * token, Channel * c) {
    char path[FILE_PATH_SIZE];
    FileAttrs attrs;
    int err = 0;

    read_path(&c->inp, path, sizeof(path));
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    memset(&attrs, 0, sizeof(FileAttrs));
    json_read_struct(&c->inp, read_file_attrs, &attrs);
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);

    if (attrs.flags & ATTR_SIZE) {
        if (truncate(path, attrs.size) < 0) err = errno;
    }
#if !defined(WIN32) && !defined(_WRS_KERNEL)
    if (attrs.flags & ATTR_UIDGID) {
        if (chown(path, attrs.uid, attrs.gid) < 0) err = errno;
    }
#endif
    if (attrs.flags & ATTR_PERMISSIONS) {
        if (chmod(path, attrs.permissions) < 0) err = errno;
    }
    if (attrs.flags & ATTR_ACMODTIME) {
        struct utimbuf buf;
        buf.actime = (long)(attrs.atime / 1000);
        buf.modtime = (long)(attrs.mtime / 1000);
        if (utime(path, &buf) < 0) err = errno;
    }

    reply_setstat(token, &c->out, err);
}
コード例 #7
0
static void command_rename(char * token, Channel * c) {
    char path[FILE_PATH_SIZE];
    char newp[FILE_PATH_SIZE];
    int err = 0;

    read_path(&c->inp, path, sizeof(path));
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    read_path(&c->inp, newp, sizeof(newp));
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);

    if (rename(path, newp) < 0) err = errno;

    write_stringz(&c->out, "R");
    write_stringz(&c->out, token);
    write_fs_errno(&c->out, err);
    write_stream(&c->out, MARKER_EOM);
}
コード例 #8
0
int main(int argc, char *argv[]) {
  if (argc != 3) {
    fprintf(stdout, "Usage: ./rmdir_eval [path] [fanout]\n");
    return -1;
  }

  int fanout = atoi(argv[2]);
  if (fanout > 9) {
    fprintf(stderr, "Too large fanout: %d > 9.\n", fanout);
    return -1;
  }
  char *prefix = argv[1];
  g_offset = strlen(prefix);

  char path[MAX_LEN];
  strcpy(path, prefix);

  int depth;
  for (depth = 0; depth < fanout; ++depth) {  
    write_path(path, depth, fanout - 1);
  }
  --depth;
  
  long tran_cnt = 0;
  struct timeval begin, end;
  gettimeofday(&begin, NULL);
  while (depth >= 0) {
    end_path(path, depth);
    // Transaction executes.
    // fprintf(stdout, "%s\n", path);
    if (rmdir(path) != 0) {
      fprintf(stderr, "Error: creating dir %s.\n", path);
      return -1;
    }
    ++tran_cnt;
    int cur, i;
    for (i = 0; i <= depth; ++i) {
      cur = read_path(path, i);
      if (cur > 0) {
        dec_path(path, i);
        break;
      } else {
        write_path(path, i, fanout - 1);        
      }
    }
    if (i == depth + 1) {
      --depth;
    }
  }
  gettimeofday(&end, NULL);

  double sec = end.tv_sec - begin.tv_sec + (double)(end.tv_usec - begin.tv_usec) / 1000000;
  fprintf(stdout, "# Evaluation of rmdir()\n"
         "# Transaction Count # Time (s) # Transactions per Second\n"
         "%ld\t%.2f\t%.2f\n", tran_cnt, sec, tran_cnt / sec);
  return 0;
}
コード例 #9
0
static void command_symlink(char * token, Channel * c) {
    char link[FILE_PATH_SIZE];
    char target[FILE_PATH_SIZE];
    int err = 0;

    read_path(&c->inp, link, sizeof(link));
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    read_path(&c->inp, target, sizeof(target));
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);

#if defined(WIN32) || defined(_WRS_KERNEL)
    err = ENOSYS;
#else
    if (symlink(target, link) < 0) err = errno;
#endif

    write_stringz(&c->out, "R");
    write_stringz(&c->out, token);
    write_fs_errno(&c->out, err);
    write_stream(&c->out, MARKER_EOM);
}
コード例 #10
0
static void command_lstat(char * token, Channel * c) {
    char path[FILE_PATH_SIZE];
    struct stat buf;
    int err = 0;

    read_path(&c->inp, path, sizeof(path));
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);

    memset(&buf, 0, sizeof(buf));
    if (lstat(path, &buf) < 0) err = errno;

    reply_stat(token, &c->out, err, &buf);
}
コード例 #11
0
int
mtree_reader_read_path(struct mtree_reader *r, const char *path,
    struct mtree_entry **entries)
{
	int ret;

	r->entries = NULL;
	ret = read_path(r, path, &r->entries, NULL);
	if (ret == -1)
		return (-1);

	ret = finish_entries(r, entries);

	mtree_reader_reset(r);
	return (ret);
}
コード例 #12
0
ファイル: dijkstra.c プロジェクト: kjrz/porr
int *dijkstra_algorithm(float **graph) {
  int i, u, v, alt;                      // utility variables
  int Q[GRAPHSIZE] = {0};                // empty Q

  float dist[GRAPHSIZE];
  for (i = 0; i < GRAPHSIZE; i++)
    dist[i] = INFINITY;
	
  int visited [GRAPHSIZE] = {0};         // mark all nodes as unvisited
  int previous[GRAPHSIZE] = {0};         // previous node in optimal path 
                                         // from source

  dist[0] = 0;                           // distance from source to itself is zero
  Q   [0] = 1;                           // start off with the source node

  while (not_empty(Q)) {
    u = find_u(Q, dist, visited);        // see function desc
    if (u == TARGET)                     // terminate once target is reached
      break;

    Q[u]       = 0;                      // remove this node from Q
    visited[u] = 1;                      // mark it as visited

    for (v = 0; v < GRAPHSIZE; v++) {
      if (!graph[u][v] == INFINITY)      // neighbours only
	continue;

      alt = dist[u] + graph[u][v];       // accumulate shortest distance 
                                         // from source
      if (alt < dist[v]) {
	dist[v] = alt;                   // keep the shortest distance
                                         // from source to v
	previous[v]  = u;

	if (!visited[v])	         // add unvisited v to Q
          Q[v] = 1;                      // to be processed
      }
    }
  }
	
  return read_path(previous);
}
コード例 #13
0
ファイル: duffdriver.c プロジェクト: carriercomm/duff
/* Initializes the driver, processes the specified arguments and reports the
 * clusters found.
 */
void process_args(int argc, char** argv)
{
    size_t i;

    memset(&recorded_dirs, 0, sizeof(DirList));

    for (i = 0;  i < BUCKET_COUNT;  i++)
        init_file_list(&buckets[i]);

    if (argc)
    {
        /* Read file names from command line */
        for (i = 0;  i < argc;  i++)
        {
            kill_trailing_slashes(argv[i]);
            process_path(argv[i], 0);
        }
    }
    else
    {
        char* path;

        /* Read file names from stdin */
        while ((path = read_path(stdin)))
        {
            kill_trailing_slashes(path);
            process_path(path, 0);
            free(path);
        }
    }

    if (unique_files_flag)
        process_uniques();
    else
        process_clusters();

    for (i = 0;  i < BUCKET_COUNT;  i++)
        free_file_list(&buckets[i]);

    free(recorded_dirs.dirs);
    memset(&recorded_dirs, 0, sizeof(DirList));
}
コード例 #14
0
static void command_realpath(char * token, Channel * c) {
    char path[FILE_PATH_SIZE];
    char * real = NULL;
    int err = 0;

    read_path(&c->inp, path, sizeof(path));
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);

    real = canonicalize_file_name(path);
    if (real == NULL) err = errno;

    write_stringz(&c->out, "R");
    write_stringz(&c->out, token);
    write_fs_errno(&c->out, err);
    json_write_string(&c->out, real);
    write_stream(&c->out, 0);
    write_stream(&c->out, MARKER_EOM);
    if (real != NULL) free(real);
}
コード例 #15
0
ファイル: syscall.c プロジェクト: MatthewTighe/GNURootDebian
/**
 * Copy in @path a C string (PATH_MAX bytes max.) from the @tracee's
 * memory address space pointed to by the @reg argument of the
 * current syscall.  This function returns -errno if an error occured,
 * otherwise it returns the size in bytes put into the @path.
 */
int get_sysarg_path(const Tracee *tracee, char path[PATH_MAX], Reg reg)
{
	int size;
	word_t src;

	src = peek_reg(tracee, CURRENT, reg);

	/* Check if the parameter is not NULL. Technically we should
	 * not return an -EFAULT for this special value since it is
	 * allowed for some syscall, utimensat(2) for instance. */
	if (src == 0) {
		path[0] = '\0';
		return 0;
	}

	/* Get the path from the tracee's memory space. */
	size = read_path(tracee, path, src);
	if (size < 0)
		return size;

	path[size] = '\0';
	return size;
}
コード例 #16
0
static void command_opendir(char * token, Channel * c) {
    char path[FILE_PATH_SIZE];
    DIR * dir = NULL;
    int err = 0;
    OpenFileInfo * handle = NULL;

    read_path(&c->inp, path, sizeof(path));
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);

    dir = opendir(path);
    if (dir == NULL) {
        err = errno;
    }
    else {
        handle = create_open_file_info(c, path, -1, dir);
    }

    write_stringz(&c->out, "R");
    write_stringz(&c->out, token);
    write_fs_errno(&c->out, err);
    write_file_handle(&c->out, handle);
    write_stream(&c->out, MARKER_EOM);
}
コード例 #17
0
/*
 * Read directory structure and store entries in `entries', which must initially
 * point to an empty list.
 */
static int
read_path(struct mtree_reader *r, const char *path, struct mtree_entry **entries,
    struct mtree_entry *parent)
{
	DIR			*dirp;
	struct dirent		*dp;
	struct mtree_entry	*entry;
	struct mtree_entry	*dirs = NULL;
	struct mtree_entry	*dot = NULL;
	char			*wd = NULL;
	int			 ret;
	int			 skip;
	int			 skip_children;

	if (parent == NULL) {
		entry = mtree_entry_create(path);
		if (entry == NULL)
			return (-1);
		ret = read_path_file(r, entry, &skip, &skip_children);
		if (ret == -1) {
			mtree_entry_free(entry);
			return (-1);
		}
		/*
		 * If the path doesn't point to a directory, simply store
		 * the single entry.
		 */
		if (entry->data.type != MTREE_ENTRY_DIR) {
			*entries = entry;
			return (0);
		}
		mtree_entry_free(entry);

		if ((r->options & MTREE_READ_PATH_DONT_CROSS_MOUNT) != 0) {
			struct stat st;

			if ((r->options & MTREE_READ_PATH_FOLLOW_SYMLINKS) != 0)
				ret = stat(path, &st);
			else
				ret = lstat(path, &st);
			if (ret == -1) {
				mtree_reader_set_error(r, errno, "`%s'", path);
				return (-1);
			}
			r->base_dev = st.st_dev;
		}

		/*
		 * Change to the directory to be able to read the files
		 * with the mtree's "./" prefix.
		 */
		wd = mtree_getcwd();
		if (wd == NULL) {
			mtree_reader_set_error(r, errno,
			    "Could not determine the current working directory");
			return (-1);
		}
		if (chdir(path) == -1) {
			mtree_reader_set_error(r, errno,
			    "Could not change the working directory to `%s'",
			    path);
			return (-1);
		}
	}

	/*
	 * Read the directory structure.
	 */
	ret = 0;
	if ((dirp = opendir((parent != NULL) ? path : ".")) == NULL) {
		if ((r->options & MTREE_READ_PATH_SKIP_ON_ERROR) == 0) {
			ret = -1;
			goto end;
		}
		return (0);
	}
	while ((dp = readdir(dirp)) != NULL) {
		if (IS_DOTDOT(dp->d_name))
			continue;
		/*
		 * Dot is read only in the initial directory.
		 */
		if (parent != NULL && IS_DOT(dp->d_name))
			continue;

		entry = mtree_entry_create_empty();
		if (entry == NULL) {
			ret = -1;
			break;
		}
		entry->name = strdup(dp->d_name);
		if (entry->name == NULL) {
			ret = -1;
			break;
		}
		entry->parent = parent;
		entry->path = create_v1_path(entry);
		if (entry->path == NULL) {
			ret = -1;
			break;
		}

		ret = read_path_file(r, entry, &skip, &skip_children);
		if (ret == -1)
			break;
		if (IS_DOT(dp->d_name)) {
			if (skip)
				mtree_entry_free(entry);
			else
				dot = entry;
			if (skip_children) {
				/*
				 * This is a bit artificial, but when the user
				 * asks to skip children below ".", remove
				 * all the entries, except for the dot itself
				 * (unless the dot is skipped as well).
				 */
				mtree_entry_free_all(*entries);
				mtree_entry_free_all(dirs);
				*entries = NULL;
				dirs = NULL;
				break;
			}
			continue;
		}
		if (skip && skip_children) {
			mtree_entry_free(entry);
			continue;
		}
		if (entry->data.type == MTREE_ENTRY_DIR) {
			if (skip)
				entry->flags |= __MTREE_ENTRY_SKIP;
			if (skip_children)
				entry->flags |= __MTREE_ENTRY_SKIP_CHILDREN;
			dirs = mtree_entry_prepend(dirs, entry);
		} else if (!skip)
			*entries = mtree_entry_prepend(*entries, entry);
	}
end:
	if (ret == 0) {
		if (dot != NULL) {
			/* Put the initial dot at the (reversed) start. */
			*entries = mtree_entry_append(*entries, dot);
		}
		closedir(dirp);

		/* Directories are processed after files. */
		entry = dirs;
		while (entry != NULL) {
			struct mtree_entry *next = entry->next;

			if ((entry->flags & __MTREE_ENTRY_SKIP) == 0) {
				dirs = mtree_entry_unlink(dirs, entry);
				*entries = mtree_entry_prepend(*entries, entry);
			}
			if ((entry->flags & __MTREE_ENTRY_SKIP_CHILDREN) == 0)
				ret = read_path(r, entry->path, entries, entry);

			if (ret == -1)
				break;

			entry = next;
		}
	} else {
		/* Fatal error, clean up and make our way back to the caller. */
		mtree_entry_free_all(*entries);
		*entries = NULL;
	}
	mtree_entry_free_all(dirs);

	if (parent == NULL && chdir(wd) == -1)
		WARN("Could not change the working directory back to `%s'", wd);

	return (ret);
}
コード例 #18
0
ファイル: client.cpp プロジェクト: elake/assignment3
void loop() {

    // Make sure we don't update the map tile on screen when we don't need to!
    uint8_t update_display_window = 0;

    if ( first_time ) {
        first_time = 0;
        update_display_window = 1;
        }

    // Joystick displacement.
    int16_t dx = 0;
    int16_t dy = 0;
    uint8_t select_button_event = 0;

    // If the map has been zoomed in or out we need to do a redraw,
    // and will center the display window about the cursor.
    // So a zoom in-out will re-center over a mis-positioned cursor!
    
    // if the map changed as a result of a zoom button press
    if (shared_new_map_num != current_map_num) {
        #ifdef DEBUG_SCROLLING
            Serial.print("Zoom from ");
            Serial.print(current_map_num);
            Serial.print(" x ");
            Serial.print(cursor_map_x);
            Serial.print(" y ");
            Serial.print(cursor_map_y);
        #endif

        // change the map and figure out the position of the cursor on
        // the new map.
        set_zoom();

        // center the display window around the cursor 
        move_window_to(
            cursor_map_x - display_window_width/2, 
            cursor_map_y - display_window_height/2);

        #ifdef DEBUG_SCROLLING
            Serial.print(" to ");
            Serial.print(current_map_num);
            Serial.print(" x ");
            Serial.print(cursor_map_x);
            Serial.print(" y ");
            Serial.print(cursor_map_y);
            Serial.println();
        #endif

        // Changed the zoom level, so we want to redraw the window
        update_display_window = 1;
    }


    // Now, see if the joystick has moved, in which case we want to
    // also want to move the visible cursor on the screen.

    // Process joystick input.
    select_button_event = process_joystick(&dx, &dy);

    // the joystick routine filters out small changes, so anything non-0
    // is a real movement
    if ( abs(dx) > 0 || abs(dy) > 0 ) {
        // redraw the path if the cursor moves: (brute force yay)
        // comment out if you find it runs too slowly, and live with the
        // cursor erasing the path
        if ( path_length > 0 ) {
	  draw_path(path_length, path, current_map_num);
        }
        // Is the cursor getting near the edge of the screen?  If so
        // then scroll the map over by re-centering the window.

        uint16_t new_screen_map_x = screen_map_x;
        uint16_t new_screen_map_y = screen_map_y;
        uint8_t need_to_move = 0;

        uint16_t cursor_screen_x;
        uint16_t cursor_screen_y;
        if ( get_cursor_screen_x_y(&cursor_screen_x, &cursor_screen_y) ) {
            // if the cursor is visible, then adjust the display to 
            // to scroll if near the edge.

            if ( cursor_screen_x < screen_left_margin ) {
                new_screen_map_x = screen_map_x - screen_scroll_delta;
		move_cursor_by(3, 0);
                need_to_move = 1;
                }
            else if ( cursor_screen_x > screen_right_margin ) {
                new_screen_map_x = screen_map_x + screen_scroll_delta;
		move_cursor_by(-3, 0);
                need_to_move = 1;
            }

            if ( cursor_screen_y < screen_top_margin ) {
                new_screen_map_y = screen_map_y - screen_scroll_delta;
		move_cursor_by(0, 3);
                need_to_move = 1;
                }
            else if ( cursor_screen_y > screen_bottom_margin ) {
                new_screen_map_y = screen_map_y + screen_scroll_delta;
		move_cursor_by(0, -3);
                need_to_move = 1;
            }

            if ( need_to_move ) {
                // move the display window, leaving cursor at same lat-lon
	        move_window_to(new_screen_map_x, new_screen_map_y);
		
                update_display_window = 1;
                } 
            else {
                // erase old cursor, move, and draw new one, no need to 
                // redraw the underlying map tile
                erase_cursor();
                move_cursor_by(dx, dy);
                draw_cursor();
                }
            }

    }

    // at this point the screen is updated, with a new tile window and
    // cursor position if necessary

    // will only be down once, then waits for a min time before allowing
    // pres again.
    if (select_button_event) {
        // Button was pressed, we are selecting a point!
        #ifdef DEBUG_PATH
            Serial.print("x ");
            Serial.print(cursor_map_x);
            Serial.print(" y ");
            Serial.print(cursor_map_y);
            Serial.println();
        #endif

        // which press is this, the start or the stop selection?

        // If we are making a request to find a shortest path, we will send out
        // the request on the serial port and then wait for a response from the
        // server.  While this is happening, the client user interface is
        // suspended.

        // if the stop point, then we send out the server request and wait.
        if ( request_state == 0 ) {
            // collect the start point
            start_lat = cursor_lat;
            start_lon = cursor_lon;
            request_state = 1;
            }
        else if ( request_state == 1) {
            // collect the stop point
            stop_lat = cursor_lat;
            stop_lon = cursor_lon;
            request_state = 0;

            // send out the start and stop coordinates to the server
            Serial.print(start_lat);
            Serial.print(" "); 
            Serial.print(start_lon);
            Serial.print(" "); 
            Serial.print(stop_lat);
            Serial.print(" "); 
            Serial.print(stop_lon);
            Serial.println();

            // free any existing path
            if ( path_length > 0 ) {
                free(path);
                }

            // read the path from the serial port
            status_msg("WAITING");
            if ( read_path(&path_length, &path) ) {
                #ifdef DEBUG_PATH
                    uint8_t is_visible;
                    for (uint16_t i=0; i < path_length; i++) {
                        is_visible = is_coord_visible(path[i]);
                        Serial.print(i);
                        Serial.print(": ");
                        Serial.print(path[i].lat);
                        Serial.print(",");
                        Serial.print(path[i].lon);
                        Serial.print(is_visible ? "V": "");
                        Serial.println();
                        }
                #endif
                update_display_window = 1;
                }
            else {
                // should display this error on the screen
                Serial.print("Path read error, code ");
                Serial.println(path_errno);
                if ( path_errno == 1 ) {
                    status_msg("Path too long");
                    delay(5000);
                    }
                    
                }

            }
        } // end of select_button_event processing

    // do we have to redraw the map tile?  
    if (update_display_window) {
        #ifdef DEBUG_SCROLLING
            Serial.println("Screen update");
            Serial.print(current_map_num);
            Serial.print(" ");
            Serial.print(cursor_lon);
            Serial.print(" ");
            Serial.print(cursor_lat);
            Serial.println();
        #endif

	    
        draw_map_screen();
        draw_cursor();

        // Need to redraw any other things that are on the screen
        if ( path_length > 0 ) {
	  draw_path(path_length, path, current_map_num);
            }

        // force a redisplay of status message
        clear_status_msg();
        }

    // always update the status message area if message changes
    // Indicate which point we are waiting for
    if ( request_state == 0 ) {
        status_msg("FROM?");
        }
    else {
        status_msg("TO?");
        }
    }
コード例 #19
0
ファイル: exit.c プロジェクト: meefik/PRoot
/**
 * Translate the output arguments of the current @tracee's syscall in
 * the @tracee->pid process area. This function sets the result of
 * this syscall to @tracee->status if an error occured previously
 * during the translation, that is, if @tracee->status is less than 0.
 */
void translate_syscall_exit(Tracee *tracee)
{
	word_t syscall_number;
	word_t syscall_result;
	int status;

	status = notify_extensions(tracee, SYSCALL_EXIT_START, 0, 0);
	if (status < 0) {
		poke_reg(tracee, SYSARG_RESULT, (word_t) status);
		goto end;
	}
	if (status > 0)
		return;

	/* Set the tracee's errno if an error occured previously during
	 * the translation. */
	if (tracee->status < 0) {
		poke_reg(tracee, SYSARG_RESULT, (word_t) tracee->status);
		goto end;
	}

	/* Translate output arguments:
	 * - break: update the syscall result register with "status"
	 * - goto end: nothing else to do.
	 */
	syscall_number = get_sysnum(tracee, ORIGINAL);
	syscall_result = peek_reg(tracee, CURRENT, SYSARG_RESULT);
	switch (syscall_number) {
	case PR_brk:
		translate_brk_exit(tracee);
		goto end;

	case PR_getcwd: {
		char path[PATH_MAX];
		size_t new_size;
		size_t size;
		word_t output;

		size = (size_t) peek_reg(tracee, ORIGINAL, SYSARG_2);
		if (size == 0) {
			status = -EINVAL;
			break;
		}

		/* Ensure cwd still exists.  */
		status = translate_path(tracee, path, AT_FDCWD, ".", false);
		if (status < 0)
			break;

		new_size = strlen(tracee->fs->cwd) + 1;
		if (size < new_size) {
			status = -ERANGE;
			break;
		}

		/* Overwrite the path.  */
		output = peek_reg(tracee, ORIGINAL, SYSARG_1);
		status = write_data(tracee, output, tracee->fs->cwd, new_size);
		if (status < 0)
			break;

		/* The value of "status" is used to update the returned value
		 * in translate_syscall_exit().  */
		status = new_size;
		break;
	}

	case PR_accept:
	case PR_accept4:
		/* Nothing special to do if no sockaddr was specified.  */
		if (peek_reg(tracee, ORIGINAL, SYSARG_2) == 0)
			goto end;
		/* Fall through.  */
	case PR_getsockname:
	case PR_getpeername: {
		word_t sock_addr;
		word_t size_addr;
		word_t max_size;

		/* Error reported by the kernel.  */
		if ((int) syscall_result < 0)
			goto end;

		sock_addr = peek_reg(tracee, ORIGINAL, SYSARG_2);
		size_addr = peek_reg(tracee, MODIFIED, SYSARG_3);
		max_size  = peek_reg(tracee, MODIFIED, SYSARG_6);

		status = translate_socketcall_exit(tracee, sock_addr, size_addr, max_size);
		if (status < 0)
			break;

		/* Don't overwrite the syscall result.  */
		goto end;
	}

#define SYSARG_ADDR(n) (args_addr + ((n) - 1) * sizeof_word(tracee))

#define POKE_WORD(addr, value)			\
	poke_word(tracee, addr, value);		\
	if (errno != 0)	{			\
		status = -errno;		\
		break;				\
	}

#define PEEK_WORD(addr)				\
	peek_word(tracee, addr);		\
	if (errno != 0) {			\
		status = -errno;		\
		break;				\
	}

	case PR_socketcall: {
		word_t args_addr;
		word_t sock_addr;
		word_t size_addr;
		word_t max_size;

		args_addr = peek_reg(tracee, ORIGINAL, SYSARG_2);

		switch (peek_reg(tracee, ORIGINAL, SYSARG_1)) {
		case SYS_ACCEPT:
		case SYS_ACCEPT4:
			/* Nothing special to do if no sockaddr was specified.  */
			sock_addr = PEEK_WORD(SYSARG_ADDR(2));
			if (sock_addr == 0)
				goto end;
			/* Fall through.  */
		case SYS_GETSOCKNAME:
		case SYS_GETPEERNAME:
			/* Handle these cases below.  */
			status = 1;
			break;

		case SYS_BIND:
		case SYS_CONNECT:
			/* Restore the initial parameters: this memory was
			 * overwritten at the enter stage.  Remember: POKE_WORD
			 * puts -errno in status and breaks if an error
			 * occured.  */
			POKE_WORD(SYSARG_ADDR(2), peek_reg(tracee, MODIFIED, SYSARG_5));
			POKE_WORD(SYSARG_ADDR(3), peek_reg(tracee, MODIFIED, SYSARG_6));

			status = 0;
			break;

		default:
			status = 0;
			break;
		}

		/* Error reported by the kernel or there's nothing else to do.  */
		if ((int) syscall_result < 0 || status == 0)
			goto end;

		/* An error occured in SYS_BIND or SYS_CONNECT.  */
		if (status < 0)
			break;

		/* Remember: PEEK_WORD puts -errno in status and breaks if an
		 * error occured.  */
		sock_addr = PEEK_WORD(SYSARG_ADDR(2));
		size_addr = PEEK_WORD(SYSARG_ADDR(3));
		max_size  = peek_reg(tracee, MODIFIED, SYSARG_6);

		status = translate_socketcall_exit(tracee, sock_addr, size_addr, max_size);
		if (status < 0)
			break;

		/* Don't overwrite the syscall result.  */
		goto end;
	}

#undef SYSARG_ADDR
#undef PEEK_WORD
#undef POKE_WORD

	case PR_fchdir:
	case PR_chdir:
		/* These syscalls are fully emulated, see enter.c for details
		 * (like errors).  */
		status = 0;
		break;

	case PR_rename:
	case PR_renameat: {
		char old_path[PATH_MAX];
		char new_path[PATH_MAX];
		ssize_t old_length;
		ssize_t new_length;
		Comparison comparison;
		Reg old_reg;
		Reg new_reg;
		char *tmp;

		/* Error reported by the kernel.  */
		if ((int) syscall_result < 0)
			goto end;

		if (syscall_number == PR_rename) {
			old_reg = SYSARG_1;
			new_reg = SYSARG_2;
		}
		else {
			old_reg = SYSARG_2;
			new_reg = SYSARG_4;
		}

		/* Get the old path, then convert it to the same
		 * "point-of-view" as tracee->fs->cwd (guest).  */
		status = read_path(tracee, old_path, peek_reg(tracee, MODIFIED, old_reg));
		if (status < 0)
			break;

		status = detranslate_path(tracee, old_path, NULL);
		if (status < 0)
			break;
		old_length = (status > 0 ? status - 1 : (ssize_t) strlen(old_path));

		/* Nothing special to do if the moved path is not the
		 * current working directory.  */
		comparison = compare_paths(old_path, tracee->fs->cwd);
		if (comparison != PATH1_IS_PREFIX && comparison != PATHS_ARE_EQUAL) {
			status = 0;
			break;
		}

		/* Get the new path, then convert it to the same
		 * "point-of-view" as tracee->fs->cwd (guest).  */
		status = read_path(tracee, new_path, peek_reg(tracee, MODIFIED, new_reg));
		if (status < 0)
			break;

		status = detranslate_path(tracee, new_path, NULL);
		if (status < 0)
			break;
		new_length = (status > 0 ? status - 1 : (ssize_t) strlen(new_path));

		/* Sanity check.  */
		if (strlen(tracee->fs->cwd) >= PATH_MAX) {
			status = 0;
			break;
		}
		strcpy(old_path, tracee->fs->cwd);

		/* Update the virtual current working directory.  */
		substitute_path_prefix(old_path, old_length, new_path, new_length);

		tmp = talloc_strdup(tracee->fs, old_path);
		if (tmp == NULL) {
			status = -ENOMEM;
			break;
		}

		TALLOC_FREE(tracee->fs->cwd);
		tracee->fs->cwd = tmp;

		status = 0;
		break;
	}

	case PR_readlink:
	case PR_readlinkat: {
		char referee[PATH_MAX];
		char referer[PATH_MAX];
		size_t old_size;
		size_t new_size;
		size_t max_size;
		word_t input;
		word_t output;

		/* Error reported by the kernel.  */
		if ((int) syscall_result < 0)
			goto end;

		old_size = syscall_result;

		if (syscall_number == PR_readlink) {
			output   = peek_reg(tracee, ORIGINAL, SYSARG_2);
			max_size = peek_reg(tracee, ORIGINAL, SYSARG_3);
			input    = peek_reg(tracee, MODIFIED, SYSARG_1);
		}
		else {
			output   = peek_reg(tracee, ORIGINAL,  SYSARG_3);
			max_size = peek_reg(tracee, ORIGINAL, SYSARG_4);
			input    = peek_reg(tracee, MODIFIED, SYSARG_2);
		}

		if (max_size > PATH_MAX)
			max_size = PATH_MAX;

		if (max_size == 0) {
			status = -EINVAL;
			break;
		}

		/* The kernel does NOT put the NULL terminating byte for
		 * readlink(2).  */
		status = read_data(tracee, referee, output, old_size);
		if (status < 0)
			break;
		referee[old_size] = '\0';

		/* Not optimal but safe (path is fully translated).  */
		status = read_path(tracee, referer, input);
		if (status < 0)
			break;

		if (status >= PATH_MAX) {
			status = -ENAMETOOLONG;
			break;
		}

		status = detranslate_path(tracee, referee, referer);
		if (status < 0)
			break;

		/* The original path doesn't require any transformation, i.e
		 * it is a symetric binding.  */
		if (status == 0)
			goto end;

		/* Overwrite the path.  Note: the output buffer might be
		 * initialized with zeros but it was updated with the kernel
		 * result, and then with the detranslated result.  This later
		 * might be shorter than the former, so it's safier to add a
		 * NULL terminating byte when possible.  This problem was
		 * exposed by IDA Demo 6.3.  */
		if ((size_t) status < max_size) {
			new_size = status - 1;
			status = write_data(tracee, output, referee, status);
		}
		else {
			new_size = max_size;
			status = write_data(tracee, output, referee, max_size);
		}
		if (status < 0)
			break;

		/* The value of "status" is used to update the returned value
		 * in translate_syscall_exit().  */
		status = new_size;
		break;
	}

#if defined(ARCH_X86_64)
	case PR_uname: {
		struct utsname utsname;
		word_t address;
		size_t size;

		if (get_abi(tracee) != ABI_2)
			goto end;

		/* Error reported by the kernel.  */
		if ((int) syscall_result < 0)
			goto end;

		address = peek_reg(tracee, ORIGINAL, SYSARG_1);

		status = read_data(tracee, &utsname, address, sizeof(utsname));
		if (status < 0)
			break;

		/* Some 32-bit programs like package managers can be
		 * confused when the kernel reports "x86_64".  */
		size = sizeof(utsname.machine);
		strncpy(utsname.machine, "i686", size);
		utsname.machine[size - 1] = '\0';

		status = write_data(tracee, address, &utsname, sizeof(utsname));
		if (status < 0)
			break;

		status = 0;
		break;
	}
#endif

	case PR_execve:
		translate_execve_exit(tracee);
		goto end;

	case PR_ptrace:
		status = translate_ptrace_exit(tracee);
		break;

	case PR_wait4:
	case PR_waitpid:
		if (tracee->as_ptracer.waits_in != WAITS_IN_PROOT)
			goto end;

		status = translate_wait_exit(tracee);
		break;

	case PR_setrlimit:
	case PR_prlimit64:
		/* Error reported by the kernel.  */
		if ((int) syscall_result < 0)
			goto end;

		status = translate_setrlimit_exit(tracee, syscall_number == PR_prlimit64);
		if (status < 0)
			break;

		/* Don't overwrite the syscall result.  */
		goto end;

	default:
		goto end;
	}

	poke_reg(tracee, SYSARG_RESULT, (word_t) status);

end:
	status = notify_extensions(tracee, SYSCALL_EXIT_END, status, 0);
	if (status < 0)
		poke_reg(tracee, SYSARG_RESULT, (word_t) status);
}
コード例 #20
0
ファイル: old-and-busted.c プロジェクト: Ranga123/test1
/* Allocate an entry from POOL and read it from [*BUF, END).  The
   buffer may be modified in place while parsing.  Return the new
   entry in *NEW_ENTRY.  Advance *BUF to point at the end of the entry
   record.
   The entries file format should be provided in ENTRIES_FORMAT. */
static svn_error_t *
read_entry(svn_wc_entry_t **new_entry,
           char **buf, const char *end,
           int entries_format,
           apr_pool_t *pool)
{
    svn_wc_entry_t *entry = alloc_entry(pool);
    const char *name;

#define MAYBE_DONE if (**buf == '\f') goto done

    /* Find the name and set up the entry under that name. */
    SVN_ERR(read_path(&name, buf, end, pool));
    entry->name = name ? name : SVN_WC_ENTRY_THIS_DIR;

    /* Set up kind. */
    {
        const char *kindstr;
        SVN_ERR(read_val(&kindstr, buf, end));
        if (kindstr)
        {
            if (strcmp(kindstr, ENTRIES_VALUE_FILE) == 0)
                entry->kind = svn_node_file;
            else if (strcmp(kindstr, ENTRIES_VALUE_DIR) == 0)
                entry->kind = svn_node_dir;
            else
                return svn_error_createf
                       (SVN_ERR_NODE_UNKNOWN_KIND, NULL,
                        _("Entry '%s' has invalid node kind"),
                        (name ? name : SVN_WC_ENTRY_THIS_DIR));
        }
        else
            entry->kind = svn_node_none;
    }
    MAYBE_DONE;

    /* Attempt to set revision (resolve_to_defaults may do it later, too) */
    SVN_ERR(read_revnum(&entry->revision, buf, end, pool));
    MAYBE_DONE;

    /* Attempt to set up url path (again, see resolve_to_defaults). */
    SVN_ERR(read_url(&entry->url, buf, end, entries_format, pool));
    MAYBE_DONE;

    /* Set up repository root.  Make sure it is a prefix of url. */
    SVN_ERR(read_url(&entry->repos, buf, end, entries_format, pool));
    if (entry->repos && entry->url
            && ! svn_uri__is_ancestor(entry->repos, entry->url))
        return svn_error_createf(SVN_ERR_WC_CORRUPT, NULL,
                                 _("Entry for '%s' has invalid repository "
                                   "root"),
                                 name ? name : SVN_WC_ENTRY_THIS_DIR);
    MAYBE_DONE;

    /* Look for a schedule attribute on this entry. */
    {
        const char *schedulestr;
        SVN_ERR(read_val(&schedulestr, buf, end));
        entry->schedule = svn_wc_schedule_normal;
        if (schedulestr)
        {
            if (strcmp(schedulestr, ENTRIES_VALUE_ADD) == 0)
                entry->schedule = svn_wc_schedule_add;
            else if (strcmp(schedulestr, ENTRIES_VALUE_DELETE) == 0)
                entry->schedule = svn_wc_schedule_delete;
            else if (strcmp(schedulestr, ENTRIES_VALUE_REPLACE) == 0)
                entry->schedule = svn_wc_schedule_replace;
            else
                return svn_error_createf(
                           SVN_ERR_ENTRY_ATTRIBUTE_INVALID, NULL,
                           _("Entry '%s' has invalid 'schedule' value"),
                           name ? name : SVN_WC_ENTRY_THIS_DIR);
        }
    }
    MAYBE_DONE;

    /* Attempt to set up text timestamp. */
    SVN_ERR(read_time(&entry->text_time, buf, end, pool));
    MAYBE_DONE;

    /* Checksum. */
    SVN_ERR(read_str(&entry->checksum, buf, end, pool));
    MAYBE_DONE;

    /* Setup last-committed values. */
    SVN_ERR(read_time(&entry->cmt_date, buf, end, pool));
    MAYBE_DONE;

    SVN_ERR(read_revnum(&entry->cmt_rev, buf, end, pool));
    MAYBE_DONE;

    SVN_ERR(read_str(&entry->cmt_author, buf, end, pool));
    MAYBE_DONE;

    /* has-props, has-prop-mods, cachable-props, present-props are all
       deprecated. Read any values that may be in the 'entries' file, but
       discard them, and just put default values into the entry. */
    {
        const char *unused_value;

        /* has-props flag. */
        SVN_ERR(read_val(&unused_value, buf, end));
        entry->has_props = FALSE;
        MAYBE_DONE;

        /* has-prop-mods flag. */
        SVN_ERR(read_val(&unused_value, buf, end));
        entry->has_prop_mods = FALSE;
        MAYBE_DONE;

        /* Use the empty string for cachable_props, indicating that we no
           longer attempt to cache any properties. An empty string for
           present_props means that no cachable props are present. */

        /* cachable-props string. */
        SVN_ERR(read_val(&unused_value, buf, end));
        entry->cachable_props = "";
        MAYBE_DONE;

        /* present-props string. */
        SVN_ERR(read_val(&unused_value, buf, end));
        entry->present_props = "";
        MAYBE_DONE;
    }

    /* Is this entry in a state of mental torment (conflict)? */
    {
        SVN_ERR(read_path(&entry->prejfile, buf, end, pool));
        MAYBE_DONE;
        SVN_ERR(read_path(&entry->conflict_old, buf, end, pool));
        MAYBE_DONE;
        SVN_ERR(read_path(&entry->conflict_new, buf, end, pool));
        MAYBE_DONE;
        SVN_ERR(read_path(&entry->conflict_wrk, buf, end, pool));
        MAYBE_DONE;
    }

    /* Is this entry copied? */
    SVN_ERR(read_bool(&entry->copied, ENTRIES_BOOL_COPIED, buf, end));
    MAYBE_DONE;

    SVN_ERR(read_url(&entry->copyfrom_url, buf, end, entries_format, pool));
    MAYBE_DONE;
    SVN_ERR(read_revnum(&entry->copyfrom_rev, buf, end, pool));
    MAYBE_DONE;

    /* Is this entry deleted? */
    SVN_ERR(read_bool(&entry->deleted, ENTRIES_BOOL_DELETED, buf, end));
    MAYBE_DONE;

    /* Is this entry absent? */
    SVN_ERR(read_bool(&entry->absent, ENTRIES_BOOL_ABSENT, buf, end));
    MAYBE_DONE;

    /* Is this entry incomplete? */
    SVN_ERR(read_bool(&entry->incomplete, ENTRIES_BOOL_INCOMPLETE, buf, end));
    MAYBE_DONE;

    /* UUID. */
    SVN_ERR(read_str(&entry->uuid, buf, end, pool));
    MAYBE_DONE;

    /* Lock token. */
    SVN_ERR(read_str(&entry->lock_token, buf, end, pool));
    MAYBE_DONE;

    /* Lock owner. */
    SVN_ERR(read_str(&entry->lock_owner, buf, end, pool));
    MAYBE_DONE;

    /* Lock comment. */
    SVN_ERR(read_str(&entry->lock_comment, buf, end, pool));
    MAYBE_DONE;

    /* Lock creation date. */
    SVN_ERR(read_time(&entry->lock_creation_date, buf, end, pool));
    MAYBE_DONE;

    /* Changelist. */
    SVN_ERR(read_str(&entry->changelist, buf, end, pool));
    MAYBE_DONE;

    /* Keep entry in working copy after deletion? */
    SVN_ERR(read_bool(&entry->keep_local, ENTRIES_BOOL_KEEP_LOCAL, buf, end));
    MAYBE_DONE;

    /* Translated size */
    {
        const char *val;

        /* read_val() returns NULL on an empty (e.g. default) entry line,
           and entry has already been initialized accordingly already */
        SVN_ERR(read_val(&val, buf, end));
        if (val)
            entry->working_size = (apr_off_t)apr_strtoi64(val, NULL, 0);
    }
    MAYBE_DONE;

    /* Depth. */
    {
        const char *result;
        SVN_ERR(read_val(&result, buf, end));
        if (result)
        {
            svn_boolean_t invalid;
            svn_boolean_t is_this_dir;

            entry->depth = svn_depth_from_word(result);

            /* Verify the depth value:
               THIS_DIR should not have an excluded value and SUB_DIR should only
               have excluded value. Remember that infinity value is not stored and
               should not show up here. Otherwise, something bad may have
               happened. However, infinity value itself will always be okay. */
            is_this_dir = !name;
            /* '!=': XOR */
            invalid = is_this_dir != (entry->depth != svn_depth_exclude);
            if (entry->depth != svn_depth_infinity && invalid)
                return svn_error_createf(
                           SVN_ERR_ENTRY_ATTRIBUTE_INVALID, NULL,
                           _("Entry '%s' has invalid 'depth' value"),
                           name ? name : SVN_WC_ENTRY_THIS_DIR);
        }
        else
            entry->depth = svn_depth_infinity;

    }
    MAYBE_DONE;

    /* Tree conflict data. */
    SVN_ERR(read_str(&entry->tree_conflict_data, buf, end, pool));
    MAYBE_DONE;

    /* File external URL and revision. */
    {
        const char *str;
        SVN_ERR(read_str(&str, buf, end, pool));
        SVN_ERR(svn_wc__unserialize_file_external(&entry->file_external_path,
                &entry->file_external_peg_rev,
                &entry->file_external_rev,
                str,
                pool));
    }
    MAYBE_DONE;

done:
    *new_entry = entry;
    return SVN_NO_ERROR;
}
コード例 #21
0
void
mexFunction(int nlhs, mxArray *plhs[],
            int nrhs, const mxArray *prhs[])
{
   mxArray *data;  /* element data in a structure */
   FILE *fob;
   double *pd;
   double dbu_to_uu;
   int etype;

   /* check argument number */
   if (nrhs != 3) {
      mexErrMsgTxt("3 input arguments expected.");
   }
   if (nlhs != 1) {
      mexErrMsgTxt("one output argument expected.");
   }
   
   /* get file handle argument */
   fob = get_file_ptr((mxArray *)prhs[0]);

   /* get type argument */
   pd = mxGetData(prhs[1]);
   etype = pd[0];

   /* get unit conversion factor: database units --> user units */
   pd = mxGetData(prhs[2]);
   dbu_to_uu = pd[0];

   /* decide what to do */
   switch (etype) {
     
      case BOUNDARY:
	 read_boundary(fob, &data, dbu_to_uu);
	 break;

      case PATH:
	 read_path(fob, &data, dbu_to_uu);
	 break;

      case SREF:
	 read_sref(fob, &data, dbu_to_uu);
	 break;

      case AREF:
	 read_aref(fob, &data, dbu_to_uu);
	 break;

      case TEXT:
	 read_text(fob, &data, dbu_to_uu);
	 break;

      case NODE:
	 read_node(fob, &data, dbu_to_uu);
	 break;

      case BOX:
	 read_box(fob, &data, dbu_to_uu);
	 break;

      default:
         mexErrMsgTxt("gds_read_element :  unknown element type.");
   }

   plhs[0] = data;
}
コード例 #22
0
ファイル: fake_id0.c プロジェクト: AQBoy/PRoot
/**
 * Force current @tracee's syscall to behave as if executed by "root".
 * This function returns -errno if an error occured, otherwise 0.
 */
static int handle_sysexit_end(Tracee *tracee)
{
	word_t sysnum;

	sysnum = get_sysnum(tracee, ORIGINAL);
	switch (sysnum) {
	case PR_chroot: {
		char path[PATH_MAX];
		word_t result;
		word_t input;
		int status;

		/* Override only permission errors.  */
		result = peek_reg(tracee, CURRENT, SYSARG_RESULT);
		if ((int) result != -EPERM)
			return 0;

		input = peek_reg(tracee, MODIFIED, SYSARG_1);

		status = read_path(tracee, path, input);
		if (status < 0)
			return status;

		/* Only "new rootfs == current rootfs" is supported yet.  */
		status = compare_paths(get_root(tracee), path);
		if (status != PATHS_ARE_EQUAL)
			return 0;

		/* Force success.  */
		poke_reg(tracee, SYSARG_RESULT, 0);
		return 0;
	}

	case PR_setresuid:
	case PR_setresgid:
	case PR_setresuid32:
	case PR_setresgid32:
	case PR_mknod:
	case PR_capset:
	case PR_setxattr:
	case PR_chmod:
	case PR_chown:
	case PR_fchmod:
	case PR_fchown:
	case PR_lchown:
	case PR_chown32:
	case PR_fchown32:
	case PR_lchown32:
	case PR_fchmodat:
	case PR_fchownat: {
		word_t result;

		/* Override only permission errors.  */
		result = peek_reg(tracee, CURRENT, SYSARG_RESULT);
		if ((int) result != -EPERM)
			return 0;

		/* Force success.  */
		poke_reg(tracee, SYSARG_RESULT, 0);
		return 0;
	}

	case PR_getresuid:
	case PR_getresuid32:
	case PR_getresgid:
	case PR_getresgid32:
		poke_mem(tracee, peek_reg(tracee, ORIGINAL, SYSARG_1), 0);
		if (errno != 0)
			return -EFAULT;

		poke_mem(tracee, peek_reg(tracee, ORIGINAL, SYSARG_2), 0);
		if (errno != 0)
			return -EFAULT;

		poke_mem(tracee, peek_reg(tracee, ORIGINAL, SYSARG_3), 0);
		if (errno != 0)
			return -EFAULT;

		/* Force success.  */
		poke_reg(tracee, SYSARG_RESULT, 0);
		return 0;

	case PR_fstatat64:
	case PR_newfstatat:
	case PR_stat64:
	case PR_lstat64:
	case PR_fstat64:
	case PR_stat:
	case PR_lstat:
	case PR_fstat: {
		word_t result;
		word_t address;
		word_t uid, gid;
		Reg sysarg;

		/* Override only if it succeed.  */
		result = peek_reg(tracee, CURRENT, SYSARG_RESULT);
		if (result != 0)
			return 0;

		/* Get the address of the 'stat' structure.  */
		if (sysnum == PR_fstatat64 || sysnum == PR_newfstatat)
			sysarg = SYSARG_3;
		else
			sysarg = SYSARG_2;

		address = peek_reg(tracee, ORIGINAL, sysarg);

		/* Get the uid & gid values from the 'stat' structure.  */
		uid = peek_mem(tracee, address + offsetof_stat_uid(tracee));
		if (errno != 0)
			uid = 0; /* Not fatal.  */

		gid = peek_mem(tracee, address + offsetof_stat_gid(tracee));
		if (errno != 0)
			gid = 0; /* Not fatal.  */

		/* These values are 32-bit width, even on 64-bit architecture.  */
		uid &= 0xFFFFFFFF;
		gid &= 0xFFFFFFFF;

		/* Override only if the file is owned by the current user.
		 * Errors are not fatal here.  */
		if (uid == getuid())
			poke_mem(tracee, address + offsetof_stat_uid(tracee), 0);
		if (gid == getgid())
			poke_mem(tracee, address + offsetof_stat_gid(tracee), 0);

		return 0;
	}

	case PR_getuid:
	case PR_getgid:
	case PR_getegid:
	case PR_geteuid:
	case PR_getuid32:
	case PR_getgid32:
	case PR_geteuid32:
	case PR_getegid32:
	case PR_setuid:
	case PR_setgid:
	case PR_setfsuid:
	case PR_setfsgid:
	case PR_setuid32:
	case PR_setgid32:
	case PR_setfsuid32:
	case PR_setfsgid32:
		/* Force success.  */
		poke_reg(tracee, SYSARG_RESULT, 0);
		return 0;

	default:
		return 0;
	}
}
コード例 #23
0
ファイル: shell.c プロジェクト: rooa/myshell
int main(int argc, char *argv[])
{
  int i,pid;
  int pid2;
  int status;
  int delimiter;
  
  char *tokens[NUMTOKEN];
  char *command;
  char *PIPE = "|";
  int num_tokens;
  int pipe_indices[10];
  
  read_path();

  while(1){
    allocate(tokens);
    command = (char *)malloc(sizeof(char) * 100);  // Cannot move to allocate(). TODO resolve
    printf (">>> ");
    fflush(stdout);
    
    input(0,command);
    printf ("%s\n",command);
    num_tokens = split_command(command, tokens);
    

    
    delimiter = 0;
    for (i = 0; i < num_tokens; ++i){
      if (strcmp(tokens[i],PIPE) == 0) {
	pipe_indices[delimiter] = i;
	delimiter++;
      }
    }
    child_process(delimiter+1);

    pid = fork();
    // Child process
    if (pid == 0)
      {
	puts("Child process started.");
	execvp(tokens[0],tokens);
	perror("fork error");
	exit(-1);
      }
    else if (pid == -1)
      {
    	//ERROR
      }

    waitpid(pid, &status, 0); /*子プロセスが終了するのを待つ*/    
    if (WIFEXITED(status)) {
      // 子プロセスが正常終了の場合
      printf("child exit-code=%d\n", WEXITSTATUS(status));
    } else {
      printf("child status=%04x\n", status);
    }
    free_arrays(tokens,command);
  }

  free(tokens);

  return EXIT_SUCCESS;

}
コード例 #24
0
static void command_copy(char * token, Channel * c) {
    char src[FILE_PATH_SIZE];
    char dst[FILE_PATH_SIZE];
    int copy_uidgid;
    int copy_perms;
    struct stat st;
    int fi = -1;
    int fo = -1;
    int err = 0;
    int64_t pos = 0;

    read_path(&c->inp, src, sizeof(src));
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    read_path(&c->inp, dst, sizeof(dst));
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    copy_uidgid = json_read_boolean(&c->inp);
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    copy_perms = json_read_boolean(&c->inp);
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);

    if (stat(src, &st) < 0) err = errno;
    if (err == 0 && (fi = open(src, O_RDONLY | O_BINARY, 0)) < 0) err = errno;
    if (err == 0 && (fo = open(dst, O_WRONLY | O_BINARY | O_CREAT, 0775)) < 0) err = errno;

    while (err == 0 && pos < st.st_size) {
        char buf[BUF_SIZE];
        int wr = 0;
        int rd = read(fi, buf, sizeof(buf));
        if (rd == 0) break;
        if (rd < 0) {
            err = errno;
            break;
        }
        wr = write(fo, buf, rd);
        if (wr < 0) {
            err = errno;
            break;
        }
        if (wr < rd) {
            err = ENOSPC;
            break;
        }
        pos += rd;
    }

    if (fo >= 0 && close(fo) < 0 && err == 0) err = errno;
    if (fi >= 0 && close(fi) < 0 && err == 0) err = errno;

    if (err == 0) {
        struct utimbuf buf;
        buf.actime = st.st_atime;
        buf.modtime = st.st_mtime;
        if (utime(dst, &buf) < 0) err = errno;
    }
    if (err == 0 && copy_perms && chmod(dst, st.st_mode) < 0) err = errno;
#if !defined(WIN32) && !defined(_WRS_KERNEL)
    if (err == 0 && copy_uidgid && chown(dst, st.st_uid, st.st_gid) < 0) err = errno;
#endif

    write_stringz(&c->out, "R");
    write_stringz(&c->out, token);
    write_fs_errno(&c->out, err);
    write_stream(&c->out, MARKER_EOM);
}