Changeset 27bdfa5 in mainline for uspace/srv/devman


Ignore:
Timestamp:
2011-03-30T17:34:59Z (15 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
48d4231, 87b52c9, 98169ab, e353e85
Parents:
51e5608 (diff), 917a8c8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

Location:
uspace/srv/devman
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/devman.c

    r51e5608 r27bdfa5  
    274274        }
    275275       
    276         if (read(fd, buf, len) <= 0) {
     276        ssize_t read_bytes = safe_read(fd, buf, len);
     277        if (read_bytes <= 0) {
    277278                printf(NAME ": unable to read file '%s'.\n", conf_path);
    278279                goto cleanup;
    279280        }
    280         buf[len] = 0;
     281        buf[read_bytes] = 0;
    281282       
    282283        suc = parse_match_ids(buf, ids);
     
    11311132fun_node_t *find_fun_node_by_path(dev_tree_t *tree, char *path)
    11321133{
     1134        assert(path != NULL);
     1135
     1136        bool is_absolute = path[0] == '/';
     1137        if (!is_absolute) {
     1138                return NULL;
     1139        }
     1140
    11331141        fibril_rwlock_read_lock(&tree->rwlock);
    11341142       
     
    11401148        char *rel_path = path;
    11411149        char *next_path_elem = NULL;
    1142         bool cont = (rel_path[0] == '/');
     1150        bool cont = true;
    11431151       
    11441152        while (cont && fun != NULL) {
  • uspace/srv/devman/main.c

    r51e5608 r27bdfa5  
    477477                dev = fun->dev;
    478478
    479         if (fun == NULL && dev == NULL) {
     479        /*
     480         * For a valid function to connect to we need a device. The root
     481         * function, for example, has no device and cannot be connected to.
     482         * This means @c dev needs to be valid regardless whether we are
     483         * connecting to a device or to a function.
     484         */
     485        if (dev == NULL) {
    480486                printf(NAME ": devman_forward error - no device or function with "
    481487                    "handle %" PRIun " was found.\n", handle);
  • uspace/srv/devman/util.c

    r51e5608 r27bdfa5  
    111111}
    112112
     113ssize_t safe_read(int fd, void *buffer, size_t size)
     114{
     115        if (size == 0) {
     116                return 0;
     117        }
     118
     119        uint8_t *buf_ptr = (uint8_t *) buffer;
     120
     121        size_t total_read = 0;
     122        while (total_read < size) {
     123                ssize_t bytes_read = read(fd, buf_ptr, size - total_read);
     124                if (bytes_read < 0) {
     125                        /* Error. */
     126                        return bytes_read;
     127                } else if (bytes_read == 0) {
     128                        /* Possibly end of file. */
     129                        break;
     130                } else {
     131                        /* Read at least something. */
     132                        buf_ptr += bytes_read;
     133                        total_read += bytes_read;
     134                }
     135        }
     136
     137        return (ssize_t) total_read;
     138}
     139
    113140/** @}
    114141 */
  • uspace/srv/devman/util.h

    r51e5608 r27bdfa5  
    4747extern void replace_char(char *, char, char);
    4848
     49extern ssize_t safe_read(int, void *, size_t);
     50
    4951#endif
    5052
Note: See TracChangeset for help on using the changeset viewer.