Re: fork()/exec()/waitpid() error handling in Grip

Mikko Rapeli <[email protected]>
Newsgroups gmane.comp.multimedia.grip.user
Message-ID <20050220164156.GK13031@nalle>
Ok, I did some scratching finally and here are the results for Grip
3.2.0 and 3.3.0 respectively.

They were developed and tested with oggenc encoder returning an error 
since /usr/lib/libFLAC.so.6 symlinc pointed to a non-existing file, but the
code should work when the ripping process returns an error too.

I didn't really understand all what UpdateRipProgress does so the error 
handling path doesn't do anything except complaining yet. Perhaps ripped files
should not be deleted if the encoder fails.

The 3.2.0 patch could close this Debian bug, but that's up to the maintainer:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=166043

Any comments?

-Mikko
grip_320_add_exit_status_check_04.patch (text/plain, 2.7 KB)
Common subdirectories: grip-3.2.0-debian-orig/src/.deps and grip-3.2.0/src/.deps
Binary files grip-3.2.0-debian-orig/src/grip and grip-3.2.0/src/grip differ
Common subdirectories: grip-3.2.0-debian-orig/src/.libs and grip-3.2.0/src/.libs
diff --exclude '*.o' -u grip-3.2.0-debian-orig/src/rip.c grip-3.2.0/src/rip.c
--- grip-3.2.0-debian-orig/src/rip.c	2005-01-16 15:49:10.000000000 +0200
+++ grip-3.2.0/src/rip.c	2005-02-20 18:13:44.290689912 +0200
@@ -815,6 +815,8 @@
   gboolean result=FALSE;
   char *conv_str;
   gsize rb,wb;
+  int status;
+  pid_t pid;
 
   uinfo=&(ginfo->gui_info);
 
@@ -883,14 +885,26 @@
     }
 
     /* Check if a rip finished */
+    pid = waitpid(ginfo->rippid, &status, WNOHANG);
+    
     if((ginfo->using_builtin_cdp&&!ginfo->in_rip_thread) ||
-       (!ginfo->using_builtin_cdp&&waitpid(ginfo->rippid,NULL,WNOHANG))) {
-      if(!ginfo->using_builtin_cdp) waitpid(ginfo->rippid,NULL,0);
-      else {
+       (!ginfo->using_builtin_cdp&&WIFEXITED(status))) {
+
+      if(ginfo->using_builtin_cdp) {
 	CopyPixmap(GTK_PIXMAP(uinfo->empty_image),
 		   GTK_PIXMAP(uinfo->lcd_smile_indicator));
 	CopyPixmap(GTK_PIXMAP(uinfo->empty_image),
 		   GTK_PIXMAP(uinfo->smile_indicator));
+      } else if (WIFEXITED(status)) { 
+        if ((WEXITSTATUS(status) == EXIT_SUCCESS) &&
+            (pid == ginfo->rippid)) {
+		 LogStatus(ginfo, _("Rip succeeded! %s PID = %d returned %d\n"), 
+                   ginfo->ripexename, ginfo->rippid, WEXITSTATUS(status));
+	} else {
+		 LogStatus(ginfo, _("Rip failed! %s PID = %d returned %d\n"), 
+                   ginfo->ripexename, ginfo->rippid, WEXITSTATUS(status));
+		 DisplayMsg(_("Error: rip failed."));
+	}
       }
 
       LogStatus(ginfo,_("Rip finished\n"));
@@ -990,10 +1004,20 @@
 				percent);
       }
       
-      if(waitpid(ginfo->mp3pid[mycpu],NULL,WNOHANG)) {
-        waitpid(ginfo->mp3pid[mycpu],NULL,0);
-        ginfo->encoding&=~(1<<mycpu);
+      pid = waitpid(ginfo->mp3pid[mycpu], &status, WNOHANG);
+      
+      if(WIFEXITED(status)) {
+        if ((WEXITSTATUS(status) == EXIT_SUCCESS) &&
+            (pid == ginfo->mp3pid[mycpu])) {
+		 LogStatus(ginfo, _("Encoding succeeded! %s process PID = %d returned %d\n"), 
+                   ginfo->mp3exename, ginfo->mp3pid[mycpu], WEXITSTATUS(status));
+	} else {
+		 LogStatus(ginfo, _("Encoding failed! %s process PID = %d returned %d\n"), 
+                   ginfo->mp3exename, ginfo->mp3pid[mycpu], WEXITSTATUS(status));
+		 DisplayMsg(_("Error: encoding failed."));
+	}
 
+        ginfo->encoding&=~(1<<mycpu);
 	LogStatus(ginfo,_("Finished encoding on cpu %d\n"),mycpu);
 	ginfo->all_enclast[mycpu]=0;
         gtk_progress_bar_update(GTK_PROGRESS_BAR(uinfo->mp3progbar[mycpu]),
grip_330_add_exit_status_check_04.patch (text/plain, 2.6 KB)
Only in grip-3.3.0/src/: .deps
Only in grip-3.3.0/src/: grip
Only in grip-3.3.0/src/: .libs
Only in grip-3.3.0/src/: Makefile
diff --exclude '*.o' -u grip-3.3.0-original/src/rip.c grip-3.3.0/src/rip.c
--- grip-3.3.0-original/src/rip.c	2005-01-29 21:16:51.000000000 +0200
+++ grip-3.3.0/src/rip.c	2005-02-20 18:10:34.560533280 +0200
@@ -791,7 +791,9 @@
   gboolean result=FALSE;
   char *conv_str;
   gsize rb,wb;
-  
+  int status;
+  pid_t pid;
+
   uinfo=&(ginfo->gui_info);
 
   if(ginfo->ripping) {
@@ -865,14 +867,28 @@
     }
 
     /* Check if a rip finished */
+    pid = waitpid(ginfo->rippid, &status, WNOHANG);
+    
     if((ginfo->using_builtin_cdp&&!ginfo->in_rip_thread) ||
-       (!ginfo->using_builtin_cdp&&waitpid(ginfo->rippid,NULL,WNOHANG))) {
-      if(!ginfo->using_builtin_cdp) waitpid(ginfo->rippid,NULL,0);
-      else {
+       (!ginfo->using_builtin_cdp&&WIFEXITED(status))) {
+
+      if(ginfo->using_builtin_cdp) {
 	CopyPixmap(GTK_PIXMAP(uinfo->empty_image),
 		   GTK_PIXMAP(uinfo->lcd_smile_indicator));
 	CopyPixmap(GTK_PIXMAP(uinfo->empty_image),
 		   GTK_PIXMAP(uinfo->smile_indicator));
+      } else if (WIFEXITED(status)) { 
+        if ((WEXITSTATUS(status) == EXIT_SUCCESS) &&
+            (pid == ginfo->rippid)) {
+		 LogStatus(ginfo, _("Rip succeeded! %s PID = %d returned %d\n"), 
+                   ginfo->ripexename, ginfo->rippid, WEXITSTATUS(status));
+	} else {
+		 LogStatus(ginfo, _("Rip failed! %s PID = %d returned %d\n"), 
+                   ginfo->ripexename, ginfo->rippid, WEXITSTATUS(status));
+
+                 gnome_app_warning((GnomeApp *)ginfo->gui_info.app,
+                      _("Error: rip failed."));
+	}
       }
 
       LogStatus(ginfo,_("Rip finished\n"));
@@ -976,8 +992,20 @@
 				percent);
       }
       
-      if(waitpid(ginfo->mp3pid[mycpu],NULL,WNOHANG)) {
-        waitpid(ginfo->mp3pid[mycpu],NULL,0);
+      pid = waitpid(ginfo->mp3pid[mycpu], &status, WNOHANG);
+      
+      if(WIFEXITED(status)) {
+        if ((WEXITSTATUS(status) == EXIT_SUCCESS) &&
+            (pid == ginfo->mp3pid[mycpu])) {
+		 LogStatus(ginfo, _("Encoding succeeded! %s process PID = %d returned %d\n"), 
+                   ginfo->mp3exename, ginfo->mp3pid[mycpu], WEXITSTATUS(status));
+	} else {
+		 LogStatus(ginfo, _("Encoding failed! %s process PID = %d returned %d\n"), 
+                   ginfo->mp3exename, ginfo->mp3pid[mycpu], WEXITSTATUS(status));
+                 gnome_app_warning((GnomeApp *)ginfo->gui_info.app,
+                      _("Error: encode failed."));
+	}
+
         ginfo->encoding&=~(1<<mycpu);
 
 	LogStatus(ginfo,_("Finished encoding on cpu %d\n"),mycpu);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.