lib/socket-util-unix.c
/* Attempts to shorten 'name' by opening a file descriptor for the directory
 * part of the name and indirecting through /proc/self/fd/<dirfd>/<basename>.
 * On systems with Linux-like /proc, this works as long as <basename> isn't too
 * long.
 *
 * On success, returns 0 and stores the short name in 'short_name' and a
 * directory file descriptor to eventually be closed in '*dirfpd'. */


On success, returns 0 and stores the short name in 'short_name' and a
directory file descriptor to eventually be closed in '*dirfpd'.
On success returns 0 and stores the short name in ' short_name ' and a directory file descriptor to eventually be closed in ' * dirfpd ' .
static int
shorten_name_via_proc(const char *name, char short_name[MAX_UN_LEN + 1],
                      int *dirfdp)
{
    char *dir, *base;
    int dirfd;
    int len;
    if (!LINUX) {
        return ENAMETOOLONG;
    }
    dir = dir_name(name);
    dirfd = open(dir, O_DIRECTORY | O_RDONLY);
    if (dirfd < 0) {
        static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
        int error = errno;
        VLOG_WARN_RL(&rl, "%s: open failed (%s)", dir, ovs_strerror(error));
        free(dir);
        return error;
    }
    free(dir);
    base = base_name(name);
    len = snprintf(short_name, MAX_UN_LEN + 1,
                   "/proc/self/fd/%d/%s", dirfd, base);
    free(base);
    if (len >= 0 && len <= MAX_UN_LEN) {
        *dirfdp = dirfd;
        return 0;
    } else {
        close(dirfd);
        return ENAMETOOLONG;
    }
}
static int shorten_name_via_proc ( const char * name , char short_name [ MAX_UN_LEN + 1 ] , int * dirfdp ) { char * dir , * base ; int dirfd ; int len ; if ( ! LINUX ) { return ENAMETOOLONG ; } dir = dir_name ( name ) ; dirfd = open ( dir , O_DIRECTORY | O_RDONLY ) ; if ( dirfd < 0 ) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT ( 1 , 1 ) ; int error = errno ; VLOG_WARN_RL ( & rl , " " , dir , ovs_strerror ( error ) ) ; free ( dir ) ; return error ; } free ( dir ) ; base = base_name ( name ) ; len = snprintf ( short_name , MAX_UN_LEN + 1 , " " , dirfd , base ) ; free ( base ) ; if ( len >= 0 && len <= MAX_UN_LEN ) { * dirfdp = dirfd ; return 0 ; } else { close ( dirfd ) ; return ENAMETOOLONG ; } }
Attempts to shorten 'name' by opening a file descriptor for the directory
 part of the name and indirecting through /proc/self/fd/<dirfd>/<basename>.
Attempts to shorten ' name ' by opening a file descriptor for the directory part of the name and indirecting through / proc / self / fd / <dirfd > / <basename > .