Beispiel #1
0
static void
set_fork_info (TestResult * tr, int status, int signal_expected,
    unsigned char allowed_exit_value)
{
  int was_sig = WIFSIGNALED (status);
  int was_exit = WIFEXITED (status);
  int exit_status = WEXITSTATUS (status);
  int signal_received = WTERMSIG (status);

  if (was_sig) {
    if (signal_expected == signal_received) {
      if (alarm_received) {
        /* Got alarm instead of signal */
        tr->rtype = CK_ERROR;
        tr->msg = signal_error_msg (signal_received, signal_expected);
      } else {
        tr->rtype = CK_PASS;
        tr->msg = pass_msg ();
      }
    } else if (signal_expected != 0) {
      /* signal received, but not the expected one */
      tr->rtype = CK_ERROR;
      tr->msg = signal_error_msg (signal_received, signal_expected);
    } else {
      /* signal received and none expected */
      tr->rtype = CK_ERROR;
      tr->msg = signal_msg (signal_received);
    }
  } else if (signal_expected == 0) {
    if (was_exit && exit_status == allowed_exit_value) {
      tr->rtype = CK_PASS;
      tr->msg = pass_msg ();
    } else if (was_exit && exit_status != allowed_exit_value) {
      if (tr->msg == NULL) {    /* early exit */
        tr->rtype = CK_ERROR;
        tr->msg = exit_msg (exit_status);
      } else {
        tr->rtype = CK_FAILURE;
      }
    }
  } else {                      /* a signal was expected and none raised */
    if (was_exit) {
      tr->msg = exit_msg (exit_status);
      if (exit_status == allowed_exit_value)
        tr->rtype = CK_FAILURE; /* normal exit status */
      else
        tr->rtype = CK_FAILURE; /* early exit */
    }
  }
}
static int xmp_getattr(const char *path, struct stat *stbuf)
{
int res;
//pass_msg("getattr");
struct request_potato vrequest_potato;
struct reply_potato vreply_potato;
vrequest_potato.Opcode=4;
strcpy(vrequest_potato.fpath,path);
vreply_potato.rc=0;
vreply_potato=pass_msg(vrequest_potato);

printf("\npath=%s\n",path);

//populate
  copy_stat(stbuf,vreply_potato);

res=vreply_potato.rc;
printf("\nattr_value=%d\n",res);
//res = lstat(path, stbuf);

if (vreply_potato.rc == -1)
return vreply_potato.errno_t;

return 0;
}
Beispiel #3
0
static void set_nofork_info (TestResult *tr)
{
  if (tr->msg == NULL) {
    tr->rtype = CK_PASS;
    tr->msg = pass_msg();
  } else {
    tr->rtype = CK_FAILURE;
  }
}
static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
      off_t offset, struct fuse_file_info *fi)
{
DIR *dp;
struct dirent *de;
struct stat st;
struct request_potato vrequest_potato;
struct reply_potato vreply_potato;
struct directory_potato vdirectory_potato;
void *ptr_dir =  (void*)&vdirectory_potato;
vrequest_potato.Opcode=8;
strcpy(vrequest_potato.fpath,path);
vreply_potato=pass_msg(vrequest_potato);

(void) offset;
(void) fi;

do
{
    int recvttl,lenr;
    for(recvttl=0,lenr=1;recvttl< SIZEOF_DIRECTORY_POTATO && lenr!=0;recvttl+=lenr)
    {
        lenr=recv(server_sock,(ptr_dir+recvttl),SIZEOF_DIRECTORY_POTATO-recvttl,0);
        if(lenr<0)
        {
          perror("Recv");
          exit(1);
        }
        printf("\nRecv returned: %d\n",lenr);
    }
    if(vdirectory_potato.end!=1){
    memset(&st, 0, sizeof(st));
    st.st_ino = vdirectory_potato.st_ino_t;
    st.st_mode = vdirectory_potato.st_mode_t << 12;
    printf("\nReceived file name:%s\n",vdirectory_potato.d_name_t);
    if (filler(buf, vdirectory_potato.d_name_t, &st, 0))
    break;
	}
}
while(vdirectory_potato.end!=1);

/*dp = opendir(path);
if (dp == NULL)
return -errno;

while ((de = readdir(dp)) != NULL) {
struct stat st;
memset(&st, 0, sizeof(st));
st.st_ino = de->d_ino;
st.st_mode = de->d_type << 12;


closedir(dp);*/
return 0;
}
Beispiel #5
0
int fzp_read_ensure(struct fzp *fzp, void *ptr, size_t nmemb, const char *func)
{
	static int f;
	static int r;
	static size_t got;
	static int pass;
	for(r=0, got=0, pass=0; got!=nmemb; pass++)
	{
		r=fzp_read(fzp, ((char *)ptr)+got, nmemb-got);
		if(r>0)
		{
			got+=r;
			continue;
		}
		if(r<0)
		{
			pass_msg(nmemb, got, pass);
			logp("Error in %s, called from %s: %s\n",
				__func__, func, strerror(errno));
			return -1;
		}
		f=fzp_eof(fzp);
		if(!f) continue; // Not yet end of file, keep trying.
		if(f>0)
		{
			// End of file.
			if(!got) return 1;
			pass_msg(nmemb, got, pass);
			logp("Error in %s, called from %s: %u bytes, eof\n",
				__func__, func, got);
			return -1;
		}
		else
		{
			pass_msg(nmemb, got, pass);
			logp("Error in %s by fzp_feof, called from %s: %s\n",
				__func__, func, strerror(errno));
			return -1;
		}
	}
	return 0;
}
static int xmp_create(const char *path, mode_t mode, struct fuse_file_info *fi)
{
struct request_potato vrequest_potato;
struct reply_potato vreply_potato;
vrequest_potato.Opcode=12;
strcpy(vrequest_potato.fpath,path);
vrequest_potato.flags=fi->flags;
vrequest_potato.mode=mode;
vreply_potato=pass_msg(vrequest_potato);

if(vreply_potato.rc==-1)
return vreply_potato.errno_t;

	return 0;
}
static int xmp_unlink(const char *path)
{
int res;
struct request_potato vrequest_potato;
struct reply_potato vreply_potato;
vrequest_potato.Opcode=15;
strcpy(vrequest_potato.fpath,path);
vreply_potato=pass_msg(vrequest_potato);
res=vreply_potato.rc;
//res = unlink(path);
if (res == -1)
return vreply_potato.errno_t;

return 0;
}
static int xmp_mknod(const char *path, mode_t mode, dev_t rdev)
{
	int res;
	struct request_potato vrequest_potato;
	struct reply_potato vreply_potato;
	vrequest_potato.Opcode=13;
	strcpy(vrequest_potato.fpath,path);
	vrequest_potato.req_rdev_t=rdev;
	vrequest_potato.mode=mode;
	vreply_potato=pass_msg(vrequest_potato);
	/* On Linux this could just be 'mknod(path, mode, rdev)' but this
	   is more portable */
	if(vreply_potato.rc==-1)
	return vreply_potato.errno_t;
	
	return 0;
}
static int xmp_open(const char *path, struct fuse_file_info *fi)
{
int res;
struct request_potato vrequest_potato;
struct reply_potato vreply_potato;
vrequest_potato.Opcode=0;
vrequest_potato.mode=fi->flags;
strcpy(vrequest_potato.fpath,path);
vreply_potato=pass_msg(vrequest_potato);

//res = open(path, fi->flags);
if (vreply_potato.rc == -1)
return vreply_potato.errno_t;

//close(res);
return 0;
}
static int xmp_rmdir(const char *path)
{
int res;
struct request_potato vrequest_potato;
struct reply_potato vreply_potato;
vrequest_potato.Opcode=14;
strcpy(vrequest_potato.fpath,path);
vreply_potato=pass_msg(vrequest_potato);

res=vreply_potato.rc;
// res = rmdir(path);
if (res == -1)
return -errno;

return 0;


}
static int xmp_readlink(const char *path, char *buf, size_t size)
{
int res;
//pass_msg("readlink");
struct request_potato vrequest_potato;
struct reply_potato vreply_potato;
vrequest_potato.Opcode=10;
strcpy(vrequest_potato.fpath,path);
pass_msg(vrequest_potato);

res = readlink(path, buf, size - 1);

if (res == -1)
return -errno;

buf[res] = '\0';
return 0;
}
static int xmp_rename(const char *from, const char *to)
{
	int res;

	struct request_potato vrequest_potato;
	struct reply_potato vreply_potato;
	vrequest_potato.Opcode=17;
	//strcpy(vrequest_potato.fpath,path);
	strcpy(vrequest_potato.rename_from,from);
	strcpy(vrequest_potato.rename_to,to);

	vreply_potato=pass_msg(vrequest_potato);
	/* On Linux this could just be 'mknod(path, mode, rdev)' but this
	   is more portable */
	if(vreply_potato.rc==-1)
	return vreply_potato.errno_t;
	
	return 0;
}
static int xmp_mkdir(const char *path, mode_t mode)
{

int res;
struct request_potato vrequest_potato;
struct reply_potato vreply_potato;
vrequest_potato.Opcode=6;
strcpy(vrequest_potato.fpath,path);
vrequest_potato.mode=mode;
vreply_potato=pass_msg(vrequest_potato);

res=vreply_potato.rc;

//res = mkdir(path, mode);
if (res == -1)
return vreply_potato.errno_t;

return 0;
}
static int xmp_access(const char *path, int mask)
{
int res;
//pass_msg("access");
struct request_potato vrequest_potato;
struct reply_potato vreply_potato;
vrequest_potato.Opcode=7;
strcpy(vrequest_potato.fpath,path);
vrequest_potato.mode=mask;
vreply_potato=pass_msg(vrequest_potato);

res=vreply_potato.rc;
printf("\naccess_value=%d\n",res);
//res = access(path, mask);

if (res == -1)
return -errno;

return 0;
}
static int xmp_write(const char *path, const char *buf, size_t size,
    off_t offset, struct fuse_file_info *fi)
{

int fd;
int res;
char *buffer_t;
(void) fi;
struct request_potato vrequest_potato;
struct reply_potato vreply_potato;
vrequest_potato.Opcode=3;
strcpy(vrequest_potato.fpath,path);
vrequest_potato.buffer_size=size;
vrequest_potato.buffer_offset=offset;
vrequest_potato.mode=fi->flags;
printf("Client size =%d",vrequest_potato.buffer_size);
vreply_potato=pass_msg(vrequest_potato);

if(vreply_potato.rc==-1)
return vreply_potato.errno_t;


int sendttl,lens;

        for(sendttl=0;sendttl<(sizeof(char)*vrequest_potato.buffer_size);sendttl+=lens)
        {
            lens=send(server_sock,(buf+sendttl),(sizeof(char)*vrequest_potato.buffer_size),0);
            if(lens<0)
            {
              perror("Send:");
              exit(1);
            }
	            printf("Send returned: %d",sendttl);
        }	
//strcpy(buf,buffer_t);
/*
int recvttl,lenr;
    //struct reply_potato vreply_potato;
    void *ptr_rep = (void*)&vreply_potato;

 for(recvttl=0,lenr=1;recvttl< SIZEOF_REPLY_POTATO && lenr!=0;recvttl+=lenr)
    {
        lenr=recv(server_sock,(ptr_rep+recvttl),SIZEOF_REPLY_POTATO-recvttl,0);
        if(lenr<0)
        {
          perror("Recv");
          exit(1);
        }
        printf("Recv returned: %d\n",lenr);
    }
*/

return vrequest_potato.buffer_size;
//return vreply_potato.rc;






}
static int xmp_read(const char *path, char *buf, size_t size, off_t offset,
   struct fuse_file_info *fi)
{
int fd;
int res;
char *buffer_t;
char *temp_file_name;
char *new_file;
(void) fi;
struct request_potato vrequest_potato;
struct reply_potato vreply_potato;
vrequest_potato.Opcode=2;
strcpy(vrequest_potato.fpath,path);
vrequest_potato.buffer_size=size;
vrequest_potato.buffer_offset=offset;
vrequest_potato.mode=fi->flags;

//check with tmp

int temp_filefd;
new_file=malloc(strlen(path)+2);
new_file=strip_filename(path);
temp_file_name=malloc((sizeof(char)*strlen(new_file))+5);
strcpy(temp_file_name,"/tmp/");
strcat(temp_file_name,new_file);
printf("temp file name = %s",temp_file_name);


temp_filefd=open(temp_file_name,O_RDONLY,0666);
//check file in tmp
if(temp_filefd==-1){
printf("\nFile not found in local");
vrequest_potato.cached_t=0;
}else{
printf("\nFile found in local");
vrequest_potato.cached_t=1;
close(temp_filefd);
}

vreply_potato=pass_msg(vrequest_potato);
if(vrequest_potato.cached_t==1){

	if(vreply_potato.update==1){
	//Receive file 
	char *buffer_t;
	printf("Bytes to be received = %d",vreply_potato.st_size_t);
	buffer_t=malloc(sizeof(char)*vreply_potato.st_size_t);
	int recvttl,lenr;
	for(recvttl=0,lenr=1;recvttl< vreply_potato.st_size_t && lenr!=0;recvttl+=lenr)
	    {
		lenr=recv(server_sock,(buffer_t+recvttl),vreply_potato.st_size_t-recvttl,0);
		if(lenr<0)
		{
		  perror("Recv");
		  exit(1);
		}
		printf("Recv returned: %d\n",lenr);
	    }

	//Put it in local 
	int local_fd;
	if((local_fd=open(temp_file_name,O_CREAT|O_RDWR|O_TRUNC,0666))<0){
	perror("\nLocal File cannot be created");
	}else{
	printf("\nfile created in local\n");
	printf("\nreceived buffer %s\n",buffer_t);
	write(local_fd,buffer_t,vreply_potato.st_size_t);
	close(local_fd);
	printf("\nfile written in local\n");
	}
	//Read file and close
	fd=open(temp_file_name,fi->flags);
		if (fd == -1)
			return -errno;
		res = pread(fd, buf, size, offset);
		if (res == -1)
			return -errno;
		close(fd);


	}else if(vreply_potato.update==0){
	//Reads from local
		fd=open(temp_file_name,fi->flags);
		if (fd == -1)
			return -errno;
		res = pread(fd, buf, size, offset);
		if (res == -1)
			return -errno;
		close(fd);
	}else{
		perror("read failed");
	}

}else if(vrequest_potato.cached_t==0){
	//Receive file 
	char *buffer_t;
	printf("Bytes to be received = %d",vreply_potato.st_size_t);
	buffer_t=malloc(sizeof(char)*vreply_potato.st_size_t);
	int recvttl,lenr;
	for(recvttl=0,lenr=1;recvttl< vreply_potato.st_size_t && lenr!=0;recvttl+=lenr)
	    {
		lenr=recv(server_sock,(buffer_t+recvttl),vreply_potato.st_size_t-recvttl,0);
		if(lenr<0)
		{
		  perror("Recv");
		  exit(1);
		}
		printf("Recv returned: %d\n",lenr);
	    }

	//Put it in local 
	int local_fd;
	if((local_fd=open(temp_file_name,O_CREAT|O_RDWR|O_TRUNC,0666))<0){
	perror("\nLocal File cannot be created");
	}else{
	printf("\nfile created in local\n");
	printf("\nreceived buffer %s\n",buffer_t);
	write(local_fd,buffer_t,vreply_potato.st_size_t);
	close(local_fd);
	printf("\nfile written in local\n");
	}
	//Read file and close
	char * read_buffer;
	read_buffer=malloc(sizeof(char)*size);
	fd=open(temp_file_name,O_RDONLY);
		if (fd == -1)
			return -errno;
		res = pread(fd, read_buffer, size, offset);
		if (res == -1)
			return -errno;
		strcpy(buf,read_buffer);
		close(fd);
}else{
perror("Should not come here");
}


return vreply_potato.rc;

/*

vreply_potato=pass_msg(vrequest_potato);




if(vreply_potato.rc==-1)
return vreply_potato.errno_t;

buffer_t=malloc(sizeof(char)*vreply_potato.rc);
int recvttl,lenr;
for(recvttl=0,lenr=1;recvttl< vreply_potato.rc && lenr!=0;recvttl+=lenr)
    {
        lenr=recv(server_sock,(buffer_t+recvttl),vreply_potato.rc-recvttl,0);
        if(lenr<0)
        {
          perror("Recv");
          exit(1);
        }
        printf("Recv returned: %d\n",lenr);
    }
strcpy(buf,buffer_t);

return vreply_potato.rc;
*/

}