Пример #1
0
void bt_sighandler(int sig, siginfo_t *info,
                   void *secret) {

  void *trace[16];
  char **messages = (char **)NULL;
  int i, trace_size = 0;
  ucontext_t *uc = (ucontext_t *)secret;

  /* Do something useful with siginfo_t */
  if (sig == SIGSEGV)
    printf("Got signal %d, faulty address is %p, "
           "from %p\n", sig, info->si_addr, 
           uc->uc_mcontext.gregs[REG_EIP]);
  else
    printf("Got signal %d#92;\n", sig);

  trace_size = backtrace(trace, 16);
  /* overwrite sigaction with caller's address */
  trace[1] = (void *) uc->uc_mcontext.gregs[REG_EIP];

  messages = backtrace_symbols(trace, trace_size);
  /* skip first stack frame (points here) */
  printf("[bt] Execution path:#92;\n");
  for (i=1; i<trace_size; ++i)
  {
    printf("[bt] %s#92;\n", messages[i]);
    char syscom[256];
    sprintf(syscom,"addr2line %p -e %s", trace[i] , getExecutableName() ); //last parameter is the name of this app
    system(syscom);

  }
  exit(0);
}
Пример #2
0
Файл: main.c Проект: koron/ctags
static void makeTags (cookedArgs *args)
{
	clock_t timeStamps [3];
	boolean resize = FALSE;
	boolean files = (boolean)(! cArgOff (args) || Option.fileList != NULL
							  || Option.filter);

	if (! files)
	{
		if (filesRequired ())
			error (FATAL, "No files specified. Try \"%s --help\".",
				getExecutableName ());
		else if (! Option.recurse && ! etagsInclude ())
			return;
	}

#define timeStamp(n) timeStamps[(n)]=(Option.printTotals ? clock():(clock_t)0)
	if ((! Option.filter) && (! Option.printLanguage))
		openTagFile ();

	timeStamp (0);

	if (! cArgOff (args))
	{
		verbose ("Reading command line arguments\n");
		resize = createTagsForArgs (args);
	}
	if (Option.fileList != NULL)
	{
		verbose ("Reading list file\n");
		resize = (boolean) (createTagsFromListFile (Option.fileList) || resize);
	}
	if (Option.filter)
	{
		verbose ("Reading filter input\n");
		resize = (boolean) (createTagsFromFileInput (stdin, TRUE) || resize);
	}
	if (! files  &&  Option.recurse)
		resize = recurseIntoDirectory (".");

	timeStamp (1);

	if ((! Option.filter) && (!Option.printLanguage))
		closeTagFile (resize);

	timeStamp (2);

	if (Option.printTotals)
		printTotals (timeStamps);
#undef timeStamp
}
Пример #3
0
extern void testEtagsInvocation (void)
{
	char* const execName = eStrdup (getExecutableName ());
	char* const etags = eStrdup (ETAGS);
#ifdef CASE_INSENSITIVE_FILENAMES
	toLowerString (execName);
	toLowerString (etags);
#endif
	if (strstr (execName, etags) != NULL)
	{
		verbose ("Running in etags mode\n");
		setEtagsMode ();
	}
}
Пример #4
0
//---------------------------------------------------------------------------
static void exceptionStdErrorToSyslog(ExceptionSP & e)
{
  try {
    utf8::OemString os(getNameFromPathName(getExecutableName()).getOEMString());
    utf8::OemString er(e->stdError().getOEMString());
#if HAVE_SYSLOG_H
    openlog(os,LOG_PID,LOG_DAEMON);
    syslog(LOG_ERR,er);
    closelog();
#endif
    fprintf(stderr,"%s: %s",(const char * ) os,(const char * ) er);
  }
  catch( ... ){
  }
}
Пример #5
0
extern void error (
		const errorSelection selection, const char *const format, ...)
{
	va_list ap;

	va_start (ap, format);
	fprintf (errout, "%s: %s", getExecutableName (),
			selected (selection, WARNING) ? "Warning: " : "");
	vfprintf (errout, format, ap);
	if (selected (selection, PERROR))
#ifdef HAVE_STRERROR
		fprintf (errout, " : %s", strerror (errno));
#else
		perror (" ");
#endif
	fputs ("\n", errout);
	va_end (ap);
	if (selected (selection, FATAL))
		exit (1);
}
Пример #6
0
extern void error (
		const errorSelection selection, const char *const format, ...)
{
	va_list ap;

	va_start (ap, format);
	if (Option.json) {
		char *reason;
		vasprintf (&reason, format, ap);

		json_t *response = json_object ();
		json_object_set_new (response, "error", json_string (reason));
		if (selected (selection, WARNING))
			json_object_set_new (response, "warning", json_true ());
		if (selected (selection, FATAL))
			json_object_set_new (response, "fatal", json_true ());
		if (selected (selection, PERROR)) {
			json_object_set_new (response, "errno", json_integer (errno));
			json_object_set_new (response, "perror", json_string (strerror (errno)));
		}
		json_dumpf (response, stdout, 0);
		fprintf (stdout, "\n");

		json_decref (response);
		free (reason);
	} else {
		fprintf (errout, "%s: %s", getExecutableName (),
				selected (selection, WARNING) ? "Warning: " : "");
		vfprintf (errout, format, ap);
		if (selected (selection, PERROR))
#ifdef HAVE_STRERROR
			fprintf (errout, " : %s", strerror (errno));
#else
			perror (" ");
#endif
		fputs ("\n", errout);
	}
	va_end (ap);
	if (! Option.json && selected (selection, FATAL))
		exit (1);
}
Пример #7
0
    static FILE* openLogFile()
    {
        FILE* pFile = nullptr;

        // Get current process name
        std::string filename = getExecutableName();

        // Now we have a folder and a filename, look for an available filename (we don't overwrite existing files)
        std::string prefix = std::string(filename);
        std::string executableDir = getExecutableDirectory();
        std::string logFile;
        if(findAvailableFilename(prefix, executableDir, "log", logFile))
        {
            if(fopen_s(&pFile, logFile.c_str(), "w") == 0)
            {
                // Success
                return pFile;
            }
        }
        // If we got here, we couldn't create a log file
        should_not_get_here();
        return pFile;
    }
Пример #8
0
int createSemaphore()
{
    const int maxExeFileName=1000;
    char exeFileName[maxExeFileName];  
    
    if(getExecutableName(exeFileName,maxExeFileName)!=0)
    {
        printf("getExecutableName failed\n");
        return -1;
    }
    
    printf("exe: <%s>\n",exeFileName);
    
    //key_t ipc_key = ftok(exeFileName,33);
    
    key_t ipc_key = 553745195;
    
    if(ipc_key==-1)
    {
        printf("ftok failed %s\n",strerror(errno));
        return -1;
    }
     
    printf("ipc_key: %d\n",ipc_key);
    
    int sem_id = semget(ipc_key,1,IPC_CREAT /*| 0660*/);
    
    if(sem_id==-1)
    {
        printf("semget failed\n");
        return -1;
    }
    
    printf("sem id: %d\n",sem_id);
    
    return sem_id;    
}
Пример #9
0
//---------------------------------------------------------------------------
void LogFile::initialize()
{
  new (&stdErr) LogFile;
  stdErr.fileName(changeFileExt(getExecutableName(),".log"));
}
Пример #10
0
// PD_TRACE_DECLARE_FUNCTION ( SDB_OSSLCEXEC, "ossLocateExecutable" )
INT32 ossLocateExecutable ( const CHAR * refPath ,
                            const CHAR * exeName ,
                            CHAR * buf ,
                            UINT32 bufSize )
{
   INT32          rc          = SDB_OK ;
   PD_TRACE_ENTRY ( SDB_OSSLCEXEC );
   INT32          dirLen      = 0 ;
   UINT32         exeLen      = 0 ;
   const CHAR *   separator   = NULL ;
   CHAR newExeName[ OSS_MAX_PATHSIZE + 1 ] = {0} ;

   ossMemset ( newExeName , 0 , sizeof ( newExeName ) ) ;

   if ( ! ( refPath && exeName && buf && bufSize > 0 ) )
   {
      rc = SDB_INVALIDARG ;
      goto error ;
   }

#ifdef _WINDOWS
   rc = getExecutableName ( exeName , newExeName , sizeof ( newExeName ) ) ;
   if ( rc != SDB_OK )
   {
      goto error ;
   }
#else
   if ( ossStrlen ( exeName ) >= sizeof ( newExeName ) )
   {
      rc = SDB_INVALIDSIZE ;
      goto error ;
   }
   ossStrncpy ( newExeName , exeName, sizeof ( newExeName ) ) ;
#endif

   exeLen = ossStrlen ( newExeName ) ;

   separator = ossStrrchr ( refPath , OSS_PATH_SEP_CHAR ) ;
   if ( ! separator )
   {
      if ( exeLen >= bufSize )
      {
         rc = SDB_INVALIDSIZE ;
         goto error ;
      }
      ossStrcpy ( buf , newExeName ) ;
      goto done ;
   }

   dirLen = separator - refPath ; // length without separator

   if ( dirLen + exeLen + 1 >= bufSize )
   {
      rc = SDB_INVALIDSIZE ;
      goto error ;
   }

   ossStrncpy ( buf , refPath , dirLen + 1 ) ; // 1 for separator
   buf[dirLen + 1] = '\0' ;
   ossStrncat ( buf , newExeName , exeLen ) ;

done :
   PD_TRACE_EXITRC ( SDB_OSSLCEXEC, rc );
   return rc ;
error :
   goto done ;
}
Пример #11
0
#define selected(var,feature)	(((int)(var) & (int)(feature)) == (int)feature)

static errorPrintFunc errorPrinter;
static void *errorPrinterData;

extern void setErrorPrinter (errorPrintFunc printer, void *data)
{
	errorPrinter = printer;
	errorPrinterData = data;
}

extern bool stderrDefaultErrorPrinter (const errorSelection selection,
					  const char *const format,
					  va_list ap, void *data CTAGS_ATTR_UNUSED)
{
	fprintf (stderr, "%s: %s", getExecutableName (),
		 selected (selection, WARNING) ? "Warning: " : "");
	vfprintf (stderr, format, ap);
	if (selected (selection, PERROR))
#ifdef HAVE_STRERROR
		fprintf (stderr, " : %s", strerror (errno));
#else
	perror (" ");
#endif
	fputs ("\n", stderr);

	return (selected (selection, FATAL) || Option.fatalWarnings)? true: false;
}

extern void error (const errorSelection selection,
		   const char *const format, ...)