@@ -478,13 +478,7 @@ void darshan_core_shutdown(int write_log)
478478 * mmap log file, in case an interrupt happens before the completion of
479479 * this subroutine, leaving the log file corrupted. See github issue #1052.
480480 */
481- int sys_page_size = sysconf (_SC_PAGESIZE );
482- size_t mmap_size = sizeof (struct darshan_header ) + DARSHAN_JOB_RECORD_SIZE +
483- + final_core -> config .name_mem + final_core -> config .mod_mem ;
484- if (mmap_size % sys_page_size )
485- mmap_size = ((mmap_size / sys_page_size ) + 1 ) * sys_page_size ;
486-
487- msync (final_core -> log_hdr_p , mmap_size , MS_SYNC );
481+ msync (final_core -> log_hdr_p , final_core -> mmap_size , MS_SYNC );
488482
489483 /* Duplicate the log file, Below we on purpose ignore errors from open(),
490484 * lseek(), read(), write(), and close(), as they are not fatal and should
@@ -493,25 +487,20 @@ void darshan_core_shutdown(int write_log)
493487 * of duplicated file will become useless, but such problem will be even
494488 * more serious than being unable to duplicate the file.
495489 */
496- int dup_mmap_fd = open (final_core -> mmap_log_name , O_RDONLY , 0644 );
497- if (dup_mmap_fd != -1 ) {
498- off_t fileSize = lseek (dup_mmap_fd , 0 , SEEK_END );
499- if (fileSize >= 0 ) {
500- void * buf = (void * ) malloc (fileSize );
501- lseek (dup_mmap_fd , 0 , SEEK_SET );
502- read (dup_mmap_fd , buf , fileSize );
490+ int mmap_fd = open (final_core -> mmap_log_name , O_RDONLY , 0644 );
491+ if (mmap_fd != -1 ) {
492+ int dup_mmap_fd ;
493+ void * buf = (void * ) malloc (final_core -> mmap_size );
494+ read (dup_mmap_fd , buf , final_core -> mmap_size );
495+ close (dup_mmap_fd );
496+ snprintf (dup_log_fame , strlen (final_core -> mmap_log_name ), "%s.dup" ,
497+ final_core -> mmap_log_name );
498+ dup_mmap_fd = open (dup_log_fame , O_CREAT | O_WRONLY , 0644 );
499+ if (dup_mmap_fd != -1 ) {
500+ write (dup_mmap_fd , buf , final_core -> mmap_size );
503501 close (dup_mmap_fd );
504- snprintf (dup_log_fame , strlen (final_core -> mmap_log_name ), "%s.dup" ,
505- final_core -> mmap_log_name );
506- dup_mmap_fd = open (dup_log_fame , O_CREAT | O_WRONLY , 0644 );
507- if (dup_mmap_fd != -1 ) {
508- write (dup_mmap_fd , buf , fileSize );
509- close (dup_mmap_fd );
510- }
511- free (buf );
512502 }
513- else
514- close (dup_mmap_fd );
503+ free (buf );
515504 }
516505#endif
517506
@@ -854,6 +843,8 @@ static void *darshan_init_mmap_log(struct darshan_core_runtime* core, int jobid)
854843 if (mmap_size % sys_page_size )
855844 mmap_size = ((mmap_size / sys_page_size ) + 1 ) * sys_page_size ;
856845
846+ core -> mmap_size = mmap_size ;
847+
857848 darshan_get_user_name (cuser );
858849
859850 /* generate a random number to help differentiate the temporary log */
0 commit comments