1.1 --- a/bl/spawn.c Fri Jan 27 16:18:02 2012 +0000
1.2 +++ b/bl/spawn.c Fri Jan 27 21:40:35 2012 +0000
1.3 @@ -7,26 +7,22 @@
1.4
1.5 #define SPAWN_BUFSIZE 128
1.6
1.7 -gboolean spawn_sync(char **argv,char **standard_output,int *exit_status)
1.8 +gboolean spawn_sync(char **argv,char **standard_output,int *exit_status,
1.9 + GError **error)
1.10 {
1.11 /* Don't use g_spawn_sync on WIN32 for now to avoid needing the helper */
1.12 #ifndef WIN32
1.13 - char *standard_error;
1.14 - GError *error=NULL;
1.15 + char *standard_error=NULL;
1.16 gboolean retval;
1.17 GSpawnFlags flags=G_SPAWN_SEARCH_PATH;
1.18 if (!standard_output)
1.19 flags=G_SPAWN_STDOUT_TO_DEV_NULL;
1.20 retval=g_spawn_sync(NULL,argv,NULL,flags,NULL,NULL,standard_output,
1.21 - &standard_error,exit_status,&error);
1.22 - fputs(standard_error,stderr);
1.23 + &standard_error,exit_status,error);
1.24 + if (standard_error)
1.25 + fputs(standard_error,stderr);
1.26 g_free(standard_error);
1.27 - if (!retval)
1.28 - {
1.29 - fprintf(stderr,"%s\n",error->message);
1.30 - g_error_free(error);
1.31 - }
1.32 - else if (exit_status)
1.33 + if (retval && exit_status)
1.34 *exit_status=WEXITSTATUS(*exit_status);
1.35 return retval;
1.36 #else
1.37 @@ -45,7 +41,8 @@
1.38 g_string_free(command_line,TRUE);
1.39 if (!fp)
1.40 {
1.41 - perror(command_line->str);
1.42 + g_set_error(error,G_FILE_ERROR,g_file_error_from_errno(errno),
1.43 + "%s: %s",command_line->str,g_strerror(errno));
1.44 return FALSE;
1.45 }
1.46 string=g_string_new(NULL);
1.47 @@ -56,7 +53,8 @@
1.48 n=fread(string->str+len,1,SPAWN_BUFSIZE,fp);
1.49 if (n<0)
1.50 {
1.51 - perror("fread");
1.52 + g_set_error(error,G_FILE_ERROR,g_file_error_from_errno(errno),
1.53 + "Error reading from bookloupe: %s",g_strerror(errno));
1.54 (void)pclose(fp);
1.55 g_string_free(string,TRUE);
1.56 return FALSE;
1.57 @@ -66,7 +64,8 @@
1.58 r=pclose(fp);
1.59 if (r<0)
1.60 {
1.61 - perror("pclose");
1.62 + g_set_error(error,G_FILE_ERROR,g_file_error_from_errno(errno),
1.63 + "Error reading from bookloupe: %s",g_strerror(errno));
1.64 g_string_free(string,TRUE);
1.65 return FALSE;
1.66 }