- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Error handling for sem_open() API
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 02:11 AM - last edited on 04-10-2023 08:18 PM by support_s
04-10-2023 02:11 AM - last edited on 04-10-2023 08:18 PM by support_s
Error handling for sem_open() API
Hi ,
I have written the wrapper function for sem_open() based on my requirent , but my team asking to add more error contions to that, like error handling
I am attching the sample code, I had written,Can you please help on this code how to handling error or return values
sem_t *sem;
sem = sem_open(sem_path, flag, mode, value);
if (sem == (void *)-1) {
FYI(FYI_FATAL,"sem_open() failed %s\n",__FUNCTION__);
}
return sem;
}
- Tags:
- Operating System
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 07:25 PM - edited 04-10-2023 07:30 PM
04-10-2023 07:25 PM - edited 04-10-2023 07:30 PM
Re: Error handling for sem_open() API
> [...] my team asking to add more error contions to that, like error
> handling
With my weak psychic powers, I don't know what sort of error handling
your team might like.
According to the documentation, sem_open() sets errno when it fails.
You might do something to display or return that value.
> [...] (void *)-1 [...]
"(sem_t *)(-1)" might be a little classier. In some environments,
the macro SEM_FAILED is defined, so you wouldn't need to worry so much
about the implementation.
> FYI(FYI_FATAL,"sem_open() failed %s\n",__FUNCTION__);
Also, if I see a message like "sem_open() failed", I'd like to know
_what_, exactly, it was trying to open. In this case, sem_path.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 11:11 PM
04-10-2023 11:11 PM
Re: Error handling for sem_open() API
EACCES The semaphore exists, but the caller does not have permission to open it. EEXIST Both O_CREAT and O_EXCL were specified in oflag, but a semaphore with this name already exists. EINVAL value was greater than SEM_VALUE_MAX. EINVAL name consists of just "/", followed by no other characters. EMFILE The per-process limit on the number of open file descriptors has been reached. ENAMETOOLONG name was too long. ENFILE The system-wide limit on the total number of open files has been reached. ENOENT The O_CREAT flag was not specified in oflag and no semaphore with this name exists; or, O_CREAT was specified, but name wasn't well formed. ENOMEM Insufficient memory.
These are the error condifion , So i need implement those error contions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 04:34 AM
04-11-2023 04:34 AM
Re: Error handling for sem_open() API
> These are the error condifion , [...]
Thanks, but I had already seen the sem_open "man" page.
> [...] So i need implement those error contions
I don't know what that means to you,
> With my weak psychic powers, I don't know what sort of error handling
> your team might like.
Still true.