]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_copy: use exit() to replace killall()
authorJunxiao Bi <junxiao.bi@oracle.com>
Tue, 20 May 2014 08:30:23 +0000 (18:30 +1000)
committerDave Chinner <david@fromorbit.com>
Tue, 20 May 2014 08:30:23 +0000 (18:30 +1000)
Sending a SIGKILL signal to child thread will terminate the whole process,
xfs_copy will return an error value 137. This cause confuse for script to
know whether the copy successes.

Calling exit() in main thread can terminate the whole process and return the
right value. Replace killall()+abort() with exit(1) to match the old way
exit in error case. Also remove killall()+pthread_exit(NULL) since return 0
will be followed by an exit(0) to terminate the process.

[ Christoph Hellwig:
Btw, I think the reason for this cruft is that xfs_copy was originally
written using the IRIX sproc interface, and the port to pthreads didn't
remove this gem:

http://marc.info/?l=linux-xfs&m=99535721110020&w=2 ]

Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
copy/xfs_copy.c

index 71adb5700d5567ddd6d8f4cc08547c31212228e2..f4c84e30ddbd0eda6b53cd156ad6be41994d7c20 100644 (file)
@@ -216,25 +216,6 @@ handle_error:
        return NULL;
 }
 
-void
-killall(void)
-{
-       int i;
-
-       /* only the parent gets to kill things */
-
-       if (getpid() != parent_pid)
-               return;
-
-       for (i = 0; i < num_targets; i++)  {
-               if (target[i].state == ACTIVE)  {
-                       /* kill up target threads */
-                       pthread_kill(target[i].pid, SIGKILL);
-                       pthread_mutex_unlock(&targ[i].wait);
-               }
-       }
-}
-
 void
 handler(int sig)
 {
@@ -400,8 +381,7 @@ read_wbuf(int fd, wbuf *buf, xfs_mount_t *mp)
        if (buf->length > buf->size)  {
                do_warn(_("assert error:  buf->length = %d, buf->size = %d\n"),
                        buf->length, buf->size);
-               killall();
-               abort();
+               exit(1);
        }
 
        if ((res = read(fd, buf->data, buf->length)) < 0)  {
@@ -594,11 +574,6 @@ main(int argc, char **argv)
 
        parent_pid = getpid();
 
-       if (atexit(killall))  {
-               do_log(_("%s: couldn't register atexit function.\n"), progname);
-               die_perror();
-       }
-
        /* open up source -- is it a file? */
 
        open_flags = O_RDONLY;
@@ -1177,9 +1152,6 @@ main(int argc, char **argv)
        }
 
        check_errors();
-       killall();
-       pthread_exit(NULL);
-       /*NOTREACHED*/
        return 0;
 }