@@ -162,6 +162,12 @@ void TargetRegistry::generatePolicyBasedMapping(std::vector<std::string>& policy
162162 }
163163}
164164
165+ static std::string trimStr (const std::string &s) {
166+ size_t start = s.find_first_not_of (" \t " );
167+ size_t end = s.find_last_not_of (" \t\r " );
168+ return (start == std::string::npos) ? " " : s.substr (start, end - start + 1 );
169+ }
170+
165171void TargetRegistry::getClusterIdBasedMapping () {
166172 const std::string cpuDir = " /sys/devices/system/cpu" ;
167173 const std::regex cpuRegex (" ^cpu([0-9]+)$" );
@@ -551,6 +557,95 @@ ErrCode TargetRegistry::addIrqAffine(std::vector<std::string>& values,
551557 return RC_SUCCESS ;
552558}
553559
560+ ErrCode TargetRegistry::addLogLimit (std::vector<std::string>& values) {
561+ if (values.size () < 1 ) {
562+ return RC_INVALID_VALUE ;
563+ }
564+
565+ std::string logLevel = values[0 ];
566+ if (logLevel != " minimal" ) {
567+ return RC_SUCCESS ;
568+ }
569+
570+ const std::string journaldConfFile = " /etc/systemd/journald.conf" ;
571+ const std::unordered_map<std::string, std::string> configOptions = {
572+ {" RuntimeMaxUse" , " 20M" },
573+ {" RuntimeMaxFileSize" , " 128K" },
574+ {" MaxLevelStore" , " notice" },
575+ {" MaxLevelSyslog" , " notice" },
576+ {" MaxLevelKMsg" , " notice" },
577+ {" MaxLevelConsole" , " notice" },
578+ {" ForwardToSyslog" , " no" }
579+ };
580+
581+ std::ifstream confInStream (journaldConfFile);
582+ if (!confInStream) {
583+ return RC_SUCCESS ;
584+ }
585+
586+ std::ostringstream oldContent;
587+ std::ostringstream newContent;
588+ std::string line;
589+ int8_t journalSectionFound = false ;
590+
591+ std::unordered_map<std::string, int8_t > keyUpdated;
592+ for (auto &entry : configOptions) {
593+ keyUpdated[entry.first ] = false ;
594+ }
595+
596+ while (std::getline (confInStream, line)) {
597+ std::string trimmedLine = trimStr (line);
598+ int8_t replaced = false ;
599+
600+ if (trimmedLine == " [Journal]" ) {
601+ journalSectionFound = true ;
602+ }
603+
604+ for (auto &entry : configOptions) {
605+ if (trimmedLine.find (entry.first + " =" ) == 0 ||
606+ trimmedLine.find (" #" + entry.first + " =" ) == 0 ) {
607+ newContent << entry.first << " =" << entry.second << " \n " ;
608+ keyUpdated[entry.first ] = true ;
609+ replaced = true ;
610+ break ;
611+ }
612+ }
613+ if (!replaced) {
614+ newContent << line << " \n " ;
615+ }
616+ oldContent << line << " \n " ;
617+ }
618+ confInStream.close ();
619+
620+ if (!journalSectionFound) {
621+ newContent << " \n [Journal]\n " ;
622+ }
623+
624+ for (auto &entry : configOptions) {
625+ if (!keyUpdated[entry.first ]) {
626+ newContent << entry.first << " =" << entry.second << " \n " ;
627+ }
628+ }
629+
630+ std::ofstream confOutStream (journaldConfFile);
631+ confOutStream << newContent.str ();
632+ confOutStream.close ();
633+
634+ // Set printk kernel logging to minimal
635+ const std::string printkPath = " /proc/sys/kernel/printk" ;
636+ const std::string newLevels = " 3 4 1 3" ;
637+
638+ std::ofstream printkFile (printkPath);
639+ if (printkFile.is_open ()) {
640+ printkFile << newLevels;
641+ printkFile.close ();
642+ }
643+
644+ // Restart journald
645+ RestuneSDBus::getInstance ()->restartService (" systemd-journald.service" );
646+ return RC_SUCCESS ;
647+ }
648+
554649// Methods for Building CGroup Config from InitConfigs.yaml
555650CGroupConfigInfoBuilder::CGroupConfigInfoBuilder () {
556651 this ->mCGroupConfigInfo = new (std::nothrow) CGroupConfigInfo;
0 commit comments