Exemplo n.º 1
0
slice* forkorsomething(char *uuid)
{
    int fd[2];
    pipe(fd);
    pid_t childpid;
    char *shellpath = "./tevs.sh";
    size_t sz = strlen(shellpath)+strlen(uuid)+2;
    printf("size : %d\n",sz);
    char *command = malloc(sizeof(char)*sz);
    size_t s_sz = sprintf(command, "%s %s", shellpath, uuid);
    
    printf("printed chars: %d\n",s_sz);
    
    printf("%s\n",command);  

    childpid = fork();
    if (childpid == -1){
       fprintf(stderr, "FORK failed");
       return NULL;
    } else if (childpid == 0) {
       close(1);
       dup2(fd[1], 1);
       close(fd[0]);
       execlp("/bin/sh","/bin/sh","-c", command, NULL);
    }

    close(fd[1]);
    int nread;
    char buffer[4096];
    slice *result = make_slice();
    append(result,uuid); 

    while((nread=read(fd[0], buffer, 4096))>0) {
        appendn(result,buffer,nread); 
    }

    printf("read %d bytes from result\n",result->len);
//    wait(NULL); 
    return result;
}
Exemplo n.º 2
0
static void append (char **ptr, char *app)
{
	appendn(ptr,app,0);
}
Exemplo n.º 3
0
/** @brief Canonicalize a path
 * @param a Allocator for result
 * @param result Result so far
 * @param nresultp Size of current result
 * @param path Path to process
 * @param flags Flags as for sftp_find_realpath()
 * @return Modified result
 */
static char *process_path(struct allocator *a, char *result, size_t *nresultp,
			  const char *path, unsigned flags) {
  D(("process_path path='%s' result='%s'", path, result));
  while(*path) {
    if(*path == '/')
      ++path;
    else {
      /* Find the next path element */
      const size_t elementlen = strcspn(path, "/");

      if(elementlen == 1 && path[0] == '.')
        /* Stay where we are */
        ;
      else if(elementlen == 2 && path[0] == '.' && path[1] == '.') {
        /* Go up one level */
        char *const ls = strrchr(result, '/');
        assert(ls != 0);
        if(ls != result)
          *ls = 0;
        else
          strcpy(result, "/");          /* /.. = / */
        D(("result[0] -> '%s'", result));
      } else {
        const size_t oldresultlen = strlen(result);
        /* Append the new path element */
        if(result[1])
          result = append(a, result, nresultp, "/");
        result = appendn(a, result, nresultp, path, elementlen);
        D(("result[1] -> '%s'", result));
        /* If we're following symlinks, see if the path so far points to a
         * link */
        if(flags & RP_READLINK) {
          const char *const target = sftp_do_readlink(a, result);
        
          if(target) {
            if(target[0] == '/')
              /* Absolute symlink, go back to the root */
              strcpy(result, "/");
            else
              /* Relative symlink, lose the last path element */
              result[oldresultlen] = 0;
            /* Process all! the elements of the link target */
            if(!(result = process_path(a, result, nresultp, target, flags)))
              return result;
          } else {
            switch(errno) {
            case EINVAL:
              /* Not a link.  Proceed. */
              break;
            default:
              if((flags & RP_MUST_EXIST)) {
                /* Nonexistent files are bad.  Return an error. */
                D(("error reading link: %s", strerror(errno)));
                return 0;
              }
              /* Nonexistent files are OK.  Proceed. */
              break;
            }
          }
        }
        D(("result[2] -> '%s'", result));
      }
     path += elementlen;
    }
  }
  D(("returning '%s'", result));
  return result;
}