예제 #1
0
static void conflict_rename_rename_2(struct rename *ren1,
				     const char *branch1,
				     struct rename *ren2,
				     const char *branch2)
{
	char *new_path1 = unique_path(ren1->pair->two->path, branch1);
	char *new_path2 = unique_path(ren2->pair->two->path, branch2);
	output(1, "Renamed %s to %s and %s to %s instead",
	       ren1->pair->one->path, new_path1,
	       ren2->pair->one->path, new_path2);
	remove_file(0, ren1->pair->two->path, 0);
	update_file(0, ren1->pair->two->sha1, ren1->pair->two->mode, new_path1);
	update_file(0, ren2->pair->two->sha1, ren2->pair->two->mode, new_path2);
	free(new_path2);
	free(new_path1);
}
예제 #2
0
파일: metrics.cpp 프로젝트: imaxxs/cyton
double cpu_system_func ( void ) {
	char *p;
	double val;
	double last_system_jiffies,  system_jiffies,
                 last_total_jiffies, total_jiffies, diff;
 
	p = update_file(&proc_stat);
	p = skip_token(p);
	p = skip_token(p);
	p = skip_token(p);
	system_jiffies = strtod( p , (char **)NULL );
	if (num_cpustates > NUM_CPUSTATES_24X) {
		p = skip_token(p);
		p = skip_token(p);
		p = skip_token(p);
		system_jiffies += strtod( p , (char **)NULL ); /* "intr" counted in system */
		p = skip_token(p);
		system_jiffies += strtod( p , (char **)NULL ); /* "sintr" counted in system */
	}
	total_jiffies  = total_jiffies_func();

	diff = system_jiffies  - last_system_jiffies;

	if ( diff )
	val = (diff/(total_jiffies - last_total_jiffies))*100;
	else
	val = 0.0;

	last_system_jiffies  = system_jiffies;
	last_total_jiffies = total_jiffies;   

	return val;
}
예제 #3
0
static int update_cnstat(uint32_t udp, uint32_t tcp, uint32_t other)
{
	char path[1024];

	struct stat s;
	struct conn_entry e;

	snprintf(path, sizeof(path), DB_CN_FILE);

	if (stat(path, &s))
	{
		if (init_file(path, sizeof(struct conn_entry)))
		{
			fprintf(stderr, "Failed to init %s: %s\n",
					path, strerror(errno));

			return -1;
		}
	}

	e.time  = htonl(time(NULL));
	e.udp   = htonl(udp);
	e.tcp   = htonl(tcp);
	e.other = htonl(other);

	return update_file(path, &e, sizeof(struct conn_entry));
}
예제 #4
0
static int update_ldstat(uint16_t load1, uint16_t load5, uint16_t load15)
{
	char path[1024];

	struct stat s;
	struct load_entry e;

	snprintf(path, sizeof(path), DB_LD_FILE);

	if (stat(path, &s))
	{
		if (init_file(path, sizeof(struct load_entry)))
		{
			fprintf(stderr, "Failed to init %s: %s\n",
					path, strerror(errno));

			return -1;
		}
	}

	e.time   = htonl(time(NULL));
	e.load1  = htons(load1);
	e.load5  = htons(load5);
	e.load15 = htons(load15);

	return update_file(path, &e, sizeof(struct load_entry));
}
예제 #5
0
static int update_ifstat(
	const char *ifname, uint32_t rxb, uint32_t rxp, uint32_t txb, uint32_t txp
) {
	char path[1024];

	struct stat s;
	struct traffic_entry e;

	snprintf(path, sizeof(path), DB_IF_FILE, ifname);

	if (stat(path, &s))
	{
		if (init_file(path, sizeof(struct traffic_entry)))
		{
			fprintf(stderr, "Failed to init %s: %s\n",
					path, strerror(errno));

			return -1;
		}
	}

	e.time = htonl(time(NULL));
	e.rxb  = htonl(rxb);
	e.rxp  = htonl(rxp);
	e.txb  = htonl(txb);
	e.txp  = htonl(txp);

	return update_file(path, &e, sizeof(struct traffic_entry));
}
예제 #6
0
static int update_radiostat(
	const char *ifname, uint16_t rate, uint8_t rssi, uint8_t noise
) {
	char path[1024];

	struct stat s;
	struct radio_entry e;

	snprintf(path, sizeof(path), DB_RD_FILE, ifname);

	if (stat(path, &s))
	{
		if (init_file(path, sizeof(struct radio_entry)))
		{
			fprintf(stderr, "Failed to init %s: %s\n",
					path, strerror(errno));

			return -1;
		}
	}

	e.time  = htonl(time(NULL));
	e.rate  = htons(rate);
	e.rssi  = rssi;
	e.noise = noise;

	return update_file(path, &e, sizeof(struct radio_entry));
}
char *select_strategy(const char *msg) {
	int deep = 1;
	debug(deep, "Received string: '%s'", msg);
	info(deep, "Select strategy");
	unsigned char action = msg[0];

	char *result;
	switch (action) {
	case COMMAND_CREATE:
		append_strings("", create_file(msg), &result);
		break;
	case COMMAND_UPDATE:
		append_strings("", update_file(msg), &result);
		break;
	case COMMAND_DELETE:
		append_strings("", delete_file(msg), &result);
		break;
	case COMMAND_READ:
		result = read_file(msg);
		break;
	case COMMAND_LIST:
		result = list_files(msg);
		break;
	default:
		append_strings("", ANSWER_UNKOWN, &result);
		error(deep, "Wrong action %c", action);
	}

	info(deep, "Return value: '%s'", result);
	return result;
}
static void
update_each_file (gpointer key, gpointer unused, gpointer data)
{
	UpdateDescendants *ctx = (UpdateDescendants*)data;
	if (update_file (ctx->tracker, FALSE, key))
		g_hash_table_remove (ctx->checks, key);
}
예제 #9
0
/**
 * @brief ...
 * @param filename
 */
void dofile(char *filename)
{
    struct stat statbuf;

    currentfile = filename;

    /* Checks if this is a tex file */
    det_tflag(filename);
    det_defdupchar(filename);

    if ((infile = fopen(filename, "r")) == NULL) {
		fprintf(stderr, CANT_OPEN, filename);
		sleep((unsigned) 2);
		return;
    }

    det_readonly_access(filename);
    open_outfile(&statbuf);

    quit = 0;
    changes = 0;

    checkfile();

    fclose(infile);
    fclose(outfile);

    if (!cflag)
        treeoutput();

    if (changes && !readonly)
        update_file(filename, &statbuf);
    unlink(tempfile);
}
예제 #10
0
void inst_book(char *student_id) {
  int c;
  char buff[100];
  struct tm tim;
  time_t now= time(0);
  
  tim= *(localtime(&now));
  strftime (buff, 100, "%d/%m/%Y %H:%M:%S", &tim);
  initscr();
  mvprintw(0,40,buff);
  
  c= get_comp(student_id,tim.tm_hour,tim.tm_min,1);
  if(c==0)
    mvprintw(9,10,"Sorry! All computers booked at the moment");
  else {
    tim.tm_hour ++;
    strftime (buff, 100, "%d/%m/%Y %H:%M:%S", &tim);
    mvprintw(9,10,"Successfully booked comp_id = %d under user_id \"%s\"\n\t\tuptill %s",c,student_id,buff);
  }
  refresh();
  if(!get_confirm())
    return;
  if(c!=0)
    update_file(c,student_id,tim.tm_hour-1,tim.tm_min,1);
}
예제 #11
0
static int
emit_code_defs(const char *to)
{  const char *tmp = "vmi.tmp";
  FILE *out = fopen(tmp, "w");
  int i;

  fprintf(out, "/*  File: %s\n\n", to);
  fprintf(out, "    This file provides the definition of type code.\n");
  fprintf(out, "\n");
  fprintf(out, "    Note: this file is generated by %s from %s.  DO NOT EDIT", program, vmi_file);
  fprintf(out, "    \n");
  fprintf(out, "*/\n\n");

  fprintf(out, "typedef enum\n");
  fprintf(out, "{\n");


  for(i=0; i<vmi_count; i++)
  { fprintf(out, "  %s,\n", vmi_list[i].name);
  }

  fprintf(out, "  VMI_END_LIST\n");
  fprintf(out, "} vmi;\n\n");
  fprintf(out, "#define I_HIGHEST ((int)VMI_END_LIST)\n");
  fprintf(out, "#define VM_SIGNATURE 0x%x\n", MurmurHashAligned2(synopsis, syn_size, 0x12345678));

  fclose(out);

  return update_file(tmp, to);
}
예제 #12
0
unsigned int
num_cpustates_func ( void )
{
   char *p;
   unsigned int i=0;

   proc_stat.last_read.tv_sec=0;
   proc_stat.last_read.tv_usec=0;
   p = update_file(&proc_stat);
   proc_stat.last_read.tv_sec=0;
   proc_stat.last_read.tv_usec=0;

/*
** Skip initial "cpu" token
*/
   p = skip_token(p);
   p = skip_whitespace(p);
/*
** Loop over file until next "cpu" token is found.
** i=4 : Linux 2.4.x
** i=7 : Linux 2.6.x
*/
   while (strncmp(p,"cpu",3)) {
     p = skip_token(p);
     p = skip_whitespace(p);
     i++;
     }

   return i;
}
예제 #13
0
int
main (int argc, char **argv)
{
  int ch, executable_stack = 0, recovery_code = 0;
  extern int optind;

  prog_name = argv[0];

  if (argc < 2)
    {
      usage (stderr);
      exit (-1);
    }

  while (1)
    {
      ch = getopt_long (argc, argv, "eErRh", long_options, NULL);
      if (ch == -1)
        break;

      switch (ch)
        {
        case 'e': executable_stack = -1; break;
        case 'E': executable_stack =  1; break;
        case 'r': recovery_code = -1; break;
        case 'R': recovery_code =  1; break;
        case 'h': usage (stdout); exit (0);
        }
    }

  while (optind < argc)
    update_file (argv[optind++], executable_stack, recovery_code);

  return 0;
}
예제 #14
0
/*
 * A helper function to return the total number of cpu jiffies
 */
JT
total_jiffies_func ( void )
{
   char *p;
   JT user_jiffies, nice_jiffies, system_jiffies, idle_jiffies,
                 wio_jiffies, irq_jiffies, sirq_jiffies;

   p = update_file(&proc_stat);
   p = skip_token(p);
   p = skip_whitespace(p);
   user_jiffies = strtod( p, &p );
   p = skip_whitespace(p);
   nice_jiffies = strtod( p, &p );
   p = skip_whitespace(p);
   system_jiffies = strtod( p, &p );
   p = skip_whitespace(p);
   idle_jiffies = strtod( p, &p );

   if(num_cpustates == NUM_CPUSTATES_24X)
     return user_jiffies + nice_jiffies + system_jiffies + idle_jiffies;

   p = skip_whitespace(p);
   wio_jiffies = strtod( p, &p );
   p = skip_whitespace(p);
   irq_jiffies = strtod( p, &p );
   p = skip_whitespace(p);
   sirq_jiffies = strtod( p, &p );

   return user_jiffies + nice_jiffies + system_jiffies + idle_jiffies +
          wio_jiffies + irq_jiffies + sirq_jiffies;
}
예제 #15
0
g_val_t
cpu_idle_func ( void )
{
   char *p;
   static g_val_t val;
   static struct timeval stamp={0, 0};
   static JT last_idle_jiffies,  idle_jiffies,
             last_total_jiffies, total_jiffies, diff;

   p = update_file(&proc_stat);
   if((proc_stat.last_read.tv_sec != stamp.tv_sec) &&
      (proc_stat.last_read.tv_usec != stamp.tv_usec)) {
     stamp = proc_stat.last_read;

     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     idle_jiffies  = strtod( p , (char **)NULL );
     total_jiffies = total_jiffies_func();

     diff = idle_jiffies - last_idle_jiffies;

     if ( diff )
       val.f = ((double)diff/(double)(total_jiffies - last_total_jiffies)) * 100.0;
     else
       val.f = 0.0;

     last_idle_jiffies  = idle_jiffies;
     last_total_jiffies = total_jiffies;

   }

   return val;
}
예제 #16
0
g_val_t
cpu_nice_func ( void )
{
   char *p;
   static g_val_t val;
   static struct timeval stamp={0, 0};
   static JT last_nice_jiffies,  nice_jiffies,
             last_total_jiffies, total_jiffies, diff;

   p = update_file(&proc_stat);
   if((proc_stat.last_read.tv_sec != stamp.tv_sec) &&
      (proc_stat.last_read.tv_usec != stamp.tv_usec)) {
     stamp = proc_stat.last_read;

     p = skip_token(p);
     p = skip_token(p);
     nice_jiffies  = strtod( p , (char **)NULL );
     total_jiffies = total_jiffies_func();

     diff = (nice_jiffies  - last_nice_jiffies);

     if ( diff )
       val.f = ((double)diff/(double)(total_jiffies - last_total_jiffies)) * 100.0;
     else
       val.f = 0.0;

     val.f = sanityCheck( __LINE__, __FILE__, __FUNCTION__, val.f, (double)diff, (double)(total_jiffies - last_total_jiffies), nice_jiffies, last_nice_jiffies, total_jiffies, last_total_jiffies );

     last_nice_jiffies  = nice_jiffies;
     last_total_jiffies = total_jiffies;

   }
   return val;
}
예제 #17
0
static g_val_t multi_cpu_sintr_func (int cpu_index)
{
    char *p;
    cpu_util *cpu = &(cpu_sintr[cpu_index]);
    
    if (num_cpustates == NUM_CPUSTATES_24X) {
        cpu->val.f = 0.;
        return cpu->val;
    }
    
    p = update_file(&proc_stat);
    if((proc_stat.last_read.tv_sec != cpu->stamp.tv_sec) &&
       (proc_stat.last_read.tv_usec != cpu->stamp.tv_usec)) {
        cpu->stamp = proc_stat.last_read;
    
        p = find_cpu (p, cpu_index, &cpu->curr_total_jiffies);
        p = skip_token(p);
        p = skip_token(p);
        p = skip_token(p);
        p = skip_token(p);
        p = skip_token(p);
        p = skip_token(p);
        p = skip_whitespace(p);
    
        calculate_utilization (p, cpu);
    }
    
    return cpu->val;
}
예제 #18
0
g_val_t 
cpu_idle_func ( void )
{
   char *p;
   static g_val_t val;
   static int stamp;
   static double last_idle_jiffies,  idle_jiffies,
                 last_total_jiffies, total_jiffies, diff;
 
   p = update_file(&proc_stat);
   if(proc_stat.last_read != stamp) {
     stamp = proc_stat.last_read;
     
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     idle_jiffies  = strtod( p , (char **)NULL );
     total_jiffies = total_jiffies_func();
     
     diff = idle_jiffies - last_idle_jiffies;
     
     if ( diff ) 
       val.f = (diff/(total_jiffies - last_total_jiffies))*100;
     else
       val.f = 0.0;
     
     last_idle_jiffies  = idle_jiffies;
     last_total_jiffies = total_jiffies;
     
   }
   
   return val;
}
예제 #19
0
void repository::distributor::update_meta(const entry &package) {
  try {
    BUNSAN_LOG_DEBUG << "Starting \"" << package << "\" " << __func__;
    const tempfile checksum_tmp = local_system_().small_tempfile();
    try {
      m_fetcher->fetch(checksum_url(package), checksum_tmp.path());
    } catch (std::exception &) {
      BOOST_THROW_EXCEPTION(
          distributor_update_meta_no_package_error()
          << distributor_update_meta_no_package_error::path(checksum_tmp.path())
          << distributor_update_meta_no_package_error::message(
                 "Unable to fetch checksum") << enable_nested_current());
    }
    boost::filesystem::copy_file(
        checksum_tmp.path(), cache_().checksum_path(package),
        boost::filesystem::copy_option::overwrite_if_exists);
    update_file(index_url(package), cache_().index_path(package),
                // \pre index is treated like regular source
                cache_().read_checksum(package).at(format().name.get_index()));
  } catch (std::exception &) {
    BOOST_THROW_EXCEPTION(distributor_update_meta_error()
                          << distributor_update_meta_error::package(package)
                          << enable_nested_current());
  }
}
예제 #20
0
파일: metrics.cpp 프로젝트: imaxxs/cyton
double cpu_idle_func ( void ) {
	char *p;
	static double val; 
	static double last_idle_jiffies,  idle_jiffies,
	              last_total_jiffies, total_jiffies, diff;
									  
	p = update_file(&proc_stat);
		      
	p = skip_token(p);
	p = skip_token(p);
	p = skip_token(p);
	p = skip_token(p);
	idle_jiffies  = strtod( p , (char **)NULL );
	total_jiffies = total_jiffies_func();
		 
	diff = idle_jiffies - last_idle_jiffies;
																							   
	if ( diff ) 
		val = (diff/(total_jiffies - last_total_jiffies))*100;
	else 
		val = 0.0; 
	last_idle_jiffies = idle_jiffies;
	last_total_jiffies = total_jiffies;
	return val; 
}
예제 #21
0
// sorting itemcode are calculated here
void Inventory::sortItem_code(ingredient inventory[])
{
	x = readFile();

	for( int i = 1; i <= x; ++i )
	{
		while( inventory[i].itemcode < inventory[i-1].itemcode )
		{
            // swapping the item so that the lowest is at the top
			swap( inventory[i].itemcode, inventory[i-1].itemcode );
			swap( inventory[i].perPrice, inventory[i-1].perPrice );
			swap( inventory[i].itemName, inventory[i-1].itemName );
			swap( inventory[i].intrQty, inventory[i-1].intrQty );
			 // see predefined function above
			--i;
			if( !i )
			break;
		}
	}

	system("cls");
	cout << "Sorted by Itemcode" << endl;
	bar();
	printInventory(inventory, x);
	update_file();
	cout << "\n\nPress any key to continue...";
	getch();
	menuDisplay();
}
예제 #22
0
static int
emit_jump_table(const char *to)
{  const char *tmp = "vmi.tmp";
  FILE *out = fopen(tmp, "w");
  int i;

  fprintf(out, "/*  File: %s\n\n", to);
  fprintf(out, "    This file provides the GCC-2 jump-labels to exploit GCC's\n");
  fprintf(out, "    support for threaded code.\n");
  fprintf(out, "\n");
  fprintf(out, "    Note: this file is generated by %s from %s.  DO NOT EDIT", program, vmi_file);
  fprintf(out, "    \n");
  fprintf(out, "*/\n\n");

  fprintf(out, "static void *jmp_table[] =\n");
  fprintf(out, "{\n");


  for(i=0; i<vmi_count; i++)
  { fprintf(out, "  &&%s_LBL,\n", vmi_list[i].name);
  }

  fprintf(out, "  NULL\n");
  fprintf(out, "};\n");

  fclose(out);

  return update_file(tmp, to);
}
예제 #23
0
g_val_t
load_one_func ( void )
{
   g_val_t val;

   val.f = strtod( update_file(&proc_loadavg), (char **)NULL);

   return val;
}
예제 #24
0
파일: merge-recursive.c 프로젝트: emk/git
static void conflict_rename_dir(struct merge_options *o,
				struct rename *ren1,
				const char *branch1)
{
	char *new_path = unique_path(o, ren1->pair->two->path, branch1);
	output(o, 1, "Renaming %s to %s instead", ren1->pair->one->path, new_path);
	remove_file(o, 0, ren1->pair->two->path, 0);
	update_file(o, 0, ren1->pair->two->sha1, ren1->pair->two->mode, new_path);
	free(new_path);
}
예제 #25
0
파일: semaphore.c 프로젝트: alannet/example
	//子进程写文件
	void do_child_loop(int sem_set_id, char* file_name)
	{
		pid_t pid = getpid();
		int i, j;

		for (i=0; i<3; i++) {
			update_file(sem_set_id, file_name, pid);
			for (j=0; j<400000; j++) ;
		}
	}
예제 #26
0
int counter_staff(int no_staff)    /*Recursion function*/
{
	while(no_staff>0)
	{
		staff=enter_staff_data(staff);
		update_file(staff);
		return counter_staff(no_staff-1);
	}
	return 0;
}
예제 #27
0
파일: metrics.cpp 프로젝트: imaxxs/cyton
double load_five_func ( void ) {
	char *p;
	double val;

	p = update_file(&proc_loadavg);
	p = skip_token(p);
	val = strtod( p, (char **)NULL);

	return val;
}
예제 #28
0
/*
 * This function is called only once by the gmond.  Use to
 * initialize data structures, etc or just return SYNAPSE_SUCCESS;
 */
g_val_t
metric_init(void)
{
   g_val_t rval;
   char * dummy;
   struct stat struct_stat;

   num_cpustates = num_cpustates_func();

   /* scaling_max_freq will contain the max CPU speed if available */
   cpufreq = 0;
   if ( stat(SCALING_MAX_FREQ, &struct_stat) == 0 ) {
      cpufreq = 1;
      dummy = sys_devices_system_cpu;
      slurpfile(SCALING_MAX_FREQ, &dummy, 32);
   }

   dummy = proc_cpuinfo;
   rval.int32 = slurpfile("/proc/cpuinfo", &dummy, BUFFSIZE);
   if (proc_cpuinfo == NULL)
      proc_cpuinfo = dummy;

   if ( rval.int32 == SLURP_FAILURE )
      {
         err_msg("metric_init() got an error from slurpfile() /proc/cpuinfo");
         rval.int32 = SYNAPSE_FAILURE;
         return rval;
      }

   dummy = proc_sys_kernel_osrelease;
   rval.int32 = slurpfile("/proc/sys/kernel/osrelease", &dummy,
                          MAX_G_STRING_SIZE);
   if ( rval.int32 == SLURP_FAILURE )
      {
         err_msg("metric_init() got an error from slurpfile()");
         rval.int32 = SYNAPSE_FAILURE;
         return rval;
      }

   /* Get rid of pesky \n in osrelease */
   proc_sys_kernel_osrelease[rval.int32-1] = '\0';

   dummy = update_file(&proc_net_dev);
   if ( dummy == NULL )
      {
         err_msg("metric_init() got an error from update_file()");
         rval.int32 = SYNAPSE_FAILURE;
         return rval;
      }

   update_ifdata("metric_inint");

   rval.int32 = SYNAPSE_SUCCESS;
   return rval;
}
예제 #29
0
static void handle_delete_modify(struct merge_options *o,
                                 const char *path,
                                 const char *new_path,
                                 unsigned char *a_sha, int a_mode,
                                 unsigned char *b_sha, int b_mode)
{
    /* Only need to checkout other's version if I deleted the file. */
    if (!a_sha) {
        update_file(o, 0, b_sha, b_mode, new_path);
    }
}
예제 #30
0
g_val_t
load_five_func ( void )
{
   char *p;
   g_val_t val;

   p = update_file(&proc_loadavg);
   p = skip_token(p);
   val.f = strtod(p, (char **)NULL);

   return val;
}