summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Cantrell <dcantrell@redhat.com>2009-11-16 19:00:49 -1000
committerDavid Cantrell <dcantrell@redhat.com>2009-11-18 14:42:02 -1000
commit5a29882c8c85d94d7cc4705f719512f59e48bb24 (patch)
tree96ef369adf67bfd183bfd6319d67dc5b79b7c5e0
parent56ff71cb5b8ff889cf0881c2471ab2cb673b0253 (diff)
downloadanaconda-5a29882c8c85d94d7cc4705f719512f59e48bb24.tar.gz
anaconda-5a29882c8c85d94d7cc4705f719512f59e48bb24.tar.xz
anaconda-5a29882c8c85d94d7cc4705f719512f59e48bb24.zip
Clean up initProductInfo() in loader.c.
Use g_file_get_contents() and g_strsplit() to read in .buildstamp data and split it up. Remove static buffers.
-rw-r--r--loader/loader.c82
1 files changed, 45 insertions, 37 deletions
diff --git a/loader/loader.c b/loader/loader.c
index 0ea57cb31..89edee257 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -251,51 +251,59 @@ void stopNewt(void) {
newtRunning = 0;
}
-static char * productName = NULL;
-static char * productPath = NULL;
-static char * productArch = NULL;
-static char * productStamp = NULL;
+static gchar *productName = NULL;
+static gchar *productPath = NULL;
+static gchar *productArch = NULL;
static void initProductInfo(void) {
- FILE *f;
- int i;
+ gchar *contents = NULL;
+ gchar **lines = NULL, **stamp = NULL;
+ GError *fileErr = NULL;
+
+ if (!g_file_get_contents("/.buildstamp", &contents, NULL, &fileErr)) {
+ logMessage(ERROR, "error reading .buildstamp: %s", fileErr->message);
+ g_error_free(fileErr);
+ productName = g_strdup("anaconda");
+ productArch = g_strdup("unknown architecture");
+ productPath = g_strdup("anaconda");
+ return;
+ }
- f = fopen("/.buildstamp", "r");
- if (!f) {
- productName = strdup("anaconda");
- productPath = strdup("anaconda");
- } else {
- productStamp = malloc(256);
- productName = malloc(256);
- productPath = malloc(256);
- productStamp = fgets(productStamp, 256, f); /* stamp time and architecture */
- productArch = strstr(productStamp, "."); /* architecture is separated by dot */
- if(productArch) productArch++;
-
- productName = fgets(productName, 256, f); /* product name */
- productPath = fgets(productPath, 256, f); /* product version */
- productPath = fgets(productPath, 256, f); /* product path */
-
- i = strlen(productName) - 1;
- while (isspace(*(productName + i))) {
- *(productName + i) = '\0';
- i--;
- }
- i = strlen(productPath) - 1;
- while (isspace(*(productPath + i))) {
- *(productPath + i) = '\0';
- i--;
+ /* .buildstamp uses the first 3 lines in this format:
+ * STAMP.productArch
+ * productName
+ * productPath
+ */
+ lines = g_strsplit(contents, "\n", 0);
+ g_free(contents);
+
+ if ((lines != NULL) && (g_strv_length(lines) >= 3)) {
+ /* STAMP.productArch */
+ stamp = g_strsplit(lines[0], ".", 0);
+
+ if ((stamp != NULL) && (g_strv_length(stamp) == 2)) {
+ productArch = g_strdup(stamp[1]);
+ } else {
+ productArch = g_strdup("unknown architecture");
}
- i = strlen(productArch) - 1;
- while (isspace(*(productArch + i))) {
- *(productArch + i) = '\0';
- i--;
+
+ if (stamp) {
+ g_strfreev(stamp);
}
+
+ productName = g_strdup(lines[1]);
+ productPath = g_strdup(lines[2]);
+ } else {
+ productName = g_strdup("anaconda");
+ productArch = g_strdup("unknown architecture");
+ productPath = g_strdup("anaconda");
}
- if(!productArch) productArch = strdup("unknown architecture");
+ if (lines) {
+ g_strfreev(lines);
+ }
- fclose(f);
+ return;
}
char * getProductName(void) {