Example #1
0
static int v4l2_case_take_pic(void* user_ptr, int test_num)
{
	FUNC_ENTER()
	BLTS_DEBUG("Test number %i:\n", test_num);
	v4l2_data* data = (v4l2_data*)user_ptr;

	if(!open_device (data->device))
	{
		BLTS_ERROR("Can't open device %s\n", data->device->dev_name);
		return -1;
	}

	if(init_device (data->device, data->device->requested_format.fmt.pix.width, data->device->requested_format.fmt.pix.height))
	{
		if(data->snapshot_filename != NULL)
		{
			free(data->snapshot_filename);
			data->snapshot_filename = NULL;
		}
		data->snapshot_filename = create_picture_filename(data->device);
		BLTS_DEBUG("Filename to create: '%s'\n", data->snapshot_filename);
		BLTS_DEBUG("Maximum resolution is: %ix%i\n", data->device->format.fmt.pix.width, data->device->format.fmt.pix.height);

		if(!start_capturing (data->device))
			goto err;
		if(!mainloop (data->device, 0))
			goto err;
		BLTS_DEBUG("Taking picture %s\n", data->snapshot_filename);
		if(!do_snapshot (data->device, data->snapshot_filename))
			goto err;
		// ensure that image is actual JPEG
		if(read_jpeg_image(data->snapshot_filename))
		{
			BLTS_DEBUG("Error, image %s is not JPEG standard.\n", data->snapshot_filename);
			return -1;
		}


		stop_capturing (data->device);
		uninit_device (data->device);
	}
	else
	{
		BLTS_ERROR("Can't initialize device\n");
		goto err;
	}

	close_device (data->device);
	FUNC_LEAVE()
	return 0;

err:

	stop_capturing(data->device);
	uninit_device(data->device);
	close_device(data->device);
	FUNC_LEAVE()
	return -1;
}
Example #2
0
int
main(int argc, char *argv[])
{
	PGconn			*conn;
	StringInfoData	 conn_info;
	int				 num_options;

	num_options = pgut_getopt(argc, argv, options);

	/* command-line arguments is not necessary */
	if (num_options != argc)
		ereport(ERROR,
			(errcode(EINVAL),
			 errmsg("too many argumetns")));

	/* can't specified the mode two or more */
	if ((mode_list && (mode_size || mode_report || mode_snapshot || mode_delete)) ||
		(mode_size && (mode_report || mode_snapshot || mode_delete)) ||
		(mode_report && (mode_snapshot || mode_delete)) ||
		(mode_snapshot && mode_delete))
		ereport(ERROR,
			(errcode(EINVAL),
			 errmsg("can't specify two or more mode")));

	/* connect to database */
	initStringInfo(&conn_info);
	if (dbname && dbname[0])
		appendStringInfo(&conn_info, "dbname=%s ", dbname);
	if (host && host[0])
		appendStringInfo(&conn_info, "host=%s ", host);
	if (port && port[0])
		appendStringInfo(&conn_info, "port=%s ", port);
	if (username && username[0])
		appendStringInfo(&conn_info, "user=%s ", username);

	conn = pgut_connect(conn_info.data, prompt_password, ERROR);
	termStringInfo(&conn_info);

	/* execute a specified operation */
	if (mode_list)
		do_list(conn, instid);
	else if (mode_size)
		do_size(conn);
	else if (mode_report)
		do_report(conn, mode_report,
			instid, beginid, endid, begindate, enddate, output);
	else if (mode_snapshot)
		do_snapshot(conn, mode_snapshot);
	else if (mode_delete)
		do_delete(conn, mode_delete);
	else
		ereport(ERROR,
			(errcode(EINVAL),
			 errmsg("please specify operation option (-l, -s, -r, -S, -D)")));

	pgut_disconnect(conn);
	return 0;
}
Example #3
0
void UCAM529::takePicture() {
    if (send_initial())
    {
        if (set_package_size())
        {
            if (do_snapshot())
            {
                if (get_picture())
                {
                    get_data();
                }
            }
        }
    }
}
static void 
take_snapshot(Fixture *fixture, const void *data) {
	g_message("enter func %s", __func__);
	char content[REQ_SIZE];
	int offset = 0;
	int i = 0;

	memset(content, 0, REQ_SIZE);
	while (offset < TOTAL_SIZE) {
		int ret1 = hlfs_write(fixture->ctrl, content, REQ_SIZE, offset);
		g_assert_cmpint(ret1, ==, REQ_SIZE);
		do_snapshot(fixture, i);
		offset += REQ_SIZE;
		i += 1;
	}
	g_message("leave func %s", __func__);
	return;
}
Example #5
0
/*===========================================================================*
 *				main                                         *
 *===========================================================================*/
PUBLIC int main(int argc, char **argv)
{
/* This is the main routine of this service. The main loop consists of 
 * three major activities: getting new work, processing the work, and
 * sending the reply. The loop never terminates, unless a panic occurs.
 */
  message m;
  int result;                 

  /* SEF local startup. */
  env_setargs(argc, argv);
  sef_local_startup();

  /* Main loop - get work and do it, forever. */         
  while (TRUE) {              

      /* Wait for incoming message, sets 'callnr' and 'who'. */
      get_work(&m);

      if (is_notify(callnr)) {
          printf("DS: warning, got illegal notify from: %d\n", m.m_source);
          result = EINVAL;
          goto send_reply;
      }

      switch (callnr) {
      case DS_PUBLISH:
          result = do_publish(&m);
          break;
      case DS_RETRIEVE:
	  result = do_retrieve(&m);
	  break;
      case DS_RETRIEVE_LABEL:
	  result = do_retrieve_label(&m);
	  break;
      case DS_DELETE:
	  result = do_delete(&m);
	  break;
      case DS_SUBSCRIBE:
	  result = do_subscribe(&m);
	  break;
      case DS_CHECK:
	  result = do_check(&m);
	  break;
      case DS_SNAPSHOT:
	  result = do_snapshot(&m);
	  break;
      case GETSYSINFO:
	  result = do_getsysinfo(&m);
	  break;
      default: 
          printf("DS: warning, got illegal request from %d\n", m.m_source);
          result = EINVAL;
      }

send_reply:
      /* Finally send reply message, unless disabled. */
      if (result != EDONTREPLY) {
          m.m_type = result;  		/* build reply message */
	  reply(who_e, &m);		/* send it away */
      }
  }
  return(OK);				/* shouldn't come here */
}
Example #6
0
int restore_line(const char *filename,uint64_t lv,char *line) {
	char *ptr;
	uint32_t ts;
	int status;
	char* errormsgs[]={ ERROR_STRINGS };

	status = ERROR_MISMATCH;
	ptr = line;

	EAT(ptr,filename,lv,':');
	EAT(ptr,filename,lv,' ');
	GETU32(ts,ptr);
	EAT(ptr,filename,lv,'|');
	switch (*ptr) {
		case 'A':
			if (strncmp(ptr,"ACCESS",6)==0) {
				status = do_access(filename,lv,ts,ptr+6);
			} else if (strncmp(ptr,"ATTR",4)==0) {
				status = do_attr(filename,lv,ts,ptr+4);
			} else if (strncmp(ptr,"APPEND",6)==0) {
				status = do_append(filename,lv,ts,ptr+6);
			} else if (strncmp(ptr,"ACQUIRE",7)==0) {
				status = do_acquire(filename,lv,ts,ptr+7);
			} else if (strncmp(ptr,"AQUIRE",6)==0) {
				status = do_acquire(filename,lv,ts,ptr+6);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'C':
			if (strncmp(ptr,"CREATE",6)==0) {
				status = do_create(filename,lv,ts,ptr+6);
			} else if (strncmp(ptr,"CUSTOMER",8)==0) {	// deprecated
				status = do_session(filename,lv,ts,ptr+8);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'E':
			if (strncmp(ptr,"EMPTYTRASH",10)==0) {
				status = do_emptytrash(filename,lv,ts,ptr+10);
			} else if (strncmp(ptr,"EMPTYRESERVED",13)==0) {
				status = do_emptyreserved(filename,lv,ts,ptr+13);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'F':
			if (strncmp(ptr,"FREEINODES",10)==0) {
				status = do_freeinodes(filename,lv,ts,ptr+10);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'I':
			if (strncmp(ptr,"INCVERSION",10)==0) {
				status = do_incversion(filename,lv,ts,ptr+10);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'L':
			if (strncmp(ptr,"LENGTH",6)==0) {
				status = do_length(filename,lv,ts,ptr+6);
			} else if (strncmp(ptr,"LINK",4)==0) {
				status = do_link(filename,lv,ts,ptr+4);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'M':
			if (strncmp(ptr,"MOVE",4)==0) {
				status = do_move(filename,lv,ts,ptr+4);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'P':
			if (strncmp(ptr,"PURGE",5)==0) {
				status = do_purge(filename,lv,ts,ptr+5);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'Q':
			if (strncmp(ptr,"QUOTA",5)==0) {
				status = do_quota(filename,lv,ts,ptr+5);
			}
			break;
		case 'R':
			if (strncmp(ptr,"RELEASE",7)==0) {
				status = do_release(filename,lv,ts,ptr+7);
			} else if (strncmp(ptr,"REPAIR",6)==0) {
				status = do_repair(filename,lv,ts,ptr+6);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'S':
			if (strncmp(ptr,"SETEATTR",8)==0) {
				status = do_seteattr(filename,lv,ts,ptr+8);
			} else if (strncmp(ptr,"SETGOAL",7)==0) {
				status = do_setgoal(filename,lv,ts,ptr+7);
			} else if (strncmp(ptr,"SETPATH",7)==0) {
				status = do_setpath(filename,lv,ts,ptr+7);
			} else if (strncmp(ptr,"SETTRASHTIME",12)==0) {
				status = do_settrashtime(filename,lv,ts,ptr+12);
			} else if (strncmp(ptr,"SETXATTR",8)==0) {
				status = do_setxattr(filename,lv,ts,ptr+8);
			} else if (strncmp(ptr,"SNAPSHOT",8)==0) {
				status = do_snapshot(filename,lv,ts,ptr+8);
			} else if (strncmp(ptr,"SYMLINK",7)==0) {
				status = do_symlink(filename,lv,ts,ptr+7);
			} else if (strncmp(ptr,"SESSION",7)==0) {
				status = do_session(filename,lv,ts,ptr+7);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'T':
			if (strncmp(ptr,"TRUNC",5)==0) {
				status = do_trunc(filename,lv,ts,ptr+5);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'U':
			if (strncmp(ptr,"UNLINK",6)==0) {
				status = do_unlink(filename,lv,ts,ptr+6);
			} else if (strncmp(ptr,"UNDEL",5)==0) {
				status = do_undel(filename,lv,ts,ptr+5);
			} else if (strncmp(ptr,"UNLOCK",6)==0) {
				status = do_unlock(filename,lv,ts,ptr+6);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'W':
			if (strncmp(ptr,"WRITE",5)==0) {
				status = do_write(filename,lv,ts,ptr+5);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		default:
			printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
	}
	if (status>STATUS_OK) {
		printf("%s:%"PRIu64": error: %d (%s)\n",filename,lv,status,errormsgs[status]);
	}
	return status;
}
Example #7
0
int replay(const char *log_data) {
	uint64_t fv,lv; //fv = filesystem's version lv = log's version
	uint32_t ts;
	uint8_t status;
	char buff[10000];
	char *ptr;
	char* errormsgs[]={ ERROR_STRINGS };

	char *test_ptr;

	sprintf(buff,"%s",log_data);
	ptr = buff;
//for test
	test_ptr = buff;
	fv = shadow_fs_getversion();
	GETU64(lv,ptr);
	if(lv < fv) {
		MFSLOG(LOG_ERR,"the changelog's verison %lu is smaller than filesystem's version %lu",lv,fv);
		//more complicated method to ensure consistency
	} else {
		status = ERROR_MISMATCH; 
                EAT(ptr,lv,':');
                EAT(ptr,lv,' ');
                GETU32(ts,ptr);
                EAT(ptr,lv,'|');
                switch (*ptr) {
                	case 'A':
                                if (strncmp(ptr,"ACCESS",6)==0) {
                                        status = do_access(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"ATTR",4)==0) {
                                        status = do_attr(lv,ts,ptr+4);
                                } else if (strncmp(ptr,"APPEND",6)==0) {
                                        status = do_append(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"AQUIRE",6)==0) {
                                        status = do_aquire(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                } 
                                break;  
                        case 'C':
                                if (strncmp(ptr,"CREATE",6)==0) {
                                        status = do_create(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"CUSTOMER",8)==0) {      // deprecated
                                        status = do_session(lv,ts,ptr+8);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                } 
                                break;  
                        case 'E':
                                if (strncmp(ptr,"EMPTYTRASH",10)==0) {
                                        status = do_emptytrash(lv,ts,ptr+10);
                                } else if (strncmp(ptr,"EMPTYRESERVED",13)==0) {
                                        status = do_emptyreserved(lv,ts,ptr+13);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                } 
                                break;  
                        case 'F': 
                                if (strncmp(ptr,"FREEINODES",10)==0) {
                                        status = do_freeinodes(lv,ts,ptr+10);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'I':
                                if (strncmp(ptr,"INCVERSION",10)==0) {
                                        status = do_incversion(lv,ts,ptr+10);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'L':
                                if (strncmp(ptr,"LENGTH",6)==0) {
                                        status = do_length(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"LINK",4)==0) {
                                        status = do_link(lv,ts,ptr+4);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'M':
                                if (strncmp(ptr,"MOVE",4)==0) {
                                        status = do_move(lv,ts,ptr+4);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'P':
                                if (strncmp(ptr,"PURGE",5)==0) {
                                        status = do_purge(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'R':
                                if (strncmp(ptr,"RELEASE",7)==0) {
                                        status = do_release(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"REPAIR",6)==0) {
                                        status = do_repair(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'S':
                                if (strncmp(ptr,"SETEATTR",8)==0) {
                                        status = do_seteattr(lv,ts,ptr+8);
                                } else if (strncmp(ptr,"SETGOAL",7)==0) {
                                        status = do_setgoal(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SETPATH",7)==0) {
                                        status = do_setpath(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SETTRASHTIME",12)==0) {
                                        status = do_settrashtime(lv,ts,ptr+12);
                                } else if (strncmp(ptr,"SNAPSHOT",8)==0) {
                                        status = do_snapshot(lv,ts,ptr+8);
                                } else if (strncmp(ptr,"SYMLINK",7)==0) {
                                        status = do_symlink(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SESSION",7)==0) {
                                        status = do_session(lv,ts,ptr+7);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'T':
                                if (strncmp(ptr,"TRUNC",5)==0) {
                                        status = do_trunc(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'U':
                                if (strncmp(ptr,"UNLINK",6)==0) {
                                        status = do_unlink(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"UNDEL",5)==0) {
                                        status = do_undel(lv,ts,ptr+5);
                                } else if (strncmp(ptr,"UNLOCK",6)==0) {
                                        status = do_unlock(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'W':
                                if (strncmp(ptr,"WRITE",5)==0) {
                                        status = do_write(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        default:
                                MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                        }
			/**
			  * if master is down, slave switch, we may missed some metadata 
			  * return 0 to let the process continue, otherwise, we will reply the 
			  * log forever.
			  * 
			  * Dongyang, Zhang
			  */				
			if (status!=STATUS_OK) {
				MFSLOG(LOG_ERR,"%"PRIu64": error: %"PRIu8" (%s),the log is (%s)",lv,status,errormsgs[status],test_ptr);
//                                syslog(LOG_ERR,"%"PRIu64": error: %"PRIu8" (%s)",lv,status,errormsgs[status]);
                           return 1;
                        }               
                        fv = shadow_fs_getversion();
                        if (lv+1!=fv) {
                                MFSLOG(LOG_ERR,"%"PRIu64": version mismatch fsversion:%"PRIu64"",lv,fv);
                                return 1;
                        }
	}
	return 0;
}                
Example #8
0
int restore(void) {
        FILE *fd;
        char buff[10000];
        char *ptr;
        uint64_t v,lv;
        uint32_t ts;
        uint8_t status;
	uint32_t dplen;
	char *datapath = NULL;
	char *logpath = NULL;
        char* errormsgs[]={ ERROR_STRINGS };
        
        v = shadow_fs_getversion();
        lv = 0;

        MFSLOG(LOG_NOTICE,"meta data version: %"PRIu64"",v);
        
	datapath = strdup(DATA_PATH);
	dplen = strlen(datapath);
	logpath = malloc(dplen+sizeof("/changelog.0.mfs"));
	memcpy(logpath,datapath,dplen);
	memcpy(logpath+dplen,"/changelog.0.mfs",sizeof("/changelog.0.mfs"));
        fd = fopen(logpath,"r");
        if (fd==NULL) {
                MFSLOG(LOG_NOTICE,"can't open changemeta file: %s",logpath);
                return 1;
        }
        while (fgets(buff,10000,fd)) {
                ptr = buff;
                GETU64(lv,ptr);
                if (lv<v) {
                        // skip
                } else {
                        status = ERROR_MISMATCH;
                        EAT(ptr,lv,':');
                        EAT(ptr,lv,' ');
                        GETU32(ts,ptr);
                        EAT(ptr,lv,'|');
                        switch (*ptr) {
                        case 'A':
                                if (strncmp(ptr,"ACCESS",6)==0) {
                                        status = do_access(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"ATTR",4)==0) {
                                        status = do_attr(lv,ts,ptr+4);
                                } else if (strncmp(ptr,"APPEND",6)==0) {
                                        status = do_append(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"AQUIRE",6)==0) {
                                        status = do_aquire(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'C':
                                if (strncmp(ptr,"CREATE",6)==0) {
                                        status = do_create(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"CUSTOMER",8)==0) {      // deprecated
                                        status = do_session(lv,ts,ptr+8);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'E':
                                if (strncmp(ptr,"EMPTYTRASH",10)==0) {
                                        status = do_emptytrash(lv,ts,ptr+10);
                                } else if (strncmp(ptr,"EMPTYRESERVED",13)==0) {
                                        status = do_emptyreserved(lv,ts,ptr+13);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'F':
                                if (strncmp(ptr,"FREEINODES",10)==0) {
                                        status = do_freeinodes(lv,ts,ptr+10);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'I':
                                if (strncmp(ptr,"INCVERSION",10)==0) {
                                        status = do_incversion(lv,ts,ptr+10);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'L':
                                if (strncmp(ptr,"LENGTH",6)==0) {
                                        status = do_length(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"LINK",4)==0) {
                                        status = do_link(lv,ts,ptr+4);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'M':
                                if (strncmp(ptr,"MOVE",4)==0) {
                                        status = do_move(lv,ts,ptr+4);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'P':
                                if (strncmp(ptr,"PURGE",5)==0) {
                                        status = do_purge(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'R':
                                if (strncmp(ptr,"RELEASE",7)==0) {
                                        status = do_release(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"REPAIR",6)==0) {
                                        status = do_repair(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'S':
                                if (strncmp(ptr,"SETEATTR",8)==0) {
                                        status = do_seteattr(lv,ts,ptr+8);
                                } else if (strncmp(ptr,"SETGOAL",7)==0) {
                                        status = do_setgoal(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SETPATH",7)==0) {
                                        status = do_setpath(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SETTRASHTIME",12)==0) {
                                        status = do_settrashtime(lv,ts,ptr+12);
                                } else if (strncmp(ptr,"SNAPSHOT",8)==0) {
                                        status = do_snapshot(lv,ts,ptr+8);
                                } else if (strncmp(ptr,"SYMLINK",7)==0) {
                                        status = do_symlink(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SESSION",7)==0) {
                                        status = do_session(lv,ts,ptr+7);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'T':
                                if (strncmp(ptr,"TRUNC",5)==0) {
                                        status = do_trunc(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'U':
                                if (strncmp(ptr,"UNLINK",6)==0) {
                                        status = do_unlink(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"UNDEL",5)==0) {
                                        status = do_undel(lv,ts,ptr+5);
                                } else if (strncmp(ptr,"UNLOCK",6)==0) {
                                        status = do_unlock(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'W':
                                if (strncmp(ptr,"WRITE",5)==0) {
                                        status = do_write(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        default:
                                MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                        }
			    /**
			      *  let the restore continue if we missed some meta data, otherwise the 
			      *
			      * Dongyang Zhang
			      */
                        if (status!=STATUS_OK) {
                                MFSLOG(LOG_ERR,"%"PRIu64": error: %"PRIu8" (%s)",lv,status,errormsgs[status]);
                                return 1;
                        }
                        v = shadow_fs_getversion();
                        if (lv+1!=v) {
                                MFSLOG(LOG_ERR,"%"PRIu64": version mismatch",lv);
                                return 1;
                        }
                }
        }
        fclose(fd);
        MFSLOG(LOG_NOTICE,"version after applying changelog: %"PRIu64"",v);
        return 0;
}
Example #9
0
int
main(int argc, char * const argv[])
{
    Boolean			doDNS	= FALSE;
    Boolean			doNet	= FALSE;
    Boolean			doNWI	= FALSE;
    Boolean			doPrefs	= FALSE;
    Boolean			doProxy	= FALSE;
    Boolean			doReach	= FALSE;
    Boolean			doSnap	= FALSE;
    char			*get	= NULL;
    char			*log	= NULL;
    extern int		optind;
    int			opt;
    int			opti;
    const char		*prog	= argv[0];
    char			*renew	= NULL;
    char			*set	= NULL;
    char			*nc_cmd	= NULL;
    InputRef		src;
    int			timeout	= 15;	/* default timeout (in seconds) */
    char			*wait	= NULL;
    Boolean			watch	= FALSE;
    int			xStore	= 0;	/* non dynamic store command line options */

    /* process any arguments */

    while ((opt = getopt_long(argc, argv, "dDvprt:w:W", longopts, &opti)) != -1)
        switch(opt) {
        case 'd':
            _sc_debug = TRUE;
            _sc_log   = FALSE;	/* enable framework logging */
            break;
        case 'D':
            doDispatch = TRUE;
            break;
        case 'v':
            _sc_verbose = TRUE;
            _sc_log     = FALSE;	/* enable framework logging */
            break;
        case 'p':
            enablePrivateAPI = TRUE;
            break;
        case 'r':
            doReach = TRUE;
            xStore++;
            break;
        case 't':
            timeout = atoi(optarg);
            break;
        case 'w':
            wait = optarg;
            xStore++;
            break;
        case 'W':
            watch = TRUE;
            break;
        case 0:
            if        (strcmp(longopts[opti].name, "dns") == 0) {
                doDNS = TRUE;
                xStore++;
            } else if (strcmp(longopts[opti].name, "get") == 0) {
                get = optarg;
                xStore++;
            } else if (strcmp(longopts[opti].name, "nc") == 0) {
                nc_cmd = optarg;
                xStore++;
            } else if (strcmp(longopts[opti].name, "net") == 0) {
                doNet = TRUE;
                xStore++;
            } else if (strcmp(longopts[opti].name, "nwi") == 0) {
                doNWI = TRUE;
                xStore++;
            } else if (strcmp(longopts[opti].name, "prefs") == 0) {
                doPrefs = TRUE;
                xStore++;
            } else if (strcmp(longopts[opti].name, "proxy") == 0) {
                doProxy = TRUE;
                xStore++;
            } else if (strcmp(longopts[opti].name, "renew") == 0) {
                renew = optarg;
                xStore++;
            } else if (strcmp(longopts[opti].name, "set") == 0) {
                set = optarg;
                xStore++;
            } else if (strcmp(longopts[opti].name, "snapshot") == 0) {
                doSnap = TRUE;
                xStore++;
            } else if (strcmp(longopts[opti].name, "log") == 0) {
                log = optarg;
                xStore++;
            } else if (strcmp(longopts[opti].name, "user") == 0) {
                username = CFStringCreateWithCString(NULL, optarg, kCFStringEncodingUTF8);
            } else if (strcmp(longopts[opti].name, "password") == 0) {
                password = CFStringCreateWithCString(NULL, optarg, kCFStringEncodingUTF8);
            } else if (strcmp(longopts[opti].name, "secret") == 0) {
                sharedsecret = CFStringCreateWithCString(NULL, optarg, kCFStringEncodingUTF8);
            }
            break;
        case '?':
        default :
            usage(prog);
        }
    argc -= optind;
    argv += optind;

    if (xStore > 1) {
        // if we are attempting to process more than one type of request
        usage(prog);
    }

    /* are we checking (or watching) the reachability of a host/address */
    if (doReach) {
        if (argc < 1) {
            usage(prog);
        }
        if (watch) {
            do_watchReachability(argc, (char **)argv);
        } else {
            do_checkReachability(argc, (char **)argv);
        }
        /* NOT REACHED */
    }

    /* are we waiting on the presense of a dynamic store key */
    if (wait) {
        do_wait(wait, timeout);
        /* NOT REACHED */
    }

    /* are we looking up the DNS configuration */
    if (doDNS) {
        do_showDNSConfiguration(argc, (char **)argv);
        /* NOT REACHED */
    }

    if (doNWI) {
        do_nwi(argc, (char**)argv);
        /* NOT REACHED */
    }

    if (doSnap) {
        if (!enablePrivateAPI
#if	!TARGET_IPHONE_SIMULATOR
                || (geteuid() != 0)
#endif	// !TARGET_IPHONE_SIMULATOR
           ) {
            usage(prog);
        }

        do_open(0, NULL);	/* open the dynamic store */
        do_snapshot(argc, (char**)argv);
        exit(0);
    }

    /* are we looking up a preference value */
    if (get) {
        if (argc != 2) {
            if (findPref(get) < 0) {
                usage(prog);
            }
        } else {
            /* need to go back one argument
             * for the filename */
            argc++;
            argv--;
        }

        do_getPref(get, argc, (char **)argv);
        /* NOT REACHED */
    }

    /* are we looking up the proxy configuration */
    if (doProxy) {
        do_showProxyConfiguration(argc, (char **)argv);
        /* NOT REACHED */
    }

    /* are we changing a preference value */
    if (set) {
        if (findPref(set) < 0) {
            usage(prog);
        }
        do_setPref(set, argc, (char **)argv);
        /* NOT REACHED */
    }

    /* verbose log */
    if (log != NULL) {
        if (strcasecmp(log, "IPMonitor")) {
            usage(prog);
        }
        do_log(log, argc, (char * *)argv);
        /* NOT REACHED */
    }
    /* network connection commands */
    if (nc_cmd) {
        if (find_nc_cmd(nc_cmd) < 0) {
            usage(prog);
        }
        do_nc_cmd(nc_cmd, argc, (char **)argv, watch);
        /* NOT REACHED */
    }

    if (doNet) {
        /* if we are going to be managing the network configuration */
        commands  = (cmdInfo *)commands_net;
        nCommands = nCommands_net;

        if (!getenv("ENABLE_EXPERIMENTAL_SCUTIL_COMMANDS")) {
            usage(prog);
        }

        do_net_init();				/* initialization */
        do_net_open(argc, (char **)argv);	/* open prefs */
    } else if (doPrefs) {
        /* if we are going to be managing the network configuration */
        commands  = (cmdInfo *)commands_prefs;
        nCommands = nCommands_prefs;

        do_dictInit(0, NULL);			/* start with an empty dictionary */
        do_prefs_init();			/* initialization */
        do_prefs_open(argc, (char **)argv);	/* open prefs */
    } else {
        /* if we are going to be managing the dynamic store */
        commands  = (cmdInfo *)commands_store;
        nCommands = nCommands_store;

        do_dictInit(0, NULL);	/* start with an empty dictionary */
        do_open(0, NULL);	/* open the dynamic store */
    }

    /* are we trying to renew a DHCP lease */
    if (renew != NULL) {
        do_renew(renew);
        /* NOT REACHED */
    }

    /* allocate command input stream */
    src = (InputRef)CFAllocatorAllocate(NULL, sizeof(Input), 0);
    src->fp = stdin;
    src->el = NULL;
    src->h  = NULL;

    if (isatty(fileno(src->fp))) {
        int		editmode	= 1;
        HistEvent	ev;
        struct termios	t;

        if (tcgetattr(fileno(src->fp), &t) != -1) {
            if ((t.c_lflag & ECHO) == 0) {
                editmode = 0;
            }
        }
        src->el = el_init(prog, src->fp, stdout, stderr);
        src->h  = history_init();

        (void)history(src->h, &ev, H_SETSIZE, INT_MAX);
        el_set(src->el, EL_HIST, history, src->h);

        if (!editmode) {
            el_set(src->el, EL_EDITMODE, 0);
        }

        el_set(src->el, EL_EDITOR, "emacs");
        el_set(src->el, EL_PROMPT, prompt);

        el_source(src->el, NULL);

        if ((el_get(src->el, EL_EDITMODE, &editmode) != -1) && editmode != 0) {
            el_set(src->el, EL_SIGNAL, 1);
        } else {
            history_end(src->h);
            src->h = NULL;
            el_end(src->el);
            src->el = NULL;
        }
    }

    while (TRUE) {
        Boolean	ok;

        ok = process_line(src);
        if (!ok) {
            break;
        }
    }

    /* close the socket, free resources */
    if (src->h)	history_end(src->h);
    if (src->el)	el_end(src->el);
    (void)fclose(src->fp);
    CFAllocatorDeallocate(NULL, src);

    exit (EX_OK);	// insure the process exit status is 0
    return 0;	// ...and make main fit the ANSI spec.
}