this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use data from version.conf for uname() (fixes #103)

+88 -3
+34 -3
src/kernel/emulation/linux/misc/sysctl.c
··· 12 12 #include <limits.h> 13 13 #include "../ext/sys/utsname.h" 14 14 #include "../ext/syslog.h" 15 + #include "darling-config.h" 16 + #include <util/IniConfig.h> 15 17 16 18 static long sysctl_name_to_oid(const char* name, int* oid_name, 17 19 unsigned long* oid_len); ··· 37 39 }; 38 40 39 41 static struct linux_utsname lu; 42 + static iniconfig_t version_conf = NULL; 43 + static inivalmap_t version_conf_sect = NULL; 40 44 static void copyout_string(const char* str, char* out, unsigned long* out_len); 41 45 static void need_uname(void); 42 46 ··· 188 192 switch (name[1]) 189 193 { 190 194 case KERN_OSTYPE: 191 - copyout_string(lu.sysname, (char*) old, oldlen); 195 + { 196 + const char* s = NULL; 197 + if (version_conf_sect != NULL) 198 + s = iniconfig_valmap_get(version_conf_sect, "sysname"); 199 + if (s == NULL) 200 + s = lu.sysname; 201 + 202 + copyout_string(s, (char*) old, oldlen); 192 203 return 0; 204 + } 193 205 case KERN_HOSTNAME: 194 206 copyout_string(lu.nodename, (char*) old, oldlen); 195 207 return 0; 196 208 case KERN_OSRELEASE: 197 - copyout_string(lu.release, (char*) old, oldlen); 209 + { 210 + const char* s = NULL; 211 + if (version_conf_sect != NULL) 212 + s = iniconfig_valmap_get(version_conf_sect, "release"); 213 + if (s == NULL) 214 + s = lu.release; 215 + 216 + copyout_string(s, (char*) old, oldlen); 198 217 return 0; 218 + } 199 219 case KERN_VERSION: 200 - copyout_string(lu.version, (char*) old, oldlen); 220 + { 221 + const char* s = NULL; 222 + if (version_conf_sect != NULL) 223 + s = iniconfig_valmap_get(version_conf_sect, "version"); 224 + if (s == NULL) 225 + s = lu.version; 226 + 227 + copyout_string(s, (char*) old, oldlen); 201 228 return 0; 229 + } 202 230 case KERN_DOMAINNAME: 203 231 copyout_string(lu.domainname, (char*) old, oldlen); 204 232 return 0; ··· 214 242 if (!lu.sysname[0]) 215 243 { 216 244 __linux_uname(&lu); 245 + version_conf = iniconfig_load(ETC_DARLING_PATH "/version.conf"); 246 + if (version_conf != NULL) 247 + version_conf_sect = iniconfig_getsection(version_conf, "uname"); 217 248 } 218 249 } 219 250
+32
src/util/IniConfig.cpp
··· 142 142 143 143 #endif 144 144 145 + // C API 146 + 147 + iniconfig_t iniconfig_load(const char* path) 148 + { 149 + try 150 + { 151 + return new IniConfig(path); 152 + } 153 + catch (...) 154 + { 155 + return nullptr; 156 + } 157 + } 158 + 159 + void iniconfig_free(iniconfig_t config) 160 + { 161 + delete config; 162 + } 163 + 164 + inivalmap_t iniconfig_getsection(iniconfig_t config, const char* section) 165 + { 166 + return config->getSection(section); 167 + } 168 + 169 + const char* iniconfig_valmap_get(inivalmap_t map, const char* key) 170 + { 171 + auto it = map->find(key); 172 + if (it == map->end()) 173 + return nullptr; 174 + else 175 + return it->second.c_str(); 176 + } 145 177
+22
src/util/IniConfig.h
··· 1 1 #ifndef UTIL_INICONFIG_H 2 2 #define UTIL_INICONFIG_H 3 + 4 + #ifdef __cplusplus 5 + 3 6 #include <map> 4 7 #include <string> 5 8 #include <vector> ··· 25 28 private: 26 29 SectionMap m_sections; 27 30 }; 31 + 32 + typedef IniConfig* iniconfig_t; 33 + typedef const IniConfig::ValueMap* inivalmap_t; 34 + extern "C" { 35 + #else 36 + 37 + typedef struct __iniconfig* iniconfig_t; 38 + typedef struct __inivalmap* inivalmap_t; 39 + 40 + #endif 41 + 42 + iniconfig_t iniconfig_load(const char* path); 43 + void iniconfig_free(iniconfig_t config); 44 + inivalmap_t iniconfig_getsection(iniconfig_t config, const char* section); 45 + const char* iniconfig_valmap_get(inivalmap_t map, const char* key); 46 + 47 + #ifdef __cplusplus 48 + } 49 + #endif 28 50 29 51 #endif 30 52