| 8 | #include <string> |
| 9 | |
| 10 | int main(int argc, char** argv){ |
| 11 | setenv("HOME", "/system", 1); // Default home |
| 12 | setenv("PATH", "/initrd:/system/bin", 1); // Default path |
| 13 | |
| 14 | Lemon::JSONParser confParser = Lemon::JSONParser("/system/lemon/lemond.json"); |
| 15 | auto json = confParser.Parse(); |
| 16 | if(json.IsObject()){ |
| 17 | std::map<Lemon::JSONKey, Lemon::JSONValue>& values = *json.object; |
| 18 | |
| 19 | if(auto it = values.find("environment"); it != values.end() && it->second.IsArray()){ |
| 20 | std::vector<Lemon::JSONValue>& env = *it->second.array; |
| 21 | |
| 22 | for(auto& v : env){ |
| 23 | std::string str; |
| 24 | size_t eq = std::string::npos; |
| 25 | if(v.IsString() && (eq = (str = v.AsString()).find("=")) != std::string::npos){ |
| 26 | setenv(str.substr(0, eq - 1).c_str(), str.substr(eq + 1).c_str(), 1); |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | } else { |
| 31 | printf("[Lemond] Warning: Error parsing JSON configuration file!\n"); |
| 32 | } |
| 33 | |
| 34 | __attribute__((unused)) char* lemonwm = "/system/lemon/lemonwm.lef"; |
| 35 | __attribute__((unused)) char* login = "/system/lemon/login.lef"; |
| 36 | __attribute__((unused)) char* shell = "/system/bin/shell.lef"; |
| 37 | |
| 38 | if(long ret = lemon_spawn(lemonwm, 1, &lemonwm); ret <= 0){ |
| 39 | printf("Error %ld attempting to load %s. Attempting to load again\n", ret, lemonwm); |
| 40 | lemon_spawn(lemonwm, 1, &lemonwm); // Attempt twice |
| 41 | } |
| 42 | |
| 43 | if(long ret = lemon_spawn(shell, 1, &shell); ret <= 0){ |
| 44 | printf("Error %ld attempting to load %s. Attempting to load again\n", ret, shell); |
| 45 | lemon_spawn(shell, 1, &shell); // Attempt twice |
| 46 | } |
| 47 | |
| 48 | return 0; |
| 49 | } |
nothing calls this directly
no test coverage detected