コード例 #1
0
ファイル: misc.c プロジェクト: axelmuhr/Helios-NG
void cc_fatalerr_l(int32 n, char *errorcode, va_list a)
{
    announce(misc_message_fatal, n);
    superrprintf(errorcode, a);
    errprintf(misc_message_abandoned);
    if (syserr_behaviour)
    {   show_store_use();
        syserr(syserr_syserr);  /* rethink this msg if syserrs lack strings */
    }
    compile_abort(-1);  /* (-1) is not a signal number used by signal() */
}
コード例 #2
0
ファイル: timefunc.c プロジェクト: tjyang/cpam
static int minutes(char *p)
{
	/* Converts string HHMM to number indicating minutes since midnight (0-1440) */
	if (isdigit((int)*(p+0)) && isdigit((int)*(p+1)) && isdigit((int)*(p+2)) && isdigit((int)*(p+3))) {
		return (10*(*(p+0)-'0')+(*(p+1)-'0'))*60 + (10*(*(p+2)-'0')+(*(p+3)-'0'));
	}
	else {
		errprintf("Invalid timespec - expected 4 digits, got: '%s'\n", p);
		return 0;
	}
}
コード例 #3
0
ファイル: io_matlab.c プロジェクト: ihrke/libeegtools
double get_double_from_struct_field( matvar_t *eeg, const char *name, int struct_array_index ){
  matvar_t *tmp; 

  tmp = Mat_VarGetStructField( eeg, (char*)name, BY_NAME, struct_array_index );
  if( tmp->rank != 1 && tmp->dims[0]<1 ){
	 errprintf("field '%s' wrong, rank=%i,tmp->dims[0]=%i\n",name, tmp->rank,tmp->dims[0] );
	 return -1;
  }  
  dprintf( "found: %s=%f\n", name, (((double*)tmp->data)[0]) );
  return (((double*)tmp->data)[0]);
}
コード例 #4
0
ファイル: lyutils.c プロジェクト: Masacs/coursework
void scanner_userinit (void) {
   if (basefilename == NULL)
      errprintf ("%s: %s: %s: %s: %s\n", get_execname(), "Error",
                 "lyutils.c", "scanner_userinit()",
                 "null file pointer");
   char *tokname = malloc (strlen (basefilename) + strlen (".tok") + 1);
   xstrcpy (tokname, basefilename);
   xstrcat (tokname, ".tok");
   tokfile = fopen (tokname, "w+");
   free (tokname);
}
コード例 #5
0
ファイル: strdico.c プロジェクト: DieterBaum/qt-fasarchiver
int strdico_set_valid_keys(cstrdico *d, const char *keys)
{
    assert(d);
    
    if ((d->validkeys=strdup(keys))==NULL)
    {   errprintf("strdup() failed: out of memory\n");
        return FSAERR_ENOMEM;
    }
    
    return FSAERR_SUCCESS;
}
コード例 #6
0
ファイル: regmulti.c プロジェクト: Rudlandh/qt-fasarchiver
int regmulti_init(cregmulti *m, u32 maxblksize)
{
    if (!m)
    {   errprintf("invalid param\n");
        return -1;
    }
    
    m->maxitems=FSA_MAX_SMALLFILECOUNT;
    m->maxblksize=min(maxblksize, FSA_MAX_BLKSIZE);
    return regmulti_empty(m);
}
コード例 #7
0
ファイル: archwriter.c プロジェクト: necrose99/qt4-fsarchiver
int archwriter_write_buffer(carchwriter *ai, struct s_writebuf *wb)
{
    struct statvfs64 statvfsbuf;
    char textbuf[128];
    long lres;
    
    assert(ai);
    assert(wb);

    if (wb->size == 0)
    {   errprintf("wb->size=%ld\n", (long)wb->size);
        return -1;
    }

    if ((lres=write(ai->archfd, (char*)wb->data, (long)wb->size))!=(long)wb->size)
    {
        errprintf("write(size=%ld) returned %ld\n", (long)wb->size, (long)lres);
        if ((lres>0) && (lres < (long)wb->size)) // probably "no space left"
        {
            if (fstatvfs64(ai->archfd, &statvfsbuf)!=0)
            {   sysprintf("fstatvfs(fd=%d) failed\n", ai->archfd);
                return -1;
            }
            
            u64 freebytes = statvfsbuf.f_bfree * statvfsbuf.f_bsize;
            errprintf("Can't write to the archive file. Space on device is %s. \n"
                "If the archive is being written to a FAT filesystem, you may have reached \n"
                "the maximum filesize that it can handle (in general 2 GB)\n", 
                format_size(freebytes, textbuf, sizeof(textbuf), 'h'));
             werte_uebergeben (109,4);     
            return -1;
        }
        else // another error
        {
            sysprintf("write(size=%ld) failed\n", (long)wb->size);
            return -1;
        }
    }
    
    return 0;
}
コード例 #8
0
ファイル: pxtop.c プロジェクト: ststeiger/ghostsvg
/* Report any errors after running a job */
static int   /* ret 0 ok, else -ve error code */
pxl_impl_report_errors(
	pl_interp_instance_t *instance,         /* interp instance to wrap up job in */
   int                  code,              /* prev termination status */
   long                 file_position,     /* file position of error, -1 if unknown */
   bool                 force_to_cout      /* force errors to cout */
)
{
	pxl_interp_instance_t *pxli = (pxl_interp_instance_t *)instance;
	px_parser_state_t *st = pxli->st;
	px_state_t *pxs = pxli->pxs;
	int report = pxs->error_report;
	const char *subsystem =
	  (code <= px_error_next ? "KERNEL" : "GRAPHICS");
	char message[px_max_error_line+1];
	int N = 0;
	int y;

	if (code >= 0)
	  return code;  /* not really an error */
	if ( report & eErrorPage )
	  y = px_begin_error_page(pxs);
	while ( (N = px_error_message_line(message, N, subsystem,
	   code, st, pxs)) >= 0
	)
	  { if ( (report & eBackChannel) || force_to_cout )
	      errprintf(pxli->memory, message);
	    if ( report & eErrorPage )
	      y = px_error_page_show(message, y, pxs);
	  }
	if ( ((report & pxeErrorReport_next) && file_position != -1L) || force_to_cout )
	  errprintf(pxli->memory, "file position of error = %ld\n", file_position);
	if ( report & eErrorPage )
	  { px_args_t args;
	    args.pv[0] = 0;
	    pxEndPage(&args, pxs);
	  }
	px_reset_errors(pxs);

	return code;
}
コード例 #9
0
char *xstrdup(const char *s)
{
	char *result;

	if (s == NULL) {
		errprintf("xstrdup: Cannot dup NULL string\n");
		abort();
	}

	result = strdup(s);
	if (result == NULL) {
		errprintf("xstrdup: Out of memory\n");
		abort();
	}

#ifdef MEMORY_DEBUG
	add_to_memlist(result, strlen(result)+1);
#endif

	return result;
}
コード例 #10
0
ファイル: environ.c プロジェクト: tjyang/abmon
void loadenv(char *envfile, char *area)
{
	FILE *fd;
	strbuffer_t *inbuf;
	char *p, *oneenv;
	int n;

	MEMDEFINE(l);
	inbuf = newstrbuffer(0);

	fd = stackfopen(envfile, "r", NULL);
	if (fd) {
		while (stackfgets(inbuf, NULL)) {
			sanitize_input(inbuf, 1, 1);

			if (STRBUFLEN(inbuf) && strchr(STRBUF(inbuf), '=')) {
				/*
				 * Do the environment "area" stuff: If the input
				 * is of the form AREA/NAME=VALUE, then setup the variable
				 * only if we're called with the correct AREA setting.
				 */
				oneenv = NULL;

				p = STRBUF(inbuf) + strcspn(STRBUF(inbuf), "=/");
				if (*p == '/') {
					if (area) {
						*p = '\0';
						if (strcasecmp(STRBUF(inbuf), area) == 0) oneenv = strdup(expand_env(p+1));
					}
				}
				else oneenv = strdup(expand_env(STRBUF(inbuf)));

				if (oneenv) {
					p = strchr(oneenv, '=');
					if (*(p+1) == '"') {
						/* Move string over the first '"' */
						memmove(p+1, p+2, strlen(p+2)+1);
						/* Kill a trailing '"' */
						if (*(oneenv + strlen(oneenv) - 1) == '"') *(oneenv + strlen(oneenv) - 1) = '\0';
					}
					n = putenv(oneenv);
				}
			}
		}
		stackfclose(fd);
	}
	else {
		errprintf("Cannot open env file %s - %s\n", envfile, strerror(errno));
	}

	freestrbuffer(inbuf);
	MEMUNDEFINE(l);
}
コード例 #11
0
ファイル: filesys.c プロジェクト: Rudlandh/fsarchiver
int generic_umount(char *mntbuf)
{
    int res=0;
    int i;

    if (!mntbuf)
    {   errprintf("invalid param: mntbuf is null\n");
        return -1;
    }

    msgprintf(MSG_DEBUG1, "generic_umount(%s)\n", mntbuf);
    for (i=0, errno=0 ; (i < 4) && (res=umount2(mntbuf, 0)!=0) && (errno==EBUSY) ; i++)
    {   sync();
        sleep(i+1);
    }

    if (res!=0)
        errprintf("Failed to umount device %s after %d attempts\n", mntbuf, (int)i);

    return res;
}
コード例 #12
0
ファイル: wireless.c プロジェクト: peterlintang/apue
void readwirelessmod(char *path)
{
	int fd;
	char buf[1024];
	char *wsmode;
	char *bridgename=NULL;
	char *bridge_A=NULL;
	char *bridge_B=NULL;

	memset(buf, 0, 1024);
	if ((fd = open(path, O_RDONLY)) < 0)
	{
		errprintf("open %s error\n", path);
		exit(1);
	}
	if (read(fd, buf, 1024) < 0)
	{
		errprintf("read %s error\n", path);
		exit(1);
	}
}
コード例 #13
0
ファイル: rrdcachectl.c プロジェクト: Kotty666/xymon
static int call_svc(char *buf)
{
	int n, bytesleft;
	fd_set fds;
	struct timeval tmo;
	char *bufp;

	/* First, send the request */
	bufp = buf;
	bytesleft = strlen(buf)+1;
	do {
		FD_ZERO(&fds);
		FD_SET(ctlsocket, &fds);
		tmo.tv_sec = 5;
		tmo.tv_usec = 0;
		n = select(ctlsocket+1, NULL, &fds, NULL, &tmo);

		if (n == 0) {
			errprintf("Send failed: Timeout\n");
			return -1;
		}
		else if (n == -1) {
			errprintf("Send failed: %s\n", strerror(errno));
			return -1;
		}

		n = send(ctlsocket, bufp, bytesleft, 0);
		if (n == -1) {
			errprintf("Send failed: %s\n", strerror(errno));
			return -1;
		}
		else {
			bytesleft -= n;
			bufp += n;
		}
	} while (bytesleft > 0);

	errprintf("Request sent\n");
	return 0;
}
コード例 #14
0
ファイル: archwriter.c プロジェクト: necrose99/qt4-fsarchiver
int archwriter_write_volheader(carchwriter *ai)
{
    struct s_writebuf *wb=NULL;
    cdico *voldico;
    
    assert(ai);
    
    if ((wb=writebuf_alloc())==NULL)
    {   msgprintf(MSG_STACK, "writebuf_alloc() failed\n");
        return -1;
    }
    
    if ((voldico=dico_alloc())==NULL)
    {   msgprintf(MSG_STACK, "voldico=dico_alloc() failed\n");
        return -1;
    }
    
    // prepare header
    dico_add_u32(voldico, 0, VOLUMEHEADKEY_VOLNUM, ai->curvol);
    dico_add_u32(voldico, 0, VOLUMEHEADKEY_ARCHID, ai->archid);
    dico_add_string(voldico, 0, VOLUMEHEADKEY_FILEFORMATVER, FSA_FILEFORMAT);
    dico_add_string(voldico, 0, VOLUMEHEADKEY_PROGVERCREAT, FSA_VERSION);
    
    // write header to buffer
    if (writebuf_add_header(wb, voldico, FSA_MAGIC_VOLH, ai->archid, FSA_FILESYSID_NULL)!=0)
    {   errprintf("archio_write_header() failed\n");
        return -1;
    }
    
    // write header to file
    if (archwriter_write_buffer(ai, wb)!=0)
    {   errprintf("archwriter_write_buffer() failed\n");
        return -1;
    }
    
    dico_destroy(voldico);
    writebuf_destroy(wb);
    
    return 0;
}
コード例 #15
0
ファイル: loadhosts.c プロジェクト: tjyang/abmon
static void build_hosttree(void)
{
	static int hosttree_exists = 0;
	namelist_t *walk;
	RbtStatus status;
	char *tstr;

	if (hosttree_exists) {
		rbtDelete(rbhosts);
		rbtDelete(rbclients);
	}
	rbhosts = rbtNew(name_compare);
	rbclients = rbtNew(name_compare);
	hosttree_exists = 1;

	for (walk = namehead; (walk); walk = walk->next) {
		status = rbtInsert(rbhosts, walk->bbhostname, walk);
		if (walk->clientname) rbtInsert(rbclients, walk->clientname, walk);

		switch (status) {
		  case RBT_STATUS_OK:
		  case RBT_STATUS_DUPLICATE_KEY:
			break;
		  case RBT_STATUS_MEM_EXHAUSTED:
			errprintf("loadhosts:build_hosttree - insert into tree failed (out of memory)\n");
			break;
		  default:
			errprintf("loadhosts:build_hosttree - insert into tree failed code %d\n", status);
			break;
		}

		tstr = bbh_item(walk, BBH_NOTBEFORE);
		walk->notbefore = (tstr ? timestr2timet(tstr) : 0);
		if (walk->notbefore == -1) walk->notbefore = 0;

		tstr = bbh_item(walk, BBH_NOTAFTER);
		walk->notafter = (tstr ? timestr2timet(tstr) : INT_MAX);
		if (walk->notafter == -1) walk->notafter = INT_MAX;
	}
}
コード例 #16
0
int main(int argc, char *argv[])
{ 
	FILE *bbhosts;
	char *fn = NULL;
	strbuffer_t *inbuf;
	int argi;
	char *include2 = NULL;


	for (argi=1; (argi < argc); argi++) {
		if (strcmp(argv[argi], "--version") == 0) {
			printf("bbhostshow version %s\n", VERSION);
			exit(0);
		}
		else if (strcmp(argv[argi], "--help") == 0) {
			printf("Usage:\n%s [filename]\n", argv[0]);
			exit(0);
		}
		else if (strcmp(argv[argi], "--bbnet") == 0) {
			include2 = "netinclude";
		}
		else if (strcmp(argv[argi], "--bbdisp") == 0) {
			include2 = "dispinclude";
		}
		else if (*argv[argi] != '-') {
			fn = strdup(argv[argi]);
		}
	}

	if (!fn || (strlen(fn) == 0)) {
		fn = getenv("BBHOSTS");
		if (!fn) {
			errprintf("Environment variable BBHOSTS is not set - aborting\n");
			exit(2);
		}
	}

	bbhosts = stackfopen(fn, "r", NULL);
	if (bbhosts == NULL) {
		printf("Cannot open the BBHOSTS file '%s'\n", fn);
		exit(1);
	}

	inbuf = newstrbuffer(0);
	while (stackfgets(inbuf, include2)) {
		printf("%s", STRBUF(inbuf));
	}

	stackfclose(bbhosts);
	freestrbuffer(inbuf);
	return 0;
}
コード例 #17
0
ファイル: build.c プロジェクト: rosrad/go-rep
// copy copies the file src to dst, via memory (so only good for small files).
static void
copy(char *dst, char *src, int exec)
{
	Buf b;

	if(vflag > 1)
		errprintf("cp %s %s\n", src, dst);

	binit(&b);
	readfile(&b, src);
	writefile(&b, dst, exec);
	bfree(&b);
}
コード例 #18
0
ファイル: cgi.c プロジェクト: Kotty666/xymon
int cgi_refererok(char *expected)
{
	static char cgi_checkstr[1024];
	int isok = 0;
	char *p, *httphost;

	p = getenv("HTTP_REFERER");
	dbgprintf(" - checking if referer is OK (http_referer: %s, http_host: %s, xymonwebhost: %s, checkstr: %s\n", textornull(p), textornull(getenv("HTTP_HOST")),  textornull(xgetenv("XYMONWEBHOST")), textornull(expected));
	if (!p) return 0;

	/* If passed NULL, just check that there _is_ a REFERER */
	if (!expected) return 1;

	httphost = getenv("HTTP_HOST");
	if (!httphost) {
		if (strcmp(xgetenv("XYMONWEBHOST"), "http://localhost") != 0) {
			/* If XYMONWEBHOST is set by the admin, use that */
			snprintf(cgi_checkstr, sizeof(cgi_checkstr), "%s%s", getenv("XYMONWEBHOST"), expected);
			if (strncmp(p, cgi_checkstr, strlen(cgi_checkstr)) == 0) isok = 1;
		}
		else {
			errprintf("Disallowed request due to missing HTTP_HOST variable\n");
			return 0;
		}
	}
	else {
		/* skip the protocol specifier, which HTTP_REFERER has but HTTP_HOST doesn't */
		p += (strncasecmp(p, "https://", 8) == 0) ? 8 : (strncasecmp(p, "http://", 7) == 0) ? 7 : 0;

		if (*p == '\0') { errprintf("Disallowed request due to unexpected referer '%s'\n", getenv("HTTP_REFERER")); return 0; }

		snprintf(cgi_checkstr, sizeof(cgi_checkstr), "%s%s", httphost, expected);
		if (strncmp(p, cgi_checkstr, strlen(cgi_checkstr)) == 0) isok = 1;
	}
	
	if (!isok) errprintf("Disallowed request due to unexpected referer '%s', wanted '%s' (originally '%s')\n", p, cgi_checkstr, expected);

	return isok;
}
コード例 #19
0
ファイル: threadfork.c プロジェクト: peterlintang/apue
int 
main(int argc, char *argv[])
{
	int		err;
	pid_t		pid;
	pthread_t	tid;

	#if defined(BSD) || defined(MACOS)
		printf("pthreaqd_atfork is unsupported\n");
	#else
		if ((err = pthread_atfork(prepare, parent, child)) !=0)
		{
			errprintf("pthread_atfork error\n");
			exit(1);
		}
		err = pthread_create(&tid, NULL, thr_fn, 0);
		if (err != 0)
		{
			errprintf("can't create thread\n");
			exit(1);
		}
		sleep(2);
		printf("parent about to fork...\n");
		if ((pid = fork()) < 0)
		{
			errprintf("fork error\n");
			exit(1);
		}
		else if (pid == 0)
		{
			printf("child returned from fork\n");
		}
		else
		{
			printf("parent returned from fork\n");
		}
	#endif
	exit(0);
}
コード例 #20
0
ファイル: strfunc.c プロジェクト: tjyang/cpam
void strbufferuse(strbuffer_t *buf, int bytes)
{
	if (buf == NULL) return;

	if ((buf->used + bytes) < buf->sz) {
		buf->used += bytes;
	}
	else {
		errprintf("strbuffer: Attempt to use more than allocated (sz=%d, used=%d, growbytes=%d\n", 
			  buf->sz, buf->used, bytes);
	}
	*(buf->s+buf->used) = '\0';
}
コード例 #21
0
ファイル: archwriter.c プロジェクト: necrose99/qt4-fsarchiver
int archwriter_write_volfooter(carchwriter *ai, bool lastvol)
{
    struct s_writebuf *wb=NULL;
    cdico *voldico;
    
    assert(ai);
    
    if ((wb=writebuf_alloc())==NULL)
    {   errprintf("writebuf_alloc() failed\n");
        return -1;
    }
    
    if ((voldico=dico_alloc())==NULL)
    {   errprintf("voldico=dico_alloc() failed\n");
        return -1;
    }
    
    // prepare header
    dico_add_u32(voldico, 0, VOLUMEFOOTKEY_VOLNUM, ai->curvol);
    dico_add_u32(voldico, 0, VOLUMEFOOTKEY_ARCHID, ai->archid);
    dico_add_u32(voldico, 0, VOLUMEFOOTKEY_LASTVOL, lastvol);
    
    // write header to buffer
    if (writebuf_add_header(wb, voldico, FSA_MAGIC_VOLF, ai->archid, FSA_FILESYSID_NULL)!=0)
    {   msgprintf(MSG_STACK, "archio_write_header() failed\n");
        return -1;
    }
    
    // write header to file
    if (archwriter_write_buffer(ai, wb)!=0)
    {   msgprintf(MSG_STACK, "archwriter_write_data(size=%ld) failed\n", (long)wb->size);
        return -1;
    }
    
    dico_destroy(voldico);
    writebuf_destroy(wb);
    
    return 0;
}
コード例 #22
0
ファイル: regmulti.c プロジェクト: Rudlandh/qt-fasarchiver
bool regmulti_save_enough_space_for_new_file(cregmulti *m, u32 filesize)
{
    if (!m)
    {   errprintf("invalid param\n");
        return false;
    }
    
    if (m->count >= m->maxitems)
        return false;
    if (m->usedsize + filesize > m->maxblksize)
        return false;
    return true;
}
コード例 #23
0
ファイル: distances.c プロジェクト: ihrke/libeegtools
/** build a distance matrix D from data X which consists of n observations with
	 p features each. 
	 Observations are compared using f.
	 \param f distance function
	 \param X data (nxp)
	 \param D output matrix or NULL -> own memory allocation
	 \param progress NULL or a progressbar
	 \param optargs may contain arguments for the vectordistancefunction f
	 - <tt>progress=void*</tt> progress-bar function, called every now and then.
	 \return the distance matrix between all columns in X
 */
Array* matrix_distmatrix( VectorDistanceFunction f, 
								  const Array *X, Array *D, 
								  OptArgList *optargs ){
  int i,j;
  int idx;
  int N,p;
  void *ptr;
  ProgressBarFunction progress=NULL; 
  if( optarglist_has_key( optargs, "progress" ) ){
	 ptr = optarglist_ptr_by_key( optargs, "progress" );
	 if( ptr ) progress = (ProgressBarFunction)ptr;
  }
  
  bool ismatrix;
  matrix_CHECK( ismatrix, X );
  if( !ismatrix ) return NULL;
  N = X->size[0];
  p = X->size[1];
  if( D==ALLOC_IN_FCT ){
	 D = array_new2( DOUBLE, 2, N, N );
  } else {
	 matrix_CHECK( ismatrix, D );
	 if( !ismatrix ) return NULL;
	 if( D->size[0]<N || D->size[1]<N ){
		errprintf("Matrix not large enough, need %i x %i, have %i x %i\n",
					 N, N, D->size[0], D->size[1] );
	 }
  }

  if( progress ){
	 progress( PROGRESSBAR_INIT, N*(N-1)/2 );
  }
  
  idx=1;
  for( i=0; i<N; i++ ){
	 for( j=i+1; j<N; j++ ){
		if( progress ){
		  progress( PROGRESSBAR_CONTINUE_LONG, idx );
		}
		mat_IDX( D, i, j) = f( (double*)array_INDEXMEM2(X, i, 0), 
									  (double*)array_INDEXMEM2(X, j, 0), p, optargs );
		mat_IDX(D, j,i) = mat_IDX( D, i,j);
		idx++;
	 }
  }
  if( progress ){
	 progress( PROGRESSBAR_FINISH, 0 );
  }

  return D;
}
コード例 #24
0
ファイル: dnstalk.c プロジェクト: gvsurenderreddy/xymon-2
void dns_lookup(myconn_t *rec)
{
	/* Push a normal DNS lookup into the DNS queue */

	time_t updtime = 0;
	char *res = NULL;

	dbgprintf("dns_lookup(): Lookup %s, family %d\n", rec->netparams.lookupstring, rec->netparams.af_index-1);

	if (xymon_sqldb_dns_lookup_search(dns_lookup_sequence[rec->netparams.af_index], rec->netparams.lookupstring, &updtime, &res) != 0) {
		rec->netparams.lookupstatus = LOOKUP_FAILED;
		return;
	}

	if (!rec->netparams.lookupstring || (strlen(rec->netparams.lookupstring) == 0)) {
		errprintf("Invalid DNS lookup - string is %s\n", (rec->netparams.lookupstring ? "empty" : "null"));
		rec->netparams.lookupstatus = LOOKUP_FAILED;
		return;
	}
	
	if (!res) {
		/* No cache record, create one */
		xymon_sqldb_dns_lookup_create(dns_lookup_sequence[rec->netparams.af_index], rec->netparams.lookupstring);
	}
	else if (res && ((time(NULL) - updtime) < 3600)) {
		/* We have a valid cache-record */
		if ((strcmp(res, "-") != 0)) {
			/* Successfully resolved from cache */
			dns_return_lookupdata(rec, res);
		}
		else {
			/* Continue with next address family */
			rec->netparams.af_index++;
			rec->netparams.lookupstatus = LOOKUP_NEEDED;
		}
	}

	xymon_sqldb_dns_lookup_finish();

	/* Cache data missing or invalid, do the DNS lookup */
	if (rec->netparams.af_index == 0) getntimer(&rec->netparams.lookupstart);

	rec->netparams.lookupstatus = LOOKUP_ACTIVE;
	/*
	 * Must increment af_index before calling ares_gethostbyname(), since the callback may be triggered
	 * immediately (e.g. if the hostname is listed in /etc/hosts)
	 */
	rec->netparams.af_index++;
	/* Use ares_search() here, we want to use the whole shebang of name lookup options */
	ares_gethostbyname(dns_lookupchannel, rec->netparams.lookupstring, dns_lookup_sequence[rec->netparams.af_index-1], dns_lookup_callback, rec);
}
コード例 #25
0
char *xstrncat(char *dest, const char *src, size_t maxlen)
{
	if (src == NULL) {
		errprintf("xstrncat: NULL destination\n");
		abort();
	}

	if (dest == NULL) {
		errprintf("xstrncat: NULL destination\n");
		abort();
	}

#ifdef MEMORY_DEBUG
	dmem = find_in_memlist(dest);
	if (dmem == NULL) {
		errprintf("xstrncat: Bogus destination\n");
		abort();
	}

	allocend = dmem->sdata + dmem->ssize - 1;
	if (strlen(src) <= maxlen)
		copyend = dest + strlen(dest) + strlen(src);
	else
		copyend = dest + strlen(dest) + maxlen;

	if ((void *)copyend > (void *)allocend) {
		errprintf("xstrncat: Potential overwrite of %d bytes\n", (copyend - allocend));
		abort();
	}

	if (strlen(dest) + strlen(src) >= maxlen) {
		errprintf("xstrncat: destination is not NULL terminated - dst '%s', src '%s', max %d\n", dest, src, maxlen);
	}
#endif

	strncat(dest, src, maxlen);
	return dest;
}
コード例 #26
0
ファイル: regmulti.c プロジェクト: Rudlandh/qt-fasarchiver
int regmulti_save_addfile(cregmulti *m, cdico *header, char *data, u32 datsize)
{
    if (!m)
    {   errprintf("invalid param\n");
        return -1;
    }

    if (m->count >= m->maxitems)
    {   errprintf("regmulti is full: it contains %ld items\n", (long)m->count);
        return -1;
    }

    if (m->usedsize+datsize > m->maxblksize)
    {   errprintf("block is too small to store that new sub-block of data\n");
        return -1;
    }
    
    m->objhead[m->count]=header;
    memcpy(m->data+m->usedsize, data, datsize);
    m->usedsize+=datsize;
    m->count++;
    return 0;
}
コード例 #27
0
ファイル: tomltk.c プロジェクト: trws/flux-core
/* Given an error message response from toml_parse(), parse the
 * error message into line number and message, e.g.
 *   "line 42: bad key"
 * is parsed to:
 *   error->lineno=42, error->errbuf="bad key"
 */
static void errfromtoml (struct tomltk_error *error,
                         const char *filename, char *errstr)
{
    if (error) {
        char *msg = errstr;
        int lineno = -1;
        if (!strncmp (errstr, "line ", 5)) {
            lineno = strtoul (errstr + 5, &msg, 10);
            if (!strncmp (msg, ": ", 2))
                msg += 2;
        }
        return errprintf (error, filename, lineno, "%s", msg);
    }
}
コード例 #28
0
ファイル: io_matlab.c プロジェクト: ihrke/libeegtools
/** \brief write EEG-struct to EEGlab-compatible MATLAB file.

	 This write uses MatIO to create an EEGlab file.
	 It was developed with EEGlab version 6.01b.
	 
	 \todo NOT IMPLEMENTED!

	 \param eeg the struct
	 \param file eeglab .set file
	 \return error code
*/
int write_eeglab_file( EEG* eeg, const char *file ){
  mat_t *mfile;
  matvar_t *meeg=NULL;
  if( !(mfile=Mat_Create( file, NULL )) ){
	 errprintf("Could not open '%s' for writing\n", file);
	 return -1;
  }

  //int dims[2]={1,1}, rank=2;
  //meeg = Mat_VarCreate( "EEG", MAT_T_STRUCT, , rank, dims, NULL, 0 );
  
  Mat_VarWrite( mfile, meeg, 0 );
  return 0;
}
コード例 #29
0
ファイル: rrdcachectl.c プロジェクト: Kotty666/xymon
int init_svc(char *sockfn)
{
	ctlsocket = socket(AF_UNIX, SOCK_DGRAM, 0);
	if (ctlsocket == -1) {
		errprintf("Cannot get socket: %s\n", strerror(errno));
		return -1;
	}

	memset(&myaddr, 0, sizeof(myaddr));
	myaddr.sun_family = AF_UNIX;
	sprintf(myaddr.sun_path, "%s/%s", xgetenv("XYMONTMP"), sockfn);
	myaddrsz = sizeof(myaddr);

	if (connect(ctlsocket, (struct sockaddr *)&myaddr, myaddrsz) == -1) {
		errprintf("Cannot set target address: %s (%s)\n", sockfn, strerror(errno));
		close(ctlsocket);
		ctlsocket = -1;
		return -1;
	}

	fcntl(ctlsocket, F_SETFL, O_NONBLOCK);
	return 0;
}
コード例 #30
0
ファイル: dnstalk.c プロジェクト: gvsurenderreddy/xymon-2
void dns_library_init(void)
{
	int status;

	status = ares_library_init(ARES_LIB_INIT_ALL);
	if (status != ARES_SUCCESS) {
		errprintf("Cannot initialize ARES library: %s\n", ares_strerror(status));
		return;
	}
	
	dns_atype= dns_name_type("A");
	dns_aaaatype= dns_name_type("AAAA");
	dns_aclass = dns_name_class("IN");
}