Austin Group Defect Tracker

Aardvark Mark III


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0000138 [1003.1(2008)/Issue 7] System Interfaces Comment Error 2009-08-26 16:01 2009-08-27 15:46
Reporter geoffclare View Status public  
Assigned To ajosey
Priority normal Resolution Accepted As Marked  
Status Resolved  
Name Geoff Clare
Organization The Open Group
User Reference
Section sem_timedwait
Page Number 1826
Line Number 58299
Interp Status ---
Final Accepted Text Note: 0000206
Summary 0000138: errno indeterminate in sem_timedwait() example
Description The 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 Action Replace 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;
}

Tags No tags attached.
Attached Files

- Relationships

-  Notes
(0000206)
nick (manager)
2009-08-27 15:44

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 => Note: 0000206


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker