Example #1
0
const char *
mfn_timestr(MFUNARGS)
{
	int tm = atol(argv[0]);
	int dy, hr, mn;

	dy = hr = mn = 0;
	if (tm >= 86400) {
		dy = tm / 86400;		/* Days */
		tm %= 86400;
	}
	if (tm >= 3600) {
		hr = tm / 3600;			/* Hours */
		tm %= 3600;
	}
	if (tm >= 60) {
		mn = tm / 60;			/* Minutes */
		tm %= 60;				/* Seconds */
	}

	*buf = '\0';
	if (dy) {
		snprintf(buf, BUFFER_LEN, "%dd %02d:%02d", dy, hr, mn);
	} else {
		snprintf(buf, BUFFER_LEN, "%02d:%02d", hr, mn);
	}
	return buf;
}
Example #2
0
int main(int argc, char *argv[])
{
	size_t i;
	
	for (i=0; i<(sizeof(fxo_modes)/sizeof(struct fxo_mode)); i++) {
		if (fxo_modes[i].name == NULL) break;
		int reg16=0, reg26=0, reg30=0, reg31=0x20;
		char ring_osc[BUFSIZ]="", ring_x[BUFSIZ] = "";
		
		reg16 |= (fxo_modes[i].ohs << 6);
		reg16 |= (fxo_modes[i].rz << 1);
		reg16 |= (fxo_modes[i].rt);
		
		reg26 |= (fxo_modes[i].dcv << 6);
		reg26 |= (fxo_modes[i].mini << 4);
		reg26 |= (fxo_modes[i].ilim << 1);
		
		reg30 = (fxo_modes[i].acim);
		
		reg31 |= (fxo_modes[i].ohs2 << 3);

		if (fxo_modes[i].ring_osc)
			snprintf(ring_osc, BUFSIZ, "ring_osc=%04X", fxo_modes[i].ring_osc);
		if (fxo_modes[i].ring_x)
			snprintf(ring_x, BUFSIZ, "ring_x=%04X", fxo_modes[i].ring_x);
		printf("%-15s\treg16=%02X\treg26=%02X\treg30=%02X\treg31=%02X\t%s\t%s\n",
		       fxo_modes[i].name, reg16, reg26, reg30, reg31, ring_osc, ring_x);
	}
	return 0;
}
Example #3
0
static tree
gfc_sym_mangled_common_id (gfc_common_head *com)
{
  int has_underscore;
  char mangled_name[GFC_MAX_MANGLED_SYMBOL_LEN + 1];
  char name[GFC_MAX_SYMBOL_LEN + 1];

  /* Get the name out of the common block pointer.  */
  strcpy (name, com->name);

  /* If we're suppose to do a bind(c).  */
  if (com->is_bind_c == 1 && com->binding_label)
    return get_identifier (com->binding_label);

  if (strcmp (name, BLANK_COMMON_NAME) == 0)
    return get_identifier (name);

  if (gfc_option.flag_underscoring)
    {
      has_underscore = strchr (name, '_') != 0;
      if (gfc_option.flag_second_underscore && has_underscore)
        snprintf (mangled_name, sizeof mangled_name, "%s__", name);
      else
        snprintf (mangled_name, sizeof mangled_name, "%s_", name);

      return get_identifier (mangled_name);
    }
  else
    return get_identifier (name);
}
Example #4
0
/* Temporary hack so we can move this out from user code */
void SaveSystem::PrepareFilesystem()
{
    FilePath tmpPath[SEED_MAX_FOLDER_SIZE];

#if defined(WIN32)
    _snwprintf(tmpPath, SEED_MAX_FOLDER_SIZE, L"%s%S\\",  pSystem->GetHomeFolder(), pConfiguration->GetPublisherName());
#else
#if SEED_PATH_WIDE == 1
    swprintf(tmpPath, SEED_MAX_FOLDER_SIZE, L"%s/.%s/", pSystem->GetHomeFolder(), pConfiguration->GetPublisherName());
#else
    snprintf((char *)tmpPath, SEED_MAX_FOLDER_SIZE, "%s/.%s/", pSystem->GetHomeFolder(), pConfiguration->GetPublisherName());
#endif
#endif

    pFileSystem->MakeDirectory(tmpPath);

#if defined(WIN32)
    _snwprintf(pcSaveGameFolder, SEED_MAX_FOLDER_SIZE, L"%s%S\\",  tmpPath, pConfiguration->GetApplicationTitle());
#else
#if SEED_PATH_WIDE == 1
    swprintf(pcSaveGameFolder, SEED_MAX_FOLDER_SIZE, L"%S%s/", tmpPath, pConfiguration->GetApplicationTitle());
#else
    snprintf((char *)pcSaveGameFolder, SEED_MAX_FOLDER_SIZE, "%s%s/", tmpPath, pConfiguration->GetApplicationTitle());
#endif
#endif

    pFileSystem->MakeDirectory(pcSaveGameFolder);
    pFileSystem->SetWriteableDirectory(pcSaveGameFolder);
}
Example #5
0
int datalist_writedb(DSTATE *s)
{
	if (!s->dodbsave) {
		return 1;
	}

	if (!checkdb(s->datalist->data.interface, s->dirname)) {
		return 0;
	}

	if (spacecheck(s->dirname)) {
		if (writedb(s->datalist->data.interface, s->dirname, 0)) {
			if (!s->dbsaved) {
				snprintf(errorstring, 512, "Database write possible again.");
				printe(PT_Info);
				s->dbsaved = 1;
			}
		} else {
			if (s->dbsaved) {
				snprintf(errorstring, 512, "Unable to write database, continuing with cached data.");
				printe(PT_Error);
				s->dbsaved = 0;
			}
		}
	} else {
		/* show freespace error only once */
		if (s->dbsaved) {
			snprintf(errorstring, 512, "Free diskspace check failed, unable to write database, continuing with cached data.");
			printe(PT_Error);
			s->dbsaved = 0;
		}
	}

	return 1;
}
Example #6
0
/*
 * At any point we should be able to construct an ascii representation of
 * the type descriptor. Including the variable references.
 */
str
getTypeName(malType tpe)
{
	char buf[PATHLENGTH], *s;
	size_t l = PATHLENGTH;
	int k;

	if (tpe == TYPE_any)
		return GDKstrdup("any");
	if (isaBatType(tpe)) {
		snprintf(buf, l, "bat[");
		l -= strlen(buf);
		s = buf + strlen(buf);
		k = getColumnIndex(tpe);
		if (k)
			snprintf(s, l, ":any%c%d]",TMPMARKER,  k);
		else if (getColumnType(tpe) == TYPE_any)
			snprintf(s, l, ":any]");
		else
			snprintf(s, l, ":%s]", ATOMname(getColumnType(tpe)));
		return GDKstrdup(buf);
	}
	if (isAnyExpression(tpe)) {
		strncpy(buf, "any", 4);
		if (isAnyExpression(tpe))
			snprintf(buf + 3, PATHLENGTH - 3, "%c%d",
					TMPMARKER, getColumnIndex(tpe));
		return GDKstrdup(buf);
	}
	return GDKstrdup(ATOMname(tpe));
}
Example #7
0
static int ixgbe_txqavg(char *page, char __always_unused **start,
			off_t __always_unused off, int count,
			int __always_unused *eof, void *data)
{
	int index;
	int diff = 0;
	u16 ntc;
	u16 ntu;
	struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
	if (adapter == NULL)
		return snprintf(page, count, "error: no adapter\n");

	for (index = 0; index < adapter->num_tx_queues; index++) {
		ntc = adapter->tx_ring[index]->next_to_clean;
		ntu = adapter->tx_ring[index]->next_to_use;

		if (ntc >= ntu)
			diff += (ntc - ntu);
		else
			diff += (adapter->tx_ring[index]->count - ntu + ntc);
	}
	if (adapter->num_tx_queues <= 0)
		return snprintf(page, count,
				"can't calculate, number of queues %d\n",
				adapter->num_tx_queues);
	return snprintf(page, count, "%d\n",
			diff/adapter->num_tx_queues);
}
Example #8
0
int TagInfo( int nOutputFormat, TS_ELEMENT *pTSElmnt, ES_ELEMENT *pESElmnt, char* pBuffer, int nSize )
{
	int i, pos = 0;
	char *p = pBuffer;
	 
	if ( IS_TS_TYPE(nOutputFormat) )
	{
		return snprintf( p+pos, nSize-pos,  "tag=%04x;pid=%d;", pTSElmnt->pid, pTSElmnt->pid );
	} else
	{
		if ( pESElmnt->private_bytes == 0 )
		{
			return snprintf( p+pos, nSize-pos,  "tag=%02x;", pESElmnt->pes.stream_id  );
		} else
		{
			pos += snprintf( p+pos, nSize-pos,  "tag=%02x-", pESElmnt->pes.stream_id  );
			for ( i = 0; i<pESElmnt->private_bytes; i++ )
			{	
				pos += snprintf( p+pos, nSize-pos,  "%02x", pESElmnt->private_data[i] );
			}
			if ( pos <nSize ) p[pos++] = ';';
			return pos;
		}
	}
	return pos;
}
Example #9
0
bool StackTraceBase::Translate(void *frame, StackTraceBase::Frame * f,
                               Dl_info &dlInfo, void* data,
                               void *bfds, unsigned bfds_size) {
  char sframe[32];
  snprintf(sframe, sizeof(sframe), "%p", frame);

  if (!dladdr(frame, &dlInfo)) {
    return false;
  }

  // frame pointer offset in previous frame
  f->offset = (char*)frame - (char*)dlInfo.dli_saddr;

  if (dlInfo.dli_fname) {

    // 1st attempt without offsetting base address
    if (!Addr2line(dlInfo.dli_fname, sframe, f, data, bfds, bfds_size) &&
        dlInfo.dli_fname && strstr(dlInfo.dli_fname,".so")) {
      // offset shared lib's base address
      frame = (char*)frame - (size_t)dlInfo.dli_fbase;
      snprintf(sframe, sizeof(sframe), "%p", frame);

      // Use addr2line to get line number info.
      Addr2line(dlInfo.dli_fname, sframe, f, data, bfds, bfds_size);
    }
  }
  return true;
}
Example #10
0
File: sys.c Project: futex/radare2
R_API char *r_sys_pid_to_path(int pid) {
#if __WINDOWS__
	// TODO: implement r_sys_pid_to_path on W32
	return NULL;
#elif __APPLE__
	char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
	int ret = proc_pidpath (pid, pathbuf, sizeof (pathbuf));
	if (ret <= 0)
		return NULL;
	return strdup (pathbuf);
#else
	int ret;
	char buf[128], pathbuf[1024];
#if __FreeBSD__
	snprintf (buf, sizeof (buf), "/proc/%d/file", pid);
#else
	snprintf (buf, sizeof (buf), "/proc/%d/exe", pid);
#endif
	ret = readlink (buf, pathbuf, sizeof (pathbuf)-1);
	if (ret<1)
		return NULL;
	pathbuf[ret] = 0;
	return strdup (pathbuf);
#endif
}
Example #11
0
static int MpegVideoInf( MPEG_VIDEO *pMpegVideo, char* pBuffer, int nSize )
{
	char* p = pBuffer;
	int pos = 0;
	if ( nSize <= 0 ) return 0;
	if ( pMpegVideo->extension_present )
	{
		char* chrome_format="";
		if ( pMpegVideo->chrome == 1  ) chrome_format = "cs=yuv420p;"; else
		if ( pMpegVideo->chrome == 2  ) chrome_format = "cs=yuv422p;"; else
		if ( pMpegVideo->chrome == 3  ) chrome_format = "cs=yuv444p;"; 
			
		pos += snprintf( p+pos, nSize-pos, "fps=%f;fpsn=%d;fpsd=%d;ar=%f;arn=%d;ard=%d;w=%ld;h=%ld;lace=%d;%s",
			              (float)pMpegVideo->frame_rate_nomi/pMpegVideo->frame_rate_deno,
						  pMpegVideo->frame_rate_nomi, 
						  pMpegVideo->frame_rate_deno,
						  Mepg2AspectRatioF( (unsigned char)(pMpegVideo->ar_info & 0x0f), pMpegVideo->width, pMpegVideo->height ),
						  Mepg2AspectRatioNomiValue( (unsigned char)(pMpegVideo->ar_info & 0x0f), pMpegVideo->width, pMpegVideo->height ),
						  Mepg2AspectRatioDenoValue( (unsigned char)(pMpegVideo->ar_info & 0x0f), pMpegVideo->width, pMpegVideo->height ),
						  pMpegVideo->width, 
						  pMpegVideo->height,
						  !pMpegVideo->progressive,
						  chrome_format );

	} else
	{
		pos += snprintf( p+pos, nSize-pos, "fps=%f;fpsn=%d;fpsd=%d;ar=%f;w=%ld;h=%ld;",
			              (float)pMpegVideo->frame_rate_nomi/pMpegVideo->frame_rate_deno,
						  pMpegVideo->frame_rate_nomi, 
						  pMpegVideo->frame_rate_deno,
						  Mepg1AspectRatioF( (unsigned char)(pMpegVideo->ar_info & 0x0f), pMpegVideo->width, pMpegVideo->height ),
						  pMpegVideo->width, pMpegVideo->height );
	}
	return pos;
}
Example #12
0
ssize_t show_time_in_state(struct device *dev, struct device_attribute *attr, char *buf)
{
	struct kbase_device *kbdev;
	ssize_t ret = 0;
	int i;

	kbdev = dev_get_drvdata(dev);

#ifdef CONFIG_MALI_T6XX_DVFS
	update_time_in_state(mali_dvfs_status_current.step);
#endif
	if (!kbdev)
		return -ENODEV;

	for (i = 0; i < MALI_DVFS_STEP; i++)
		ret += snprintf(buf + ret, PAGE_SIZE - ret, "%d %llu\n", mali_dvfs_infotbl[i].clock, mali_dvfs_infotbl[i].time);

	if (ret < PAGE_SIZE - 1)
		ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
	else {
		buf[PAGE_SIZE - 2] = '\n';
		buf[PAGE_SIZE - 1] = '\0';
		ret = PAGE_SIZE - 1;
	}

	return ret;
}
void Lwm2mCore_AddressTypeToPath(char * path, size_t pathSize, AddressType * addr)
{
    char buffer[255];
    const char* ip;
    int port;


    memcpy(path, "coap", 4);
    path += 4;
    pathSize -= 4;

    if (addr->Secure)
    {
        *path = 's';
        path++;
        pathSize--;
    }

    switch (addr->Addr.Sa.sa_family)
    {
        case AF_INET:
            ip = inet_ntop(AF_INET, &addr->Addr.Sin.sin_addr, buffer, sizeof(buffer));
            port = ntohs(addr->Addr.Sin.sin_port);
            snprintf(path, pathSize, "://%s:%d", ip, port);
            break;
        case AF_INET6:
            ip = inet_ntop(AF_INET6, &addr->Addr.Sin6.sin6_addr, buffer, sizeof(buffer));
            port =  ntohs(addr->Addr.Sin6.sin6_port);
            snprintf(path, pathSize, "://[%s]:%d", ip, port);
            break;
        default:
            Lwm2m_Error("Unsupported address family: %d\n", addr->Addr.Sa.sa_family);
            break;
    }
}
Example #14
0
/* Provide a string that is 2 + 1 + 2 + 1 + 2 = 8 letters long (plus the zero
   byte) */
static void time2str(char *r, curl_off_t seconds)
{
  curl_off_t d, h, m, s;
  if(seconds <= 0) {
    strcpy(r, "--:--:--");
    return;
  }
  h = seconds / CURL_OFF_T_C(3600);
  if(h <= CURL_OFF_T_C(99)) {
    m = (seconds - (h*CURL_OFF_T_C(3600))) / CURL_OFF_T_C(60);
    s = (seconds - (h*CURL_OFF_T_C(3600))) - (m*CURL_OFF_T_C(60));
    snprintf(r, 9, "%2" CURL_FORMAT_CURL_OFF_T ":%02" CURL_FORMAT_CURL_OFF_T
             ":%02" CURL_FORMAT_CURL_OFF_T, h, m, s);
  }
  else {
    /* this equals to more than 99 hours, switch to a more suitable output
       format to fit within the limits. */
    d = seconds / CURL_OFF_T_C(86400);
    h = (seconds - (d*CURL_OFF_T_C(86400))) / CURL_OFF_T_C(3600);
    if(d <= CURL_OFF_T_C(999))
      snprintf(r, 9, "%3" CURL_FORMAT_CURL_OFF_T
               "d %02" CURL_FORMAT_CURL_OFF_T "h", d, h);
    else
      snprintf(r, 9, "%7" CURL_FORMAT_CURL_OFF_T "d", d);
  }
}
Example #15
0
static char *convert_hostnames(char *s1)
{
        char *converted, *s2 = 0, *c;
        char sep;
        int left = MAXNIDSTR;
        lnet_nid_t nid;

        converted = malloc(left);
        if (converted == NULL) {
                fprintf(stderr, "out of memory: needed %d bytes\n",
                        MAXNIDSTR);
                return NULL;
        }
        c = converted;
        while ((left > 0) && (*s1 != '/')) {
                s2 = strpbrk(s1, ",:");
                if (!s2)
                        goto out_free;
                sep = *s2;
                *s2 = '\0';
                nid = libcfs_str2nid(s1);
                *s2 = sep;                      /* back to original string */
                if (nid == LNET_NID_ANY)
                        goto out_free;
                c += snprintf(c, left, "%s%c", libcfs_nid2str(nid), sep);
                left = converted + MAXNIDSTR - c;
                s1 = s2 + 1;
        }
        snprintf(c, left, "%s", s1);
        return converted;
out_free:
        fprintf(stderr, "%s: Can't parse NID '%s'\n", progname, s1);
        free(converted);
        return NULL;
}
Example #16
0
int Board_show_board(int board_type, struct char_data *ch, char *arg, struct obj_data *board)
{
  int i;
  char tmp[MAX_STRING_LENGTH], buf[MAX_STRING_LENGTH];

  if (!ch->desc)
    return (0);

  one_argument(arg, tmp);

  if (!*tmp || !isname(tmp, board->name))
    return (0);

  if (GET_LEVEL(ch) < READ_LVL(board_type)) {
    send_to_char(ch, "You try but fail to understand the holy words.\r\n");
    return (1);
  }
  act("$n studies the board.", TRUE, ch, 0, 0, CommTarget::TO_ROOM);

  if (!num_of_msgs[board_type])
    send_to_char(ch, "This is a bulletin board.  Usage: READ/REMOVE <messg #>, WRITE <header>.\r\nThe board is empty.\r\n");
  else {
    size_t len = 0;
    int nlen;

    len = snprintf(buf, sizeof(buf),
		"This is a bulletin board.  Usage: READ/REMOVE <messg #>, WRITE <header>.\r\n"
		"You will need to look at the board to save your message.\r\n"
		"There are %d messages on the board.\r\n",
		num_of_msgs[board_type]);
#if NEWEST_AT_TOP
    for (i = num_of_msgs[board_type] - 1; i >= 0; i--) {
      if (!MSG_HEADING(board_type, i))
        goto fubar;

      nlen = snprintf(buf + len, sizeof(buf) - len, "%-2d : %s\r\n", num_of_msgs[board_type] - i, MSG_HEADING(board_type, i));
      if (len + nlen >= sizeof(buf) || nlen < 0)
        break;
      len += nlen;
    }
#else
    for (i = 0; i < num_of_msgs[board_type]; i++) {
      if (!MSG_HEADING(board_type, i))
        goto fubar;

      nlen = snprintf(buf + len, sizeof(buf) - len, "%-2d : %s\r\n", i + 1, MSG_HEADING(board_type, i));
      if (len + nlen >= sizeof(buf) || nlen < 0)
        break;
      len += nlen;
    }
#endif
    page_string(ch->desc, buf, TRUE);
  }
  return (1);

fubar:
  log("SYSERR: Board %d is fubar'd.", board_type);
  send_to_char(ch, "Sorry, the board isn't working.\r\n");
  return (1);
}
ProcessParamsTable *next_process_param( 
        const char *name, 
        const char *type,
            const char *fmt, ... )
{
  ProcessParamsTable *pp;
  va_list ap;
  pp = calloc( 1, sizeof( *pp ) );

  if ( ! pp )
  {
    perror( "next_process_param" );
    exit( 1 );
  }
  strncpy( pp->program, PROGRAM_NAME, LIGOMETA_PROGRAM_MAX );
  if ( ! strcmp( name, "userTag" ) || ! strcmp( name, "user-tag" ) )
    snprintf( pp->param, LIGOMETA_PARAM_MAX, "-userTag" );
  else
    snprintf( pp->param, LIGOMETA_PARAM_MAX, "--%s", name );
  strncpy( pp->type, type, LIGOMETA_TYPE_MAX );
  va_start( ap, fmt );
  vsnprintf( pp->value, LIGOMETA_VALUE_MAX, fmt, ap );
  va_end( ap );

  return pp;
}
Example #18
0
/**
 * @brief Fills in single XML column in the monitoring table
 *
 * @param val numerical value to be put into the column
 * @param data place to put formatted column into
 * @param sz_data available size for the column
 * @param is_monitored if true then \a val holds valid data
 * @param is_column_present if true then corresponding event is
 *        selected for display
 * @param node_name defines XML node name for the column
 * @return Number of characters added to \a data excluding NULL
 */
static size_t
fillin_xml_column(const double val, char data[], const size_t sz_data,
                  const int is_monitored, const int is_column_present,
                  const char node_name[])
{
        size_t offset = 0;

        if (is_monitored) {
                /**
                 * This is monitored and we have the data
                 */
                snprintf(data, sz_data - 1, "\t<%s>%.1f</%s>\n",
                         node_name, val, node_name);
                offset = strlen(data);
        } else if (is_column_present) {
                /**
                 * The column exists though there's no data
                 */
                snprintf(data, sz_data - 1, "\t<%s></%s>\n",
                         node_name, node_name);
                offset = strlen(data);
        }

        return offset;
}
Example #19
0
static int ixgbe_linkstat(char *page, char __always_unused **start,
			  off_t __always_unused off, int count,
			  int __always_unused *eof, void *data)
{
	struct ixgbe_hw *hw;
	struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
	int bitmask = 0;
	u32 link_speed;
	bool link_up = false;

	if (adapter == NULL)
		return snprintf(page, count, "error: no adapter\n");

	hw = &adapter->hw;
	if (hw == NULL)
		return snprintf(page, count, "error: no hw data\n");

	if (!test_bit(__IXGBE_DOWN, &adapter->state))
		bitmask |= 1;

	if (hw->mac.ops.check_link)
		hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
	else
		/* always assume link is up, if no check link function */
		link_up = true;
	if (link_up)
		bitmask |= 2;

	if (adapter->old_lsc != adapter->lsc_int) {
		bitmask |= 4;
		adapter->old_lsc = adapter->lsc_int;
	}

	return snprintf(page, count, "0x%X\n", bitmask);
}
Example #20
0
/*
 * Load .psqlrc file, if found.
 */
static void
process_psqlrc(char *argv0)
{
    char		home[MAXPGPATH];
    char		rc_file[MAXPGPATH];
    char		my_exec_path[MAXPGPATH];
    char		etc_path[MAXPGPATH];
    char	   *envrc = getenv("PSQLRC");

    if (find_my_exec(argv0, my_exec_path) < 0)
    {
        fprintf(stderr, _("%s: could not find own program executable\n"), argv0);
        exit(EXIT_FAILURE);
    }

    get_etc_path(my_exec_path, etc_path);

    snprintf(rc_file, MAXPGPATH, "%s/%s", etc_path, SYSPSQLRC);
    process_psqlrc_file(rc_file);

    if (envrc != NULL && strlen(envrc) > 0)
    {
        /* might need to free() this */
        char	   *envrc_alloc = pstrdup(envrc);

        expand_tilde(&envrc_alloc);
        process_psqlrc_file(envrc_alloc);
    }
    else if (get_home_path(home))
    {
        snprintf(rc_file, MAXPGPATH, "%s/%s", home, PSQLRC);
        process_psqlrc_file(rc_file);
    }
}
Example #21
0
static void VerifyProcesses(EvalContext *ctx, Attributes a, Promise *pp)
{
    CfLock thislock;
    char lockname[CF_BUFSIZE];

    if (a.restart_class)
    {
        snprintf(lockname, CF_BUFSIZE - 1, "proc-%s-%s", pp->promiser, a.restart_class);
    }
    else
    {
        snprintf(lockname, CF_BUFSIZE - 1, "proc-%s-norestart", pp->promiser);
    }

    thislock = AcquireLock(ctx, lockname, VUQNAME, CFSTARTTIME, a.transaction, pp, false);

    if (thislock.lock == NULL)
    {
        return;
    }

    EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_THIS, "promiser", pp->promiser, DATA_TYPE_STRING);
    PromiseBanner(pp);
    VerifyProcessOp(ctx, PROCESSTABLE, a, pp);
    EvalContextVariableRemoveSpecial(ctx, SPECIAL_SCOPE_THIS, "promiser");

    YieldCurrentLock(thislock);
}
Example #22
0
void sagan_ext_thread ( _SaganEvent *Event )
{

    int in[2];
    int out[2];
    int n, pid;
    char buf[MAX_SYSLOGMSG];
    char data[MAX_SYSLOGMSG];
    char *tmpref = NULL;
    char tmp[6];

    if ( debug->debugexternal ) Sagan_Log(S_WARN, "[%s, line %d] In sagan_ext_thread()", __FILE__, __LINE__);

    if ( config->sagan_exttype == 1 )
        {

            /* Parsable */

            tmpref = Reference_Lookup( Event->found, 1 );

            if ( Event->drop == 1 )
                {
                    snprintf(tmp, sizeof(tmp), "True");
                }
            else
                {
                    snprintf(tmp, sizeof(tmp), "False");
                }

            snprintf(data, sizeof(data), "\nID:%lu:%s\nMessage:%s\nClassification:%s\nDrop:%s\nPriority:%d\nDate:%s\nTime:%s\nSource:%s\nSource Port:%d\nDestination:%s\nDestination Port:%d\nFacility:%s\nSyslog Priority:%s\n%sSyslog message:%s\n", Event->generatorid, Event->sid, Event->f_msg, Event->class, tmp, Event->pri, Event->date, Event->time, Event->ip_src, Event->src_port,  Event->ip_dst, Event->dst_port, Event->facility, Event->priority, tmpref, Event->message);

        }
Example #23
0
static void Par_GetBoundary (void)
  {
   const char *PtrToBoundary;

   /*
   If data are received ==> the environment variable CONTENT_TYPE will hold:
   multipart/form-data; boundary=---------------------------7d13ca2e948
   Gbl.Boundary.StrWithCRLF will be set to:
			  "\r\n-----------------------------7d13ca2e948"
   I.e. 0x0D, 0x0A, '-', '-', and boundary.
   */
   /***** Get pointer to boundary string *****/
   PtrToBoundary = strstr (getenv ("CONTENT_TYPE"),"boundary=") + strlen ("boundary=");

   /***** Check that boundary string is not too long *****/
   if (2 + 2 + strlen (PtrToBoundary) > Par_MAX_BYTES_BOUNDARY_WITH_CR_LF)
      Lay_ShowErrorAndExit ("Delimiter string too long.");

   /***** Create boundary strings *****/
   snprintf (Gbl.Boundary.StrWithoutCRLF,sizeof (Gbl.Boundary.StrWithoutCRLF),
	     "--%s",
	     PtrToBoundary);
   snprintf (Gbl.Boundary.StrWithCRLF,sizeof (Gbl.Boundary.StrWithCRLF),
	     "%c%c%s",
	     0x0D,0x0A,Gbl.Boundary.StrWithoutCRLF);

   /***** Compute lengths *****/
   Gbl.Boundary.LengthWithoutCRLF = strlen (Gbl.Boundary.StrWithoutCRLF);
   Gbl.Boundary.LengthWithCRLF    = 2 + Gbl.Boundary.LengthWithoutCRLF;
  }
Example #24
0
void shutdown_kbdfront(struct kbdfront_dev *dev)
{
    char* err = NULL, *err2;
    XenbusState state;

    char path[strlen(dev->backend) + strlen("/state") + 1];
    char nodename[strlen(dev->nodename) + strlen("/request-abs-pointer") + 1];

    printk("close kbd: backend at %s\n",dev->backend);

    snprintf(path, sizeof(path), "%s/state", dev->backend);
    snprintf(nodename, sizeof(nodename), "%s/state", dev->nodename);
    if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosing)) != NULL) {
        printk("shutdown_kbdfront: error changing state to %d: %s\n",
               XenbusStateClosing, err);
        goto close_kbdfront;
    }
    state = xenbus_read_integer(path);
    while (err == NULL && state < XenbusStateClosing)
        err = xenbus_wait_for_state_change(path, &state, &dev->events);
    free(err);

    if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosed)) != NULL) {
        printk("shutdown_kbdfront: error changing state to %d: %s\n",
               XenbusStateClosed, err);
        goto close_kbdfront;
    }
    state = xenbus_read_integer(path);
    while (state < XenbusStateClosed) {
        err = xenbus_wait_for_state_change(path, &state, &dev->events);
        free(err);
    }

    if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateInitialising)) != NULL) {
        printk("shutdown_kbdfront: error changing state to %d: %s\n",
               XenbusStateInitialising, err);
        goto close_kbdfront;
    }
    state = xenbus_read_integer(path);
    while (err == NULL && (state < XenbusStateInitWait || state >= XenbusStateClosed))
        err = xenbus_wait_for_state_change(path, &state, &dev->events);

close_kbdfront:
    free(err);
    err2 = xenbus_unwatch_path_token(XBT_NIL, path, path);
    free(err2);

    snprintf(nodename, sizeof(nodename), "%s/page-ref", dev->nodename);
    err2 = xenbus_rm(XBT_NIL, nodename);
    free(err2);
    snprintf(nodename, sizeof(nodename), "%s/event-channel", dev->nodename);
    err2 = xenbus_rm(XBT_NIL, nodename);
    free(err2);
    snprintf(nodename, sizeof(nodename), "%s/request-abs-pointer", dev->nodename);
    err2 = xenbus_rm(XBT_NIL, nodename);
    free(err2);

    if (!err)
        free_kbdfront(dev);
}
Example #25
0
// Log error messages to system specific places
//
void log_message_error(const char* msg) {
    char evt_msg[2048];
    char* time_string = time_to_string(dtime());
#ifdef _WIN32
    char buf[1024];
    snprintf(evt_msg, sizeof(evt_msg),
             "%s %s\n"
             "GLE: %s\n",
             time_string, msg,
             windows_format_error_string(GetLastError(), buf, sizeof(buf))
            );
#else
    snprintf(evt_msg, sizeof(evt_msg),
             "%s %s\n",
             time_string, msg
            );
#endif
    if (!gstate.executing_as_daemon) {
        fprintf(stderr, "%s", evt_msg);
    } else {
#ifdef _WIN32
        LogEventErrorMessage(evt_msg);
#elif defined(__EMX__)
#elif defined (__APPLE__)
#elif defined (ANDROID)
        __android_log_print(ANDROID_LOG_ERROR, "BOINC", evt_msg);
#else
        syslog(LOG_DAEMON|LOG_ERR, "%s", evt_msg);
#endif
    }
}
Example #26
0
static int group_list_function_read(struct ast_channel *chan, const char *cmd,
                                    char *data, char *buf, size_t len)
{
    struct ast_group_info *gi = NULL;
    char tmp1[1024] = "";
    char tmp2[1024] = "";

    if (!chan)
        return -1;

    ast_app_group_list_rdlock();

    for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
        if (gi->chan != chan)
            continue;
        if (!ast_strlen_zero(tmp1)) {
            ast_copy_string(tmp2, tmp1, sizeof(tmp2));
            if (!ast_strlen_zero(gi->category))
                snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, gi->group, gi->category);
            else
                snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, gi->group);
        } else {
            if (!ast_strlen_zero(gi->category))
                snprintf(tmp1, sizeof(tmp1), "%s@%s", gi->group, gi->category);
            else
                snprintf(tmp1, sizeof(tmp1), "%s", gi->group);
        }
    }

    ast_app_group_list_unlock();

    ast_copy_string(buf, tmp1, len);

    return 0;
}
Example #27
0
static int _handle_list_command(t_connection * conn, int numparams, char ** params, char * text)
{
    char temp[MAX_IRC_MESSAGE_LEN];

    irc_send(conn,RPL_LISTSTART,"Channel :Users Names"); /* backward compatibility */

    if (numparams==0) {
        t_elem const * curr;

        LIST_TRAVERSE_CONST(channellist(),curr)
        {
            t_channel const * channel = (const t_channel*)elem_get_data(curr);
            char const * tempname;
            char * topic = channel_get_topic(channel_get_name(channel));

            tempname = irc_convert_channel(channel,conn);

            /* FIXME: AARON: only list channels like in /channels command */
            if (topic) {
                if (std::strlen(tempname)+1+20+1+1+std::strlen(topic)<MAX_IRC_MESSAGE_LEN)
                    snprintf(temp, sizeof(temp), "%s %u :%s",tempname,channel_get_length(channel),topic);
                else
                    eventlog(eventlog_level_warn,__FUNCTION__,"LISTREPLY length exceeded");
            }
            else {
                if (std::strlen(tempname)+1+20+1+1<MAX_IRC_MESSAGE_LEN)
                    snprintf(temp, sizeof(temp), "%s %u :",tempname,channel_get_length(channel));
                else
                    eventlog(eventlog_level_warn,__FUNCTION__,"LISTREPLY length exceeded");
            }
            irc_send(conn,RPL_LIST,temp);
        }
static void topicNameFromThingAndAction(char *pTopic, const char *pThingName, ShadowActions_t action,
										ShadowAckTopicTypes_t ackType) {

	char actionBuf[10];
	char ackTypeBuf[10];

	if(SHADOW_GET == action) {
		strncpy(actionBuf, "get", 10);
	} else if(SHADOW_UPDATE == action) {
		strncpy(actionBuf, "update", 10);
	} else if(SHADOW_DELETE == action) {
		strncpy(actionBuf, "delete", 10);
	}

	if(SHADOW_ACCEPTED == ackType) {
		strncpy(ackTypeBuf, "accepted", 10);
	} else if(SHADOW_REJECTED == ackType) {
		strncpy(ackTypeBuf, "rejected", 10);
	}

	if(SHADOW_ACTION == ackType) {
		snprintf(pTopic, MAX_SHADOW_TOPIC_LENGTH_BYTES, "$aws/things/%s/shadow/%s", pThingName, actionBuf);
	} else {
		snprintf(pTopic, MAX_SHADOW_TOPIC_LENGTH_BYTES, "$aws/things/%s/shadow/%s/%s", pThingName, actionBuf,
				 ackTypeBuf);
	}
}
Example #29
0
char *
TimeString (time_t start, time_t end)
{
  static char datestr[255];
  char t1[64], t2[64];
  struct tm *tbuff;

  if (start)
    {
      tbuff = localtime (&start);
      if (!tbuff)
	{
	  perror ("Error time convert");
	  exit (250);
	}
      strftime (t1, 63, "%Y-%m-%d %H:%M:%S", tbuff);

      tbuff = localtime (&end);
      if (!tbuff)
	{
	  perror ("Error time convert");
	  exit (250);
	}
      strftime (t2, 63, "%Y-%m-%d %H:%M:%S", tbuff);

      snprintf (datestr, 254, "%s - %s", t1, t2);
    }
  else
    {
      snprintf (datestr, 254, "Time Window unknown");
    }
  datestr[254] = 0;
  return datestr;
}
Example #30
0
int op_scal8 (char *op, u8 code[], u8 len, char buf[], u8 buflen, u8 opts)  {
	char reg[8];

	if (len < 2) return -1;

	if (code[0] == 0x4)  {
		if ((opts & 0x1) == INTEL_FLAVOR)
			snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\tal,0x%x\n", op, code[1]);
		else
			snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t$0x%x,al\n", op, code[1]);

		return 0;
	}

	switch ((code[0] & 0xf8) >> 3)  {
		case 0x16:
			get_dstreg8 (code[0], reg, sizeof(reg), opts);
			
			if ((opts & 0x1) == INTEL_FLAVOR)
				snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t%s,0x%x\n", op, reg, code[1]);
			else
				snprintf (buf+strlen(buf), buflen-strlen(buf), "%s\t$0x%x,%s\n", op, code[1], reg);
			break;
	}

	return 0;
}