[haiku-commits] r41389 - in haiku/trunk: headers/posix/sys headers/private/kernel src/system/kernel src/system/kernel/debug src/system/libroot/posix/sys ...

  • From: zooey@xxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 8 May 2011 22:02:42 +0200 (CEST)

Author: zooey
Date: 2011-05-08 22:02:42 +0200 (Sun, 08 May 2011)
New Revision: 41389
Changeset: https://dev.haiku-os.org/changeset/41389

Modified:
   haiku/trunk/headers/posix/sys/utsname.h
   haiku/trunk/headers/private/kernel/ksystem_info.h
   haiku/trunk/src/system/kernel/debug/debug.cpp
   haiku/trunk/src/system/kernel/main.cpp
   haiku/trunk/src/system/kernel/system_info.cpp
   haiku/trunk/src/system/libroot/posix/sys/uname.c
   haiku/trunk/src/tools/set_haiku_revision.cpp
Log:
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


Modified: haiku/trunk/headers/posix/sys/utsname.h
===================================================================
--- haiku/trunk/headers/posix/sys/utsname.h     2011-05-08 19:36:47 UTC (rev 
41388)
+++ haiku/trunk/headers/posix/sys/utsname.h     2011-05-08 20:02:42 UTC (rev 
41389)
@@ -6,7 +6,7 @@
 #define _SYS_UTSNAME_H
 
 
-#define _SYS_NAMELEN 32
+#define _SYS_NAMELEN 128
 
 struct utsname {
        char sysname[_SYS_NAMELEN];             /* Name of the OS */

Modified: haiku/trunk/headers/private/kernel/ksystem_info.h
===================================================================
--- haiku/trunk/headers/private/kernel/ksystem_info.h   2011-05-08 19:36:47 UTC 
(rev 41388)
+++ haiku/trunk/headers/private/kernel/ksystem_info.h   2011-05-08 20:02:42 UTC 
(rev 41389)
@@ -19,7 +19,7 @@
 
 status_t system_info_init(struct kernel_args *args);
 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_etc(int32 id, void *buffer,

Modified: haiku/trunk/src/system/kernel/debug/debug.cpp
===================================================================
--- haiku/trunk/src/system/kernel/debug/debug.cpp       2011-05-08 19:36:47 UTC 
(rev 41388)
+++ haiku/trunk/src/system/kernel/debug/debug.cpp       2011-05-08 20:02:42 UTC 
(rev 41389)
@@ -1402,7 +1402,7 @@
 
        char revisionBuffer[64];
        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());
        syslog_write(revisionBuffer,
                std::min(length, (ssize_t)sizeof(revisionBuffer) - 1), false);

Modified: haiku/trunk/src/system/kernel/main.cpp
===================================================================
--- haiku/trunk/src/system/kernel/main.cpp      2011-05-08 19:36:47 UTC (rev 
41388)
+++ haiku/trunk/src/system/kernel/main.cpp      2011-05-08 20:02:42 UTC (rev 
41389)
@@ -111,7 +111,7 @@
                debug_init(&sKernelArgs);
                set_dprintf_enabled(true);
                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
                TRACE("init CPU\n");

Modified: haiku/trunk/src/system/kernel/system_info.cpp
===================================================================
--- haiku/trunk/src/system/kernel/system_info.cpp       2011-05-08 19:36:47 UTC 
(rev 41388)
+++ haiku/trunk/src/system/kernel/system_info.cpp       2011-05-08 20:02:42 UTC 
(rev 41389)
@@ -31,6 +31,7 @@
 #include <real_time_clock.h>
 #include <sem.h>
 #include <smp.h>
+#include <sys/utsname.h>
 #include <team.h>
 #include <thread.h>
 #include <util/AutoLock.h>
@@ -44,7 +45,8 @@
 
 // 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.
-static uint32 sHaikuRevision __attribute__((section("_haiku_revision")));
+static char sHaikuRevision[_SYS_NAMELEN]
+       __attribute__((section("_haiku_revision")));
 
 
 static int
@@ -52,7 +54,7 @@
 {
        kprintf("kernel build: %s %s (gcc%d %s)\n", __DATE__, __TIME__, 
__GNUC__,
                __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());
 
@@ -466,7 +468,7 @@
 }
 
 
-uint32
+const char*
 get_haiku_revision(void)
 {
        return sHaikuRevision;

Modified: haiku/trunk/src/system/libroot/posix/sys/uname.c
===================================================================
--- haiku/trunk/src/system/libroot/posix/sys/uname.c    2011-05-08 19:36:47 UTC 
(rev 41388)
+++ haiku/trunk/src/system/libroot/posix/sys/uname.c    2011-05-08 20:02:42 UTC 
(rev 41389)
@@ -16,8 +16,8 @@
 
 // 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.
-static uint32 sHaikuRevision __attribute__((section("_haiku_revision")));
-static uint32 sHaikuRevision = 0;
+static char sHaikuRevision[_SYS_NAMELEN]
+       __attribute__((section("_haiku_revision")));
 
 
 int
@@ -35,11 +35,10 @@
 
        strlcpy(info->sysname, "Haiku", sizeof(info->sysname));
 
-       info->version[0] = '\0';
-       if (sHaikuRevision) {
-               snprintf(info->version, sizeof(info->version), "r%ld ",
-                       sHaikuRevision);
-       }
+       if (sHaikuRevision[0] != '\0')
+               snprintf(info->version, sizeof(info->version), "r%s ", 
sHaikuRevision);
+       else
+               info->version[0] = '\0';
        strlcat(info->version, systemInfo.kernel_build_date, 
sizeof(info->version));
        strlcat(info->version, " ", sizeof(info->version));
        strlcat(info->version, systemInfo.kernel_build_time, 
sizeof(info->version));

Modified: haiku/trunk/src/tools/set_haiku_revision.cpp
===================================================================
--- haiku/trunk/src/tools/set_haiku_revision.cpp        2011-05-08 19:36:47 UTC 
(rev 41388)
+++ haiku/trunk/src/tools/set_haiku_revision.cpp        2011-05-08 20:02:42 UTC 
(rev 41389)
@@ -10,6 +10,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/utsname.h>
 #include <unistd.h>
 
 #include <algorithm>
@@ -304,11 +305,11 @@
                fFileSize = FileSize();
                if (fFileSize < 0)
                        throw Exception("Failed to get the file size.");
-       
+
                // read ELF header
                Elf32_Ehdr fileHeader;
                Read(0, &fileHeader, sizeof(Elf32_Ehdr), "Failed to read ELF 
header.");
-       
+
                // check data encoding (endianess)
                switch (fileHeader.e_ident[EI_DATA]) {
                        case ELFDATA2LSB:
@@ -322,14 +323,14 @@
                                throw Exception(EIO, "Unsupported ELF data 
encoding.");
                                break;
                }
-       
+
                // get the header values
                fELFHeaderSize  = GetUInt16(fileHeader.e_ehsize);
                fSectionHeaderTableOffset = GetUInt32(fileHeader.e_shoff);
                fSectionHeaderSize      = GetUInt16(fileHeader.e_shentsize);
                fSectionHeaderCount = GetUInt16(fileHeader.e_shnum);
                bool hasSectionHeaderTable = (fSectionHeaderTableOffset != 0);
-       
+
                // check the sanity of the header values
                // ELF header size
                if (fELFHeaderSize < sizeof(Elf32_Ehdr) || fELFHeaderSize > 
kMaxELFHeaderSize) {
@@ -570,7 +571,6 @@
        // parameters
        const char* fileName = argv[1];
        const char* revisionString = argv[2];
-       uint32_t revision = atol(revisionString);
 
        try {
                ELFObject elfObject;
@@ -583,9 +583,9 @@
                        exit(1);
                }
 
-               // convert revision number to object endianess and write to 
section
-               uint32_t revisionBuffer = elfObject.GetUInt32(revision);
-               elfObject.Write(info.offset, &revisionBuffer, 
sizeof(revisionBuffer),
+               // write revision string to section
+               elfObject.Write(info.offset, revisionString,
+                       std::min(sizeof(utsname::version), 
strlen(revisionString) + 1),
                        "Failed to write revision.");
 
        } catch (Exception exception) {
@@ -596,7 +596,7 @@
                                strerror(exception.Error()));
                }
                exit(1);
-       }       
+       }
 
        return 0;
 }


Other related posts: