View Issue Details

IDProjectCategoryView StatusLast Update
00001381003.1(2008)/Issue 7System Interfacespublic2013-04-16 13:06
Reportergeoffclare Assigned Toajosey  
PrioritynormalSeverityCommentTypeError
Status ClosedResolutionAccepted As Marked 
NameGeoff Clare
OrganizationThe Open Group
User Reference
Sectionsem_timedwait
Page Number1826
Line Number58299
Interp Status---
Final Accepted Text0000138:0000206
Summary0000138: errno indeterminate in sem_timedwait() example
DescriptionThe example code on the sem_timedwait() page has a signal handler
that does not save and restore errno, and calls functions that
can change errno. Thus the value of errno where it is used in
main() is indeterminate.

The example also exhibits poor programming practice in its use of
hard-coded constants (24 and 18) in the write() calls in the handler.
Desired ActionReplace the definition of the handler() function (lines 58299-58307)
with:
static void
handler(int sig)
{
    int sav_errno = errno;
    static char info_msg[] = "sem_post() from handler\n";
    write(STDOUT_FILENO, info_msg, sizeof info_msg - 1);
    if (sem_post(&sem) == -1) {
        static char err_msg[] = "sem_post() failed\n";
        write(STDERR_FILENO, err_msg, sizeof err_msg - 1);
        _exit(EXIT_FAILURE);
    }
    errno = sav_errno;
}

Tagstc1-2008

Activities

nick

2009-08-27 15:44

manager   bugnote:0000206

Make the info_msg[] and err_msg[] arrays const.

static void
handler(int sig)
{
    int sav_errno = errno;
    static const char info_msg[] = "sem_post() from handler\n";
    write(STDOUT_FILENO, info_msg, sizeof info_msg - 1);
    if (sem_post(&sem) == -1) {
        static const char err_msg[] = "sem_post() failed\n";
        write(STDERR_FILENO, err_msg, sizeof err_msg - 1);
        _exit(EXIT_FAILURE);
    }
    errno = sav_errno;
}

Issue History

Date Modified Username Field Change
2009-08-26 16:01 geoffclare New Issue
2009-08-26 16:01 geoffclare Status New => Under Review
2009-08-26 16:01 geoffclare Assigned To => ajosey
2009-08-26 16:01 geoffclare Name => Geoff Clare
2009-08-26 16:01 geoffclare Organization => The Open Group
2009-08-26 16:01 geoffclare Section => sem_timedwait
2009-08-26 16:01 geoffclare Page Number => 1826
2009-08-26 16:01 geoffclare Line Number => 58299
2009-08-26 16:01 geoffclare Interp Status => ---
2009-08-27 15:44 nick Note Added: 0000206
2009-08-27 15:44 nick Final Accepted Text => See note 0000206
2009-08-27 15:44 nick Resolution Open => Accepted As Marked
2009-08-27 15:45 nick Status Under Review => Resolved
2009-08-27 15:46 nick Final Accepted Text See note 0000206 => bugnote: 206
2009-08-27 15:46 nick Final Accepted Text bugnote: 206 => 0000138:0000206
2010-08-27 13:13 ajosey Tag Attached: tc1-2008
2013-04-16 13:06 ajosey Status Resolved => Closed