diff --git a/glnx-fdio.c b/glnx-fdio.c
index c15639d5810cc2bdd92ae71c9a78abc6cdc19049..55eef098d177558941364d7224560f2bce560e6d 100644
--- a/glnx-fdio.c
+++ b/glnx-fdio.c
@@ -255,7 +255,7 @@ glnx_link_tmpfile_at (int dfd,
               g_set_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
                "Exhausted %u attempts to create temporary file", count);
             }
-          if (renameat (dfd, tmpname_buf, target_dfd, target) < 0)
+          if (renameat (target_dfd, tmpname_buf, target_dfd, target) < 0)
             {
               glnx_set_error_from_errno (error);
               return FALSE;