Пример #1
0
/*
 * run /etc/rc. The environment is passed to the script, so the RC environment
 * variable can be used to decide what to do. RC may be set from LILO.
 */
static int do_rc(void)
{
	int rc;

	rc = do_command(_PATH_BSHELL, _PATH_RC, 1);
	if (rc)
		return(rc);
#ifdef CONFIG_USER_INIT_RUN_FIREWALL
	rc = do_command(_PATH_FIREWALL, "-i", 1);
	if (rc)
		err(_PATH_FIREWALL " failed!");
#endif
#ifdef CONFIG_USER_FLATFSD_FLATFSD
	rc = do_command(_PATH_BSHELL, _PATH_CONFIGRC, 1);
	if (rc)
		err(_PATH_CONFIGRC " failed!");
#endif
#ifdef CONFIG_USER_INIT_RUN_FIREWALL
	rc = do_command(_PATH_FIREWALL, NULL, 0);
	if (rc)
		err(_PATH_FIREWALL " failed!");
#endif
#ifdef INCLUDE_TIMEZONE
	/* We read the timezone file here, because the flat file system
	 * has probably been created by now.
	 */
	set_tz();
#endif
	return(0);
}
Пример #2
0
/* Use time zone TZ to compute mktime (TM).  */
time_t
mktime_z (timezone_t tz, struct tm *tm)
{
  if (!tz)
    return timegm (tm);
  else
    {
      timezone_t old_tz = set_tz (tz);
      if (old_tz)
        {
          time_t t = mktime (tm);
#if HAVE_TM_ZONE || HAVE_TZNAME
          time_t badtime = -1;
          struct tm tm_1;
          if ((t != badtime
               || (localtime_r (&t, &tm_1) && equal_tm (tm, &tm_1)))
              && !save_abbr (tz, tm))
            t = badtime;
#endif
          if (revert_tz (old_tz))
            return t;
        }
      return -1;
    }
}
Пример #3
0
time_t c_parse_unix_time_gmt(char *fmt, char *src) {
    struct tm dst;
    char *local_tz;
    init_locale();
    memset(&dst, 0, sizeof(struct tm));
    local_tz = set_tz_utc();
#if THREAD_SAFE
    strptime_l(src, fmt, &dst, c_locale);
#else
    strptime(src, fmt, &dst);
#endif
    set_tz(local_tz);
    return timegm(&dst);
}
Пример #4
0
/* Use time zone TZ to compute localtime_r (T, TM).  */
struct tm *
localtime_rz (timezone_t tz, time_t const *t, struct tm *tm)
{
  if (!tz)
    return gmtime_r (t, tm);
  else
    {
      timezone_t old_tz = set_tz (tz);
      if (old_tz)
        {
          bool abbr_saved = localtime_r (t, tm) && save_abbr (tz, tm);
          if (revert_tz (old_tz) && abbr_saved)
            return tm;
        }
      return NULL;
    }
}
Пример #5
0
size_t c_format_unix_time_gmt(char *fmt, time_t src, char* dst, int siz) {
    struct tm tim;
    char *local_tz;
    size_t dst_size;

    init_locale();
    gmtime_r(&src, &tim);

    local_tz = set_tz_utc();
#if THREAD_SAFE
    dst_size = strftime_l(dst, siz, fmt, &tim, c_locale);
#else
    dst_size = strftime(dst, siz, fmt, &tim);
#endif
    set_tz(local_tz);
    return dst_size;
}
Пример #6
0
/* Use time zone TZ to compute localtime_r (T, TM).  */
struct tm *
localtime_rz (timezone_t tz, time_t const *t, struct tm *tm)
{
  if (!tz)
    return gmtime_r (t, tm);
  else
    {
      timezone_t old_tz = set_tz (tz);
      if (old_tz)
        {
          tm = localtime_r (t, tm);
          if (tm && !save_abbr (tz, tm))
            tm = NULL;
          if (revert_tz (old_tz))
            return tm;
        }
      return NULL;
    }
}
Пример #7
0
function router(request, res){
	try{
		switch(request.path){
			case "param/TZ":
				set_tz(request, res);
			case "param/12":
				set_twelve(request, res);
			case "alert":
				//for emergency alerts
				//not implemented yet
				alert(request, res) ;//send dummy response
			default:
				if (request.method == "OPTIONS" && request.path == ""){
					res.header("ALLOW", "GET,PUT,DELETE,OPTIONS");
					res.send(200, "OK");
				}
				res.send(400, "Bad Request");
		}
	}
	catch(e){
		res.send(500, "Server Error" + e);
	}
}
Пример #8
0
lsb_lua_sandbox* lsb_create(void *parent,
                            const char *lua_file,
                            const char *cfg,
                            lsb_logger logger)
{
  if (!lua_file) {
    if (logger) logger(__FUNCTION__, 3, "lua_file must be specified");
    return NULL;
  }

  if (!set_tz()) {
    if (logger) logger(__FUNCTION__, 3, "fail to set the TZ to UTC");
    return NULL;
  }

  set_random_seed();

  lsb_lua_sandbox *lsb = malloc(sizeof*lsb);
  if (!lsb) {
    if (logger) logger(__FUNCTION__, 3, "memory allocation failed");
    return NULL;
  }
  memset(lsb->usage, 0, sizeof(lsb->usage));

#ifdef LUA_JIT
  lsb->lua = luaL_newstate();
#else
  lsb->lua = lua_newstate(memory_manager, lsb);
#endif

  if (!lsb->lua) {
    if (logger) logger(__FUNCTION__, 3, "lua state creation failed");
    free(lsb);
    return NULL;
  }

  // add the config to the lsb_config registry table
  lua_State *lua_cfg = load_sandbox_config(cfg, logger);
  if (!lua_cfg) {
    lua_close(lsb->lua);
    free(lsb);
    return NULL;
  }
  lua_pushnil(lua_cfg);
  lua_pushvalue(lua_cfg, LUA_GLOBALSINDEX);
  copy_table(lsb->lua, lua_cfg, logger);
  lua_pop(lua_cfg, 2);
  lua_close(lua_cfg);
  size_t ml = get_usage_config(lsb->lua, -1, "memory_limit");
  size_t il = get_usage_config(lsb->lua, -1, "instruction_limit");
  size_t ol = get_usage_config(lsb->lua, -1, "output_limit");
  lua_setfield(lsb->lua, LUA_REGISTRYINDEX, LSB_CONFIG_TABLE);
  lua_pushcclosure(lsb->lua, &read_config, 0);
  lua_setglobal(lsb->lua, "read_config");

  lua_pushlightuserdata(lsb->lua, (void *)lsb);
  lua_pushcclosure(lsb->lua, &output, 1);
  lua_setglobal(lsb->lua, "output");

  lsb->parent = parent;
  lsb->usage[LSB_UT_MEMORY][LSB_US_LIMIT] = ml;
  lsb->usage[LSB_UT_INSTRUCTION][LSB_US_LIMIT] = il;
  lsb->usage[LSB_UT_OUTPUT][LSB_US_LIMIT] = ol;
  lsb->state = LSB_UNKNOWN;
  lsb->error_message[0] = 0;
  lsb->lua_file = malloc(strlen(lua_file) + 1);
  lsb->state_file = NULL;

  if (!lsb->lua_file || lsb_init_output_buffer(&lsb->output, ol)) {
    if (logger) logger(__FUNCTION__, 3, "memory allocation failed failed");
    lsb_free_output_buffer(&lsb->output);
    free(lsb->lua_file);
    lua_close(lsb->lua);
    lsb->lua = NULL;
    free(lsb);
    return NULL;
  }
  strcpy(lsb->lua_file, lua_file);
  return lsb;
}
Пример #9
0
int timezone_from_string (const char *name, const char *uri, const char *s)
{
  set_tz (s);
  return 0;
}