a4974cc65d6b21f11b02481bfbb0fff67814f245
Stefan Schuermans add exe and cwd to proc_begin

Stefan Schuermans authored 4 years ago

liblwpttr/src/symlink.c  1) #include "symlink.h"
liblwpttr/src/symlink.c  2) #include "cleaner.h"
liblwpttr/src/symlink.c  3) 
liblwpttr/src/symlink.c  4) #include <stdlib.h>
liblwpttr/src/symlink.c  5) #include <unistd.h>
liblwpttr/src/symlink.c  6) 
liblwpttr/src/symlink.c  7) /**
liblwpttr/src/symlink.c  8)  * @brief read target of symlink
liblwpttr/src/symlink.c  9)  * @param[in] pathname path to symbolic link
liblwpttr/src/symlink.c 10)  * @return malloc-ed string containting link target or NULL
liblwpttr/src/symlink.c 11)  */
Stefan Schuermans formatting

Stefan Schuermans authored 4 years ago

libuptev/src/symlink.c  12) static char *uptev_symlink_read_target(char const *pathname) {
Stefan Schuermans add exe and cwd to proc_begin

Stefan Schuermans authored 4 years ago

liblwpttr/src/symlink.c 13)   size_t sz = 256;
liblwpttr/src/symlink.c 14)   char *target = NULL;
liblwpttr/src/symlink.c 15)   while (1) {
liblwpttr/src/symlink.c 16)     /* get buffer */
liblwpttr/src/symlink.c 17)     target = malloc(sz);
Stefan Schuermans formatting

Stefan Schuermans authored 4 years ago

libuptev/src/symlink.c  18)     if (!target) {
Stefan Schuermans add exe and cwd to proc_begin

Stefan Schuermans authored 4 years ago

liblwpttr/src/symlink.c 19)       return NULL;
liblwpttr/src/symlink.c 20)     }
liblwpttr/src/symlink.c 21)     /* get link target */
liblwpttr/src/symlink.c 22)     ssize_t len = readlink(pathname, target, sz);
liblwpttr/src/symlink.c 23)     if (len < 0) {
liblwpttr/src/symlink.c 24)       free(target);
liblwpttr/src/symlink.c 25)       return NULL;
liblwpttr/src/symlink.c 26)     }
liblwpttr/src/symlink.c 27)     /* link target fit into buffer -> terminate string and return */
liblwpttr/src/symlink.c 28)     if ((size_t)len + 1 < sz) {
liblwpttr/src/symlink.c 29)       target[len] = 0;
liblwpttr/src/symlink.c 30)       return target;
liblwpttr/src/symlink.c 31)     }
liblwpttr/src/symlink.c 32)     /* free buffer and try again with larger buffer */
liblwpttr/src/symlink.c 33)     free(target);
liblwpttr/src/symlink.c 34)     sz *= 2;
liblwpttr/src/symlink.c 35)   }
liblwpttr/src/symlink.c 36) }
liblwpttr/src/symlink.c 37) 
Stefan Schuermans formatting

Stefan Schuermans authored 4 years ago

libuptev/src/symlink.c  38) char *uptev_symlink_read(char const *pathname, uptev_cleaner_t *cleaner) {
Stefan Schuermans rename: lwproctrace -> upro...

Stefan Schuermans authored 4 years ago

libuptev/src/symlink.c  39)   char *target = uptev_symlink_read_target(pathname);
Stefan Schuermans formatting

Stefan Schuermans authored 4 years ago

libuptev/src/symlink.c  40)   if (!target) {
Stefan Schuermans rename: lwproctrace -> upro...

Stefan Schuermans authored 4 years ago

libuptev/src/symlink.c  41)     return NULL;
Stefan Schuermans add exe and cwd to proc_begin

Stefan Schuermans authored 4 years ago

liblwpttr/src/symlink.c 42)   }
Stefan Schuermans handle cleaner out of memory

Stefan Schuermans authored 4 years ago

libuptev/src/symlink.c  43)   /* add malloc-ed object to cleaner */
libuptev/src/symlink.c  44)   if (uptev_cleaner_add_ptr(cleaner, target) != 0) {
libuptev/src/symlink.c  45)     return NULL;
libuptev/src/symlink.c  46)   }
libuptev/src/symlink.c  47)   /* success, return target string */
Stefan Schuermans rename: lwproctrace -> upro...

Stefan Schuermans authored 4 years ago

libuptev/src/symlink.c  48)   return target;