示例#1
0
static void
c_output(char *infile, char *define, int extend, char *outfile)
{
	definition *def;
	char *include;
	char *outfilename;
	long tell;

	c_initialize();
	open_input(infile, define);	
	outfilename = extend ? extendfile(infile, outfile) : outfile;
	open_output(infile, outfilename);
	add_warning();
	if (infile && (include = extendfile(infile, ".h"))) {
		f_print(fout, "#include \"%s\"\n", basename(include));
		free(include);
		/* .h file already contains rpc/rpc.h */
	} else
	  f_print(fout, "#include <rpc/rpc.h>\n");
	tell = ftell(fout);
	while ((def = get_definition()) != NULL) {
		emit(def);
	}
	if (extend && tell == ftell(fout)) {
		(void) unlink(outfilename);
	}
}
示例#2
0
文件: rpc_main.c 项目: vkamra/openafs
static void
l_output(char *infile, char *define, int extend, char *outfile)
{
    char *include;
    definition *def;
    int foundprogram;
    char *outfilename;

    open_input(infile, define);
    outfilename = extend ? extendfile(infile, outfile) : outfile;
    open_output(infile, outfilename);
    f_print(fout, "#include <rpc/rpc.h>\n");
    f_print(fout, "#include <sys/time.h>\n");
    if (infile && (include = extendfile(infile, ".h"))) {
	f_print(fout, "#include \"%s\"\n", include);
	free(include);
    }
    foundprogram = 0;
    while ((def = get_definition())) {
	foundprogram |= (def->def_kind == DEF_PROGRAM);
    }
    if (extend && !foundprogram) {
	(void)unlink(outfilename);
	return;
    }
    write_stubs();
}
示例#3
0
文件: rpc_main.c 项目: vkamra/openafs
/*
 * Compile into an RPC service
 */
static void
s_output(int argc, char *argv[], char *infile, char *define, int extend,
	 char *outfile, int nomain)
{
    char *include;
    definition *def;
    int foundprogram;
    char *outfilename;

    open_input(infile, define);
    outfilename = extend ? extendfile(infile, outfile) : outfile;
    open_output(infile, outfilename);
    f_print(fout, "#include <stdio.h>\n");
    f_print(fout, "#include <rpc/rpc.h>\n");
    if (infile && (include = extendfile(infile, ".h"))) {
	f_print(fout, "#include \"%s\"\n", include);
	free(include);
    }
    foundprogram = 0;
    while ((def = get_definition())) {
	foundprogram |= (def->def_kind == DEF_PROGRAM);
    }
    if (extend && !foundprogram) {
	(void)unlink(outfilename);
	return;
    }
    if (nomain) {
	write_programs((char *)NULL);
    } else {
	write_most();
	do_registers(argc, argv);
	write_rest();
	write_programs("static");
    }
}
示例#4
0
void gen_tabfile()
{
	FILE *file = fopen("Unihan.tab", "wb");
	gunichar uc;
	gchar utf8[7];
	for (std::map<std::string, std::list<std::pair<std::string, std::string> > >::iterator iter = unihan_map.begin(); iter != unihan_map.end(); ++iter) {
		uc = htoi(iter->first.c_str());
		gint n = g_unichar_to_utf8(uc, utf8);
		utf8[n] = '\0';
		fprintf(file, "%s\tU+%s", utf8, iter->first.c_str());
		std::string definition = get_definition(iter->second);
		fprintf(file, "%s\n", definition.c_str());
	}
	fclose(file);
	g_print("File Unihan.tab generated.\n");
}
示例#5
0
/*############################ check_changes() ##########################*/
void
check_changes(FILE *p_data)
{
   static int          old_amg_status = PROC_INIT_VALUE,
                       old_archive_watch_status = PROC_INIT_VALUE,
                       old_fd_status = PROC_INIT_VALUE,
                       old_max_connections;
   static unsigned int old_sys_log_ec;
   static time_t       next_stat_time,
                       old_st_mtime;
   static char         old_receive_log_history[MAX_LOG_HISTORY],
                       old_sys_log_history[MAX_LOG_HISTORY],
                       old_trans_log_history[MAX_LOG_HISTORY];
   register int        i;
   time_t              now;

   if (check_fsa(YES, AFDD) == YES)
   {
      int loop_counter = 0,
          status;

retry_check:
      if (old_error_history != NULL)
      {
         FREE_RT_ARRAY(old_error_history);
         old_error_history = NULL;
      }

      if (check_fsa(YES, AFDD) == YES)
      {
         loop_counter++;
         if (loop_counter < 10)
         {
            system_log(DEBUG_SIGN, __FILE__, __LINE__,
                       _("Hmm, FSA has changed again!"));
            my_usleep(500000L);
            goto retry_check;
         }
      }

      status = 0;
      while (p_afd_status->amg_jobs & WRITTING_JID_STRUCT)
      {
         (void)my_usleep(100000L);
         status++;
         if ((status > 1) && ((status % 100) == 0))
         {
            system_log(INFO_SIGN, __FILE__, __LINE__,
                       _("AFDD: Timeout arrived for waiting for AMG to finish writting to JID structure."));
         }
      }

      RT_ARRAY(old_error_history, no_of_hosts, ERROR_HISTORY_LENGTH,
               unsigned char);
      for (i = 0; i < no_of_hosts; i++)
      {
         if (fsa[i].real_hostname[0][0] == GROUP_IDENTIFIER)
         {
            (void)memset(old_error_history[i], 0, ERROR_HISTORY_LENGTH);
         }
         else
         {
            (void)memcpy(old_error_history[i], fsa[i].error_history,
                         ERROR_HISTORY_LENGTH);
         }
      }
      host_config_counter = (int)*(unsigned char *)((char *)fsa - AFD_WORD_OFFSET + SIZEOF_INT);
      show_host_list(p_data);
      show_job_list(p_data);
   }
   else
   {
      if (host_config_counter != (int)*(unsigned char *)((char *)fsa - AFD_WORD_OFFSET + SIZEOF_INT))
      {
         FREE_RT_ARRAY(old_error_history);
         RT_ARRAY(old_error_history, no_of_hosts, ERROR_HISTORY_LENGTH,
                  unsigned char);
         for (i = 0; i < no_of_hosts; i++)
         {
            if (fsa[i].real_hostname[0][0] == GROUP_IDENTIFIER)
            {
               (void)memset(old_error_history[i], 0, ERROR_HISTORY_LENGTH);
            }
            else
            {
               (void)memcpy(old_error_history[i], fsa[i].error_history,
                            ERROR_HISTORY_LENGTH);
            }
         }
         host_config_counter = (int)*(unsigned char *)((char *)fsa - AFD_WORD_OFFSET + SIZEOF_INT);
         show_host_list(p_data);
      }
   }
   if (check_fra(YES) == YES)
   {
      show_dir_list(p_data);
   }

   /*
    * It costs too much system performance to constantly stat()
    * the AFD_CONFIG file to see if the modification time has
    * changed. For this reason lets only stat() this file at a
    * reasonable interval of say STAT_INTERVAL seconds.
    */
   now = time(NULL);
   if (next_stat_time < now)
   {
      struct stat stat_buf;

      next_stat_time = now + STAT_INTERVAL;
      if (stat(afd_config_file, &stat_buf) == 0)
      {
         if (stat_buf.st_mtime != old_st_mtime)
         {
            char *buffer;

            old_st_mtime = stat_buf.st_mtime;
            if ((eaccess(afd_config_file, F_OK) == 0) &&
                (read_file_no_cr(afd_config_file, &buffer, YES, __FILE__, __LINE__) != INCORRECT))
            {
               int  max_connections = 0;
               char value[MAX_INT_LENGTH];

               if (get_definition(buffer,
                                  MAX_CONNECTIONS_DEF,
                                  value, MAX_INT_LENGTH) != NULL)
               {
                  max_connections = atoi(value);
               }
               if ((max_connections < 1) ||
                   (max_connections > MAX_CONFIGURABLE_CONNECTIONS))
               {
                  max_connections = MAX_DEFAULT_CONNECTIONS;
               }
               if (max_connections != old_max_connections)
               {
                  old_max_connections = max_connections;
                  (void)fprintf(p_data, "MC %d\r\n", old_max_connections);
               }
               free(buffer);
            }
         }
      }
      else
      {
         if (errno != ENOENT)
         {
            system_log(DEBUG_SIGN, __FILE__, __LINE__,
                      _("Failed to stat() `%s' : %s"),
                      afd_config_file, strerror(errno));
         }
      }
   }

   if (old_sys_log_ec != p_afd_status->sys_log_ec)
   {
      char buf[LOG_FIFO_SIZE + 1];

      old_sys_log_ec = p_afd_status->sys_log_ec;
      for (i = 0; i < LOG_FIFO_SIZE; i++)
      {
         buf[i] = p_afd_status->sys_log_fifo[i] + ' ';
      }
      buf[i] = '\0';
      (void)fprintf(p_data, "SR %u %s\r\n", old_sys_log_ec, buf);
   }

   if (memcmp(old_receive_log_history, p_afd_status->receive_log_history,
              MAX_LOG_HISTORY) != 0)
   {
      char buf[MAX_LOG_HISTORY + 1];

      (void)memcpy(old_receive_log_history, p_afd_status->receive_log_history,
                   MAX_LOG_HISTORY);
      for (i = 0; i < MAX_LOG_HISTORY; i++)
      {
         buf[i] = p_afd_status->receive_log_history[i] + ' ';
      }
      buf[i] = '\0';
      (void)fprintf(p_data, "RH %s\r\n", buf);
   }
   if (memcmp(old_sys_log_history, p_afd_status->sys_log_history,
              MAX_LOG_HISTORY) != 0)
   {
      char buf[MAX_LOG_HISTORY + 1];

      (void)memcpy(old_sys_log_history, p_afd_status->sys_log_history,
                   MAX_LOG_HISTORY);
      for (i = 0; i < MAX_LOG_HISTORY; i++)
      {
         buf[i] = p_afd_status->sys_log_history[i] + ' ';
      }
      buf[i] = '\0';
      (void)fprintf(p_data, "SH %s\r\n", buf);
   }
   if (memcmp(old_trans_log_history, p_afd_status->trans_log_history,
              MAX_LOG_HISTORY) != 0)
   {
      char buf[MAX_LOG_HISTORY + 1];

      (void)memcpy(old_trans_log_history, p_afd_status->trans_log_history,
                   MAX_LOG_HISTORY);
      for (i = 0; i < MAX_LOG_HISTORY; i++)
      {
         buf[i] = p_afd_status->trans_log_history[i] + ' ';
      }
      buf[i] = '\0';
      (void)fprintf(p_data, "TH %s\r\n", buf);
   }
   for (i = 0; i < no_of_hosts; i++)
   {
      if (fsa[i].real_hostname[0][0] != GROUP_IDENTIFIER)
      {
         if (memcmp(old_error_history[i], fsa[i].error_history,
                    ERROR_HISTORY_LENGTH) != 0)
         {
            int k;

            (void)memcpy(old_error_history[i], fsa[i].error_history,
                         ERROR_HISTORY_LENGTH);
            (void)fprintf(p_data, "EL %d %d", i, old_error_history[i][0]);
            for (k = 1; k < ERROR_HISTORY_LENGTH; k++)
            {
               (void)fprintf(p_data, " %d", old_error_history[i][k]);
            }
            (void)fprintf(p_data, "\r\n");
         }
      }
   }

   /*
    * Check if status of any of the main process (AMG, FD and
    * archive_watch) have changed.
    */
   if (old_amg_status != p_afd_status->amg)
   {
      old_amg_status = p_afd_status->amg;
      (void)fprintf(p_data, "AM %d\r\n", old_amg_status);
   }
   if (old_fd_status != p_afd_status->fd)
   {
      old_fd_status = p_afd_status->fd;
      (void)fprintf(p_data, "FD %d\r\n", old_fd_status);
   }
   if (old_archive_watch_status != p_afd_status->archive_watch)
   {
      old_archive_watch_status = p_afd_status->archive_watch;
      (void)fprintf(p_data, "AW %d\r\n", old_archive_watch_status);
   }

   (void)fflush(p_data);

   return;
}
示例#6
0
文件: p0macros.c 项目: mingpen/OpenNT
/************************************************************************
**  BEGIN DEFINE A MACRO {
************************************************************************/
void   define(void)
{
    UCHAR	c;

    if (! (LX_IS_IDENT(c = skip_cwhite())) ) {
	Msg_Temp = GET_MSG (2007);
	SET_MSG (Msg_Text, Msg_Temp);
        error (2007); /* #define syntax */
	skip_cnew();
	return;
    }
    getid(c);
    N_formals = 0;
    P_defn_start = Macro_buffer;
/*
**  the next character must be white space or an open paren
*/
first_switch:
    switch(CHARMAP(c = GETCH())) {
    case LX_OPAREN:			/*  we have formal parameters  */
	get_formals();		/*  changes N_formals and fills Macro_buffer */
	if(N_formals == 0) {/*  empty formal list  */
		/*
		**  we must special case this since the expand() reads in the
		**  actual arguments iff there are formal parameters. thus if we
		**	#define	foo()	bar()
		**		. . .
		**		foo()
		**  will expand as 
		**		bar()()
		**  we put the right paren in to fool the expander into looking
		**  for actuals.
		*/
	    N_formals = -1;
	}
	break;
    case LX_WHITE:
	break;
    case LX_CR:
	goto first_switch;
    case LX_SLASH:
	if( ! skip_comment()) {
	    Msg_Temp = GET_MSG (2008);
            SET_MSG (Msg_Text, Msg_Temp, '/');
            error (2008);
	}
	break;
    case LX_NL:			/* no definition */
	UNGETCH();
	definstall((ptext_t)0, 0, 0);
	return;
	break;
    case LX_EOS:
	if(handle_eos() != BACKSLASH_EOS) {
	    goto first_switch;
	}
	/* got BACKSLASH_EOS */
	/*
	**  FALLTHROUGH
	*/
    default:
	Msg_Temp = GET_MSG (2008);
        SET_MSG (Msg_Text, Msg_Temp, c);
        error (2008); /* unexpected character in macro definition */
    }
    definstall(P_defn_start, get_definition(), N_formals);
}
示例#7
0
static void
S_output(char *infile, char *define, int extend, char *outfile, int append)
{
    char *include;
    char *outfilename;
    char fullname[1024];
    definition *def;
    long tell;
    char *currfile = (OutFileFlag ? OutFile : infile);

    Sflag = 1;
    open_input(infile, define);
    memset(fullname, 0, sizeof(fullname));
    if (append) {
	strcpy(fullname, prefix);
	strcat(fullname, infile);
    } else
	strcpy(fullname, infile);
    outfilename = extend ? extendfile(fullname, outfile) : outfile;
    open_output(infile, outfilename);
    f_print(fout, "/* Machine generated file -- Do NOT edit */\n\n");
    if (currfile && (include = extendfile(currfile, ".h"))) {
	if (kflag) {
	    f_print(fout, "#include \"%s\"\n", include);
	} else {
	    f_print(fout, "#include <afsconfig.h>\n");
	    f_print(fout, "#include <afs/param.h>\n");
	    f_print(fout, "#include <roken.h>\n");
	    f_print(fout, "#include \"%s\"\n\n", include);
	}
	free(include);
    } else {
	if (kflag) {
	    f_print(fout, "#include \"h/types.h\"\n");
	    f_print(fout, "#include \"h/socket.h\"\n");
	    f_print(fout, "#include \"h/file.h\"\n");
	    f_print(fout, "#include \"h/stat.h\"\n");
	    f_print(fout, "#include \"netinet/in.h\"\n");
	    f_print(fout, "#include \"h/time.h\"\n");
	    f_print(fout, "#include \"rpc/types.h\"\n");
	    f_print(fout, "#include \"rx/xdr.h\"\n");
	    f_print(fout, "#include \"afs/rxgen_consts.h\"\n");
	    f_print(fout, "#include \"afs/afs_osi.h\"\n");
	    f_print(fout, "#include \"rx/rx.h\"\n");
	    if (xflag) {
		f_print(fout, "#include \"rx/rx_globals.h\"\n");
	    }
	    if (brief_flag) {
		f_print(fout, "#include \"rx/rx_opaque.h\"\n");
	    }
	} else {
	    f_print(fout, "#include <sys/types.h>\n");
	    f_print(fout, "#include <rx/xdr.h>\n");
	    f_print(fout, "#include <rx/rx.h>\n");
	    if (xflag) {
		f_print(fout, "#include <rx/rx_globals.h>\n");
	    }
	    if (brief_flag) {
		f_print(fout, "#include <rx/rx_opaque.h>\n");
	    }
	    f_print(fout, "#include <afs/rxgen_consts.h>\n");
	}
    }

    tell = ftell(fout);
    fflush(fout);
    while ((def = get_definition())) {
	fflush(fout);
	print_datadef(def);
    }

    er_Proc_CodeGeneration();

    if (extend && tell == ftell(fout)) {
	(void)unlink(outfilename);
    }
    Sflag = 0;
}
示例#8
0
/*
 * Compile into an XDR header file
 */
static void
h_output(char *infile, char *define, int extend, char *outfile, int append)
{
    definition *def;
    char *outfilename;
    long tell;
    char fullname[1024], *p;

    open_input(infile, define);
    hflag = 1;
    memset(fullname, 0, sizeof(fullname));
    if (append) {
	strcpy(fullname, prefix);
	strcat(fullname, infile);
    } else
	strcpy(fullname, infile);
    outfilename = extend ? extendfile(fullname, outfile) : outfile;
    open_output(infile, outfilename);
    strcpy(fullname, outfilename);
    if ((p = strchr(fullname, '.')))
	*p = '\0';
    f_print(fout, "/* Machine generated file -- Do NOT edit */\n\n");
    f_print(fout, "#ifndef	_RXGEN_%s_\n", uppercase(fullname));
    f_print(fout, "#define	_RXGEN_%s_\n\n", uppercase(fullname));
    f_print(fout, "#ifdef	KERNEL\n");
    f_print(fout,
	    "/* The following 'ifndefs' are not a good solution to the vendor's omission of surrounding all system includes with 'ifndef's since it requires that this file is included after the system includes...*/\n");
    f_print(fout, "#include <afsconfig.h>\n");
    f_print(fout, "#include \"afs/param.h\"\n");
    f_print(fout, "#ifdef	UKERNEL\n");
    f_print(fout, "#include \"afs/sysincludes.h\"\n");
    f_print(fout, "#include \"rx/xdr.h\"\n");
    f_print(fout, "#include \"rx/rx.h\"\n");
    if (xflag) {
	f_print(fout, "#include \"rx/rx_globals.h\"\n");
    }
    if (brief_flag) {
	f_print(fout, "#include \"rx/rx_opaque.h\"\n");
    }
    if (uflag)
	f_print(fout, "#include <ubik.h>\n");
    f_print(fout, "#else	/* UKERNEL */\n");
    f_print(fout, "#include \"h/types.h\"\n");
    f_print(fout, "#ifndef	SOCK_DGRAM  /* XXXXX */\n");
    f_print(fout, "#include \"h/socket.h\"\n");
    f_print(fout, "#endif\n");
    f_print(fout, "struct ubik_client;\n");
    f_print(fout, "#ifndef	DTYPE_SOCKET  /* XXXXX */\n");
    f_print(fout, "#ifndef AFS_LINUX22_ENV\n");
    f_print(fout, "#include \"h/file.h\"\n");
    f_print(fout, "#endif\n");
    f_print(fout, "#endif\n");
    f_print(fout, "#ifndef	S_IFMT  /* XXXXX */\n");
    f_print(fout, "#include \"h/stat.h\"\n");
    f_print(fout, "#endif\n");
    f_print(fout, "#if defined (AFS_OBSD_ENV) && !defined (MLEN)\n");
    f_print(fout, "#include \"sys/mbuf.h\"\n");
    f_print(fout, "#endif\n");
    f_print(fout, "#ifndef	IPPROTO_UDP /* XXXXX */\n");
    f_print(fout, "#include \"netinet/in.h\"\n");
    f_print(fout, "#endif\n");
    f_print(fout, "#ifndef	DST_USA  /* XXXXX */\n");
    f_print(fout, "#include \"h/time.h\"\n");
    f_print(fout, "#endif\n");
    f_print(fout, "#ifndef AFS_LINUX22_ENV\n");
    f_print(fout, "#include \"rpc/types.h\"\n");
    f_print(fout, "#endif /* AFS_LINUX22_ENV */\n");
    f_print(fout, "#ifndef	XDR_GETLONG /* XXXXX */\n");
    f_print(fout, "#ifdef AFS_LINUX22_ENV\n");
    f_print(fout, "#ifndef quad_t\n");
    f_print(fout, "#define quad_t __quad_t\n");
    f_print(fout, "#define u_quad_t __u_quad_t\n");
    f_print(fout, "#endif\n");
    f_print(fout, "#endif\n");
    f_print(fout, "#include \"rx/xdr.h\"\n");
    f_print(fout, "#endif /* XDR_GETLONG */\n");
    f_print(fout, "#endif   /* UKERNEL */\n");
    f_print(fout, "#include \"afs/rxgen_consts.h\"\n");
    f_print(fout, "#include \"afs_osi.h\"\n");
    f_print(fout, "#include \"rx/rx.h\"\n");
    if (xflag) {
	f_print(fout, "#include \"rx/rx_globals.h\"\n");
    }
    if (brief_flag) {
	f_print(fout, "#include \"rx/rx_opaque.h\"\n");
    }
    f_print(fout, "#else	/* KERNEL */\n");
    f_print(fout, "#include <afs/param.h>\n");
    f_print(fout, "#include <afs/stds.h>\n");
    f_print(fout, "#include <sys/types.h>\n");
    f_print(fout, "#include <rx/xdr.h>\n");
    f_print(fout, "#include <rx/rx.h>\n");
    if (xflag) {
	f_print(fout, "#include <rx/rx_globals.h>\n");
    }
    if (brief_flag) {
	f_print(fout, "#include <rx/rx_opaque.h>\n");
    }
    f_print(fout, "#include <afs/rxgen_consts.h>\n");
    if (uflag)
	f_print(fout, "#include <ubik.h>\n");
    f_print(fout, "#endif	/* KERNEL */\n\n");
    f_print(fout, "#ifdef AFS_NT40_ENV\n");
    f_print(fout, "#ifndef AFS_RXGEN_EXPORT\n");
    f_print(fout, "#define AFS_RXGEN_EXPORT __declspec(dllimport)\n");
    f_print(fout, "#endif /* AFS_RXGEN_EXPORT */\n");
    f_print(fout, "#else /* AFS_NT40_ENV */\n");
    f_print(fout, "#define AFS_RXGEN_EXPORT\n");
    f_print(fout, "#endif /* AFS_NT40_ENV */\n\n");
    tell = ftell(fout);
    while ((def = get_definition())) {
	print_datadef(def);
    }
    h_Proc_CodeGeneration();
    h_opcode_stats();
    hflag = 0;
    f_print(fout, "#endif	/* _RXGEN_%s_ */\n", uppercase(fullname));
    if (extend && tell == ftell(fout)) {
	(void)unlink(outfilename);
    }
}
示例#9
0
/*
 * Compile into an XDR routine output file
 */
static void
c_output(char *infile, char *define, int extend, char *outfile, int append)
{
    definition *def;
    char *include;
    char *outfilename;
    long tell;
    char fullname[1024];
    char *currfile = (OutFileFlag ? OutFile : infile);
    int i, j;

    open_input(infile, define);
    cflag = 1;
    memset(fullname, 0, sizeof(fullname));
    if (append) {
	strcpy(fullname, prefix);
	strcat(fullname, infile);
    } else
	strcpy(fullname, infile);
    outfilename = extend ? extendfile(fullname, outfile) : outfile;
    open_output(infile, outfilename);
    f_print(fout, "/* Machine generated file -- Do NOT edit */\n\n");
    if (xflag) {
	if (kflag) {
	    f_print(fout, "#include \"afsconfig.h\"\n");
	    f_print(fout, "#include \"afs/param.h\"\n");
	} else {
	    f_print(fout, "#include <afsconfig.h>\n");
	    f_print(fout, "#include <afs/param.h>\n");
	    f_print(fout, "#include <roken.h>\n");
	}
	f_print(fout, "#ifdef AFS_NT40_ENV\n");
	f_print(fout, "#define AFS_RXGEN_EXPORT __declspec(dllexport)\n");
	f_print(fout, "#endif /* AFS_NT40_ENV */\n");
    }
    if (currfile && (include = extendfile(currfile, ".h"))) {
	if (kflag) {
	    f_print(fout, "#include \"%s\"\n\n", include);
	} else
	    f_print(fout, "#include \"%s\"\n\n", include);
	free(include);
    } else {
	/* In case we can't include the interface's own header file... */
	if (kflag) {
	    f_print(fout, "#include \"h/types.h\"\n");
	    f_print(fout, "#include \"h/socket.h\"\n");
	    f_print(fout, "#include \"h/file.h\"\n");
	    f_print(fout, "#include \"h/stat.h\"\n");
	    f_print(fout, "#include \"netinet/in.h\"\n");
	    f_print(fout, "#include \"h/time.h\"\n");
	    f_print(fout, "#include \"rx/xdr.h\"\n");
	    f_print(fout, "#include \"afs/rxgen_consts.h\"\n");
	} else {
	    f_print(fout, "#include <rx/xdr.h>\n");
	}
    }

    tell = ftell(fout);
    while ((def = get_definition())) {
	if (!yflag) {
	    if ((!IsRxgenDefinition(def)) && def->def_kind != DEF_CUSTOMIZED)
		emit(def);
	}
    }

    /*
     * Print out array containing list of all functions in the interface
     * in order
     */

    if (xflag) {
	for (j = 0; j <= PackageIndex; j++) {
	    f_print(fout, "AFS_RXGEN_EXPORT\n");
	    f_print(fout, "const char *%sfunction_names[] = {\n",
		    PackagePrefix[j]);

	    for (i = 0; i < no_of_stat_funcs_header[j]; i++) {
		if (i == 0) {
		    f_print(fout, "\t\"%s\"", function_list[j][i]);
		} else {
		    f_print(fout, ",\n\t\"%s\"", function_list[j][i]);
		}
	    }


	    f_print(fout, "\n};\n");
	}
	er_Proc_CodeGeneration();
    }

    if (extend && tell == ftell(fout)) {
	(void)unlink(outfilename);
    }
    cflag = 0;
}
static void
h_output (char *infile, char *define, int extend, char *outfile)
{
  definition *def;
  char *outfilename;
  long tell;
  char *guard;
  list *l;

  open_input (infile, define);
  outfilename = extend ? extendfile (infile, outfile) : outfile;
  open_output (infile, outfilename);
  add_warning ();
  guard = generate_guard (outfilename ? outfilename : infile);

  f_print (fout, "#ifndef _%s\n#define _%s\n\n", guard,
	   guard);

#if 0
  f_print (fout, "#define RPCGEN_VERSION\t%s\n\n", RPCGEN_VERSION);
  f_print (fout, "#include <rpc/rpc.h>\n\n");
#else
  f_print (fout, "#include \"%s\"\n\n", incfile);
#endif

#if 0
  f_print (fout, "#ifdef __cplusplus\n"
"\n"
"#ifndef EXTERN\n"
"#define EXTERN extern \"C\" \n"
"#define EXTERN_DEFINED_BY_%s\n"
"#endif /* !EXTERN */\n"
"#ifndef UNION_NAME\n"
"#define UNION_NAME(name) u\n"
"#define UNION_NAME_DEFINED_BY_%s 1\n"
"#endif /* !UNION_NAME */\n"
"#ifndef CONSTRUCT\n"
"#define CONSTRUCT(Type, type)                                       \\\n"
"struct Type : public type {                                         \\\n"
"  Type () { bzero ((type *) this, sizeof (type)); }                 \\\n"
"  ~Type () { xdr_free ((xdrproc_t) xdr_ ## type,                    \\\n"
"                       (char *) (type *) this); }                   \\\n"
"};\n"
"#define CONSTRUCT_DEFINED_BY_%s\n"
"#endif /* !CONSTRUCT */\n"
"\n"
"#else /* !__cplusplus */\n"
"\n"
"#ifndef EXTERN\n"
"#define EXTERN extern\n"
"#define EXTERN_DEFINED_BY_%s\n"
"#endif /* !EXTERN */\n"
"#ifndef UNION_NAME\n"
"#define UNION_NAME(name) u\n"
"#define UNION_NAME_DEFINED_BY_%s 1\n"
"#endif /* !UNION_NAME */\n"
"#ifndef CONSTRUCT\n"
"#define CONSTRUCT(Type, type)\n"
"#define CONSTRUCT_DEFINED_BY_%s\n"
"#endif /* !CONSTRUCT */\n"
"\n"
"#endif /* !__cplusplus */\n", guard, guard, guard, guard, guard, guard);
#endif

  tell = ftell (fout);
  /* print data definitions */
  while ((def = get_definition ())) {
    print_datadef (def);
  }

  /* print function declarations.  
     Do this after data definitions because they might be used as
     arguments for functions */
  for (l = defined; l != NULL; l = l->next) {
    print_funcdef (l->val);
  }
  if (extend && tell == ftell (fout)) {
    (void) unlink (outfilename);
  }
#if 0
  f_print (fout, "\n#ifdef __cplusplus\n"
	   "}\n"
	   "#endif /* __cplusplus */\n");
#endif

  f_print (fout, "\n");

#if 0
  f_print (fout,
"#ifdef EXTERN_DEFINED_BY_%s\n"
"#undef EXTERN\n"
"#undef EXTERN_DEFINED_BY_%s\n"
"#endif /* EXTERN_DEFINED_BY_%s */\n"
"#ifdef UNION_NAME_DEFINED_BY_%s\n"
"#undef UNION_NAME\n"
"#undef UNION_NAME_DEFINED_BY_%s\n"
"#endif /* UNION_NAME_DEFINED_BY_%s */\n"
"#ifdef CONSTRUCT_DEFINED_BY_%s\n"
"#undef CONSTRUCT\n"
"#undef CONSTRUCT_DEFINED_BY_%s\n"
"#endif /* CONSTRUCT_DEFINED_BY_%s */\n",
	   guard, guard, guard, guard, guard, guard, guard, guard, guard);
#endif

  f_print (fout, "\n#endif /* !_%s */\n", guard);
}
示例#11
0
文件: event_reason.c 项目: hfs/afd
/*++++++++++++++++++++++++++ get_event_reason() +++++++++++++++++++++++++*/
static void
get_event_reason(char *reason_str, char *host_alias)
{
   int         fd,
               i,
               max_event_log_files,
               type;
   char        log_file[MAX_PATH_LENGTH],
               *p_log_file,
               *ptr,
               *src;
   struct stat stat_buf;

   /* Always reset reason_str, so we do not display incoreect data. */
   reason_str[0] = '\0';

   /* Get the maximum event log file number. */
   (void)sprintf(log_file, "%s%s%s",
                 p_work_dir, ETC_DIR, AFD_CONFIG_FILE);
   if ((eaccess(log_file, F_OK) == 0) &&
       (read_file_no_cr(log_file, &src, __FILE__, __LINE__) != INCORRECT))
   {
      char value[MAX_INT_LENGTH + 1];

      if (get_definition(src, MAX_EVENT_LOG_FILES_DEF,
                         value, MAX_INT_LENGTH) != NULL)
      {
         max_event_log_files = atoi(value);
      }
      else
      {
         max_event_log_files = MAX_EVENT_LOG_FILES;
      }
      free(src);
   }
   else
   {
      max_event_log_files = MAX_EVENT_LOG_FILES;
   }

   /* Prepare log file name. */
   p_log_file = log_file;
   p_log_file += sprintf(log_file, "%s%s/%s", p_work_dir, LOG_DIR,
                         EVENT_LOG_NAME);

   for (i = 0; i < max_event_log_files; i++)
   {
      (void)sprintf(p_log_file, "%d", i);
      if (stat(log_file, &stat_buf) < 0)
      {
         if (errno == ENOENT)
         {
            /* For some reason the file is not there. So lets */
            /* assume we have found nothing.                  */;
         }
         else
         {
            (void)xrec(WARN_DIALOG, "Failed to stat() %s : %s (%s %d)",
                       log_file, strerror(errno), __FILE__, __LINE__);
         }
         return;
      }
      if (stat_buf.st_size == 0)
      {
         return;
      }

      if ((fd = open(log_file, O_RDONLY)) == -1)
      {
         (void)xrec(FATAL_DIALOG, "Failed to open() %s : %s (%s %d)",
                    log_file, strerror(errno), __FILE__, __LINE__);
         return;
      }
#ifdef HAVE_MMAP
      if ((src = mmap(0, stat_buf.st_size, PROT_READ,
                      (MAP_FILE | MAP_SHARED), fd, 0)) == (caddr_t) -1)
      {
         (void)xrec(FATAL_DIALOG, "Failed to mmap() %s : %s (%s %d)",
                    log_file, strerror(errno), __FILE__, __LINE__);
         (void)close(fd);
         return;
      }
#else
      if ((src = malloc(stat_buf.st_size)) == NULL)
      {
         (void)xrec(FATAL_DIALOG, "malloc() error : %s (%s %d)",
                    strerror(errno), __FILE__, __LINE__);
         (void)close(fd);
         return;
      }
      if (read(fd, src, stat_buf.st_size) != stat_buf.st_size)
      {
         (void)xrec(FATAL_DIALOG, "Failed to read() from %s : %s (%s %d)",
                    log_file, strerror(errno), __FILE__, __LINE__);
         free(src);
         (void)close(fd);
         return;
      }
#endif
      if (close(fd) == -1)
      {
         system_log(DEBUG_SIGN, __FILE__, __LINE__,
                    "close() error : %s", strerror(errno));
      }
      ptr = src + stat_buf.st_size - 2;

      /*
       * Lets first search for an EA_OFFLINE or EA_ACKNOWLEDGE event
       * for this host.
       */
      while (ptr > src)
      {
         while ((ptr > src) && (*ptr != '\n'))
         {
            ptr--;
         }
         if ((ptr > src) && (*ptr == '\n') && (*(ptr + 1) != ' '))
         {
            ptr++;
            HEX_CHAR_TO_INT((*(ptr + LOG_DATE_LENGTH + 1)));
            if (type == EC_HOST)
            {
               HEX_CHAR_TO_INT((*(ptr + LOG_DATE_LENGTH + 3)));
               if (type == ET_MAN)
               {
                  int          k;
                  unsigned int event_action_no;
                  char         str_number[MAX_INT_LENGTH + 1],
                               *tmp_ptr;

                  tmp_ptr = ptr;
                  ptr += LOG_DATE_LENGTH + 5;
                  k = 0;
                  do
                  {
                     str_number[k] = *(ptr + k);
                     k++;
                  } while ((*(ptr + k) != SEPARATOR_CHAR) &&
                           (*(ptr + k) != '\n') && (k < MAX_INT_LENGTH));
                  str_number[k] = '\0';
                  event_action_no = (unsigned int)strtoul(str_number, NULL, 16);
                  if ((event_action_no == EA_ACKNOWLEDGE) ||
                      (event_action_no == EA_OFFLINE))
                  {
                     ptr += k;
                     if (*ptr == SEPARATOR_CHAR)
                     {
                        ptr++;
                        k = 0;
                        while ((*(ptr + k) != SEPARATOR_CHAR) &&
                               (*(ptr + k) != '\n') &&
                               (*(ptr + k) == *(host_alias + k)))
                        {
                           k++;
                        }
                        if (((*(ptr + k) == SEPARATOR_CHAR) ||
                             (*(ptr + k) == '\n')) &&
                            (*(host_alias + k) == '\0'))
                        {
                           ptr += k;
                           if (*ptr == SEPARATOR_CHAR)
                           {
                              ptr++;
                              k = 0;

                              /* Store user. */
                              while ((*(ptr + k) != SEPARATOR_CHAR) &&
                                     (*(ptr + k) != '\n'))
                              {
                                 *(reason_str + k) = *(ptr + k);
                                 k++;
                              }
                              if (*(ptr + k) == SEPARATOR_CHAR)
                              {
                                 int j;

                                 *(reason_str + k) = '\n';
                                 k += 1;
                                 j = k;
                                 while (*(ptr + k) != '\n')
                                 {
                                    if (*(ptr + k) == '%')
                                    {
                                       char hex_char[3];

                                       hex_char[0] = *(ptr + k + 1);
                                       hex_char[1] = *(ptr + k + 2);
                                       hex_char[2] = '\0';
                                       *(reason_str + j) = (char)strtol(hex_char, NULL, 16);
                                       k += 3;
                                       j += 1;
                                    }
                                    else
                                    {
                                       *(reason_str + j) = *(ptr + k);
                                       j++; k++;
                                    }
                                 }
                                 *(reason_str + j) = '\0';
                              }
                              else
                              {
                                 *(reason_str + k) = '\0';
                              }

                              /* Free all memory we have allocated. */
#ifdef HAVE_MMAP
                              if (munmap(src, stat_buf.st_size) < 0)
                              {
                                 (void)xrec(ERROR_DIALOG,
                                            "munmap() error : %s (%s %d)",
                                            strerror(errno),
                                            __FILE__, __LINE__);
                              }                                                  
#else
                              free(src);
#endif

                              return;
                           }
                           else
                           {
                              ptr = tmp_ptr - 2;
                           }
                        }
                        else
                        {
                           ptr = tmp_ptr - 2;
                        }
                     }
                     else
                     {
                        ptr = tmp_ptr - 2;
                     }
                  }
                  else
                  {
                     ptr = tmp_ptr - 2;
                  }
               }
               else
               {
                  ptr -= 2;
               }
            }
            else
            {
               ptr -= 2;
            }
         }
         else
         {
            ptr--;
         }
      }

      /* Free all memory we have allocated. */
#ifdef HAVE_MMAP
      if (munmap(src, stat_buf.st_size) < 0)
      {
         (void)xrec(ERROR_DIALOG, "munmap() error : %s (%s %d)",
                    strerror(errno), __FILE__, __LINE__);
      }                                                  
#else
      free(src);
#endif
   }

   return;
}
示例#12
0
/*######################### check_fake_user() ###########################*/
void
check_fake_user(int *argc, char *argv[], char *config_file, char *fake_user)
{
   register int i;
   char         wanted_user[MAX_FULL_USER_ID_LENGTH];

   wanted_user[0] = 1;
   for (i = 1; i < *argc; i++)
   {
      if (CHECK_STRCMP(argv[i], "-u") == 0)
      {
         if (((i + 1) < *argc) && (argv[i + 1][0] != '-'))
         {
            /* Check if the buffer is long enough! */
            if (MAX_FULL_USER_ID_LENGTH < strlen(argv[i + 1]))
            {
               (void)fprintf(stderr,
                             _("Buffer for storing fake user to short. (%s %d)\n"),
                             __FILE__, __LINE__);
               fake_user[0] = '\0';
               return;
            }
            (void)strcpy(wanted_user, argv[i + 1]);
            if ((i + 2) < *argc)
            {
               register int j;

               for (j = i; j < *argc; j++)
               {
                  argv[j] = argv[j + 2];
               }
               argv[j] = NULL;
            }
            else
            {
               argv[i] = NULL;
            }
            *argc -= 2;
            i = *argc;
         }
         else
         {
            /* No fake user supplied, so lets take it from */
            /* config file.                                */
            wanted_user[0] = '\0';
            if ((i + 1) < *argc)
            {
               register int j;

               for (j = i; j < *argc; j++)
               {
                  argv[j] = argv[j + 1];
               }
               argv[j] = NULL;
            }
            else
            {
               argv[i] = NULL;
            }
            *argc -= 1;
            i = *argc;
         }
         break;
      }
   }

   if (wanted_user[0] != 1)
   {
      struct passwd *pwd;

      if ((pwd = getpwuid(getuid())) != NULL)
      {
         char *buffer = NULL,
              full_config_name[MAX_PATH_LENGTH];

         (void)snprintf(full_config_name, MAX_PATH_LENGTH, "%s%s%s",
                        p_work_dir, ETC_DIR, config_file);
         if ((eaccess(full_config_name, F_OK) == 0) &&
             (read_file_no_cr(full_config_name, &buffer, YES, __FILE__, __LINE__) != INCORRECT))
         {
            char fake_user_list[MAX_PATH_LENGTH];

            if (get_definition(buffer, FAKE_USER_DEF,
                               fake_user_list, MAX_PATH_LENGTH) != NULL)
            {
               size_t length;

               length = strlen(pwd->pw_name);
               if (length > 0)
               {
                  int  change_char;
                  char real_user[MAX_FULL_USER_ID_LENGTH + 2],
                       *ptr,
                       *tmp_ptr;

                  if ((length + 1) < MAX_FULL_USER_ID_LENGTH)
                  {
                     (void)memcpy(real_user, pwd->pw_name, length);
                  }
                  else
                  {
                     (void)memcpy(real_user, pwd->pw_name,
                                  MAX_FULL_USER_ID_LENGTH - 1);
                     length = MAX_FULL_USER_ID_LENGTH - 1;
                  }
                  real_user[length] = '-';
                  real_user[length + 1] = '>';
                  real_user[length + 2] = '\0';

                  ptr = fake_user_list;
                  while ((ptr = lposi(ptr, real_user, length + 2)) != NULL)
                  {
                     ptr--;
                     tmp_ptr = ptr;
                     while ((*tmp_ptr != ',') && (*tmp_ptr != '\0'))
                     {
                        tmp_ptr++;
                     }
                     if (*tmp_ptr == ',')
                     {
                        change_char = YES;
                        *tmp_ptr = '\0';
                     }
                     else
                     {
                        change_char = NO;
                     }
                     if ((wanted_user[0] == '\0') ||
                         (CHECK_STRCMP(ptr, wanted_user) == 0))
                     {
                        i = 0;
                        while ((*(ptr + i) != ' ') && (*(ptr + i) != '\0') &&
                               (*(ptr + i) != '\t') &&
                               (i < MAX_FULL_USER_ID_LENGTH))
                        {
                           fake_user[i] = *(ptr + i);
                           i++;
                        }
                        fake_user[i] = '\0';
                        free(buffer);
                        return;
                     }
                     if (change_char == YES)
                     {
                        *tmp_ptr = ',';
                     }
                     ptr = tmp_ptr;
                  }
               }
            }
         }
         free(buffer);
         (void)fprintf(stderr, "%s (%s %d)\n",
                       PERMISSION_DENIED_STR, __FILE__, __LINE__);
         exit(INCORRECT);
      }
   }
   fake_user[0] = '\0';

   return;
}