Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=aadcf52da2706d7c7e7ffde00205a1666505cc0a

commit aadcf52da2706d7c7e7ffde00205a1666505cc0a
Author: James Buren <[email protected]>
Date:   Wed Oct 17 16:17:44 2012 -0500

replace repetitive logging commands with a macro

diff --git a/src/block.c b/src/block.c
index 0db8e53..a1d110f 100644
--- a/src/block.c
+++ b/src/block.c
@@ -131,7 +131,7 @@ static bool getuuid(struct disk *disk)

if((pipe = popen(command,"r")) == 0)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -152,7 +152,7 @@ static bool getuuid(struct disk *disk)
}
else
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}
}
@@ -222,7 +222,7 @@ static bool newpartition(struct disk *disk,long long 
size,struct partition *part
)
{
errno = ERANGE;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -243,19 +243,19 @@ extern struct device *device_open(const char *path)
if(path == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
goto bail;
}

if((fd = open(path,O_RDONLY)) == -1 || fstat(fd,&st) == -1)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
goto bail;
}

if(S_ISBLK(st.st_mode) && (ioctl(fd,BLKGETSIZE64,&size) == -1 || 
ioctl(fd,BLKSSZGET,&sectorsize) == -1))
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
goto bail;
}
else if(S_ISREG(st.st_mode))
@@ -266,7 +266,7 @@ extern struct device *device_open(const char *path)
else
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
goto bail;
}

@@ -277,7 +277,7 @@ extern struct device *device_open(const char *path)
if(size <= 0 || sectorsize <= 0 || (MEBIBYTE % sectorsize) != 0 || (size % 
sectorsize) != 0)
{
errno = ERANGE;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
goto bail;
}

@@ -336,26 +336,26 @@ extern struct disk *disk_open(struct device *device)
if(device == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
goto bail;
}

if((fd = open(device->path,O_RDONLY)) == -1)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
goto bail;
}

if((probe = blkid_new_probe()) == 0)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
goto bail;
}

if(blkid_probe_set_device(probe,fd,0,0) == -1)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
goto bail;
}

@@ -457,7 +457,7 @@ extern void disk_new_table(struct disk *disk,const char 
*type)
if(disk == 0 || type == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return;
}

@@ -470,7 +470,7 @@ extern void disk_new_table(struct disk *disk,const char 
*type)
else
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return;
}

@@ -492,7 +492,7 @@ extern int disk_create_partition(struct disk *disk,long 
long size)
if(disk == 0 || disk->size < 0 || size <= 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return -1;
}

@@ -505,7 +505,7 @@ extern int disk_create_partition(struct disk *disk,long 
long size)
)
{
errno = ERANGE;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return -1;
}

@@ -529,7 +529,7 @@ extern int disk_create_extended_partition(struct disk *disk)
if(disk == 0 || disk->size < 0 || disk->type != DISKTYPE_DOS)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return -1;
}

@@ -537,7 +537,7 @@ extern int disk_create_extended_partition(struct disk *disk)
if(disk->table[i].dostype == DOS_EXTENDED)
{
errno = EINVAL;
-      fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+      error(strerror(errno));
return -1;
}

@@ -563,7 +563,7 @@ extern int disk_create_logical_partition(struct disk 
*disk,long long size)
if(disk == 0 || disk->size < 0 || disk->type != DISKTYPE_DOS || size <= 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return -1;
}

@@ -580,7 +580,7 @@ extern int disk_create_logical_partition(struct disk 
*disk,long long size)
if(ext == 0 || ext->number > 4)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return -1;
}

@@ -608,7 +608,7 @@ extern int disk_create_logical_partition(struct disk 
*disk,long long size)
)
{
errno = ERANGE;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return -1;
}

@@ -628,7 +628,7 @@ extern void disk_delete_partition(struct disk *disk)
if(disk == 0 || disk->size <= 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return;
}

@@ -646,7 +646,7 @@ extern void disk_partition_set_purpose(struct disk 
*disk,int n,const char *purpo
if(disk == 0 || n < 0 || n > disk->size || purpose == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return;
}

@@ -693,7 +693,7 @@ extern void disk_partition_set_active(struct disk *disk,int 
n,bool active)
if(disk == 0 || n < 0 || n > disk->size)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return;
}

@@ -725,7 +725,7 @@ extern const char *disk_partition_get_purpose(struct disk 
*disk,int n)
if(disk == 0 || n < 0 || n > disk->size)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return 0;
}

@@ -773,7 +773,7 @@ extern bool disk_partition_get_active(struct disk *disk,int 
n)
if(disk == 0 || n < 0 || n > disk->size)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -794,7 +794,7 @@ extern int disk_partition_get_number(struct disk *disk,int 
n)
if(disk == 0 || n < 0 || n > disk->size)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return 0;
}

@@ -810,7 +810,7 @@ extern long long disk_partition_get_size(struct disk 
*disk,int n)
if(disk == 0 || n < 0 || n > disk->size)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return 0;
}

@@ -831,7 +831,7 @@ extern bool disk_flush(struct disk *disk)
if(disk == 0 || (disk->type != DISKTYPE_DOS && disk->type != DISKTYPE_GPT))
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

diff --git a/src/install.c b/src/install.c
index 9b1cfa1..ffb51c1 100644
--- a/src/install.c
+++ b/src/install.c
@@ -404,7 +404,7 @@ static bool install_database_update(void)
if(dl_database == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -438,7 +438,7 @@ static bool install_groups_get(struct install **groups)
if(groups == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -560,7 +560,7 @@ static bool install_groups_install(const struct install 
*groups)
if(groups == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

diff --git a/src/local.h b/src/local.h
index 8df338a..91d78b3 100644
--- a/src/local.h
+++ b/src/local.h
@@ -22,6 +22,7 @@
#define MEBIBYTE (1LL << 20LL)
#define GIBIBYTE (1LL << 30LL)
#define TEBIBYTE (1LL << 40LL)
+#define error(S) fprintf(logfile,"%s: %s\n",__func__,S)

struct global
{
diff --git a/src/postconfig.c b/src/postconfig.c
index 01a6d4d..c42339f 100644
--- a/src/postconfig.c
+++ b/src/postconfig.c
@@ -22,7 +22,7 @@ static bool is_root_setup(void)

if(file == 0)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -60,7 +60,7 @@ static bool is_user_setup(void)

if(file == 0)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -99,7 +99,7 @@ static bool root_action(struct account *account)
if(account == 0 || account->user == 0 || account->password == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -115,7 +115,7 @@ static bool user_action(struct account *account)
if(account == 0 || account->user == 0 || account->password == 0 || 
account->group == 0 || account->groups == 0 || account->home == 0 || 
account->shell == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -184,7 +184,7 @@ static bool get_timezone_data(void)
{
if(nftw(TZSEARCHDIR,timezone_nftw_callback,512,FTW_DEPTH|FTW_PHYS) == -1)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -192,7 +192,7 @@ static bool get_timezone_data(void)

if(nftw(TZSEARCHDIR,timezone_nftw_callback,512,FTW_DEPTH|FTW_PHYS) == -1)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -207,7 +207,7 @@ static bool time_action(char *zone,bool utc)

if(unlink(TZFILE) == -1 && errno != ENOENT)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -215,7 +215,7 @@ static bool time_action(char *zone,bool utc)

if(symlink(buf,TZFILE) == -1)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -235,25 +235,25 @@ static bool postconfig_run(void)

if(chdir(INSTALL_ROOT) == -1)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

if(mount("none",INSTALL_ROOT "/dev","devtmpfs",0,0) == -1)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

if(mount("none",INSTALL_ROOT "/proc","proc",0,0) == -1)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

if(mount("none",INSTALL_ROOT "/sys","sysfs",0,0) == -1)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -278,19 +278,19 @@ static bool postconfig_run(void)

if(umount2(INSTALL_ROOT "/dev",MNT_DETACH) == -1)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

if(umount2(INSTALL_ROOT "/proc",MNT_DETACH) == -1)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

if(umount2(INSTALL_ROOT "/sys",MNT_DETACH) == -1)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

diff --git a/src/ui_newt.c b/src/ui_newt.c
index 47279d4..4aa349e 100644
--- a/src/ui_newt.c
+++ b/src/ui_newt.c
@@ -46,7 +46,7 @@ extern int ui_main(int argc,char **argv)
if(module->run == 0 || module->reset == 0 || module->name == 0)
{
errno = EINVAL;
-      fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+      error(strerror(errno));
code = EXIT_FAILURE;
break;
}
@@ -89,7 +89,7 @@ extern void ui_dialog_text(const char *title,const char *text)
if(title == 0 || text == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return;
}

@@ -148,7 +148,7 @@ extern bool ui_dialog_yesno(const char *title,const char 
*text,bool defaultno)
if(title == 0 || text == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -226,7 +226,7 @@ extern bool ui_dialog_progress(const char *title,const char 
*text,int percent)
if(title == 0 || text == 0 || percent < 0 || percent > 100)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -287,7 +287,7 @@ extern bool ui_window_root(struct account *data)
if(data == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -416,7 +416,7 @@ extern bool ui_window_user(struct account *data)
if(data == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -550,7 +550,7 @@ extern bool ui_window_time(char **data,char **zone,bool 
*utc)
if(data == 0 || zone == 0 || utc == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -635,7 +635,7 @@ extern bool ui_window_install(struct install *data)
if(data == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

diff --git a/src/utility.c b/src/utility.c
index ba5a37e..2228660 100644
--- a/src/utility.c
+++ b/src/utility.c
@@ -8,7 +8,7 @@ extern bool mkdir_recurse(const char *path)
if(path == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -20,7 +20,7 @@ extern bool mkdir_recurse(const char *path)

if(mkdir(buf,0755) == -1 && errno != EEXIST)
{
-      fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+      error(strerror(errno));
return false;
}

@@ -31,7 +31,7 @@ extern bool mkdir_recurse(const char *path)

if(mkdir(buf,0755) == -1 && errno != EEXIST)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -46,7 +46,7 @@ extern bool size_to_string(char *s,size_t n,long long 
size,bool pad)
if(s == 0 || n == 0 || size < 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -92,7 +92,7 @@ extern int get_text_length(const char *s)
if(s == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return -1;
}

@@ -104,7 +104,7 @@ extern int get_text_length(const char *s)

if(n == (size_t) -1 || n == (size_t) -2)
{
-      fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+      error(strerror(errno));
return -1;
}

@@ -129,7 +129,7 @@ extern bool execute(const char *command,const char 
*root,pid_t *cpid)
if(command == 0 || root == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -137,7 +137,7 @@ extern bool execute(const char *command,const char 
*root,pid_t *cpid)

if((pid = fork()) == -1)
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -173,7 +173,7 @@ extern bool execute(const char *command,const char 
*root,pid_t *cpid)

if(waitpid(pid,&status,0) == -1 || !WIFEXITED(status))
{
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -187,7 +187,7 @@ extern void *memdup(const void *mem,size_t size)
if(mem == 0 || size == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return 0;
}

@@ -199,7 +199,7 @@ extern void *malloc0(size_t size)
if(size == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return 0;
}

@@ -218,7 +218,7 @@ extern int get_text_screen_width(const char *s)
if(s == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return -1;
}

@@ -230,7 +230,7 @@ extern int get_text_screen_width(const char *s)

if(n == (size_t) -1 || n == (size_t) -2)
{
-      fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+      error(strerror(errno));
return -1;
}

@@ -267,7 +267,7 @@ extern bool get_text_screen_size(const char *text,int 
*width,int *height)
if(text == 0 || width == 0 || height == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -304,7 +304,7 @@ extern bool get_button_screen_size(const char *text,int 
*width,int *height)
if(text == 0 || width == 0 || height == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -330,7 +330,7 @@ extern bool get_label_screen_size(const char *text,int 
*width,int *height)
if(text == 0 || width == 0 || height == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}

@@ -354,7 +354,7 @@ extern bool get_checkbox_screen_size(const char *text,int 
*width,int *height)
if(text == 0 || width == 0 || height == 0)
{
errno = EINVAL;
-    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    error(strerror(errno));
return false;
}
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to