void
_ecore_config_db_write(Ecore_Config_DB_File *db, Ecore_Config_Prop *e)
{
   char *prev_locale= NULL;
   char *val = NULL;
   char *r = NULL;
   int num;
   
   prev_locale = setlocale(LC_NUMERIC, "C");

   switch (e->type) 
     {
	case ECORE_CONFIG_INT:
	   esprintf(&val, "%i", _ecore_config_int_get(e));
	   break;
	case ECORE_CONFIG_BLN:
	   esprintf(&val, "%i", _ecore_config_boolean_get(e));
	   break;
	case ECORE_CONFIG_FLT:
	   esprintf(&val, "%16.16f", _ecore_config_float_get(e));
	   break;
	case ECORE_CONFIG_STR: 
	   val = _ecore_config_string_get(e);
	   break;
	case ECORE_CONFIG_THM:
	   val = _ecore_config_theme_get(e);
	   break;
	case ECORE_CONFIG_RGB:
	   val = _ecore_config_argbstr_get(e);
	   break;
	default:
	   WRN("Type %d not handled", e->type);
     }

   if (prev_locale)
     {
	setlocale(LC_NUMERIC, prev_locale);
     }
   
   if(val)
     {
	num = esprintf(&r, "%c%c%s%c", (char) e->type, 0, val, 0);
	if(num)
	  eet_write(db->ef, e->key, r, num, 1);
	free(r);
     }

   free(val);
}
Exemple #2
0
//---------------------------------------------------------------------------------------
void sec_printf(const char *fmt, ...)
{
    int lvl = 0;
    char *text = pr_cache;
    va_list args;

    va_start(args, fmt);

    vsnprintf(pr_cache, sizeof(pr_cache), fmt, args);

    if (text[0] == KERN_SOH_ASCII && text[1])
    {
        switch (text[1])
        {
        case '0' ... '7':
            lvl = text[1] - '0';
            text += 2;
            break;
        }
    }
    if (lvl <= pr_lvl)
    {
        esprintf(text);
    }

    va_end(args);
}
char *linux_bootchart_get_uptime () {
    char *tmp = readfile ("/proc/uptime");
    char *uptime = NULL;

    if (tmp) {
        char **t = str2set (' ', tmp);
        if (t) {
            if (t[0] && t[1]) {
                char **r = str2set ('.', t[0]);

                if (r) {
                    if (r[0] && r[1]) {
                        char buffer[30];
                        esprintf (buffer, 30, "%s%s", r[0], r[1]);

                        uptime = estrdup (buffer);
                    }

                    free (r);
                }
            }

            free (t);
        }

        free (tmp);
    }

    return uptime;
}
Exemple #4
0
static int
lock_file_1 (char *lfname, int force)
{
  int err;
  int symlink_errno;
  USE_SAFE_ALLOCA;

  /* Call this first because it can GC.  */
  printmax_t boot = get_boot_time ();

  Lisp_Object luser_name = Fuser_login_name (Qnil);
  char const *user_name = STRINGP (luser_name) ? SSDATA (luser_name) : "";
  Lisp_Object lhost_name = Fsystem_name ();
  char const *host_name = STRINGP (lhost_name) ? SSDATA (lhost_name) : "";
  ptrdiff_t lock_info_size = (strlen (user_name) + strlen (host_name)
			      + 2 * INT_STRLEN_BOUND (printmax_t)
			      + sizeof "@.:");
  char *lock_info_str = SAFE_ALLOCA (lock_info_size);
  printmax_t pid = getpid ();

  esprintf (lock_info_str, boot ? "%s@%s.%"pMd":%"pMd : "%s@%s.%"pMd,
	    user_name, host_name, pid, boot);

  err = symlink (lock_info_str, lfname);
  if (errno == EEXIST && force)
    {
      unlink (lfname);
      err = symlink (lock_info_str, lfname);
    }

  symlink_errno = errno;
  SAFE_FREE ();
  errno = symlink_errno;
  return err == 0;
}
Exemple #5
0
char               *
_ecore_config_argbstr_get(Ecore_Config_Prop *e)
{
   char               *r;

   r = NULL;
   esprintf(&r, "#%08x", _ecore_config_int_get(e));
   return r;
}
char *linux_bootchart_update_st (char *st, char *uptime) {
    char *t = readfile ("/proc/stat");
    if (t) {
        size_t len = strlen (uptime) + strlen (t) + 4 + (st ? strlen (st) : 0);
        char *tx = emalloc (len);

        if (st) {
            esprintf (tx, len, "%s\n%s\n%s\n", st, uptime, t);
            free (st);
        } else {
            esprintf (tx, len, "%s\n%s\n", uptime, t);
        }

        free (t);

        st = tx;
    }

    return st;
}
char *linux_bootchart_update_ds (char *ds, char *uptime) {
    char *t = readfile ("/proc/diskstats");
    if (t) {
        size_t len = strlen (uptime) + strlen (t) + 4 + (ds ? strlen (ds) : 0);
        char *tx = emalloc (len);

        if (ds) {
            esprintf (tx, len, "%s\n%s\n%s\n", ds, uptime, t);
            free (ds);
        } else {
            esprintf (tx, len, "%s\n%s\n", uptime, t);
        }

        free (t);

        ds = tx;
    }

    return ds;
}
Exemple #8
0
/**
 * Retrieves the key as a string.
 * @param   key The property key.
 * @return  Returns a character array in the form of 'key:type=value'.  @c NULL
 *          is returned if the property does not exist.
 * @ingroup Ecore_Config_Get_Group
 */
EAPI char               *
ecore_config_as_string_get(const char *key)
{
   Ecore_Config_Prop  *e;
   char               *val;
   char               *r;

   val = NULL;
   r = NULL;
   if (!(e = ecore_config_get(key)))
      ERR("no such property, \"%s\"...", key);
   else
     {
	switch (e->type)
	   {
	     case ECORE_CONFIG_NIL:
		val = strdup("<nil>");
		break;
	     case ECORE_CONFIG_INT:
		esprintf(&val, "%ld",    _ecore_config_int_get(e));
		break;
	     case ECORE_CONFIG_BLN:
		esprintf(&val, "%ld",    _ecore_config_boolean_get(e));
		break;
	     case ECORE_CONFIG_FLT:
		esprintf(&val, "%lf",    _ecore_config_float_get(e));
		break;
	     case ECORE_CONFIG_STR:
		esprintf(&val, "\"%s\"", _ecore_config_string_get(e));
		break;
	     case ECORE_CONFIG_RGB:
		esprintf(&val, "#%08x",  _ecore_config_int_get(e));
		break;
	     case ECORE_CONFIG_THM:
		esprintf(&val, "\"%s\"", _ecore_config_theme_get(e));
		break;
	     case ECORE_CONFIG_SCT:
		break;
	     default:
		esprintf(&r, "%s:unknown_type", key);
		break;
	   }
	if (val)
	   {
	     esprintf(&r, "%s:%s=%s", key, _ecore_config_type[e->type], val);
	     free(val);
	   }
     }
   return r;
}
int linux_hwclock_run() {
 if (!linux_hwclock_enabled) {
  linux_hwclock_enabled = 1;
  char *options = cfg_getstring ("configuration-services-hwclock/options", NULL);
  if (!options) options = "--utc";
  char tmp [BUFFERSIZE];

  esprintf (tmp, BUFFERSIZE, "/sbin/hwclock --hctosys %s", options);

  system (tmp);
 }

 return status_ok;
}
int linux_hwclock_shutdown() {
 if (linux_hwclock_enabled) {
   char *options = cfg_getstring ("configuration-services-hwclock/options", NULL);
  if (!options) options = "--utc";
  char tmp [BUFFERSIZE];

  esprintf (tmp, BUFFERSIZE, "/sbin/hwclock --systohc %s", options);

  system (tmp);

  linux_hwclock_enabled = 0;
 }

 return status_ok;
}
int checkpoint_scanmodules (struct lmodule *list) {
 struct cfgnode *node = NULL;

/* scan all modes... */
 while ((node = cfg_findnode ("mode-enable", 0, node))) {
  if (node->mode && node->mode->arbattrs) {
   size_t i = 0;
   char do_add = 0;
   char *base = NULL;
   uintptr_t cooldown = 0;

   for (; node->mode->arbattrs[i]; i+=2) {
    if (strmatch (node->mode->arbattrs[i], "wait-for-base") && parse_boolean (node->mode->arbattrs[i+1])) {
     do_add = 1;
    } else if (strmatch (node->mode->arbattrs[i], "cooldown")) {
     cooldown = parse_integer (node->mode->arbattrs[i+1]);
    } else if (strmatch (node->mode->arbattrs[i], "base")) {
     base = node->mode->arbattrs[i+1];
    }
   }

   if (do_add) {
    char buffer[BUFFERSIZE];

    esprintf (buffer, BUFFERSIZE, "checkpoint-mode-%s", node->mode->id);

    if (checkpoint_scanmodules_check_update (list, buffer)) {
     continue;
    } else {
     struct smodule *sm = emalloc (sizeof (struct smodule));
     char **base_services = checkpoint_scanmodules_find_services_from_modes (NULL, base);
     char **services = checkpoint_scanmodules_find_services_from_mode (NULL, node->mode->id);
     struct lmodule *nm;

     memset (sm, 0, sizeof (struct smodule));

     sm->rid = estrdup (buffer);
     if (checkpoint_count < CHECKPOINT_NAME_COUNT) {
      esprintf (buffer, BUFFERSIZE, "Checkpoint %s", checkpoint_names[checkpoint_count]);
      checkpoint_count++;
     } else {
      esprintf (buffer, BUFFERSIZE, "Checkpoint %i", checkpoint_count);
      checkpoint_count++;
     }
     sm->name = estrdup (buffer);

     if (base_services) {
      char *comb = set2str ('|', (const char **)base_services);
      size_t aflen = strlen (comb) + 5;
      char *af = emalloc (aflen);

      esprintf (af, aflen, "^(%s)$", comb);

      sm->si.after = str2set ('\0', af);

      free (comb);
      free (base_services);
      free (af);
     }

     if (services) {
      char *comb = set2str ('|', (const char **)services);
      size_t belen = strlen (comb) + 5;
      char *be = emalloc (belen);

      esprintf (be, belen, "^(%s)$", comb);

      sm->si.before = str2set ('\0', be);

      free (comb);
      free (services);
      free (be);
     }

     sm->eiversion = EINIT_VERSION;
     sm->eibuild = BUILDNUMBER;
     sm->configure = checkpoint_module_configure;
     sm->mode = einit_module_generic | einit_feedback_job;

     if ((nm = mod_add (NULL, sm))) {
      nm->param = (void *)cooldown;
     }
    }
   }
  }
 }

 return status_ok;
}
int einit_feedback_visual_fbsplash_enable () {
 char *tmp = NULL, *fbtheme = NULL, *fbmode = "silent";
 char freetheme = 0, freemode = 0, have_verbose_tty = 0;

 einit_feedback_visual_fbsplash_worker_thread_keep_running = 1;
 ethread_create (&fbsplash_thread, NULL, einit_feedback_visual_fbsplash_worker_thread, NULL);

 if (einit_initial_environment) {
/* check for kernel params */
  uint32_t i = 0;
  for (; einit_initial_environment[i]; i++) {
   if (strstr (einit_initial_environment[i], "splash=")) {
    char *params = estrdup(einit_initial_environment[i] + 7);

    if (params) {
     char **p = str2set (',', params);
     if (p) {
      for (i = 0; p[i]; i++) {
       char *sep = strchr (p[i], ':');
       if (sep) {
        *sep = 0;
        sep++;
        if (strmatch (p[i], "theme")) {
         fbtheme = estrdup (sep);
         freetheme = 1;
        }
       } else {
        fbmode = estrdup(p[i]);
        freemode = 1;
       }
      }
      free (p);
     }

     free (params);
    }

    break;
   }
  }
 }

/* if (fbtheme || (fbtheme = cfg_getstring ("configuration-feedback-visual-fbsplash-theme", NULL))) {
  char tmpx[BUFFERSIZE];

  esprintf (tmpx, BUFFERSIZE, "set theme %s", fbtheme);
  fbsplash_queue_comand(tmpx);

  if (freetheme) free (fbtheme);
//  notice (1, tmpx);
 }*/
 if ((tmp = cfg_getstring ("configuration-feedback-visual-fbsplash-daemon-ttys/silent", NULL))) {
  char tmpx[BUFFERSIZE];

  esprintf (tmpx, BUFFERSIZE, "set tty silent %s", tmp);
  fbsplash_queue_comand(tmpx);
 }

 if ((tmp = cfg_getstring ("configuration-feedback-visual-std-io/stdio", NULL))) {
  char *x = strstr (tmp, "tty");

  if (x && *(x+3)) {
   char tmpx[BUFFERSIZE];
   esprintf (tmpx, BUFFERSIZE, "set tty verbose %s", x+3);
   fbsplash_queue_comand(tmpx);

   have_verbose_tty = 1;
  }
 }
 if (!have_verbose_tty && (tmp = cfg_getstring ("configuration-feedback-visual-fbsplash-daemon-ttys/verbose", NULL))) {
  char tmpx[BUFFERSIZE];

  esprintf (tmpx, BUFFERSIZE, "set tty verbose %s", tmp);
  fbsplash_queue_comand(tmpx);
 }

 if ((tmp = cfg_getstring ("configuration-feedback-visual-fbsplash-daemon-fifo", NULL))) {
  fbsplash_fifo = tmp;
 }

 if (fbmode) {
  char tmpx[BUFFERSIZE];

  esprintf (tmpx, BUFFERSIZE, "set mode %s", fbmode);
  fbsplash_queue_comand(tmpx);

  fbsplash_queue_comand("repaint");

  if (freemode) free (fbmode);
//  notice (1, tmpx);
 }

 fbsplash_queue_comand("progress 0");

 return status_ok;
}
void einit_feedback_visual_fbsplash_einit_event_handler(struct einit_event *ev) {
 if ((ev->type == einit_core_mode_switching) && !fbsplash_disabled) {
  char tmp[BUFFERSIZE];

  fbsplash_queue_comand("set mode silent");
  fbsplash_queue_comand("progress 0");
  if (ev->para && ((struct cfgnode *)ev->para)->id) {
   esprintf (tmp, BUFFERSIZE, "set message eINIT now switching to mode %s", ((struct cfgnode *)ev->para)->id);
   fbsplash_queue_comand(tmp);
  }

  fbsplash_queue_comand("repaint");
 }
 if ((ev->type == einit_core_mode_switch_done) && !fbsplash_disabled) {
  char tmp[BUFFERSIZE];

  if (ev->para && ((struct cfgnode *)ev->para)->id) {
   esprintf (tmp, BUFFERSIZE, "set message mode %s now in effect.", ((struct cfgnode *)ev->para)->id);
   fbsplash_queue_comand(tmp);
  }
  fbsplash_queue_comand("progress 65535");
  fbsplash_queue_comand("repaint");
//  fbsplash_queue_comand("set mode verbose");
 }

 if ((ev->type == einit_core_service_update) && ev->set && !fbsplash_disabled) {
  char tmp[BUFFERSIZE];
  uint32_t i = 0;

  if (ev->status & status_working) {
   if (ev->task & einit_module_enable) {
    for (; ev->set[i]; i++) {
     esprintf (tmp, BUFFERSIZE, "update_svc %s svc_start", (char *)ev->set[i]);
     fbsplash_queue_comand(tmp);
    }
   } else if (ev->task & einit_module_disable) {
    for (; ev->set[i]; i++) {
     esprintf (tmp, BUFFERSIZE, "update_svc %s svc_stop", (char *)ev->set[i]);
     fbsplash_queue_comand(tmp);
    }
   }
  } else {
   if (ev->task & einit_module_enable) {
    if (ev->status & status_failed) {
     for (; ev->set[i]; i++) {
      esprintf (tmp, BUFFERSIZE, "update_svc %s svc_start_failed", (char *)ev->set[i]);
      fbsplash_queue_comand(tmp);
     }
    } else {
     for (; ev->set[i]; i++) {
      esprintf (tmp, BUFFERSIZE, "update_svc %s svc_started", (char *)ev->set[i]);
      fbsplash_queue_comand(tmp);
     }
    }
   } else if (ev->task & einit_module_disable) {
    if (ev->status & status_failed) {
     for (; ev->set[i]; i++) {
      esprintf (tmp, BUFFERSIZE, "update_svc %s svc_stop_failed", (char *)ev->set[i]);
      fbsplash_queue_comand(tmp);
     }
    } else {
     for (; ev->set[i]; i++) {
      esprintf (tmp, BUFFERSIZE, "update_svc %s svc_stopped", (char *)ev->set[i]);
      fbsplash_queue_comand(tmp);
     }
    }
   }
  }

// get_plan_progress(NULL): overall progress, 0.0-1.0
  esprintf (tmp, BUFFERSIZE, "progress %i", (int)(get_plan_progress (NULL) * 65535));
  fbsplash_queue_comand(tmp);

  fbsplash_queue_comand("repaint");
 }
}
void einit_feedback_visual_fbsplash_boot_event_handler(struct einit_event *ev) {
/* preinit */
 if ((ev->type == einit_boot_devices_available) && !(coremode & einit_mode_ipconly)) {
  if (einit_initial_environment) {
/* check for kernel params */
   uint32_t i = 0;
   char start_splash = 0, *ttypatch = NULL, *splashargs = NULL;

   for (; einit_initial_environment[i]; i++) {
    if (strstr (einit_initial_environment[i], "splash=") == einit_initial_environment[i]) {
     start_splash = 1;

     splashargs = einit_initial_environment[i]+7;

     if (!ttypatch)
      ttypatch = "tty1";
    } else if ((strstr (einit_initial_environment[i], "console=") == einit_initial_environment[i]) ||
               (strstr (einit_initial_environment[i], "einitty=") == einit_initial_environment[i])) {

     ttypatch = einit_initial_environment[i]+8;
    }
   }

   if (splashargs && *splashargs) {
    char *fbtheme = NULL/*, *fbmode = NULL*/;

    if (splashargs) {
     char **p = str2set (',', splashargs);
     if (p) {
      for (i = 0; p[i]; i++) {
       char *sep = strchr (p[i], ':');
       if (sep) {
        *sep = 0;
        sep++;
        if (strmatch (p[i], "theme")) {
         fbtheme = estrdup (sep);
        }
       }/* else {
        fbmode = estrdup(p[i]);
       }*/
      }
      free (p);
     }
    }

    if (fbtheme) {
     struct cfgnode *node = cfg_getnode ("configuration-feedback-visual-fbsplash-theme", NULL);

     if (node && node->arbattrs) {
      uint32_t u = 0;
      for (; node->arbattrs[u]; u+=2) {
       if (strmatch(node->arbattrs[u], "s")) {
        notice (4, "patching fbsplash theme to %s", fbtheme);

        node->arbattrs[u+1] = fbtheme;
        node->svalue = fbtheme;
       }
      }
     }
    }
/*    if (fbmode) {
    }*/
   } else
    fbsplash_disabled = 1;

   if (ttypatch && *ttypatch) {
    struct cfgnode *node = cfg_getnode ("configuration-feedback-visual-std-io", NULL);
    /* patch console */
    if (node && node->arbattrs) {
     uint32_t ri = 0;

     for (; node->arbattrs[ri]; ri+=2) {
      if (strmatch (node->arbattrs[ri], "stdio")) {
       char tx[BUFFERSIZE];

       if (ttypatch[0] == '/')
        esprintf (tx, BUFFERSIZE, "%s", ttypatch);
       else
        esprintf (tx, BUFFERSIZE, "/dev/%s", ttypatch);

       notice (4, "patching stdio output to go to %s", tx);

       node->arbattrs[ri+1] = estrdup(tx);
      } else if (strmatch (node->arbattrs[ri], "activate-vt")) {
       notice (4, "removing activate-vt= instruction");

       node->arbattrs = (char **)setdel ((void **)node->arbattrs, node->arbattrs[ri]);
       node->arbattrs = (char **)setdel ((void **)node->arbattrs, node->arbattrs[ri]);
      }
     }
    }
   }

   if (start_splash) {
    struct einit_event ee = evstaticinit(einit_core_change_service_status);

    ee.argv = (char **)setadd ((void **)ee.set, "splashd", SET_TYPE_STRING);
    ee.argv = (char **)setadd ((void **)ee.set, "enable", SET_TYPE_STRING);

    event_emit (&ee, einit_event_flag_broadcast);

    evstaticdestroy(ee);

    notice (4, "enabling feedack (fbsplash)");
    einit_feedback_visual_fbsplash_enable();
   }
  }
 }
}
void *linux_bootchart_thread (void *ignored) {
    struct cfgnode *node;
    char *save_to = "/var/log/bootchart.tgz";
    FILE *f;
    char try_acct = 1;
    signed int extra_wait = 0;

    if ((node = cfg_getnode ("configuration-bootchart-extra-waiting-time", NULL)) && node->value) {
        extra_wait = node->value;
    }

    char *buffer_ds = NULL;
    char *buffer_ps = NULL;
    char *buffer_st = NULL;

    while (!shutting_down && (linux_bootchart_have_thread || (extra_wait > 0))) {
        char *uptime = linux_bootchart_get_uptime();

        if (linux_bootchart_process_accounting && try_acct) {
            if (acct ("/dev/kernel_pacct") == -1)
                try_acct = 1;
        }

        if (uptime) {
            buffer_ds = linux_bootchart_update_ds (buffer_ds, uptime);
            buffer_ps = linux_bootchart_update_ps (buffer_ps, uptime);
            buffer_st = linux_bootchart_update_st (buffer_st, uptime);

            free (uptime);
            uptime = NULL;
        }

        usleep (linux_bootchart_sleep_time);
        if (!linux_bootchart_have_thread)
            extra_wait -= linux_bootchart_sleep_time;
    }

    if ((node = cfg_getnode ("configuration-bootchart-save-to", NULL)) && node->svalue) {
        save_to = node->svalue;
    }

    if (coremode & einit_mode_sandbox) {
        save_to = "bootchart.tgz";
    }

    mkdir ("/tmp/bootchart.einit", 0755);

    if (buffer_ds) {
        if ((f = fopen ("/tmp/bootchart.einit/proc_diskstats.log", "w"))) {
            fputs (buffer_ds, f);

            fclose (f);
        }

        free (buffer_ds);
        buffer_ds = NULL;
    }

    if (buffer_ps) {
        if ((f = fopen ("/tmp/bootchart.einit/proc_ps.log", "w"))) {
            fputs (buffer_ps, f);

            fclose (f);
        }

        free (buffer_ps);
        buffer_ps = NULL;
    }

    if (buffer_st) {
        if ((f = fopen ("/tmp/bootchart.einit/proc_stat.log", "w"))) {
            fputs (buffer_st, f);

            fclose (f);
        }

        free (buffer_st);
        buffer_st = NULL;
    }

    if (linux_bootchart_process_accounting) {
        char *r = readfile ("/dev/kernel_pacct");
        if (r) {
            if ((f = fopen ("/tmp/bootchart.einit/kernel_pacct", "w"))) {
                fputs (r, f);

                fclose (f);
            }

            unlink ("/dev/kernel_pacct");
        }

        acct(NULL);
    }

    if ((f = fopen ("/tmp/bootchart.einit/header", "w"))) {
        char *t, buffer[BUFFERSIZE];
        time_t ti = time(NULL);
        /* we're emulating bootchartd-0.8/0.9's format... */
        eputs ("version = 0.8\n", f);

        if (gethostname (buffer, BUFFERSIZE) == 0) {
            eprintf (f, "title = eINIT Boot Chart for %s, %s", buffer, ctime(&ti));
        } else {
            eprintf (f, "title = eINIT Boot Chart, %s", ctime(&ti));
        }

        fprintf (f, "system.uname = %s %s %s %s\n", osinfo.sysname, osinfo.release, osinfo.version, osinfo.machine);

        if ((t = readfile ("/etc/gentoo-release"))) {
            strtrim (t);
            eprintf (f, "system.release = %s\n", t);
            free (t);
        } else {
            eputs ("system.release = unknown\n", f);
        }

        if ((t = readfile ("/proc/cpuinfo"))) {
            char **r = str2set ('\n', t);
            char *n = NULL;
            int i;

            if (r) {
                for (i = 0; r[i]; i++) {
                    if (strstr (r[i], "model name") == r[i]) {
                        n = r[i];
                        break;
                    }
                }

                if (n)
                    eprintf (f, "system.cpu = %s\n", n);
                else
                    eputs ("system.cpu = unknown\n", f);
            }

            free (t);
        } else {
            eputs ("system.cpu = unknown\n", f);
        }

        if ((t = readfile ("/proc/cmdline"))) {
            eprintf (f, "system.kernel.options = %s\n", t);
            free (t);
        }

        fclose (f);
    }

    char buffer[BUFFERSIZE];
    if (coremode & einit_mode_sandbox) {
        esprintf (buffer, BUFFERSIZE, "export pwx=`pwd`; cd /tmp/bootchart.einit; tar czf \"${pwx}/%s\" *", save_to);
    } else {
        esprintf (buffer, BUFFERSIZE, "cd /tmp/bootchart.einit; tar czf %s *", save_to);
    }
    system (buffer);

    unlink_recursive ("/tmp/bootchart.einit/", 1);

    char *di = cfg_getstring ("configuration-bootchart-chart-directory", NULL);
    char *fo = cfg_getstring ("configuration-bootchart-chart-format", NULL);
    esprintf (buffer, BUFFERSIZE, "bootchart -o %s -f %s %s", di, fo, save_to);

    return NULL;
}
char *linux_bootchart_update_ps (char *ps, char *uptime) {
    DIR *d;
    struct dirent *e;
    char **data = NULL;

    d = opendir ("/proc");
    if (d != NULL) {
        while ((e = readdir (d))) {
            char *t, *u, *da = NULL;
            if (strmatch (e->d_name, ".") || strmatch (e->d_name, "..")) {
                continue;
            }

            if ((t = joinpath ("/proc/", e->d_name))) {
                if ((u = joinpath (t, "stat"))) {
                    struct stat st;
                    if (!stat (u, &st)) {
                        da = readfile (u);
                    }

                    free (u);
                }

                /*    if ((u = joinpath (t, "cmdline"))) {
                     struct stat st;
                     if (!stat (u, &st)) {
                      char *ru = readfile (u);

                      if (strstr (ru, )) {
                       linux_bootchart_have_thread = 0;
                      }
                     }

                     free (u);
                    }*/

                free (t);
            }

            if (da) {
                data = (char **)setadd ((void **)data, da, SET_TYPE_STRING);
                free (da);
                da = NULL;
            }
        }

        closedir(d);
    }

    if (data) {
        char *t = set2str ('\n', (const char **)data);

        if (t) {
            size_t len = strlen (uptime) + strlen (t) + 4 + (ps ? strlen (ps) : 0);
            char *tx = emalloc (len);

            if (ps) {
                esprintf (tx, len, "%s\n%s\n%s\n", ps, uptime, t);
                free (ps);
            } else {
                esprintf (tx, len, "%s\n%s\n", uptime, t);
            }

            free (t);

            ps = tx;
        }

        free (data);
    }

    return ps;
}
Exemple #17
0
void
lock_file (Lisp_Object fn)
{
  register Lisp_Object attack, orig_fn, encoded_fn;
  register char *lfname, *locker;
  ptrdiff_t locker_size;
  lock_info_type lock_info;
  printmax_t pid;
  struct gcpro gcpro1;
  USE_SAFE_ALLOCA;

  /* Don't do locking if the user has opted out.  */
  if (! create_lockfiles)
    return;

  /* Don't do locking while dumping Emacs.
     Uncompressing wtmp files uses call-process, which does not work
     in an uninitialized Emacs.  */
  if (! NILP (Vpurify_flag))
    return;

  orig_fn = fn;
  GCPRO1 (fn);
  fn = Fexpand_file_name (fn, Qnil);
  encoded_fn = ENCODE_FILE (fn);

  /* Create the name of the lock-file for file fn */
  MAKE_LOCK_NAME (lfname, encoded_fn);

  /* See if this file is visited and has changed on disk since it was
     visited.  */
  {
    register Lisp_Object subject_buf;

    subject_buf = get_truename_buffer (orig_fn);

    if (!NILP (subject_buf)
	&& NILP (Fverify_visited_file_modtime (subject_buf))
	&& !NILP (Ffile_exists_p (fn)))
      call1 (intern ("ask-user-about-supersession-threat"), fn);

  }
  UNGCPRO;

  /* Try to lock the lock. */
  if (lock_if_free (&lock_info, lfname) <= 0)
    /* Return now if we have locked it, or if lock creation failed */
    return;

  /* Else consider breaking the lock */
  locker_size = (strlen (lock_info.user) + strlen (lock_info.host)
		 + INT_STRLEN_BOUND (printmax_t)
		 + sizeof "@ (pid )");
  locker = SAFE_ALLOCA (locker_size);
  pid = lock_info.pid;
  esprintf (locker, "%s@%s (pid %"pMd")",
	    lock_info.user, lock_info.host, pid);
  FREE_LOCK_INFO (lock_info);

  attack = call2 (intern ("ask-user-about-lock"), fn, build_string (locker));
  SAFE_FREE ();
  if (!NILP (attack))
    /* User says take the lock */
    {
      lock_file_1 (lfname, 1);
      return;
    }
  /* User says ignore the lock */
}
char updateutmp_f (enum utmp_action options, struct utmp *new_entry) {
 int ufile;
 struct stat st;

// strip the utmp_add action if we don't get a new entry to add along with it
 if ((options & utmp_add) && !new_entry) options ^= utmp_add;
// if we don't have anything to do, bail out
 if (!options) return -1;

 if (coremode == einit_mode_sandbox)
  ufile = eopen ("var/run/utmp", O_RDWR);
 else
  ufile = eopen ("/var/run/utmp", O_RDWR);
 if (ufile) {
  if (!fstat (ufile, &st) && st.st_size) {
   struct utmp *utmpentries = mmap (NULL, st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, ufile, 0);

   if (utmpentries != MAP_FAILED) {
    uint32_t entries = st.st_size / sizeof(struct utmp),
    i = 0;
    eclose (ufile);
    ufile = 0;

    for (i = 0; i < entries; i++) {
#ifdef LINUX
     switch (utmpentries[i].ut_type) {
      case DEAD_PROCESS:
       if (options & utmp_add) {
        memcpy (&(utmpentries[i]), new_entry, sizeof (struct utmp));
        options ^= utmp_add;
       }

       break;
      case RUN_LVL:
       if (options & utmp_clean) {
/* the higher 8 bits contain the old runlevel, the lower 8 bits the current one */
        char *new_previous_runlevel = cfg_getstring ("configuration-compatibility-sysv-simulate-runlevel/before", NULL),
            *new_runlevel = cfg_getstring ("configuration-compatibility-sysv-simulate-runlevel/now", NULL);

        if (new_runlevel && new_runlevel[0]) {
         if (new_previous_runlevel)
          utmpentries[i].ut_pid = (new_previous_runlevel[0] << 8) | new_runlevel[0];
         else
          utmpentries[i].ut_pid = (utmpentries[i].ut_pid << 8) | new_runlevel[0];
        }
       }
       break;

      case UT_UNKNOWN:
      case BOOT_TIME:
      case NEW_TIME:
      case OLD_TIME:
      case INIT_PROCESS:
      case LOGIN_PROCESS:
      case USER_PROCESS:
      case ACCOUNTING:
       if (options & utmp_clean) {
#ifdef LINUX
        struct stat xst;
        char path[BUFFERSIZE];
        esprintf (path, BUFFERSIZE, "/proc/%i/", utmpentries[i].ut_pid);
        if (stat (path, &xst)) { // stat path under proc to see if process exists
// if not...
#endif
// clean utmp record
         if (options & utmp_add) {
          memcpy (&(utmpentries[i]), new_entry, sizeof (struct utmp));
          options ^= utmp_add;
         } else {
          utmpentries[i].ut_type = DEAD_PROCESS;
          memset (&(utmpentries[i].ut_user), 0, sizeof (utmpentries[i].ut_user));
          memset (&(utmpentries[i].ut_host), 0, sizeof (utmpentries[i].ut_host));
          memset (&(utmpentries[i].ut_time), 0, sizeof (utmpentries[i].ut_time));
         }
#ifdef LINUX
        }
#endif
       }
       break;
#ifdef DEBUG
      default:
       notice (6, "bad UTMP entry: [%c%c%c%c] %i (%s), %s@%s: %i.%i\n", utmpentries[i].ut_id[0], utmpentries[i].ut_id[1], utmpentries[i].ut_id[2], utmpentries[i].ut_id[3], utmpentries[i].ut_type, utmpentries[i].ut_line, utmpentries[i].ut_user, utmpentries[i].ut_host, (int)utmpentries[i].ut_tv.tv_sec, (int)utmpentries[i].ut_tv.tv_usec);
       break;
#endif
     }

     if ((options & utmp_modify) && (utmpentries[i].ut_pid == new_entry->ut_pid)) {
      memcpy (&(utmpentries[i]), new_entry, sizeof (struct utmp));
      options ^= utmp_modify;
     }
#endif
     if (!options) break;
    }

    munmap (utmpentries, st.st_size);
   } else {
    bitch(bitch_stdio, 0, "mmap() failed");
   }
  }

  if (ufile)
   eclose (ufile);
 } else {
  bitch(bitch_stdio, 0, "open() failed");
 }

 if (options & utmp_add) { // still didn't get to add this.. try to append it to the file
  if (coremode == einit_mode_sandbox)
   ufile = open ("var/run/utmp", O_WRONLY | O_APPEND);
  else
   ufile = open ("/var/run/utmp", O_WRONLY | O_APPEND);

  if (ufile) {
   if (write(ufile, new_entry, sizeof (struct utmp)) != sizeof (struct utmp)) {
    bitch(bitch_stdio, 0, "short write to utmp file");
   }
   eclose (ufile);

  } else {
   bitch(bitch_stdio, 0, "mmap() failed");
  }

  options ^= utmp_add;
 }

 return 0;
}
Exemple #19
0
void linux_hotplug_hotplug_event_handler (struct einit_event *ev) {
 if (ev->stringset) {
  char *subsystem = NULL;
  char *firmware = NULL;
  char *devpath = NULL;
  int i = 0;
  struct cfgnode *node = cfg_getnode ("configuration-system-hotplug-support-legacy-hotplug-scripts", NULL);

  for (; ev->stringset[i]; i+=2) {
   if (strmatch (ev->stringset[i], "SUBSYSTEM")) {
    subsystem = ev->stringset[i+1];
   } else if (strmatch (ev->stringset[i], "FIRMWARE")) {
    firmware = ev->stringset[i+1];
   } else if (strmatch (ev->stringset[i], "DEVPATH")) {
    devpath = ev->stringset[i+1];
   }
  }

  if (node && node->flag) {
   char **commands = NULL;

   if (subsystem) {
    char n = 0;

    for (; n < 2; n++) {
     char buffer[BUFFERSIZE];
     char *tbuffer = (n == 1) ? "/etc/einit/hotplug.d/default/" : NULL;

     switch (n) {
      case 0:
       esprintf(buffer, BUFFERSIZE, "/etc/einit/hotplug.d/%s/", subsystem);
       tbuffer = buffer;
       break;
      case 1:
       break;
      default:
       tbuffer = NULL;
       break;
     }

     if (tbuffer) {
      struct stat st;

      if (!stat (tbuffer, &st) && S_ISDIR(st.st_mode)) {
       char **cm = readdirfilter (NULL, tbuffer, "\\.hotplug$", NULL, 0);

       if (cm) {
        commands = (char **)setcombine_nc ((void **)commands, (const void **)cm, SET_TYPE_STRING);
        efree (cm);
       }
      }
     }
    }
   }

   if (commands) {
    char **env = NULL;
    char *command;
    ssize_t blen = strlen (subsystem) + 2;
    char **cd = NULL;

    for (i = 0; ev->stringset[i]; i+=2) {
     env = straddtoenviron (env, ev->stringset[i], ev->stringset[i+1]);
    }

    for (i = 0; commands[i]; i++) {
     int len = blen + strlen (commands[i]);
     char *t = emalloc (len);

     esprintf (t, len, "%s %s", commands[i], subsystem);
     cd = set_str_add (cd, t);
     efree (t);
    }

    if (cd) {
     command = set2str (';', (const char **)cd);

     pexec(command, NULL, 0, 0, NULL, NULL, env, NULL);

     efree (cd);
     efree (command);
    }

    efree (env);
    efree (commands);
   }
  }

  if (firmware && (ev->type == einit_hotplug_add)) {
   char buffer[BUFFERSIZE];
   int tblen = sizeof(SYS_DIR) + strlen (devpath) + 11;
   FILE *f;
   struct stat st;
   char *targetbuffer = emalloc (tblen);

   notice (2, "need firmware: %s", firmware);

   esprintf (buffer, BUFFERSIZE, FIRMWARE_DIR "/%s", firmware);
   if (stat (buffer, &st)) {
    esprintf (targetbuffer, tblen, SYS_DIR "/%s/loading", devpath);
    if ((f = fopen (targetbuffer, "w"))) {
     fputs ("-1\n", f);
     fclose (f);
    }

    notice (3, "can't locate firmware: %s", buffer);
   } else {
    esprintf (targetbuffer, tblen, SYS_DIR "/%s/loading", devpath);
    if ((f = fopen (targetbuffer, "w"))) {
     fputs ("1\n", f);
     fclose (f);
    }

    esprintf (targetbuffer, tblen, SYS_DIR "/%s/data", devpath);

    ssize_t ll = 0;
    char *firmware_data = readfile_l (buffer, &ll);

    if (firmware_data && ll) {
     if ((f = fopen (targetbuffer, "w"))) {
      int rembytes = ll;
      while (rembytes > 0) {
       size_t bw = fwrite (firmware_data +ll -rembytes, rembytes, 1, f);

       if (bw == 1) break;

       if (bw < 0) {
        notice (3, "error writing firmware: %s", buffer);
       }
      }
      fclose (f);
     }

     esprintf (targetbuffer, tblen, SYS_DIR "/%s/loading", devpath);
     if ((f = fopen (targetbuffer, "w"))) {
      fputs ("0\n", f);
      fclose (f);
     }

     notice (3, "firmware loaded okay: %s", buffer);
    } else {
     esprintf (targetbuffer, tblen, SYS_DIR "/%s/loading", devpath);
     if ((f = fopen (targetbuffer, "w"))) {
      fputs ("-1\n", f);
      fclose (f);
     }

     notice (3, "can't load firmware: %s", buffer);
    }
   }

   notice (3, "done loading firmware: %s", buffer);

   efree (targetbuffer);
  }
 }
}