Example #1
0
static void die(const char *file, int line, const char *expr)
{
 fflush(stdout);
 fprintf(stderr, "%s:%d: check failed: '%s'\n", file, line, expr);
 fflush(stderr);
 exit(1);
}
Example #2
0
void Log::outErrorDb()
{
    std::lock_guard<std::mutex> guard(m_worldLogMtx);

    if (m_includeTime)
        outTime();

    fprintf(stderr, "\n");

    if (logfile)
    {
        outTimestamp(logfile);
        fprintf(logfile, "ERROR:\n");
        fflush(logfile);
    }

    if (dberLogfile)
    {
        outTimestamp(dberLogfile);
        fprintf(dberLogfile, "\n");
        fflush(dberLogfile);
    }

    fflush(stderr);
}
Example #3
0
void Log::outErrorScriptLib()
{
    std::lock_guard<std::mutex> guard(m_worldLogMtx);
    if (m_includeTime)
        outTime();

    fprintf(stderr, "\n");

    if (logfile)
    {
        outTimestamp(logfile);
        if (m_scriptLibName)
            fprintf(logfile, "<%s ERROR:> ", m_scriptLibName);
        else
            fprintf(logfile, "<Scripting Library ERROR>: ");
        fflush(logfile);
    }

    if (scriptErrLogFile)
    {
        outTimestamp(scriptErrLogFile);
        fprintf(scriptErrLogFile, "\n");
        fflush(scriptErrLogFile);
    }

    fflush(stderr);
}
void displayProgressBar(int x)
{
	const int hun=100;
	int n;
	int i;
	char cr='\r';
	int numcols;
	struct winsize w;
	const char* ending="(COMPLETED)";
	const int EXTRA_CHARS=8;
	int barlen;
	x=(x>hun) ? x%hun : x;
	ioctl(0, TIOCGWINSZ, &w);
	numcols=w.ws_col;
	barlen=(numcols  - strlen(ending) - EXTRA_CHARS);
	n= barlen * x /hun;
	printf("%c",cr);
	printf("%3d\% [",x);
	fflush(stdout);
	for(i=0;i<n;i++)
	{
		printf("%s","=");
	}
	for(;i<barlen;i++)
		printf("%s"," ");
	printf("%s","]");
	if(x == hun)
	{
		printf(" %s",ending);
	}
	fflush(stdout);
}
Example #5
0
/*
   -----------------------------------------------------------
   purpose -- to write out the statistics for the Graph object

   return value -- 1 if success, 0 otherwise

   created -- 95sep29, cca
   -----------------------------------------------------------
*/
int
Graph_writeStats ( 
   Graph    *graph, 
   FILE   *fp 
) {
int   rc ;
/*
   ---------------
   check the input
   ---------------
*/
if ( graph == NULL || fp == NULL ) {
   fprintf(stderr, "\n error in Graph_writeStats(%p,%p)"
           "\n bad input\n", graph, fp) ;
   spoolesFatal();
}
switch ( graph->type ) {
case 0 : 
   rc = fprintf(fp, "\n Graph : unweighted graph object :") ;
   break ;
case 1 : 
   rc = fprintf(fp, "\n Graph : vertices weighted graph object :") ;
   break ;
case 2 : 
   rc = fprintf(fp, "\n Graph : edges weighted graph object :") ;
   break ;
case 3 : 
   rc = fprintf(fp, 
            "\n Graph : vertices and edges weighted graph object :") ;
   break ;
default :
   fprintf(stderr, "\n fatal error in Graph_writeStats(%p,%p)"
           "\n invalid graph->type = %d\n", graph, fp, graph->type) ;
   return(0) ;
}
if ( rc < 0 ) { goto IO_error ; }
fflush(fp) ;
rc = fprintf(fp, 
             "\n %d internal vertices, %d boundary vertices, %d edges",
             graph->nvtx, graph->nvbnd, graph->nedges) ;
if ( rc < 0 ) { goto IO_error ; }
fflush(fp) ;
rc = fprintf(fp, 
             "\n %d internal vertex weight, %d boundary vertex weight",
(graph->vwghts != NULL) ? IVsum(graph->nvtx, graph->vwghts) : graph->nvtx,
(graph->vwghts != NULL) ? IVsum(graph->nvbnd, graph->vwghts + graph->nvtx) : graph->nvbnd) ;
if ( rc < 0 ) { goto IO_error ; }
if ( graph->type >= 2 ) {
   rc = fprintf(fp, "\n %d total edge weight",
                graph->totewght) ;
}
if ( rc < 0 ) { goto IO_error ; }

return(1) ;

IO_error :
   fprintf(stderr, "\n fatal error in Graph_writeStats(%p,%p)"
           "\n rc = %d, return from fprintf\n", graph, fp, rc) ;
   return(0) ;
}
Example #6
0
int
key_wait(char *text)
{
    struct termios	term_attr;
    tcflag_t	lfl_orig;
    int		any_key;
    char		c;

    any_key = (text == NULL);
    if (any_key)
        text = "Press any key...";

    fprintf(stderr, text);
    fflush(stderr);

    tcgetattr(STDERR_FILENO, &term_attr);
    lfl_orig = term_attr.c_lflag;
    if (any_key)
        term_attr.c_lflag &= ~ECHO;
    term_attr.c_lflag &= ~ICANON;
    tcsetattr(STDERR_FILENO, TCSAFLUSH, &term_attr);
    read(STDERR_FILENO, &c, 1);
    term_attr.c_lflag = lfl_orig;
    tcsetattr(STDERR_FILENO, TCSAFLUSH, &term_attr);

    fprintf(stderr, (any_key ? "\r" : "\r\n"));
    fflush(stderr);
    return(c);
}
Example #7
0
void proceed_question(int delay)
{
	char buf[256];
	const char *short_yes = _("yY");

	fflush(stdout);
	fflush(stderr);
	if (delay > 0) {
		if (setjmp(alarm_env)) {
			signal(SIGALRM, SIG_IGN);
			printf("%s", _("<proceeding>\n"));
			return;
		}
		signal(SIGALRM, alarm_signal);
		printf(_("Proceed anyway (or wait %d seconds) ? (y,n) "),
		       delay);
		alarm(delay);
	} else
		fputs(_("Proceed anyway? (y,n) "), stdout);
	buf[0] = 0;
	if (!fgets(buf, sizeof(buf), stdin) ||
	    strchr(short_yes, buf[0]) == 0) {
		putc('\n', stdout);
		exit(1);
	}
	signal(SIGALRM, SIG_IGN);
}
void JNICALL callbackClassLoad(prms_CLS_LD)
{
    check_CLS_LD;
    if ( flag ) return;
    char* signature;
    char* generic;
    jboolean res = false;
    jvmtiError result;

    result = jvmti_env->GetClassSignature(klass, &signature, &generic);
    if (result != JVMTI_ERROR_NONE) return;
    if (strcmp(signature, "Ljava/lang/Runnable;")) return;
    fprintf(stderr, "\tnative: GetClassSignature result = %d (must be zero) \n", result);
    fprintf(stderr, "\tnative: klass is %p \n", klass);
    fprintf(stderr, "\tnative: signature is %s \n", signature);
    fprintf(stderr, "\tnative: generic is %s \n", generic);
    fflush(stderr);

    flag = true;
    util = true;

    result = jvmti_env->IsInterface((jclass)thread, &res);
    fprintf(stderr, "\tnative: IsInterface result = %d (must be JVMTI_ERROR_INVALID_CLASS (21)) \n", result);
    fflush(stderr);
    if ( result != JVMTI_ERROR_INVALID_CLASS ) return;
    test = true;
}
Example #9
0
File: netirc.c Project: ralight/ggz
/* Establish connection: log into an IRC server */
void net_connect(const char *host, int port, const char *name, const char *password)
{
	int fd;

	guruname = (char*)name;
	gurupassword = (char*)password;

	fd = ggz_make_socket(GGZ_SOCK_CLIENT, 6667, host);
	if(fd < 0)
	{
		status = NET_ERROR;
		return;
	}
	irc = fdopen(fd, "a+");
	if(!irc)
	{
		status = NET_ERROR;
		return;
	}

	fprintf(irc, "NICK %s\r\n", guruname);
	fflush(irc);
	fprintf(irc, "USER %s %s %s :%s\r\n", guruname, "noosphere", "localhost", guruname);
	fflush(irc);

	status = NET_LOGIN;
}
Example #10
0
int WINAPI TimedEntryPoint(VOID)
{
    // We couldn't call LoadLibrary in DllMain,
    // so we detour SleepEx here...
    LONG error;

    TrueSleepEx = (DWORD (WINAPI *)(DWORD, BOOL))
        DetourFindFunction("kernel32.dll", "SleepEx");

    DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());
    DetourAttach(&(PVOID&)TrueSleepEx, TimedSleepEx);
    error = DetourTransactionCommit();

    if (error == NO_ERROR) {
        printf("dslept" DETOURS_STRINGIFY(DETOURS_BITS) ".dll: "
               " Detoured SleepEx().\n");

    }
    else {
        printf("dslept" DETOURS_STRINGIFY(DETOURS_BITS) ".dll: "
               " Error detouring SleepEx(): %d\n", error);
    }

    Verify("SleepEx", (PVOID)SleepEx);
    printf("\n");
    fflush(stdout);

    printf("dslept" DETOURS_STRINGIFY(DETOURS_BITS) ".dll: "
           " Calling EntryPoint\n");
    fflush(stdout);

    return TrueEntryPoint();
}
Example #11
0
void shell() {
    int number_of_processes = 0, i = 0;
    FILE *f_in;
    char temp[400];
    char user_prog_path[400];
    int uid;
    printf("\n Shell begins:\n");
    printf("\n guestos:\n");
    fflush(stdin);
    printf("How many user processes to run?");
    scanf("%d", &number_of_processes);
    f_in = fopen("configfile", "w");
    for (i = 0; i < number_of_processes; i++) {
        printf("\n\n\n guestos:Enter the full path of user program to execute:");
        fflush(stdin);
        //fgets(user_prog_path,max_path_length,stdin);
        //gets(user_prog_path);
        scanf("%s", user_prog_path);
        printf ("Enter Uid for process: ");
        scanf("%d", &uid);
        printf("\n The entered file path is : %s", user_prog_path);
        sprintf(temp, "\n[ Context %d ]", i);
        fputs(temp, f_in);
        sprintf(temp, "\nExe = %s\n", user_prog_path);
        fputs(temp, f_in);
        sprintf(temp, "\nUid = %d\n", uid);
        fputs(temp, f_in);
    }
    configfile = "configfile";
    fclose(f_in);
    return;

}
Example #12
0
/* ============================================================================
Function:     =        Debugger
Purpose:      =       Print out debug phase and element types at various stages.
==============================================================================
Input arg:  =        1. flag: Flag for stage for specified output.
            =        7. my_rank: The processors rank.
            =        3. phase: The current phase of the algorithim.
            =        4. partner_size: The size of the paring among processors.
            =        5. my_list: Local list for each processor.
            =        6. global_size: The size of the input array.
            =        7. list_size: The size of the processors array.
=========================================================================== */
void Debugger(int flag, int my_rank, int phase, int partner_size, int my_list[],
                int global_size, int list_size)
{
    if (flag == 1)
    {
        printf("Processor %d's #%d %d-element butterfly now executing. \n",
                my_rank, phase, partner_size);
        fflush(stdout);
    }
    else if (flag == 2)
    {
        printf("Processor %d's #%d %d-element butterfly now executing. \n",
                my_rank, phase, partner_size);
        fflush(stdout);
    }
    else
    {
        if(my_rank == 0)
        {
            printf(" \nStage %d completed. \n", phase);
        }
        Gather(my_list, global_size, my_rank, list_size);
        fflush(stdout);
    }
}
Example #13
0
int tcp_connect(char *hostname, int port)
{
   int                 sock_fd;
   struct hostent     *host;
   struct sockaddr_in  sin;


   if((host = gethostbyname(hostname)) == NULL)
   {
      printf("[struct stat=\"ERROR\", msg=\"Couldn't find host %s\"]\n", hostname);
      fflush(stdout);
      return(0);
   }

   if((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
   {
      printf("[struct stat=\"ERROR\", msg=\"Couldn't create socket()\"]\n");
      fflush(stdout);
      return(0);
   }

   sin.sin_family = AF_INET;
   sin.sin_port = htons(port);
   bcopy(host->h_addr_list[0], &sin.sin_addr, host->h_length);

   if(connect(sock_fd, (struct sockaddr *)&sin, sizeof(sin)) < 0)
   {
      printf("[struct stat=\"ERROR\", msg=\"%s: connect failed.\"]\n", hostname);
      fflush(stdout);
      return(0);
   }

   return sock_fd;
}
Example #14
0
void locateNovelFeatures(ImageList* novelImages, GraphDiscription graphTemplate, GraphDiscription bunchGraph, JetMasks masks, char* imageDir, char* outputDir, JetDisplacementEstimator dispEst){
    ImageList *subject, *replicate;
    int i;

    for(subject = novelImages; subject != NULL; subject = subject->next_subject){
        for(replicate = subject; replicate != NULL; replicate = replicate->next_replicate){
            Image novel = readRawImage(makePath(imageDir,replicate->filename));
            int *verts = (int*)malloc(sizeof(int)*bunchGraph->numVert);
            printf("Fitting graph for image: %s |", replicate->filename); fflush(stdout);
            for(i = 0; i < bunchGraph->numVert; i++){
                printf("#"); fflush(stdout);
                guessVertexLocation(i, i, graphTemplate, bunchGraph);

                graphTemplate->verts[i].x = graphTemplate->verts[i].x;
                graphTemplate->verts[i].y = graphTemplate->verts[i].y;

                LocatePoint( &(graphTemplate->verts[i].x),  &(graphTemplate->verts[i].y), bunchGraph->bunch[i], novel, masks, dispEst);
                verts[i] = i;
            }
            printf("|\n"); fflush(stdout);

            permuteArray(verts, bunchGraph->numVert);
            freeImage(novel);
            saveGraphDiscription(makePath(outputDir,replicate->filename),graphTemplate);
        }
    }
}
Example #15
0
/* perform write command */
int dowrite(char *name, int rnum){
  DB *dbp;
  DBT key, data;
  int i, err, len;
  char buf[RECBUFSIZ];
  if(showprgr) printf("<Writing Test of Hash>\n  name=%s  rnum=%d\n\n", name, rnum);
  /* open a database */
  if(db_create(&dbp, NULL, 0) != 0){
    fprintf(stderr, "db_create failed\n");
    return 1;
  }
  if(dbp->set_pagesize(dbp, SMALL_PAGESIZE) != 0){
    fprintf(stderr, "DB->set_pagesize failed\n");
    dbp->close(dbp, 0);
    return 1;
  }
  if(dbp->set_cachesize(dbp, 0, BIG_CACHESIZE, 0) != 0){
    fprintf(stderr, "DB->set_cachesize failed\n");
    dbp->close(dbp, 0);
    return 1;
  }
  if(dbp->open(dbp, NULL, name, NULL, DB_HASH, DB_CREATE | DB_TRUNCATE, 00644) != 0){
    fprintf(stderr, "DB->open failed\n");
    dbp->close(dbp, 0);
    return 1;
  }
  err = FALSE;
  memset(&key, 0, sizeof(key));
  memset(&data, 0, sizeof(data));
  /* loop for each record */
  for(i = 1; i <= rnum; i++){
    /* store a record */
    len = sprintf(buf, "%08d", i);
    key.data = buf;
    key.size = len;
    data.data = buf;
    data.size = len;
    if(dbp->put(dbp, NULL, &key, &data, 0) != 0){
      fprintf(stderr, "DB->put failed\n");
      err = TRUE;
      break;
    }
    /* print progression */
    if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
      putchar('.');
      fflush(stdout);
      if(i == rnum || i % (rnum / 10) == 0){
        printf(" (%08d)\n", i);
        fflush(stdout);
      }
    }
  }
  /* close the database */
  if(dbp->close(dbp, 0) != 0){
    fprintf(stderr, "DB->close failed\n");
    err = TRUE;
  }
  if(showprgr && !err) printf("ok\n\n");
  return err ? 1 : 0;
}
VOID Image(IMG img, void *v)
{
    RTN rtn = RTN_FindByName(img, "ReplacedXmmRegs");
    if (RTN_Valid(rtn))
    {
        PROTO proto = PROTO_Allocate(PIN_PARG(int), CALLINGSTD_DEFAULT, "ReplacedXmmRegs", PIN_PARG_END());
        RTN_ReplaceSignature(rtn, AFUNPTR(REPLACE_ReplacedXmmRegs),
                             IARG_PROTOTYPE, proto,
                             (KnobUseIargConstContext)?IARG_CONST_CONTEXT:IARG_CONTEXT,
                             IARG_THREAD_ID,
                             IARG_ORIG_FUNCPTR,
                             IARG_END);
        PROTO_Free(proto);
        printf ("TOOL found and replaced ReplacedXmmRegs\n");
        fflush (stdout);

        RTN rtn = RTN_FindByName(img, "ExecutedAtFunc");
        if (RTN_Valid(rtn))
        {
            executeAtAddr = RTN_Address(rtn);
            printf ("TOOL found ExecutedAtFunc for later PIN_ExecuteAt\n");
            fflush (stdout);
        }

        rtn = RTN_FindByName(img, "DumpXmmRegsAtException");
        if (RTN_Valid(rtn))
        {
            dumpXmmRegsAtExceptionAddr = RTN_Address(rtn);
            printf ("TOOL found DumpXmmRegsAtException for later Exception\n");
            fflush (stdout);
        }
    }
}
Example #17
0
/*Ejercicio 20*/
int main(int argc, char *argv[])
 {
	float val_hora, antig, cant_hs_trab, totalbrut, imp_a_cob, descuento;
	char nombre[20];
	totalbrut=0;
	imp_a_cob=0;
	descuento=0;
	
	printf ("Ingrese nombre del empleado: \n");
	scanf  ("%s", &nombre);
	fflush (stdin);
	printf ("Ingrese antiguedad del empleado: \n");
	scanf  ("%f", &antig);
	fflush (stdin);
	printf ("Ingrese el valor de la hora de un empleado: \n");
	scanf  ("%f", &val_hora);
	fflush (stdin);
	printf ("Ingrese cantidad de horas trabajadas en el mes: \n");
	scanf  ("%f", &cant_hs_trab);
	fflush (stdin);
	
	totalbrut= (val_hora * cant_hs_trab) +(antig *30);
	imp_a_cob= totalbrut*0.87;
	descuento= totalbrut - imp_a_cob;
	
	printf("NOMBRE\tANTIGUEDAD\tVALORHORA\tTOTBRUTO\tDESCUENTO\tTOTNETO\n\n");
	
	printf("%s\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\n\n", nombre,antig,val_hora,totalbrut,descuento,imp_a_cob);
	
	system ("PAUSE");
	return 0;
}
void CheckAndSetFpContextXmmRegs (const CONTEXT *ctxtFrom, CONTEXT *ctxtTo)
{
    fprintf (stdout, "TOOL CheckAndSetFpContextXmmRegs\n");
    fflush (stdout);
    CHAR fpContextSpaceForFpConextFromPin[FPSTATE_SIZE];
    FPSTATE *fpContextFromPin = reinterpret_cast<FPSTATE *>(fpContextSpaceForFpConextFromPin);

    // the application set the each byte in the xmm regs in the state to be 0xa5 before the exception was caused
    PIN_GetContextFPState(ctxtFrom, fpContextFromPin);
    for (int i=0; i<NUM_XMM_REGS; i++)
    {
        for (int j=0; j<16; j++)
        {
            if (fpContextFromPin->fxsave_legacy._xmms[i]._vec8[j] != 0xa5)
            {
                fprintf (stdout, "TOOL unexpected _xmm[%d]._vec8[%d] value %x\n", i, j,
                         (unsigned int)fpContextFromPin->fxsave_legacy._xmms[i]._vec8[j]);
                fflush (stdout);
                //exit (-1);
            }
        }
    }
    fprintf (stdout, "TOOL Checked ctxtFrom OK\n");
    fflush (stdout);


    // the tool now sets the each byte of the xmm regs in the ctxtTo to be 0x5a
    for (int i=0; i<NUM_XMM_REGS; i++)
    {
        for (int j=0; j<16; j++)
        {
            fpContextFromPin->fxsave_legacy._xmms[i]._vec8[j] = 0x5a;
        }
    }
    PIN_SetContextFPState(ctxtTo, fpContextFromPin);

    // verify the setting worked
    for (int i=0; i<NUM_XMM_REGS; i++)
    {
        fpContextFromPin->fxsave_legacy._xmms[i]._vec64[0] = 0x0;
        fpContextFromPin->fxsave_legacy._xmms[i]._vec64[1] = 0x0;
    }
    PIN_GetContextFPState(ctxtTo, fpContextFromPin);
    for (int i=0; i<NUM_XMM_REGS; i++)
    {
        for (int j=0; j<16; j++)
        {
            if (fpContextFromPin->fxsave_legacy._xmms[i]._vec8[j] != 0x5a)
            {
                printf ("TOOL ERROR\n");
                fflush (stdout);
                exit (-1);
            }
        }
    }
    printf ("TOOL Checked ctxtTo OK\n");
    fflush (stdout);

    // application will verify that actual xmm registers contain 0x5a in each byte
}
Example #19
0
/*
 * printerror
 *
 * format a nice and consistent error string using the errno to string
 * conversion utilities and the arguments supplied
 */
void printerror(const int ecode, char *(*error_itoa)(int),
		const char *func, const char *format, ...)
{
  char     message[512];
  char     err[128];
  char     ts[16];
  char     fs[64];
  va_list  ap;

  va_start(ap, format);
  vsnprintf(message, sizeof(message), format, ap);
  va_end(ap);

  error_str(ecode, error_itoa, err, sizeof(err));
  timestamp_str(ts, sizeof(ts));

  if(func != NULL) snprintf(fs, sizeof(fs), "%s: ", func);
  else             fs[0] = '\0';

  fprintf(stderr, "%s%s%s%s\n", ts, fs, message, err);
  fflush(stderr);

#ifndef WITHOUT_DEBUGFILE
  if(debugfile != NULL)
    {
      fprintf(debugfile, "%s%s%s%s\n", ts, fs, message, err);
      fflush(debugfile);
    }
#endif

  return;
}
Example #20
0
FILE* changelog(FILE* log,SETTING* setting){
	char label[] = "[log]vhext.txt";
	const char *path = setting->data_user_path;
	if(path == NULL ){
		path = setting->data_owner_path;
	}
	if(path == NULL ){
		path = setting->data_optional_path;
	}
	if(path == NULL){
		return log;
	}
	long l = strlen(path) + strlen(label) + 1;
	char *newname = (char *)malloc(l);
	if(newname==NULL){
		return log;
	}
	long pos = strcspn(path,"_");
	strncpy(newname,path,pos);
	newname[pos] = '\0';
	strcat(newname,label);
	FILE* newlog = fopen(newname,"w");
	free(newname);
	if(newlog==NULL){
		return log;
	}
	fflush(log);
	filecopy(newlog,log);
	fclose(log);
	fflush(newlog);
	return newlog;
}
Example #21
0
void error(const char *func, const char *msg) {
  fflush(stdout);
  fprintf(stderr, "\n=====\nERROR: [%s] %s\n=====\n\n", func, msg);
  perror("\t");
  fflush(stderr);
  exit(-1);
}
Example #22
0
int pobox_getcands(char *yomi, char *candstr, int len, int mode)
{
	char r;
	int i;
	int ret;

	if (mode) {
		fprintf(gWrServ, "1%s \n", yomi);
	} else {
		fprintf(gWrServ, "1%s\n", yomi);
	}
	ret = fflush(gWrServ);
	if (ret < 0) {
		pobox_disconnect();
		pobox_connect();
		if (mode) {
			fprintf(gWrServ, "1%s \n", yomi);
		} else {
			fprintf(gWrServ, "1%s\n", yomi);
		}
		fflush(gWrServ);
	}
	read(gServSock, &r, 1);
	if (r == '1') {		/* succeeded */
		i = read(gServSock, candstr, len - 1);
		candstr[i] = '\0';
		//printf("pobox_getcands recv =  '%s'\n",candstr);
	} else {
		while (read(gServSock, &r, 1) > 0 && r != '\n');
		return 1;
	}
	return 0;
}
Example #23
0
static void large_request_handler(void *token, void *buf, size_t nbytes, int arg) {
  uint32_t *recvdbuf = (uint32_t *)buf;
  #if VERBOSE
    printf("%i: large_request_handler(). starting...\n", myproc); fflush(stdout);
  #endif

  assert(arg == 666);
  assert(buf == ((uint8_t *)VMseg) + 100);
  assert(nbytes == AM_MaxLong());

  /*  verify the result */
  { int i;
    for (i = 0; i < AM_MaxLong()/4; i++) {
      if (recvdbuf[i] != (uint32_t)((count << 16) + i))
        AMX_FatalErr("%i: ERROR: mismatched data recvdbuf[%i]=%i\n", myproc, i, (int)recvdbuf[i]);
    }
    count++;
    for (i = 0; i < AM_MaxLong()/4; i++) {
      recvdbuf[i] = (uint32_t)((count << 16) + i);
    }
    if (numprocs > 1) count++;
  }

  #if VERBOSE
    printf("%i: large_request_handler(). sending reply...\n", myproc); fflush(stdout);
  #endif


  AM_Safe(AM_ReplyXfer1(token, 100, LARGE_REP_HANDLER, buf, nbytes, 666));
  done++;
}
Example #24
0
static void
err_doit(int errnoflag, int level, const char *fmt, va_list ap)
{
	int		errno_save, n;
	char	buf[MAXLINE + 1];

	errno_save = errno;		/* value caller might want printed */
#ifdef	HAVE_VSNPRINTF
	vsnprintf(buf, MAXLINE, fmt, ap);	/* safe */
#else
	vsprintf(buf, fmt, ap);					/* not safe */
#endif
	n = strlen(buf);
	if (errnoflag)
		snprintf(buf + n, MAXLINE - n, ": %s", strerror(errno_save));
	strcat(buf, "\n");

	if (daemon_proc) {
		syslog(level, buf);
	} else {
		fflush(stdout);		/* in case stdout and stderr are the same */
		fputs(buf, stderr);
		fflush(stderr);
	}
	return;
}
Example #25
0
//Entry point of the P2- microshell implementation
int main(int argc, char *argv[])
{
  Pipe p;
  ctrlCFlag = 1;
  signalHandling();
  ushrcProcessing();
  char *hostName = (char *)malloc(1000);
  gethostname(hostName,1024);    
  while(1){
    fflush(stdin);
    if(isatty(fileno(stdin)) && ctrlCFlag == 1){
       printf("%s%%", hostName);
       fflush(stdout);
    }
    ctrlCFlag = 1;
    p = parse();
    if(p == NULL)
    {
	continue;
    }
    if(p!=NULL && strcmp(p->head->args[0], "end"))
    {
    	prPipe(p);
    }
    else if(isatty(fileno(stdin)) && !strcmp(p->head->args[0], "end"))
    {
	exit(0);
    }	
    else if(!isatty(fileno(stdin)) && !strcmp(p->head->args[0], "end")){
	break;
    }
    freePipe(p);
  }
}
void print_dms(char *hostname, int myid, int numprocs, int local_numdms, double *dms)
{
    /* Print the nodes and the DMs they are handling */
    int jj, kk;

    MPI_Barrier(MPI_COMM_WORLD);
    fflush(NULL);
    if (myid == 0)
        printf("Node\t\tDMs\n----\t\t---\n");
    fflush(NULL);
    for (jj = 1; jj < numprocs; jj++) {
        MPI_Barrier(MPI_COMM_WORLD);
        if (myid == jj) {
            printf("%s\t\t", hostname);
            for (kk = 0; kk < local_numdms - 1; kk++)
                printf("%.2f\t", dms[kk]);
            printf("%.2f\n", dms[kk]);
        }
        fflush(NULL);
        MPI_Barrier(MPI_COMM_WORLD);
    }
    if (myid == 0)
        printf("\n");
    fflush(NULL);
}
Example #27
0
void Log::outErrorEventAI()
{
    std::lock_guard<std::mutex> guard(m_worldLogMtx);

    if (m_includeTime)
        outTime();

    fprintf(stderr, "\n");

    if (logfile)
    {
        outTimestamp(logfile);
        fprintf(logfile, "ERROR CreatureEventAI\n");
        fflush(logfile);
    }

    if (eventAiErLogfile)
    {
        outTimestamp(eventAiErLogfile);
        fprintf(eventAiErLogfile, "\n");
        fflush(eventAiErLogfile);
    }

    fflush(stderr);
}
Example #28
0
void process_input(char *input) {
    char *stringp = (char *)malloc(sizeof(input));
    strcpy(stringp, input);
    const char *delim = " ";
    char *token;

    //stringp is updated to point to the next token
    token = strtok(stringp, delim);
    // printf("%s\n", token);
    if(strcmp(token, "init") == 0 && stringp != NULL) {
        printf("Adding new client\n");
        fflush(stdout);
        token = strtok(NULL, "|");
        char * client_pid = (char *)malloc(sizeof(token));
        strcpy(client_pid,token);
        // client_pid[strlen(client_pid)-1] = '\0';

        client_fifos_fds[client_fd_index++] = open(client_pid, O_WRONLY);
        printf("New client added %s\n", client_pid);
        fflush(stdout);
        return;
    }

    printf("%s", input);
    int i;
    for(i = 0; i<client_fd_index; i++) {
        // printf("writing to fifo id%d\n", client_fifos_fds[i]);
        int w = write(client_fifos_fds[i], input, PIPE_BUF); //writing to each client
        // fflush(stdout);
        print_error(w, "write to fifo failed");
    }
    memset(input, 0, sizeof(input));
}
Example #29
0
static void vhost_virtqueue_cleanup(struct vhost_dev *dev,
                                    struct VirtIODevice *vdev,
                                    struct vhost_virtqueue *vq,
                                    unsigned idx)
{
    struct vhost_vring_state state = {
        .index = idx,
    };
    int r;
    r = vdev->binding->set_host_notifier(vdev->binding_opaque, idx, false);
    if (r < 0) {
        fprintf(stderr, "vhost VQ %d host cleanup failed: %d\n", idx, r);
        fflush(stderr);
    }
    assert (r >= 0);
    r = ioctl(dev->control, VHOST_GET_VRING_BASE, &state);
    if (r < 0) {
        fprintf(stderr, "vhost VQ %d ring restore failed: %d\n", idx, r);
        fflush(stderr);
    }
    virtio_queue_set_last_avail_idx(vdev, idx, state.num);
    assert (r >= 0);
    cpu_physical_memory_unmap(vq->ring, virtio_queue_get_ring_size(vdev, idx),
                              0, virtio_queue_get_ring_size(vdev, idx));
    cpu_physical_memory_unmap(vq->used, virtio_queue_get_used_size(vdev, idx),
                              1, virtio_queue_get_used_size(vdev, idx));
    cpu_physical_memory_unmap(vq->avail, virtio_queue_get_avail_size(vdev, idx),
                              0, virtio_queue_get_avail_size(vdev, idx));
    cpu_physical_memory_unmap(vq->desc, virtio_queue_get_desc_size(vdev, idx),
                              0, virtio_queue_get_desc_size(vdev, idx));
}
int main (int argc, char *argv[])
{
    void *handle = dlopen(argv[1], RTLD_LAZY);
    if (!handle)
    {
        fprintf(stderr, " Failed to load: %s because: %s\n", argv[1], dlerror());
        fflush(stderr);
        exit(RES_LOAD_FAILED);
    }

    while(!AfterAttach2())
    {
        sleep(1);
    }

    handle = dlopen(argv[2], RTLD_LAZY);
    if (!handle)
    {
        fprintf(stderr, " Failed to load: %s because: %s\n", argv[1], dlerror());
        fflush(stderr);
        exit(RES_LOAD_FAILED);
    }

    while(1)
    {
        // expected to be stopped by tool.
        sleep(1);
    }

    return RES_SUCCESS;
}