Changeset 9347914


Ignore:
Timestamp:
07/02/15 11:18:07 (2 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, releng/10.2
Children:
3b74399, 3bd74f8, 285a20a
Parents:
266cffe
Message:

Re-work how jail information is found/saved. Now it should be much more reliable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src-sh/syscache/daemon/DB.cpp

    r266cffe r9347914  
    827827  QStringList jails = HASH->value("JailList","").split(LISTDELIMITER); 
    828828  //Now get the current list of running jails and insert individual jail info 
    829   QStringList info = directSysCmd("jls"); 
     829  QStringList jinfo = directSysCmd("jls"); 
    830830  QStringList found; 
    831   for(int i=1; i<info.length() && !stopping; i++){ //skip the header line 
    832     info[i] = info[i].replace("\t"," ").simplified(); 
    833     QString name = info[i].section(" ",2,2); //hostname 
    834     found << name; //add it to the new list 
    835     jails.removeAll(name); //remove from the old list 
    836     bool haspkg = QFile::exists(info[i].section(" ",3,3)+"/usr/local/sbin/pkg-static"); 
    837     HASH->insert("Jails/"+name+"/JID", info[i].section(" ",0,0)); 
    838     HASH->insert("Jails/"+name+"/jailIP", info[i].section(" ",1,1)); 
    839     HASH->insert("Jails/"+name+"/jailPath", info[i].section(" ",3,3)); 
    840     HASH->insert("Jails/"+name+"/haspkg",haspkg ? "true": "false" ); 
    841   } 
    842   HASH->insert("JailList", found.join(LISTDELIMITER)); 
     831  for(int i=1; i<jinfo.length() && !stopping; i++){ //skip the header line 
     832    jinfo[i] = jinfo[i].replace("\t"," ").simplified(); 
     833    //QString name = info[i].section(" ",2,2); //hostname 
     834    //found << name; //add it to the new list 
     835    //jails.removeAll(name); //remove from the old list 
     836    //bool haspkg = QFile::exists(info[i].section(" ",3,3)+"/usr/local/sbin/pkg-static"); 
     837    //HASH->insert("Jails/"+name+"/JID", info[i].section(" ",0,0)); 
     838    //HASH->insert("Jails/"+name+"/jailIP", info[i].section(" ",1,1)); 
     839    //HASH->insert("Jails/"+name+"/jailPath", info[i].section(" ",3,3)); 
     840    //HASH->insert("Jails/"+name+"/haspkg",haspkg ? "true": "false" ); 
     841    //qDebug() << "Jail Info:" <<  
     842  } 
     843  //HASH->insert("JailList", found.join(LISTDELIMITER)); 
    843844  if(stopping){ return; } //catch for if the daemon is stopping 
    844845  //Remove any old jails from the hash 
    845   for(int i=0; i<jails.length() && !stopping; i++){ //anything left over in the list 
     846  /*for(int i=0; i<jails.length() && !stopping; i++){ //anything left over in the list 
    846847    clearJail(jails[i]);  
    847   } 
     848  }*/ 
    848849  //Now also fetch the list of inactive jails on the system 
    849   info = directSysCmd("iocage list"); //"warden list -v"); 
     850  QStringList info = directSysCmd("iocage list"); //"warden list -v"); 
    850851  QStringList inactive; 
    851852  //info = info.join("----").simplified().split("id: "); 
     
    859860    QString HOST, IPV4, AIPV4, BIPV4, ABIPV4, ROUTERIPV4, IPV6, AIPV6, BIPV6, ABIPV6, ROUTERIPV6, AUTOSTART, VNET, TYPE; 
    860861    HOST = ID; 
     862    jails.removeAll(HOST); 
    861863    bool isRunning = (info[i].section(" ",3,3,QString::SectionSkipEmpty).simplified() != "down"); 
     864    QStringList junk = jinfo.filter(ID); 
     865    if(!junk.isEmpty()){ 
     866      //This jail is running - add extra information 
     867      bool haspkg = QFile::exists(junk[0].section(" ",3,3)+"/usr/local/sbin/pkg-static"); 
     868      HASH->insert("Jails/"+HOST+"/JID", junk[0].section(" ",0,0)); 
     869      HASH->insert("Jails/"+HOST+"/jailIP", junk[0].section(" ",1,1)); 
     870      HASH->insert("Jails/"+HOST+"/jailPath", junk[0].section(" ",3,3)); 
     871      HASH->insert("Jails/"+HOST+"/haspkg", haspkg ? "true": "false" ); 
     872    }else{ 
     873      HASH->insert("Jails/"+HOST+"/JID", ""); 
     874      HASH->insert("Jails/"+HOST+"/jailIP", ""); 
     875      HASH->insert("Jails/"+HOST+"/jailPath", ""); 
     876      HASH->insert("Jails/"+HOST+"/haspkg", "false" ); 
     877    } 
    862878    //qDebug() << "IoCage Jail:" << ID << isRunning; 
    863879    for(int j=0; j<tmp.length(); j++){ 
     
    885901      QString prefix = "Jails/"+HOST+"/"; 
    886902      if(!isRunning){ inactive << HOST; } //only save inactive jails - active are already taken care of 
     903      else{ found << HOST; } 
    887904      HASH->insert(prefix+"WID", ID); //Warden ID 
    888905      HASH->insert(prefix+"ipv4", IPV4); 
     
    902919  } 
    903920  HASH->insert("StoppedJailList",inactive.join(LISTDELIMITER)); 
    904    
     921  HASH->insert("JailList", found.join(LISTDELIMITER)); 
     922  //Remove any old jails from the hash (ones that no longer exist) 
     923  for(int i=0; i<jails.length() && !stopping; i++){ //anything left over in the list 
     924    clearJail(jails[i]);  
     925  } 
    905926} 
    906927 
Note: See TracChangeset for help on using the changeset viewer.