return F_data_not;
}
- if (close(signal->id) < 0) {
+ if (close(signal->id) == -1) {
if (errno == EBADF) return F_status_set_error(F_descriptor);
if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block);
if (errno == EINTR) return F_status_set_error(F_interrupt);
}
#endif // _di_f_signal_close_
+#ifndef _di_f_signal_mask_
+ f_status_t f_signal_mask(const int how, const sigset_t * const next, sigset_t * const current) {
+ #ifndef _di_level_0_parameter_checking_
+ if (!next && !current) return F_status_set_error(F_parameter);
+ #endif // _di_level_0_parameter_checking_
+
+ if (sigprocmask(how, next, current) == -1) {
+ if (errno == EFAULT) return F_status_set_error(F_buffer);
+ if (errno == EINVAL) return F_status_set_error(F_parameter);
+
+ return F_status_set_error(F_failure);
+ }
+
+ return F_none;
+ }
+#endif // _di_f_signal_mask_
+
#ifndef _di_f_signal_open_
f_status_t f_signal_open(f_signal_t * const signal) {
#ifndef _di_level_0_parameter_checking_
const int result = signalfd(signal->id, &signal->set, signal->flags);
- if (result < 0) {
+ if (result == -1) {
if (errno == EINVAL) return F_status_set_error(F_parameter);
if (errno == EMFILE) return F_status_set_error(F_file_descriptor_max);
if (errno == ENFILE) return F_status_set_error(F_file_open_max);
}
#endif // _di_f_signal_open_
-#ifndef _di_f_signal_read_
- f_status_t f_signal_read(const f_signal_t signal, const int timeout, struct signalfd_siginfo * const information) {
+#ifndef _di_f_signal_queue_
+ f_status_t f_signal_queue(const pid_t id, const int signal, const union sigval value) {
- if (!signal.id) {
- return F_data_not;
+ if (sigqueue(id, signal, value) == -1) {
+ if (errno == EAGAIN) return F_status_set_error(F_resource_not);
+ if (errno == ENOSYS) return F_status_set_error(F_supported_not);
+ if (errno == EINVAL) return F_status_set_error(F_parameter);
+ if (errno == ESRCH) return F_status_set_error(F_found_not);
+
+ return F_status_set_error(F_failure);
}
+ return F_none;
+ }
+#endif // _di_f_signal_queue_
+
+#ifndef _di_f_signal_read_
+ f_status_t f_signal_read(const f_signal_t signal, const int timeout, struct signalfd_siginfo * const information) {
+ #ifndef _di_level_0_parameter_checking_
+ if (!information) return F_status_set_error(F_parameter);
+ #endif // _di_level_0_parameter_checking_
+
struct pollfd data_poll;
memset(&data_poll, 0, sizeof(struct pollfd));
data_poll.fd = signal.id;
data_poll.events = POLLIN;
- struct pollfd polls[] = { data_poll };
-
- const int result = poll(polls, 1, timeout);
+ const int result = poll(&data_poll, 1, timeout);
- if (result < 0) {
+ if (result == -1) {
if (errno == EFAULT) return F_status_set_error(F_buffer);
if (errno == EINTR) return F_status_set_error(F_interrupt);
if (errno == EINVAL) return F_status_set_error(F_parameter);
return F_status_set_error(F_failure);
}
- else if (result) {
- const ssize_t total = read(signal.id, information, sizeof(struct signalfd_siginfo));
-
- if (total < 0) {
- if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block);
- if (errno == EBADF) return F_status_set_error(F_descriptor);
- if (errno == EFAULT) return F_status_set_error(F_buffer);
- if (errno == EINTR) return F_status_set_error(F_interrupt);
- if (errno == EINVAL) return F_status_set_error(F_parameter);
- if (errno == EIO) return F_status_set_error(F_input_output);
- if (errno == EISDIR) return F_status_set_error(F_file_type_directory);
-
- return F_status_set_error(F_failure);
+
+ if (result) {
+ if (data_poll.revents & POLLNVAL) {
+ return F_status_set_error(F_parameter);
}
- return F_signal;
+ if (data_poll.revents & POLLHUP) {
+ return F_status_set_error(F_file_closed);
+ }
+
+ if (data_poll.revents & POLLERR) {
+ return F_status_set_error(F_stream);
+ }
+
+ if (data_poll.revents & POLLIN) {
+ const ssize_t total = read(signal.id, information, sizeof(struct signalfd_siginfo));
+
+ if (total == -1) {
+ if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block);
+ if (errno == EBADF) return F_status_set_error(F_descriptor);
+ if (errno == EFAULT) return F_status_set_error(F_buffer);
+ if (errno == EINTR) return F_status_set_error(F_interrupt);
+ if (errno == EINVAL) return F_status_set_error(F_parameter);
+ if (errno == EIO) return F_status_set_error(F_input_output);
+ if (errno == EISDIR) return F_status_set_error(F_file_type_directory);
+
+ return F_status_set_error(F_failure);
+ }
+
+ return F_signal;
+ }
}
return F_none;
#ifndef _di_f_signal_send_
f_status_t f_signal_send(const int signal, const pid_t process_id) {
- if (kill(process_id, signal) < 0) {
+ if (kill(process_id, signal) == -1) {
if (errno == EINVAL) return F_status_set_error(F_parameter);
if (errno == EPERM) return F_status_set_error(F_prohibited);
if (errno == ESRCH) return F_status_set_error(F_found_not);
if (!set) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (sigaddset(set, signal) < 0) {
+ if (sigaddset(set, signal) == -1) {
if (errno == EINVAL) return F_status_set_error(F_parameter);
return F_status_set_error(F_failure);
if (!set) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (sigdelset(set, signal) < 0) {
+ if (sigdelset(set, signal) == -1) {
if (errno == EINVAL) return F_status_set_error(F_parameter);
return F_status_set_error(F_failure);
if (!set) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (sigemptyset(set) < 0) {
+ if (sigemptyset(set) == -1) {
if (errno == EINVAL) return F_status_set_error(F_parameter);
return F_status_set_error(F_failure);
if (!set) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (sigfillset(set) < 0) {
+ if (sigfillset(set) == -1) {
if (errno == EFAULT) return F_status_set_error(F_buffer);
if (errno == EINVAL) return F_status_set_error(F_parameter);
}
#endif // _di_f_signal_set_fill_
-#ifndef _di_f_signal_mask_
- f_status_t f_signal_mask(const int how, const sigset_t * const next, sigset_t * const current) {
- #ifndef _di_level_0_parameter_checking_
- if (!next && !current) return F_status_set_error(F_parameter);
- #endif // _di_level_0_parameter_checking_
-
- if (sigprocmask(how, next, current) < 0) {
- if (errno == EFAULT) return F_status_set_error(F_buffer);
- if (errno == EINVAL) return F_status_set_error(F_parameter);
-
- return F_status_set_error(F_failure);
- }
-
- return F_none;
- }
-#endif // _di_f_signal_mask_
-
-#ifndef _di_f_signal_queue_
- f_status_t f_signal_queue(const pid_t id, const int signal, const union sigval value) {
-
- if (sigqueue(id, signal, value) < 0) {
- if (errno == EAGAIN) return F_status_set_error(F_resource_not);
- if (errno == ENOSYS) return F_status_set_error(F_supported_not);
- if (errno == EINVAL) return F_status_set_error(F_parameter);
- if (errno == ESRCH) return F_status_set_error(F_found_not);
-
- return F_status_set_error(F_failure);
- }
-
- return F_none;
- }
-#endif // _di_f_signal_queue_
-
#ifndef _di_f_signal_set_has_
f_status_t f_signal_set_has(const int signal, const sigset_t * const set) {
#ifndef _di_level_0_parameter_checking_
const int result = sigismember(set, signal);
- if (result < 0) {
+ if (result == -1) {
if (errno == EINVAL) return F_status_set_error(F_parameter);
return F_status_set_error(F_failure);
#ifndef _di_f_signal_wait_
f_status_t f_signal_wait(const sigset_t * const set, siginfo_t * const information) {
- if (sigwaitinfo(set, information) < 0) {
+ if (sigwaitinfo(set, information) == -1) {
if (errno == EINTR) return F_status_set_error(F_interrupt);
if (errno == EINVAL) return F_status_set_error(F_parameter);
#ifndef _di_f_signal_wait_until_
f_status_t f_signal_wait_until(const sigset_t * const set, const struct timespec * timeout, siginfo_t * const information) {
- if (sigtimedwait(set, information, timeout) < 0) {
+ if (sigtimedwait(set, information, timeout) == -1) {
if (errno == EAGAIN) return F_time_out;
if (errno == EINTR) return F_status_set_error(F_interrupt);
if (errno == EINVAL) return F_status_set_error(F_parameter);
#endif // _di_f_signal_close_
/**
+ * Get or assign the current signal set in use.
+ *
+ * Either set or previous may be NULL but not both (at least one is required).
+ *
+ * @param how
+ * How to handle the signal.
+ * Set this to 0 when only trying to get the current signal set.
+ * @param next
+ * (optional) The new set of signals to handle.
+ * Set to NULL to not use.
+ * @param current
+ * (optional) The current set of signals being handled.
+ * Set to NULL to not use.
+ *
+ * @return
+ * F_none on success but no signal found.
+ *
+ * F_parameter (with error bit) if a parameter is invalid.
+ *
+ * F_failure (with error bit) for any other error.
+ *
+ * @see sigprocmask()
+ */
+#ifndef _di_f_signal_mask_
+ extern f_status_t f_signal_mask(const int how, const sigset_t * const next, sigset_t * const current);
+#endif // _di_f_signal_mask_
+
+/**
* Open a signal descriptor, listening for the given set of signals.
*
* The signal.id is assigned with the signal descriptor on success.
*
* @return
* F_none on success but no signal found.
+ *
* F_device (with error bit) if could not mount the internal inode device.
* F_file_descriptor_max (with error bit) if max file descriptors is reached.
* F_memory_not (with error bit) if out of memory.
#endif // _di_f_signal_open_
/**
+ * Send the signal and value to the given process.
+ *
+ * @param id
+ * The PID to signal.
+ * @param signal
+ * The signal to send to the thread.
+ * @param value
+ * The signal value to send.
+ *
+ * @return
+ * F_none on success but no signal found.
+ *
+ * F_found_not (with error bit) if the given PID was found.
+ * F_parameter (with error bit) if a parameter is invalid.
+ * F_resource_not (with error bit) if the max signals is reached.
+ * F_supported_not (with error bit) if this action is not supported by the current OS.
+ *
+ * F_failure (with error bit) for any other error.
+ *
+ * @see sigqueue()
+ */
+#ifndef _di_f_signal_queue_
+ extern f_status_t f_signal_queue(const pid_t id, const int signal, const union sigval value);
+#endif // _di_f_signal_queue_
+
+/**
* Read a current process signal, if one exists.
*
* @param signal
* F_block (with error bit) if file descriptor is set to non-block and the read would result in a blocking operation.
* F_buffer (with error bit) if the buffer is invalid.
* F_descriptor (with error bit) if the signal descriptor is invalid.
+ * F_file_closed (with error bit) if the signal descriptor stream is closed.
* F_interrupt (with error bit) if interrupt was received.
* F_memory_not (with error bit) on out of memory.
* F_parameter (with error bit) if a parameter is invalid.
+ * F_stream (with error bit) when the poll() returns POLLERR (file stream error).
* F_input_output (with error bit) on I/O error.
* F_file_type_directory (with error bit) if file descriptor represents a directory.
*
#endif // _di_f_signal_set_fill_
/**
- * Get or assign the current signal set in use.
- *
- * Either set or previous may be NULL but not both (at least one is required).
- *
- * @param how
- * How to handle the signal.
- * Set this to 0 when only trying to get the current signal set.
- * @param next
- * (optional) The new set of signals to handle.
- * Set to NULL to not use.
- * @param current
- * (optional) The current set of signals being handled.
- * Set to NULL to not use.
- *
- * @return
- * F_none on success but no signal found.
- *
- * F_parameter (with error bit) if a parameter is invalid.
- *
- * F_failure (with error bit) for any other error.
- *
- * @see sigprocmask()
- */
-#ifndef _di_f_signal_mask_
- extern f_status_t f_signal_mask(const int how, const sigset_t * const next, sigset_t * const current);
-#endif // _di_f_signal_mask_
-
-/**
- * Send the signal and value to the given process.
- *
- * @param id
- * The PID to signal.
- * @param signal
- * The signal to send to the thread.
- * @param value
- * The signal value to send.
- *
- * @return
- * F_none on success but no signal found.
- *
- * F_found_not (with error bit) if the given PID was found.
- * F_parameter (with error bit) if a parameter is invalid.
- * F_resource_not (with error bit) if the max signals is reached.
- * F_supported_not (with error bit) if this action is not supported by the current OS.
- *
- * F_failure (with error bit) for any other error.
- *
- * @see sigqueue()
- */
-#ifndef _di_f_signal_queue_
- extern f_status_t f_signal_queue(const pid_t id, const int signal, const union sigval value);
-#endif // _di_f_signal_queue_
-
-/**
* Check to see if the given signal set has a given signal.
*
* @param signal