static void message( fchar iset[] , /* input sets */ fint isub[] , /* input subsets */ fint inset , /* number of input sets */ fchar oset[] , /* output sets */ fint osub[] , /* output subsets */ fint onset ) /* number of output sets */ { char m[1024]; fint k, l = 0; for ( k = 0; k < inset; k++ ) { if ( k ) { strcat( m, " + " ); l += 3; } l += set2str( &m[l], iset[k] ); l += sub2str( &m[l], iset[k], isub[k] ); } strcat( m, " --> " ); l += 5; for ( k = 0; k < onset; k++ ) { if ( k ) { strcat( m, " + " ); l += 3; } l += set2str( &m[l], oset[k] ); l += sub2str( &m[l], oset[k], osub[k] ); } status_c( tofchar( m ) ); }
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; }
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; }
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); } } }
// Interface implemented by objects that listen for observations a traceStream reads. Such objects // call traceStream::registerObserver() to inform a given traceStream that it should observations. void traceFileWriterTSV::observe(int traceID, const std::map<std::string, std::string>& ctxt, const std::map<std::string, std::string>& obs, const std::map<std::string, anchor>& obsAnchor) { /*cout << "traceFileWriterTSV::observe("<<traceID<<")"<<endl; cout << " ctxt="; for(map<string, string>::const_iterator c=ctxt.begin(); c!=ctxt.end(); c++) { cout << c->first << "=>"<<c->second<<" "; } cout << endl; cout << " obs="; for(map<string, string>::const_iterator o=obs.begin(); o!=obs.end(); o++) { cout << o->first << "=>"<<o->second<<" "; } cout << endl;*/ // Get the keys of ctxt and obs set<string> curCtxtKeys; for(map<string, string>::const_iterator i=ctxt.begin(); i!=ctxt.end(); i++) curCtxtKeys.insert(i->first); set<string> curTraceKeys; for(map<string, string>::const_iterator i=obs.begin(); i!=obs.end(); i++) curTraceKeys.insert(i->first); // Verify that all observations have the same context and trace keys if(numObservations==0) { ctxtKeys = curCtxtKeys; traceKeys = curTraceKeys; } else { if(ctxtKeys != curCtxtKeys) { cerr << "traceFileWriterTSV::observe() ERROR: Inconsistent context keys. Previously observed "<<set2str(ctxtKeys)<<" but this observation has "<<set2str(curCtxtKeys)<<"!"; assert(0); } if(traceKeys != curTraceKeys) { cerr << "traceFileWriterTSV::observe() ERROR: Inconsistent trace keys. Previously observed "<<set2str(traceKeys)<<" but this observation has "<<set2str(curTraceKeys)<<"!"; assert(0); } } // Print out the header line if(numObservations==0) { for(map<string, string>::const_iterator i=ctxt.begin(); i!=ctxt.end(); i++) { if(i!=ctxt.begin()) out << "\t"; out << i->first; } if(ctxt.size()>0) out << "\t"; for(map<string, string>::const_iterator i=obs.begin(); i!=obs.end(); i++) { if(i!=obs.begin()) out << "\t"; out << i->first; } out << endl; } // Print out the observation line for(map<string, string>::const_iterator i=ctxt.begin(); i!=ctxt.end(); i++) { if(i!=ctxt.begin()) out << "\t"; attrValue val(i->second, attrValue::unknownT); out << val.getAsStr(); //cout << val.getAsStr(); } if(ctxt.size()>0) out << "\t"; for(map<string, string>::const_iterator i=obs.begin(); i!=obs.end(); i++) { if(i!=obs.begin()) out << "\t"; attrValue val(i->second, attrValue::unknownT); out << val.getAsStr(); //cout << val.getAsStr(); } out << endl; //cout << endl; numObservations++; }