From: ahoward Date: 2003-01-27T02:13:55+09:00 Subject: Re: solaris porting problem -- flock failure? On Mon, 27 Jan 2003, ts wrote: > a> does your solaris os have this disclaimer? > > ruby use fcntl() ???? ~ > uname -a && ruby -v Linux eli.fsl.noaa.gov 2.4.2-2 #1 SMP Fri Nov 23 20:51:15 GMT 2001 i686 unknown ruby 1.6.7 (2002-03-01) [i686-linux] file.c : 1531 #if defied(EWOULDBLOCK) && 0 1532 static int 1533 rb_thread_flock(fd, op, fptr) 1534 int fd, op; 1535 OpenFile *fptr; 1536 { 1537 if (rb_thread_alone() || (op & LOCK_NB)) { 1538 return flock(fd, op); 1539 } 1540 op |= LOCK_NB; 1541 while (flock(fd, op) < 0) { 1542 switch (errno) { 1543 case EAGAIN: 1544 case EACCES: 1545 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN 1546 case EWOULDBLOCK: 1547 #endif 1548 rb_thread_polling(); /* busy wait */ 1549 rb_io_check_closed(fptr); 1550 continue; 1551 default: 1552 return -1; 1553 } 1554 } 1555 return 0; 1556 } 1557 #define flock(fd, op) rb_thread_flock(fd, op, fptr) 1558 #endif 1559 1560 static VALUE 1561 rb_file_flock(obj, operation) 1562 VALUE obj; 1563 VALUE operation; 1564 { 1565 #ifndef __CHECKER__ 1566 OpenFile *fptr; 1567 int ret; 1568 1569 rb_secure(2); 1570 GetOpenFile(obj, fptr); 1571 1572 if (fptr->mode & FMODE_WRITABLE) { 1573 fflush(GetWriteFile(fptr)); 1574 } 1575 TRAP_BEG; 1576 ret = flock(fileno(fptr->f), NUM2INT(operation)); 1577 TRAP_END; 1578 if (ret < 0) { 1579 switch (errno) { 1580 case EAGAIN: 1581 case EACCES: 1582 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN 1583 case EWOULDBLOCK: 1584 #endif 1585 return Qfalse; 1586 } 1587 rb_sys_fail(fptr->path); 1588 } 1589 #endif 1590 return INT2FIX(0); 1591 } 1592 #undef flock also, it appears to me (just glancing over sources) that ruby uses fflush(stream) which only flushes into kernel space and does not guaruntee data is written to disk *even on file close* !! eg. sync must also be used. -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ahoward@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================