Exemple #1
1
bool initlogging(const char *identity, int facility_, int consolethres, int filethres, int syslogthres, bool logtimestamp)
{
    facility = facility_ & 7;
    timestamp = logtimestamp;
    if(consolethres >= 0) consolethreshold = min(consolethres, (int)ACLOG_NUM);
    if(filethres >= 0) filethreshold = min(filethres, (int)ACLOG_NUM);
    if(syslogthres >= 0) syslogthreshold = min(syslogthres, (int)ACLOG_NUM);
    if(ident != identity)
        copystring(ident, identity);
    formatstring(ident_full)("ACR[%s]", identity);
    if(syslogthreshold < ACLOG_NUM)
    {
#ifdef AC_USE_SYSLOG
        openlog(ident_full, LOG_NDELAY, facilities[facility]);
#else
        if((logsock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM)) == ENET_SOCKET_NULL || enet_address_set_host(&logdest, "localhost") < 0) syslogthreshold = ACLOG_NUM;
#endif
    }
    static int lognum = 0;
    formatstring(filepath)("serverlog_%s_%s.part%d.txt", timestring(true), identity, ++lognum);
    if(fp) { fclose(fp); fp = NULL; }
    if(filethreshold < ACLOG_NUM)
    {
        fp = fopen(filepath, "w");
        if(!fp) printf("failed to open \"%s\" for writing\n", filepath);
    }
    defformatstring(msg)("logging started: console(%s), file(%s", levelname[consolethreshold], levelname[fp ? filethreshold : ACLOG_NUM]);
    if(fp) concatformatstring(msg, ", \"%s\"", filepath);
    concatformatstring(msg, "), syslog(%s", levelname[syslogthreshold]);
    if(syslogthreshold < ACLOG_NUM) concatformatstring(msg, ", \"%s\", local%d", ident_full, facility);
    concatformatstring(msg, "), timestamp(%s)", timestamp ? "ENABLED" : "DISABLED");
    enabled = consolethreshold < ACLOG_NUM || fp || syslogthreshold < ACLOG_NUM;
    if(enabled) printf("%s\n", msg);
    return enabled;
}
Exemple #2
0
static void list_file_entry(struct file_struct *f)
{
	char perms[11];

	if (!f->basename) {
		/* this can happen if duplicate names were removed */
		return;
	}

	permstring(perms, f->mode);

#ifdef SUPPORT_LINKS
	if (preserve_links && S_ISLNK(f->mode)) {
		rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
			perms,
			(double)f->length, timestring(f->modtime),
			safe_fname(f_name(f)), safe_fname(f->u.link));
	} else
#endif
	{
		rprintf(FINFO, "%s %11.0f %s %s\n",
			perms,
			(double)f->length, timestring(f->modtime),
			safe_fname(f_name(f)));
	}
}
Exemple #3
0
void
sigcb_check ()
{
  if (sigdocheck) {
    char buf[64];
    while (read (sigpipes[0], buf, sizeof (buf)) > 0)
      ;
    sigdocheck = 0;
    for (int i = 1; i < nsig; i++)
      if (sigcaught[i]) {
	sigcaught[i] = 0;
	if (cbv::ptr cb = sighandler[i]) {
#ifdef WRAP_DEBUG
	  if ((callback_trace & CBTR_SIG) && i != SIGCHLD) {
# ifdef NEED_SYS_SIGNAME_DECL
	    warn ("CALLBACK_TRACE: %ssignal %d %s <- %s\n",
		  timestring (), i, cb->dest, cb->line);
# else /* !NEED_SYS_SIGNAME_DECL */
	    warn ("CALLBACK_TRACE: %sSIG%s %s <- %s\n", timestring (),
		  sys_signame[i], cb->dest, cb->line);
# endif /* !NEED_SYS_SIGNAME_DECL */
	  }
#endif /* WRAP_DEBUG */
	  STOP_ACHECK_TIMER ();
	  sfs_leave_sel_loop ();
	  (*cb) ();
	  START_ACHECK_TIMER ();
	}
      }
  }
}
Exemple #4
0
/*
  Properties:
  UserInfo.AccountName
  UserInfo.FullName
  UserInfo.Description
  UserInfo.HomeDirectory
  UserInfo.HomeDrive
  UserInfo.Comment
  UserInfo.LogonScript
  UserInfo.AcctExpiry
  UserInfo.AllowPasswordChange
  UserInfo.ForcePasswordChange
 */
struct MprVar mprCreateUserInfo(TALLOC_CTX *mem_ctx, struct libnet_UserInfo *info)
{
	const char *name = "UserInfo";
	NTSTATUS status;
	struct MprVar mprUserInfo;
	struct MprVar mprAccountName, mprFullName, mprDescription;
	struct MprVar mprHomeDir, mprHomeDrive, mprComment;
	struct MprVar mprLogonScript;
	struct MprVar mprAcctExpiry, mprAllowPassChange, mprForcePassChange;

	if (info == NULL || mem_ctx == NULL) {
		mprUserInfo = mprCreateNullVar();
		goto done;
	}

	mprUserInfo = mprObject(name);

	mprAccountName = mprString(info->out.account_name);
	mprFullName = mprString(info->out.full_name);
	mprDescription = mprString(info->out.description);
	mprHomeDir = mprString(info->out.home_directory);
	mprHomeDrive = mprString(info->out.home_drive);
	mprComment = mprString(info->out.comment);
	mprLogonScript = mprString(info->out.logon_script);
	mprAcctExpiry = mprString(timestring(mem_ctx, info->out.acct_expiry->tv_sec));
	mprAllowPassChange = mprString(timestring(mem_ctx, info->out.allow_password_change->tv_sec));
	mprForcePassChange = mprString(timestring(mem_ctx, info->out.force_password_change->tv_sec));

	status = mprSetVar(&mprUserInfo, "AccountName", mprAccountName);
	if (!NT_STATUS_IS_OK(status)) goto done;
	status = mprSetVar(&mprUserInfo, "FullName", mprFullName);
	if (!NT_STATUS_IS_OK(status)) goto done;
	status = mprSetVar(&mprUserInfo, "Description", mprDescription);
	if (!NT_STATUS_IS_OK(status)) goto done;
	status = mprSetVar(&mprUserInfo, "HomeDirectory", mprHomeDir);
	if (!NT_STATUS_IS_OK(status)) goto done;
	status = mprSetVar(&mprUserInfo, "HomeDrive", mprHomeDrive);
	if (!NT_STATUS_IS_OK(status)) goto done;
	status = mprSetVar(&mprUserInfo, "Comment", mprComment);
	if (!NT_STATUS_IS_OK(status)) goto done;
	status = mprSetVar(&mprUserInfo, "LogonScript", mprLogonScript);
	if (!NT_STATUS_IS_OK(status)) goto done;
	status = mprSetVar(&mprUserInfo, "AcctExpiry", mprAcctExpiry);
	if (!NT_STATUS_IS_OK(status)) goto done;
	status = mprSetVar(&mprUserInfo, "AllowPasswordChange", mprAllowPassChange);
	if (!NT_STATUS_IS_OK(status)) goto done;
	status = mprSetVar(&mprUserInfo, "ForcePasswordChange", mprForcePassChange);
	if (!NT_STATUS_IS_OK(status)) goto done;

done:
	return mprUserInfo;
}
Exemple #5
0
void Log_info_client(client_t *client, const char *logstring, ...)
{
	va_list argp;
	char buf[STRSIZE + 1];
	int offset = 0;
	
	if (termprint || logfile)
		offset = sprintf(buf, "INFO: ");

	va_start(argp, logstring);
	offset += vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp);
	va_end(argp);
	
	offset += snprintf(&buf[offset], STRSIZE - offset, " - [%d] %s@%s:%d",
					   client->sessionId,
					   client->username == NULL ? "" : client->username,
					   inet_ntoa(client->remote_tcp.sin_addr),
					   ntohs(client->remote_tcp.sin_port));
	if (termprint)
		fprintf(stderr, "%s\n", buf);
	else if (logfile)
		fprintf(logfile, "%s %s\n", timestring(), buf);
	else
		syslog(LOG_INFO, "%s", buf);
}
Exemple #6
0
void Log_fatal(const char *logstring, ...)
{
	va_list argp;
	char buf[STRSIZE + 1];
	int offset = 0;
	
	if (termprint || logfile)
		offset = sprintf(buf, "FATAL: ");
	
	va_start(argp, logstring);	
	vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp);
	va_end(argp);
	
	if (termprint)
		fprintf(stderr, "%s\n", buf);
	else if (logfile)
		fprintf(logfile, "%s %s\n", timestring(), buf);
	else { /* If logging subsystem is not initialized, fall back to stderr +
			* syslog logging for fatal errors. 
			*/
		if (!init) {
			openlog("uMurmurd", LOG_PID, LOG_DAEMON);
			fprintf(stderr, "%s\n", buf);
		}
		syslog(LOG_CRIT, "%s", buf);
	}
	
	exit(1);
}
Exemple #7
0
void
chldcb_check ()
{
  for (;;) {
    int status;
    pid_t pid = waitpid (-1, &status, WNOHANG);
    if (pid == 0 || pid == -1)
      break;
    if (child *c = chldcbs[pid]) {
      chldcbs.remove (c);
#ifdef WRAP_DEBUG
      if (callback_trace & CBTR_CHLD)
	warn ("CALLBACK_TRACE: %schild pid %d (status %d) %s <- %s\n",
	      timestring (), pid, status, c->cb->dest, c->cb->line);
#endif /* WRAP_DEBUG */
      STOP_ACHECK_TIMER ();
      sfs_leave_sel_loop ();
      (*c->cb) (status);
      START_ACHECK_TIMER ();
      delete c;
    } else if (sfs_core::g_zombie_collect) {
      zombie_t *z = zombies[pid];
      if (z) {
	z->_status = status;
      } else {
	zombies.insert (New zombie_t (pid, status));
      }
    }
  }
}
Exemple #8
0
void
lazycb_check ()
{
  time_t my_timenow = 0;

 restart:
  lazycb_removed = false;
  for (lazycb_t *lazy = lazylist->first; lazy; lazy = lazylist->next (lazy)) {

    if (my_timenow == 0) {
      sfs_set_global_timestamp ();
      my_timenow = sfs_get_timenow ();
    }

    if (my_timenow < lazy->next)
      continue;
    lazy->next = my_timenow + lazy->interval;
#ifdef WRAP_DEBUG
    if (callback_trace & CBTR_LAZY)
      warn ("CALLBACK_TRACE: %slazy %s <- %s\n", timestring (),
	    lazy->cb->dest, lazy->cb->line);
#endif /* WRAP_DEBUG */
    STOP_ACHECK_TIMER ();
    sfs_leave_sel_loop ();
    (*lazy->cb) ();
    START_ACHECK_TIMER ();
    if (lazycb_removed)
      goto restart;
  }
}
Exemple #9
0
/* return true if access should be allowed to a service*/
BOOL check_access(int snum)
{
  char *denyl,*allowl;
  BOOL ret = False;

  denyl = lp_hostsdeny(snum);
  if (denyl) denyl = strdup(denyl);

  allowl = lp_hostsallow(snum);
  if (allowl) allowl = strdup(allowl);

  if ((!denyl || *denyl==0) && (!allowl || *allowl==0))
    ret = True;

  if (!ret)
    {
      if (allow_access(denyl,allowl,client_name(),client_addr()))
	{
	  if (snum >= 0)
	    DEBUG(2,("Allowed connection from %s (%s) to %s\n",
		     client_name(),client_addr(),
		     lp_servicename(snum)));
	  ret = True;
	}
      else
	if (snum >= 0)
	  DEBUG(0,("%s Denied connection from %s (%s) to %s\n",
		   timestring(), client_name(),client_addr(),
		   lp_servicename(snum)));
    }

  if (denyl) free(denyl);
  if (allowl) free(allowl);
  return(ret);
}
Exemple #10
0
static void ls_one(char *fname)
{
    char perms[11] = "----------";
    char *perm_map = "rwxrwxrwx";
    struct stat st;
    int i;

    if (lstat(fname, &st) != 0) {
        perror(fname);
        return;
    }

    for (i=0; i<9; i++) {
        if (st.st_mode & (1<<i)) perms[9-i] = perm_map[8-i];
    }
    if (S_ISLNK(st.st_mode)) perms[0] = 'l';
    if (S_ISDIR(st.st_mode)) perms[0] = 'd';
    if (S_ISBLK(st.st_mode)) perms[0] = 'b';
    if (S_ISCHR(st.st_mode)) perms[0] = 'c';
    if (S_ISSOCK(st.st_mode)) perms[0] = 's';
    if (S_ISFIFO(st.st_mode)) perms[0] = 'p';


    printf("%s %11.0f %s %s\n",
           perms,
           (double)st.st_size, timestring(st.st_mtime), fname);
}
Exemple #11
0
void callback_trace_fdcb (int i, int fd, cbv::ptr cb)
{
  if (fd != errfd && fd != sigpipes[0] && (callback_trace & CBTR_FD))
    warn ("CALLBACK_TRACE: %sfdcb %d%c %s <- %s\n",
	  timestring (), fd, "rwe"[i],
	  cb->dest, cb->line);
}
Exemple #12
0
void Log_info_client(client_t *client, const char *logstring, ...)
{
	va_list argp;
	char buf[STRSIZE + 1];
	int offset = 0;

	if (termprint || logfile)
		offset = sprintf(buf, "INFO: ");

	va_start(argp, logstring);
	offset += vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp);
	va_end(argp);

	char *clientAddressString = Util_clientAddressToString(client);
	offset += snprintf(&buf[offset], STRSIZE - offset, " - [%d] %s@%s:%d",
		client->sessionId,
		client->username == NULL ? "" : client->username,
		clientAddressString,
		Util_clientAddressToPortTCP(client));
	free(clientAddressString);

	if (termprint)
		fprintf(stderr, "%s\n", buf);
	else if (logfile)
		fprintf(logfile, "%s %s\n", timestring(), buf);
	else
		syslog(LOG_INFO, "%s", buf);
}
Exemple #13
0
void log_init(int restart)
{
	if (log_initialised) {
		if (!restart)
			return;
		if (strcmp(logfile_name, lp_log_file(module_id)) != 0) {
			if (logfile_fp) {
				fclose(logfile_fp);
				logfile_fp = NULL;
			} else
				closelog();
			logfile_name = NULL;
		} else if (*logfile_name)
			return; /* unchanged, non-empty "log file" names */
		else if (lp_syslog_facility(-1) != lp_syslog_facility(module_id))
			closelog();
		else
			return; /* unchanged syslog settings */
	} else
		log_initialised = 1;

	/* This looks pointless, but it is needed in order for the
	 * C library on some systems to fetch the timezone info
	 * before the chroot. */
	timestring(time(NULL));

	/* Optionally use a log file instead of syslog.  (Non-daemon
	 * rsyncs will have already set logfile_name, as needed.) */
	if (am_daemon && !logfile_name)
		logfile_name = lp_log_file(module_id);
	if (logfile_name && *logfile_name)
		logfile_open();
	else
		syslog_init();
}
Exemple #14
0
bool logline(int level, const char *msg, ...)
{
    if(!enabled) return false;
    if(level < 0 || level >= ACLOG_NUM) return false;
    defvformatstring(sf, msg, msg);
    filtertext(sf, sf, 2);
    const char *ts = timestamp ? timestring(true, "%b %d %H:%M:%S ") : "", *ld = levelprefix[level];
    char *p, *l = sf;
    do
    { // break into single lines first
        if((p = strchr(l, '\n'))) *p = '\0';
        if(consolethreshold <= level) printf("%s%s%s\n", ts, ld, l);
        if(fp && filethreshold <= level) fprintf(fp, "%s%s%s\n", ts, ld, l);
        if(syslogthreshold <= level)
#ifdef AC_USE_SYSLOG
            syslog(levels[level], "%s", l);
#else
        {
            defformatstring(text)("<%d>%s: %s", (16 + facility) * 8 + levels[level], ident, l); // no TIMESTAMP, no hostname: syslog will add this
            ENetBuffer buf;
            buf.data = text;
            buf.dataLength = strlen(text);
            enet_socket_send(logsock, &logdest, &buf, 1);
        }
#endif
        l = p + 1;
    }
    while(p);
    if(consolethreshold <= level) fflush(stdout);
    if(fp && filethreshold <= level) fflush(fp);
    return consolethreshold <= level;
}
Exemple #15
0
/* ************************************************************************** **
 * Print a Debug Header.
 *
 *  Input:  level - Debug level of the message (not the system-wide debug
 *                  level.
 *          file  - Pointer to a string containing the name of the file
 *                  from which this function was called, or an empty string
 *                  if the __FILE__ macro is not implemented.
 *          func  - Pointer to a string containing the name of the function
 *                  from which this function was called, or an empty string
 *                  if the __FUNCTION__ macro is not implemented.
 *          line  - line number of the call to dbghdr, assuming __LINE__
 *                  works.
 *
 *  Output: Always True.  This makes it easy to fudge a call to dbghdr()
 *          in a macro, since the function can be called as part of a test.
 *          Eg: ( (level <= DEBUGLEVEL) && (dbghdr(level,"",line)) )
 *
 *  Notes:  This function takes care of setting syslog_level.
 *
 * ************************************************************************** **
 */
BOOL
dbghdr (int level, const char *file, const char *func, int line)
{
    if (format_pos)
    {
        /* This is a fudge.  If there is stuff sitting in the format_bufr, then
         * the *right* thing to do is to call
         *   format_debug_text( "\n" );
         * to write the remainder, and then proceed with the new header.
         * Unfortunately, there are several places in the code at which
         * the DEBUG() macro is used to build partial lines.  That in mind,
         * we'll work under the assumption that an incomplete line indicates
         * that a new header is *not* desired.
         */
        return (True);
    }

    /* Don't print a header if we're logging to stdout. */
    if (stdout_logging)
        return (True);

    /* Print the header if timestamps are turned on.  If parameters are
     * not yet loaded, then default to timestamps on.
     */
    if (lp_timestamp_logs () || !(lp_loaded ()))
    {
        /* Print it all out at once to prevent split syslog output. */
        (void) Debug1 ("[%s, %d] %s:%s(%d)\n", timestring (), level, file, func, line);
    }

    return (True);
}                               /* dbghdr */
Exemple #16
0
_PUBLIC_ void ndr_print_time_t(struct ndr_print *ndr, const char *name, time_t t)
{
	if (t == (time_t)-1 || t == 0) {
		ndr->print(ndr, "%-25s: (time_t)%d", name, (int)t);
	} else {
		ndr->print(ndr, "%-25s: %s", name, timestring(ndr, t));
	}
}
Exemple #17
0
static value_t fl_time_string(value_t *args, uint32_t nargs)
{
    argcount("time.string", nargs, 1);
    double t = todouble(args[0], "time.string");
    char buf[64];
    timestring(t, buf, sizeof(buf));
    return string_from_cstr(buf);
}
Exemple #18
0
void
traceobj::init ()
{
  if (progname)
    cat (progname).cat (": ");
  cat (prefix);
  if (dotime)
    cat (timestring ()).cat (" ");
}
Exemple #19
0
BOOL dbghdr( int level, const char *file, const char *func, int line )
{
  /* Ensure we don't lose any real errno value. */
  int old_errno = errno;

  if( format_pos ) {
    /* This is a fudge.  If there is stuff sitting in the format_bufr, then
     * the *right* thing to do is to call
     *   format_debug_text( "\n" );
     * to write the remainder, and then proceed with the new header.
     * Unfortunately, there are several places in the code at which
     * the DEBUG() macro is used to build partial lines.  That in mind,
     * we'll work under the assumption that an incomplete line indicates
     * that a new header is *not* desired.
     */
    return( True );
  }

#ifdef WITH_SYSLOG
  /* Set syslog_level. */
  syslog_level = level;
#endif

  /* Don't print a header if we're logging to stdout. */
  if( stdout_logging )
    return( True );

  /* Print the header if timestamps are turned on.  If parameters are
   * not yet loaded, then default to timestamps on.
   */
  if( lp_timestamp_logs() || !(lp_loaded()) ) {
    char header_str[200];

	header_str[0] = '\0';

	if( lp_debug_pid())
	  slprintf(header_str,sizeof(header_str)-1,", pid=%u",(unsigned int)sys_getpid());

	if( lp_debug_uid()) {
      size_t hs_len = strlen(header_str);
	  slprintf(header_str + hs_len,
               sizeof(header_str) - 1 - hs_len,
			   ", effective(%u, %u), real(%u, %u)",
               (unsigned int)geteuid(), (unsigned int)getegid(),
			   (unsigned int)getuid(), (unsigned int)getgid()); 
	}
  
    /* Print it all out at once to prevent split syslog output. */
    (void)Debug1( "[%s, %d%s] %s:%s(%d)\n",
                  timestring(lp_debug_hires_timestamp()), level,
				  header_str, file, func, line );
  }

  errno = old_errno;
  return( True );
}
Exemple #20
0
void
timecb_check ()
{
  struct timespec my_ts;

  timecb_t *tp, *ntp;

  if (timecbs.first ()) {
    sfs_set_global_timestamp ();
    my_ts = sfs_get_tsnow ();

    for (tp = timecbs.first (); tp && tp->ts <= my_ts;
	 tp = timecbs_altered ? timecbs.first () : ntp) {
      ntp = timecbs.next (tp);
      timecbs.remove (tp);
      timecbs_altered = false;
#ifdef WRAP_DEBUG
      if (callback_trace & CBTR_TIME)
	warn ("CALLBACK_TRACE: %stimecb %s <- %s\n", timestring (),
	      tp->cb->dest, tp->cb->line);
#endif /* WRAP_DEBUG */
      STOP_ACHECK_TIMER ();
      sfs_leave_sel_loop ();
      (*tp->cb) ();
      START_ACHECK_TIMER ();
      delete tp;
    }
  }

  selwait.tv_usec = 0;
  selwait.tv_sec = 0;
  if (!sfs_core::g_busywait && !sigdocheck) {
    if (!(tp = timecbs.first ()))
      selwait.tv_sec = 86400;
    else {
      if (tp->ts.tv_sec == 0) {
	selwait.tv_sec = 0;
      } else {
	sfs_set_global_timestamp ();
	my_ts = sfs_get_tsnow ();
	if (tp->ts < my_ts)
	  selwait.tv_sec = 0;
	else if (tp->ts.tv_nsec >= my_ts.tv_nsec) {
	  selwait.tv_sec = tp->ts.tv_sec - my_ts.tv_sec;
	  selwait.tv_usec = (tp->ts.tv_nsec - my_ts.tv_nsec) / 1000;
	}
	else {
	  selwait.tv_sec = tp->ts.tv_sec - my_ts.tv_sec - 1;
	  selwait.tv_usec = (1000000000 + tp->ts.tv_nsec - 
			     my_ts.tv_nsec) / 1000;
	}
      }
    }
  }
}
Exemple #21
0
static void logit(int priority, const char *buf)
{
	if (logfile_was_closed)
		logfile_reopen();
	if (logfile_fp) {
		fprintf(logfile_fp, "%s [%d] %s", timestring(time(NULL)), (int)getpid(), buf);
		fflush(logfile_fp);
	} else {
		syslog(priority, "%s", buf);
	}
}
Exemple #22
0
//------------------------------------------------------------------------
void musicxmlfactory::encoding(const char* software)
{
	Sxmlelement encoding = element (k_encoding);
	if (software) encoding->push (element(k_software, software));

	string lib = "MusicXML Library version ";
	lib += musicxmllibVersionStr();
	encoding->push (element(k_software, lib.c_str()));
	encoding->push (element (k_encoding_date, timestring()));
	fIdentification->push (encoding);
}
Exemple #23
0
string TimeStamp::getTimeStringForFileName()
{
	time_t second_t = _seconds;
	struct tm* ldctm = localtime(&second_t);
	char timebuf[32] = "";
	sprintf_s(timebuf,32,"%4d-%02d-%02d %02d %02d %02d",
		ldctm->tm_year + 1900,
		ldctm->tm_mon + 1,
		ldctm->tm_mday,
		ldctm->tm_hour,
		ldctm->tm_min,
		ldctm->tm_sec);
	ldctm = NULL;
	string timestring(timebuf);
	return timestring;
}
Exemple #24
0
void logthis(const char *logstring, ...)
{
	va_list argp;
	char buf[STRSIZE + 1];
	
	va_start(argp, logstring);
	vsnprintf(&buf[0], STRSIZE, logstring, argp);
	va_end(argp);
	
	if (termprint)
		fprintf(stderr, "%s\n", buf);
	else if (logfile)
		fprintf(logfile, "%s %s\n", timestring(), buf);
	else
		syslog(LOG_INFO, "%s", buf);
}
Exemple #25
0
int SQLConnector::addRow(std::string tableName,
			  long int time,
		 const std::vector<std::pair<std::string, double>>& vals)
{
  struct tm* t = localtime(&time);
  char buf[50];
  snprintf(buf, 50, "%04d-%02d-%02d %02d:%02d:%02d",
	   t->tm_year+1900, t->tm_mon+1, t->tm_mday,
	   t->tm_hour, t->tm_min, t->tm_sec);
  std::string timestring(buf);

  std::vector<std::pair<std::string, double>> valsCopy(vals);
  std::pair<std::string, double> lastVal = valsCopy.back();
  valsCopy.pop_back();

  std::stringstream ss;
  ss << "INSERT INTO " << tableName << " ( time, ";
  for (auto& val : valsCopy)
  {
    ss << val.first << ", ";
  }
  ss << lastVal.first << " ) ";
  ss << "VALUES ( '" << timestring << "', ";
  for (auto& val : valsCopy)
  {
    ss << val.second << ", ";
  }
  ss << lastVal.second << ");";

  std::shared_ptr<sql::Statement> pStatement(m_pConnection->createStatement());
  bool result = pStatement->execute(ss.str());
  
  if (!result)
  {
    std::cout << SQLLOG << " added row with:" << std::endl;
    std::cout << ss.str() << std::endl;
  }
  else
  {
    std::cout << SQLLOG << " error adding row with:" << std::endl;
    std::cout << ss.str() << std::endl;
    return -1;
  }
  
  return 0;

}
Exemple #26
0
warnobj::warnobj (int f)
  : flags (f)
{
  if (flags & timeflag)
    cat (timestring ()).cat (" ");
  if (!(flags & xflag) && progname) {
    if (progpid) {
      cat (progname).cat ("[").cat (progpid).cat ("]: ");
    } else {
      cat (progname).cat (": ");
	}
  }
  if (flags & panicflag)
    cat ("PANIC: ");
  else if (flags & fatalflag)
    cat ("fatal: ");
}
Exemple #27
0
static bool test_timestring(struct torture_context *tctx)
{
	const char *start = "Thu Jan  1";
	char *result;
	/*
	 * Correct test for negative UTC offset.  Without the correction, the
	 * test fails when run on hosts with negative UTC offsets, as the date
	 * returned is back in 1969 (pre-epoch).
	 */
	time_t now = time(NULL);
	struct tm local = *localtime(&now);
	struct tm gmt = *gmtime(&now);
	time_t utc_offset = mktime(&local) - mktime(&gmt);

	result = timestring(tctx, 42 - (utc_offset < 0 ? utc_offset : 0));
	torture_assert(tctx, !strncmp(start, result, strlen(start)), result);
	return true;
}
Exemple #28
0
void Log_debug(const char *logstring, ...)
{
	va_list argp;
	char buf[STRSIZE + 1];
	int offset = 0;
	
	if (termprint || logfile)
		offset = sprintf(buf, "DEBUG: ");
	
	va_start(argp, logstring);	
	vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp);
	va_end(argp);
	if (termprint)
		fprintf(stderr, "%s\n", buf);
	else if (logfile)
		fprintf(logfile, "%s %s\n", timestring(), buf);
	else
		syslog(LOG_DEBUG, "%s", buf);
}
Exemple #29
0
float classifynn(List<Pixel> *ps) {
  if (twopass) {
    if (pass==1) {
      Vnd *summary=summarise(ps);
//      writetraindata(summary,123.456);
      data.add(IOData(summary,123.456,ps->num(1)));
//      destroy(summary);
      return 123.456;
    } else {
      return getnextmeasure();   
    }
  } else {
  Vnd *summary=summarise(ps);
  traindata.clear();
  traindata.add("SNNS pattern definition file V3.2");
  traindata.add(Sformat("generated at %s\n",timestring()));
  traindata.add("No. of patterns: 1");
  traindata.add(Sformat("No. of input units: %i",nummeasures));
  if (!twooutnodes)
    traindata.add("No. of output units: 1");
  else
    traindata.add("No. of output units: 2");
  traindata.add("");
  traindata.add("# Quick question for the NN");
  writemeasures(summary);
  destroy(summary);
  traindata.add("# Don't know output");
  if (!twooutnodes)
    traindata.add("123.456");
  else
    traindata.add("123.456 654.321");
  writelinestofile(traindata,"question.pat");
  system("./asknn > tmp.txt");
  List<String> ls=readlinesfromfile("answer.res");
//  deletefile("answer.res");
  float answer;  // Haven't bothered with twooutnodes case.
  sscanf(ls.num(14),"%f",&answer);
  printf("Answer was %f\n",answer);
  return answer;
  }
}
Exemple #30
0
bool set_write_time(struct file_id fileid, struct timespec write_time)
{
	struct share_mode_lock *lck;

	DEBUG(5,("set_write_time: %s id=%s\n",
		 timestring(talloc_tos(),
			    convert_timespec_to_time_t(write_time)),
		 file_id_string_tos(&fileid)));

	lck = get_existing_share_mode_lock(talloc_tos(), fileid);
	if (lck == NULL) {
		return False;
	}

	if (timespec_compare(&lck->data->old_write_time, &write_time) != 0) {
		lck->data->modified = True;
		lck->data->old_write_time = write_time;
	}

	TALLOC_FREE(lck);
	return True;
}