Switch haiku-revision from uint32 to string, as that's going to be required soon, no matter if we switch to Git or Mercurial

* increase _SYS_NAMELEN defined in sys/utsname.h to 128 to allow long(ish) revisions
* sHaikuRevision is now a static character array (in both libroot and kernel)
* adjust build tool set_haiku_revision to write the revision as string


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41389 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe
2011-05-08 20:02:42 +00:00
parent c356b0477f
commit 6250297a08
7 changed files with 24 additions and 23 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
#define _SYS_UTSNAME_H #define _SYS_UTSNAME_H
#define _SYS_NAMELEN 32 #define _SYS_NAMELEN 128
struct utsname { struct utsname {
char sysname[_SYS_NAMELEN]; /* Name of the OS */ char sysname[_SYS_NAMELEN]; /* Name of the OS */
+1 -1
View File
@@ -19,7 +19,7 @@ extern "C" {
status_t system_info_init(struct kernel_args *args); status_t system_info_init(struct kernel_args *args);
status_t system_notifications_init(); status_t system_notifications_init();
uint32 get_haiku_revision(void); const char* get_haiku_revision(void);
status_t _user_get_system_info(system_info *userInfo, size_t size); status_t _user_get_system_info(system_info *userInfo, size_t size);
status_t _user_get_system_info_etc(int32 id, void *buffer, status_t _user_get_system_info_etc(int32 id, void *buffer,
+1 -1
View File
@@ -1402,7 +1402,7 @@ syslog_init_post_vm(struct kernel_args* args)
char revisionBuffer[64]; char revisionBuffer[64];
length = snprintf(revisionBuffer, sizeof(revisionBuffer), length = snprintf(revisionBuffer, sizeof(revisionBuffer),
"Welcome to syslog debug output!\nHaiku revision: %lu\n", "Welcome to syslog debug output!\nHaiku revision: %s\n",
get_haiku_revision()); get_haiku_revision());
syslog_write(revisionBuffer, syslog_write(revisionBuffer,
std::min(length, (ssize_t)sizeof(revisionBuffer) - 1), false); std::min(length, (ssize_t)sizeof(revisionBuffer) - 1), false);
+1 -1
View File
@@ -111,7 +111,7 @@ _start(kernel_args *bootKernelArgs, int currentCPU)
debug_init(&sKernelArgs); debug_init(&sKernelArgs);
set_dprintf_enabled(true); set_dprintf_enabled(true);
dprintf("Welcome to kernel debugger output!\n"); dprintf("Welcome to kernel debugger output!\n");
dprintf("Haiku revision: %lu\n", get_haiku_revision()); dprintf("Haiku revision: %s\n", get_haiku_revision());
// init modules // init modules
TRACE("init CPU\n"); TRACE("init CPU\n");
+5 -3
View File
@@ -31,6 +31,7 @@
#include <real_time_clock.h> #include <real_time_clock.h>
#include <sem.h> #include <sem.h>
#include <smp.h> #include <smp.h>
#include <sys/utsname.h>
#include <team.h> #include <team.h>
#include <thread.h> #include <thread.h>
#include <util/AutoLock.h> #include <util/AutoLock.h>
@@ -44,7 +45,8 @@ const static char *kKernelName = "kernel_" HAIKU_ARCH;
// Haiku SVN revision. Will be set when copying the kernel to the image. // Haiku SVN revision. Will be set when copying the kernel to the image.
// Lives in a separate section so that it can easily be found. // Lives in a separate section so that it can easily be found.
static uint32 sHaikuRevision __attribute__((section("_haiku_revision"))); static char sHaikuRevision[_SYS_NAMELEN]
__attribute__((section("_haiku_revision")));
static int static int
@@ -52,7 +54,7 @@ dump_info(int argc, char **argv)
{ {
kprintf("kernel build: %s %s (gcc%d %s)\n", __DATE__, __TIME__, __GNUC__, kprintf("kernel build: %s %s (gcc%d %s)\n", __DATE__, __TIME__, __GNUC__,
__VERSION__); __VERSION__);
kprintf("SVN revision: %lu\n\n", sHaikuRevision); kprintf("SVN revision: %s\n\n", sHaikuRevision);
kprintf("cpu count: %ld, active times:\n", smp_get_num_cpus()); kprintf("cpu count: %ld, active times:\n", smp_get_num_cpus());
@@ -466,7 +468,7 @@ system_notifications_init()
} }
uint32 const char*
get_haiku_revision(void) get_haiku_revision(void)
{ {
return sHaikuRevision; return sHaikuRevision;
+6 -7
View File
@@ -16,8 +16,8 @@
// Haiku SVN revision. Will be set when copying libroot.so to the image. // Haiku SVN revision. Will be set when copying libroot.so to the image.
// Lives in a separate section so that it can easily be found. // Lives in a separate section so that it can easily be found.
static uint32 sHaikuRevision __attribute__((section("_haiku_revision"))); static char sHaikuRevision[_SYS_NAMELEN]
static uint32 sHaikuRevision = 0; __attribute__((section("_haiku_revision")));
int int
@@ -35,11 +35,10 @@ uname(struct utsname *info)
strlcpy(info->sysname, "Haiku", sizeof(info->sysname)); strlcpy(info->sysname, "Haiku", sizeof(info->sysname));
info->version[0] = '\0'; if (sHaikuRevision[0] != '\0')
if (sHaikuRevision) { snprintf(info->version, sizeof(info->version), "r%s ", sHaikuRevision);
snprintf(info->version, sizeof(info->version), "r%ld ", else
sHaikuRevision); info->version[0] = '\0';
}
strlcat(info->version, systemInfo.kernel_build_date, sizeof(info->version)); strlcat(info->version, systemInfo.kernel_build_date, sizeof(info->version));
strlcat(info->version, " ", sizeof(info->version)); strlcat(info->version, " ", sizeof(info->version));
strlcat(info->version, systemInfo.kernel_build_time, sizeof(info->version)); strlcat(info->version, systemInfo.kernel_build_time, sizeof(info->version));
+9 -9
View File
@@ -10,6 +10,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/utsname.h>
#include <unistd.h> #include <unistd.h>
#include <algorithm> #include <algorithm>
@@ -304,11 +305,11 @@ public:
fFileSize = FileSize(); fFileSize = FileSize();
if (fFileSize < 0) if (fFileSize < 0)
throw Exception("Failed to get the file size."); throw Exception("Failed to get the file size.");
// read ELF header // read ELF header
Elf32_Ehdr fileHeader; Elf32_Ehdr fileHeader;
Read(0, &fileHeader, sizeof(Elf32_Ehdr), "Failed to read ELF header."); Read(0, &fileHeader, sizeof(Elf32_Ehdr), "Failed to read ELF header.");
// check data encoding (endianess) // check data encoding (endianess)
switch (fileHeader.e_ident[EI_DATA]) { switch (fileHeader.e_ident[EI_DATA]) {
case ELFDATA2LSB: case ELFDATA2LSB:
@@ -322,14 +323,14 @@ public:
throw Exception(EIO, "Unsupported ELF data encoding."); throw Exception(EIO, "Unsupported ELF data encoding.");
break; break;
} }
// get the header values // get the header values
fELFHeaderSize = GetUInt16(fileHeader.e_ehsize); fELFHeaderSize = GetUInt16(fileHeader.e_ehsize);
fSectionHeaderTableOffset = GetUInt32(fileHeader.e_shoff); fSectionHeaderTableOffset = GetUInt32(fileHeader.e_shoff);
fSectionHeaderSize = GetUInt16(fileHeader.e_shentsize); fSectionHeaderSize = GetUInt16(fileHeader.e_shentsize);
fSectionHeaderCount = GetUInt16(fileHeader.e_shnum); fSectionHeaderCount = GetUInt16(fileHeader.e_shnum);
bool hasSectionHeaderTable = (fSectionHeaderTableOffset != 0); bool hasSectionHeaderTable = (fSectionHeaderTableOffset != 0);
// check the sanity of the header values // check the sanity of the header values
// ELF header size // ELF header size
if (fELFHeaderSize < sizeof(Elf32_Ehdr) || fELFHeaderSize > kMaxELFHeaderSize) { if (fELFHeaderSize < sizeof(Elf32_Ehdr) || fELFHeaderSize > kMaxELFHeaderSize) {
@@ -570,7 +571,6 @@ main(int argc, const char* const* argv)
// parameters // parameters
const char* fileName = argv[1]; const char* fileName = argv[1];
const char* revisionString = argv[2]; const char* revisionString = argv[2];
uint32_t revision = atol(revisionString);
try { try {
ELFObject elfObject; ELFObject elfObject;
@@ -583,9 +583,9 @@ main(int argc, const char* const* argv)
exit(1); exit(1);
} }
// convert revision number to object endianess and write to section // write revision string to section
uint32_t revisionBuffer = elfObject.GetUInt32(revision); elfObject.Write(info.offset, revisionString,
elfObject.Write(info.offset, &revisionBuffer, sizeof(revisionBuffer), std::min(sizeof(utsname::version), strlen(revisionString) + 1),
"Failed to write revision."); "Failed to write revision.");
} catch (Exception exception) { } catch (Exception exception) {
@@ -596,7 +596,7 @@ main(int argc, const char* const* argv)
strerror(exception.Error())); strerror(exception.Error()));
} }
exit(1); exit(1);
} }
return 0; return 0;
} }