This email list is read-only. Emails sent to this list will be discarded
----------------------------------
ChangeLog | 8 +
moblin-system-daemon/datetime/datetime.c | 256 +++++++++++++++++++++--------
moblin-system-daemon/moblin-system-tool.c | 20 ++-
3 files changed, 213 insertions(+), 71 deletions(-)
New commits:
commit b13c5d2cffac8849fb2d00b5a552376faa4665d7
Author: Lilli Szafranski <[EMAIL PROTECTED]>
Date: Thu Aug 14 11:59:08 2008 -0700
Added gerror handling; fixed bugs in get_all_timezones, set_timezone, and
moblin-system-tool.c
commit c49426251e95beba290e98c973a24374293146a3
Author: Lilli Szafranski <[EMAIL PROTECTED]>
Date: Thu Aug 14 11:57:58 2008 -0700
Added gerror handling; fixed bugs in get_all_timezones, set_timezone, and
moblin-system-tool.c
Diff in this email is a maximum of 400 lines.
diff --git a/ChangeLog b/ChangeLog
index 7c07728..27ea198 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+moblin-settings (2.14)
+
+ * Fixed bugs in get_all_timezones, set_timezone, and moblin-
+ system-tool.c
+ * Added gerror code
+
+ -- Lilli Szafranski <[EMAIL PROTECTED]> Thu Aug 14 11:58:14 PDT 2008
+
moblin-settings (2.13)
* Fixed some build warnings that came up from rpmbuild
diff --git a/moblin-system-daemon/datetime/datetime.c
b/moblin-system-daemon/datetime/datetime.c
index 8a7fe38..79234d2 100644
--- a/moblin-system-daemon/datetime/datetime.c
+++ b/moblin-system-daemon/datetime/datetime.c
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include "moblin-system-dbus.h"
+#include <glib/gil8n.h>
// lilli
#include <sys/time.h>
@@ -36,6 +37,24 @@
// end lilli
extern GQuark error_quark;
+enum
+{
+ INVALID_INPUT,
+ STDLIB_MALLOC_ERROR,
+ STDLIB_REALLOC_ERROR,
+ TIME_LOCALTIME_ERROR,
+ TIME_MKTIME_ERROR,
+ SYS_SETTIMEOFDAY_ERROR,
+ SYS_GETTIMEOFDAY_ERROR,
+ STDIO_FOPEN_ERROR,
+ STDIO_FSEEK_FTELL_ERROR,
+ STDIO_FREAD_ERROR,
+ SYS_STAT_ERROR,
+ UNISTD_UNLINK_ERROR,
+ SYS_STAT_LSTAT_ERROR,
+ UNISTD_SYMLINK_ERROR,
+ UNISTD_READLINK_ERROR
+};
gboolean __verify_time_input(const gint year, const gint month, const gint
day,
const gint hour, const
gint minute, const gint second,
@@ -104,7 +123,9 @@ system_daemon_set_time(MoblinSystemServer * server,
char* errorMsg = NULL;
if(!__verify_time_input(year, month, day, hour, minute, second,
&errorMsg))
{
- // TODO: set GError error here
+ g_set_error (error, error_quark, INVALID_INPUT,
+ errorMsg);
+
PRINTF("[system_daemon_set_time] __verify_time_input
failed:\n\t%s\n", errorMsg);
return FALSE;
}
@@ -114,7 +135,9 @@ system_daemon_set_time(MoblinSystemServer * server,
struct timeval* timev = (struct timeval*)malloc(sizeof(struct timeval));
if(!timev)
{
- // TODO: set GError error here
+ g_set_error (error, error_quark, STDLIB_MALLOC_ERROR,
+ "malloc failed");
+
PRINTF("[system_daemon_set_time] malloc failed:\n\tstruct
timeval* timev = NULL\n");
return FALSE;
@@ -126,7 +149,9 @@ system_daemon_set_time(MoblinSystemServer * server,
struct tm* time = (struct tm*)malloc(sizeof(struct tm));
if(!time)
{
- // TODO: set GError error here
+ g_set_error (error, error_quark, STDLIB_MALLOC_ERROR,
+ "malloc failed");
+
PRINTF("[system_daemon_set_time] malloc failed:\n\tstruct tm*
time = NULL\n");
free(timev);
@@ -152,7 +177,9 @@ system_daemon_set_time(MoblinSystemServer * server,
timev->tv_sec = mktime(time);
if(timev->tv_sec == (time_t)(-1))
{
- // TODO: set GError error here
+ g_set_error (error, error_quark, TIME_MKTIME_ERROR,
+ "mktime error; likely invalid input");
+
PRINTF("[system_daemon_set_time] mktime failed:\n\tLikely that
your input is not valid.\n");// errno= %s\n"), strerror(errno));
free(timev);
@@ -163,7 +190,7 @@ system_daemon_set_time(MoblinSystemServer * server,
return FALSE;
}
- PRINTF("[system_daemon_set_time] mktime successful:\n\tepoch = %d\n",
(int)timev->tv_sec);
+ PRINTF("[system_daemon_set_time] mktime successful:\n\tepoch = %d\n",
((int)timev->tv_sec));
// This function does not support milliseconds
timev->tv_usec = 0;
@@ -171,7 +198,9 @@ system_daemon_set_time(MoblinSystemServer * server,
retVal = settimeofday(timev, timez);
if(retVal)
{
- // TODO: set GError error here
+ g_set_error (error, error_quark, SYS_SETTIMEOFDAY_ERROR,
+ strerror(errno));
+
PRINTF("[system_daemon_set_time] settimeofday failed:\n\t%s\n",
strerror(errno));
free(timev);
@@ -212,18 +241,21 @@ system_daemon_get_time(MoblinSystemServer * server,
retVal = gettimeofday(&timev, &timez);
if(retVal)
{
- // TODO: set GError error here
+ g_set_error (error, error_quark, SYS_GETTIMEOFDAY_ERROR,
+ strerror(errno));
+
PRINTF("[system_daemon_get_time] gettimeofday failed:\n\t%s\n",
strerror(errno));
return FALSE;
}
- PRINTF("[system_daemon_get_time] gettimeofday successful:\n\tepoch =
%d\n", (int)timev.tv_sec);
+ PRINTF("[system_daemon_get_time] gettimeofday successful:\n\tepoch =
%d\n", ((int)timev.tv_sec));
getTime = localtime(&timev.tv_sec);
-
if(getTime == NULL)
{
- // TODO: set GError error here
+ g_set_error (error, error_quark, TIME_LOCALTIME_ERROR,
+ "localtimefailed");
+
PRINTF("[system_daemon_get_time] localtime failed.\n");
return FALSE;
@@ -271,10 +303,13 @@ system_daemon_get_all_timezones(MoblinSystemServer *
server,
{
options = TZ_NAME;
}
-
+
pFile = fopen(FILE_ZONE_TAB, "r");
if(pFile == NULL)
{
+ g_set_error (error, error_quark, STDIO_FOPEN_ERROR,
+ strerror(errno));
+
PRINTF("[system_daemon_get_all_timezones] fopen
failed:\n\t%s\n", strerror(errno));
fclose(pFile);
@@ -292,6 +327,9 @@ system_daemon_get_all_timezones(MoblinSystemServer * server,
if(fileLen == 0)
{
+ g_set_error (error, error_quark, STDIO_FSEEK_FTELL_ERROR,
+ "ftell/fseek error");
+
PRINTF("[system_daemon_get_all_timezones] fseek/ftell
failed:\n\t%s\n", strerror(errno));
fclose(pFile);
@@ -299,12 +337,15 @@ system_daemon_get_all_timezones(MoblinSystemServer *
server,
return FALSE;
}
- PRINTF("[system_daemon_get_all_timezones] fseek/ftell
successful:\n\tfile length = %d\n", (int)fileLen);
+ PRINTF("[system_daemon_get_all_timezones] fseek/ftell
successful:\n\tfile length = %d\n", ((int)fileLen));
//PRINTF("allocating buffer and zones\n");
buffer = (char*)malloc(sizeof(char) * fileLen);
if(!buffer)
{
+ g_set_error (error, error_quark, STDLIB_MALLOC_ERROR,
+ "malloc failed");
+
PRINTF("[system_daemon_get_all_timezones] malloc
failed:\n\tchar* buffer == NULL\n");
fclose(pFile);
@@ -319,6 +360,9 @@ system_daemon_get_all_timezones(MoblinSystemServer * server,
*tz_list = (char**)malloc(sizeof(char*) * approxLines);
if(!*tz_list)
{
+ g_set_error (error, error_quark, STDLIB_MALLOC_ERROR,
+ "malloc failed");
+
PRINTF("[system_daemon_get_all_timezones] malloc
failed:\n\tchar** tz_list == NULL\n");
free(buffer);
@@ -331,8 +375,13 @@ system_daemon_get_all_timezones(MoblinSystemServer *
server,
}
memset(*tz_list, '\0', approxLines);
+ PRINTF("[system_daemon_get_all_timezones] memory allocations
successful.\n");
+
if (fread (buffer, sizeof(char), fileLen, pFile) != fileLen)
{
+ g_set_error (error, error_quark, STDIO_FREAD_ERROR,
+ strerror(errno));
+
PRINTF("[system_daemon_get_all_timezones] fread
failed:\n\t%s\n", strerror(errno));
free(buffer);
@@ -346,6 +395,7 @@ system_daemon_get_all_timezones(MoblinSystemServer * server,
return FALSE;
}
+ PRINTF("[system_daemon_get_all_timezones] fread successful:\n\t%ld
bytes read.\n", fileLen);
tok = strtok(buffer, "\n");
while(tok != NULL)
@@ -355,18 +405,29 @@ system_daemon_get_all_timezones(MoblinSystemServer *
server,
//PRINTF("tok = \t\"%s\"\n", tok);
if(tok[0] != '#')
{
+ //PRINTF("%s\n", tok);
orig = origIter = tok;//(char*)malloc(sizeof(char) *
(strlen(tok)+2));
//strncpy(orig, tok, strlen(tok) + 1);
copyIter = copy = (char*)malloc(sizeof(char) *
(strlen(tok)+2));
+ if(!copyIter)
+ {
+ g_set_error (error, error_quark,
STDLIB_MALLOC_ERROR,
+ "malloc failed");
+
+ PRINTF("[system_daemon_get_all_timezones]
malloc failed:\n\tchar* copyIter == NULL\n");
+
+ fclose(pFile);
+ pFile = NULL;
+
+ return FALSE;
+ }
memset(copyIter, '\0', strlen(tok) + 2);
if(!(options & TZ_ALL))
{
while(optionsBitMask > 0)
{
-
//PRINTF("optionsBitMask=%d\tflags=%d\t(optionsBitMask&options)=%d\n",
optionsBitMask, options, (optionsBitMask & options));
-
tabIter = strpbrk(origIter, "\t");
if(!tabIter)
tabIter = strrchr(origIter,
'\0');
@@ -383,6 +444,9 @@ system_daemon_get_all_timezones(MoblinSystemServer * server,
copyIter += substrlen;
copyIter[0] = '\0';
}
+ if(*tabIter == '\0')
+ break;
+
origIter += substrlen;
optionsBitMask /= 2; // 0b00001000 ->
0b00000100 -> 0b00000010 -> 0b00000001 -> 0
@@ -398,11 +462,15 @@ system_daemon_get_all_timezones(MoblinSystemServer *
server,
if(arrIter > arrLen - 1)
{
arrLen *= 2;
- *tz_list = (char**)realloc(*tz_list,
sizeof(char*) * arrLen);
+ PRINTF("[system_daemon_get_all_timezones]
reallocating tz_list:\n\tarrLen = %d\n", arrLen);
+ *tz_list = (char**)realloc(*tz_list,
sizeof(char*) * arrLen);
if(!*tz_list)
{
-
PRINTF("[system_daemon_get_all_timezones] malloc failed:\n\tchar** tz_list =
NULL\n");
+ g_set_error (error, error_quark,
STDLIB_REALLOC_ERROR,
+ "realloc failed");
+
+
PRINTF("[system_daemon_get_all_timezones] realloc failed:\n\tchar** tz_list =
NULL\n");
free(buffer);
buffer = NULL;
@@ -413,14 +481,15 @@ system_daemon_get_all_timezones(MoblinSystemServer *
server,
return FALSE;
}
}
- *tz_list[arrIter] = copy;
-
+ (*tz_list)[arrIter] = copy;
+
arrIter++;
}
+
tok = strtok(NULL, "\n");
}
- *tz_list[arrIter] = NULL;
+ (*tz_list)[arrIter] = NULL;
free(buffer);
buffer = NULL;
@@ -436,7 +505,7 @@ gboolean
system_daemon_set_timezone(MoblinSystemServer * server,
const gchar *tz, GError **error)
{
- PRINTF("[system_daemon_set_timezone]\n");
+ PRINTF("[system_daemon_set_timezone] start\n");
//char* path = "/etc/localtime";
char* newPath = NULL;
@@ -445,64 +514,101 @@ system_daemon_set_timezone(MoblinSystemServer * server,
struct stat buffer;
int retVal = 0;
- PRINTF("[system_daemon_set_timezone] Checking for previously configured
timezone.\n");
+ len = strlen(tz) + strlen(LOCAL_INFO_DIR) + 1;
+ newPath = (char*)malloc(sizeof(char) * len);
+ if(!newPath)
+ {
+ g_set_error (error, error_quark, STDLIB_MALLOC_ERROR,
+ "malloc failed");
+
+ PRINTF("[system_daemon_set_timezone] malloc failed:\n\tchar*
newpath = NULL\n");
+
+ return FALSE;
+ }
+ memset(newPath, '\0', len);
+
+ strncpy(newPath, LOCAL_INFO_DIR, strlen(LOCAL_INFO_DIR));
+ strncat(newPath, tz, strlen(tz));
- retVal = lstat(ETC_LOCAL_DIR, &buffer);
- if(!retVal) // lstat succeeded
+ PRINTF("path:%s\n", newPath);
+ retVal = stat(newPath, &buffer);
+ if(retVal)
{
- PRINTF("[system_daemon_set_timezone] lstat successful.\n");
- if(S_ISLNK(buffer.st_mode)) // there is a symbolic link between
/etc/localtime and /usr/zoneinfo/...
+ if(errno != ENOENT) // lstat failed()
{
- PRINTF("[system_daemon_set_timezone] Previously
configured timezone found. Removing.\n");
+ g_set_error (error, error_quark, SYS_STAT_ERROR,
+ strerror(errno));
- retVal = unlink(ETC_LOCAL_DIR);
- if(retVal)
- {
- // TODO: set GError error here
- PRINTF("[system_daemon_set_timezone] ulink
failed:\n\t%s\n", strerror(errno));
-
- return FALSE;
- }
- PRINTF("[system_daemon_set_timezone] ulink
successful.\n");
- PRINTF("[system_daemon_set_timezone] Previously
configured timezone removed.\n");
- PRINTF("Timezone (symlink) removed.\n");
+ PRINTF("[system_daemon_set_timezone] stat
failed:\n\t%s\n", strerror(errno));
+
+ free(newPath);
+ newPath = NULL;
+
+ return FALSE;
}
- else // /etc/localtime exists, but there is no link to anything
+ else // lstat() failed because the file (/etc/localtime) did
not exist
{
- PRINTF("[system_daemon_set_timezone] No previously
configured timezone found.\n");
+ g_set_error (error, error_quark, SYS_STAT_ERROR,
+ "file does not exist");
+
+ PRINTF("[system_daemon_set_timezone] stat failed:\n\t%s
was not a valid timezone.\n", tz);
+
+ free(newPath);
+ newPath = NULL;
+
+ return FALSE;
+ }
+ }
+
+ PRINTF("[system_daemon_set_timezone] Checking for previously configured
timezone.\n");
+
+ retVal = lstat(ETC_LOCAL_DIR, &buffer);
+ if(!retVal) // lstat succeeded
+ {
+ PRINTF("[system_daemon_set_timezone] lstat
successful:\n\tPreviously configured timezone found. Removing.\n\n");
+
+ retVal = unlink(ETC_LOCAL_DIR);
+ if(retVal)
+ {
+ g_set_error (error, error_quark, UNISTD_UNLINK_ERROR,
+ strerror(errno));
+
+ PRINTF("[system_daemon_set_timezone] unlink
failed:\n\t%s\n", strerror(errno));
+
+ free(newPath);
+ newPath = NULL;
+
+ return FALSE;
}
+ PRINTF("[system_daemon_set_timezone] unlink successful:\n\t
Previously configured timezone removed.\n");
}
else if(errno != ENOENT) // lstat failed()
{
- // TODO: set GError error here
+ g_set_error (error, error_quark, SYS_STAT_LSTAT_ERROR,
_______________________________________________
Commits mailing list
[email protected]
https://www.moblin.org/mailman/listinfo/commits