Menu

#777 base: Add more glibc wrapper functions with error handling

5.17.08
accepted
None
enhancement
base
-
major
2017-04-10
2014-02-10
No

This is a generic ticket for adding more convenience/utility functions to BASE.

The generic strategy is to add utility functions with the same name as the corresponding glibc function, but with an osaf_ prefix. The utility functions will have the following added value:

  • For errno == EINTR, it will try the function again in a loop (only in the case if EINTR is a possible result of the function according the the manual page). Also note the important exception that the close() function shall NOT have a loop when it returns EINTR (it's a fairly common mistake to implement such a loop for close()).
  • For errors that can only happen due to a bug in the program itself (e.g. EFAULT, EINVAL, EBADF, EMFILE etc), call osaf_abort() to generate a core dump.
  • For out-of-system-resources errors (ENOMEM, ENFILE etc), typically log a message and terminate the process. We should not generate a core-dump, since it's (probably) not a bug in the process itself (of course it could be, if it is the one leaking memory). Still there is not much we can do if the system has run out of memory or file descriptors so all we can do is exit.
  • For run-time erros that can happen and do not necessarily mean there is a bug (ECONNREFUSED, ENETUNREACH, ETIMEDOUT etc), typically log the error and return -1 to let the caller handle the error. Logging in this case should be done with care, if it is something that can happen often. One possibility is to only log into a ring-buffer in the process' own memory, that can be inspected in a core dump. Or we could have some kind of suppression mechanism to avoid filling up the log files.

By using such utility functions, the program code can be made simpler. We don't need to have loops checking for EINTR everywhere, and in many cases these wrapper functions can be made so that they can never fail (meaning that the process is terminated in such a case, and the function doesn't return to the caller).

Related

Tickets: #1268
Tickets: #777

Discussion

  • Anders Widell

    Anders Widell - 2014-08-15
    • Milestone: 4.5.FC --> 4.6.FC
     
  • Mathi Naickan

    Mathi Naickan - 2015-03-16
    • Milestone: 4.6.FC --> future
     
  • Anders Widell

    Anders Widell - 2015-12-08
    • status: unassigned --> accepted
    • assigned_to: Anders Widell
    • Milestone: future --> 5.0.FC
     
  • Anders Widell

    Anders Widell - 2015-12-22
    • status: accepted --> review
     
  • Anders Widell

    Anders Widell - 2016-02-29
    • status: review --> accepted
     
  • Anders Widell

    Anders Widell - 2016-02-29

    changeset: 7290:b4e2c14d222b
    tag: tip
    user: Anders Widell an...@...com
    date: Mon Feb 29 13:37:51 2016 +0100
    summary: base: Add osaf_timerfd_* utility functions [#777]

    [staging:b4e2c1]

     

    Related

    Tickets: #777

  • Mathi Naickan

    Mathi Naickan - 2016-04-11
    • Milestone: 5.0.FC --> future
     
  • Anders Widell

    Anders Widell - 2017-04-03
    • Milestone: future --> next
     

Log in to post a comment.