errno

Unit testing error conditions - EINTR

点点圈 提交于 2019-12-05 05:30:12
In short, how do you unit test an error condition such as EINTR on a system call. One particular example I'm working on, which could be a case all by itself, is whether it's necessary to call fclose again when it returns EOF with (errno==EINTR). The behavior depends on the implementation of fclose: // Given an open FILE *fp while (fclose(fp)==EOF && errno==EINTR) { errno = 0; } This call can be unsafe if fp freed when EINTR occurs. How can I test the error handling for when (errno==EINTR)? In this particular case, it's not safe to call fclose() again, as the C standard says the stream is

Is it required for me to add a _REENTRANT macro during compile time to make my errno thread safe?

梦想的初衷 提交于 2019-12-05 04:21:24
Is it required for me to add a _REENTRANT macro during compile time to make my errno thread safe? If no, is it the case for all versions of gcc / linux / solaris or is it required for certain old versions? I recently tested a piece of code where _REENTRANT was not used and found the errno behaving in an undefined fahsion in multi thread environment? But, after adding _REENTRANT everything was working fine. The Environment was Solaris. But, the discussion here doesn't seem to say it is mandatory to add _REENTRANT. I am a little confused. Also, apart from _REENTRANT should I add be adding any

FastDFS :java.lang.Exception: getStoreStorage fail, errno code: 28

南笙酒味 提交于 2019-12-05 03:48:26
FastDFS :java.lang.Exception: getStoreStorage fail, errno code: 28 FastDFS 服务正常,突然报错:java.lang.Exception: getStoreStorage fail, errno code: 28 错误代码28表示 No space left on device。FastDFS 可在 tracker.conf 配置文件中设置 reserved_storage_sapce 参数,即 storage 的预留存储空间大小,默认为10%。如果预留空间小于该设置值,将出现28错误。 解决:1、找到配置文件,手动修改。2、扩大服务器本身存储。3、删掉垃圾文件。 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart 来源: https://www.cnblogs.com/caonw/p/11903475.html

Can I ever assume that a C stdlib function doesn't use errno?

半腔热情 提交于 2019-12-05 01:51:06
问题 I'm looking at a piece of C code which is along the lines of void printerror(char *message) { printf ("There was an error: '%s'\n", message); switch (errno) { ... do stuff depending on errno } } I think that might be a problem, because printf might change errno between entering the function and reaching the switch . However, printf's manpage doesn't say anything about it setting errno, so can I assume it won't ever set it? Is there anything in the standards that guarantees which functions

How to set errno in Linux device driver?

一世执手 提交于 2019-12-05 01:37:02
I am designing a Linux character device driver. I want to set errno when error occurs in ioctl() system call. long my_own_ioctl(struct file *file, unsigned int req, unsigned long arg) { long ret = 0; BOOL isErr = FALSE; // some operation // ... if (isErr) { // set errno // ... <--- What should I do? ret = -1; } return ret; } What should I do to achieve that? Thank you at advance! Please allow me to explain my application with more detail. My device is located in /dev/myCharDev. My user space application is like this: #define _COMMAND (1) #define _ERROR_COMMAND_PARAMETER (-1) int main() { int

c语言read()返回-1,errno:Connection reset by peer

时光怂恿深爱的人放手 提交于 2019-12-05 00:36:10
问题描述:服务器端执行完send()后调用close()关闭socket,然后exit()正常退出。客户端read()函数返回-1,errno104 : Connection reset by peer,查了一下原因: 这意味着收到了TCP RST包,可以使用tcpdump + wireshark抓包分析,并且连接现在已经关闭,这种情况可能是因为对方崩溃,或者对方调用了close()函数。 解决方法:只要TCP栈的读缓冲里还有未读取(read)数据,则调用close时会直接向对端发送RST。服务器在调用close()函数前,调用shutdown(socket, 2),先关闭socket的读写功能,这时会向客户端发送FIN包,客户端收到FIN包时read()正常返回0,可以完全读取缓冲数据,问题解决。 close()和shutdown()的区别: 请参考: https://blog.csdn.net/xyyaiguozhe/article/details/30252559 来源: CSDN 作者: ferghs 链接: https://blog.csdn.net/busai2/article/details/81350973

What kind of errors set “errno” to non-zero? Why does fopen() set “errno” while fputc() does not?

落爺英雄遲暮 提交于 2019-12-04 23:05:43
问题 What kind of errors faced by what kind of library functions affect the errno and set it to non-zero value? In my following program, I intended to use if(errno!=0) as a condition to check if the library functions I used functioned properly or not, and this is what I found (see the code below): First I used if(errno!=0) to test if a file has been opened successfully with fopen() or not. If I try to open a non-existent file, then errno is set to non-zero (2 in my case) and it is verified by

Should I use system_category or generic_category for errno on Unix?

蹲街弑〆低调 提交于 2019-12-04 22:43:40
问题 C++0x has two predefined error_category objects: generic_category() and system_category() . From what I have understood so far, system_category() should be used for errors returned by the operating system, and generic_category() should be used for the generic values found in std::errc , which correspond to errno values. However, what should be done on Unix-like systems, where errno values are the errors returned by the operating system? Should I use system_category() (which would be wrong on

tmpfile() on windows 7 x64

拜拜、爱过 提交于 2019-12-04 17:08:47
Running the following code on Windows 7 x64 #include <stdio.h> #include <errno.h> int main() { int i; FILE *tmp; for (i = 0; i < 10000; i++) { errno = 0; if(!(tmp = tmpfile())) printf("Fail %d, err %d\n", i, errno); fclose(tmp); } return 0; } Gives errno 13 (Permission denied), on the 637th and 1004th call, it works fine on XP (haven't tried 7 x86). Am I missing something or is this a bug? A bit of a refresher from the manpage of on tmpfile() , which returns a FILE* : The file will be automatically deleted when it is closed or the program terminates. My verdict for this issue: Deleting a file