linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* selftests: Testing a write attempt into a full file?
@ 2017-12-03 20:46 SF Markus Elfring
  2017-12-03 21:59 ` walter harms
  0 siblings, 1 reply; 2+ messages in thread
From: SF Markus Elfring @ 2017-12-03 20:46 UTC (permalink / raw)
  To: linux-kselftest, Shuah Khan; +Cc: LKML, kernel-janitors

Hello,

I have constructed another demonstration program.


#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	FILE *f = fopen("/dev/full", "a");

	if (!f)
		goto report_failure;

	{
	int const c = 'X';

	if (fputc(c, f) != c)
		goto report_failure;
	}

	return EXIT_SUCCESS;

report_failure:
	perror(__func__);
	return errno;
}


I got the following result.

elfring@Sonne:~/Projekte/selftests> gcc-7 putc_into_full_file1.c && ./a.out; echo $?
0


Does such a simple test example need further software development considerations?

Regards,
Markus

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: selftests: Testing a write attempt into a full file?
  2017-12-03 20:46 selftests: Testing a write attempt into a full file? SF Markus Elfring
@ 2017-12-03 21:59 ` walter harms
  0 siblings, 0 replies; 2+ messages in thread
From: walter harms @ 2017-12-03 21:59 UTC (permalink / raw)
  Cc: linux-kselftest, Shuah Khan, LKML, kernel-janitors



Am 03.12.2017 21:46, schrieb SF Markus Elfring:
> Hello,
> 
> I have constructed another demonstration program.
> 
> 
> #include <errno.h>
> #include <stdio.h>
> #include <stdlib.h>
> 
> int main(void)
> {
> 	FILE *f = fopen("/dev/full", "a");
> 
> 	if (!f)
> 		goto report_failure;
> 
> 	{
> 	int const c = 'X';
> 
> 	if (fputc(c, f) != c)
> 		goto report_failure;
> 	}
> 
Your test is broken, you are writing actualy into a buffer.
Adding setbuf(f,NULL) to disable buffering will return
main: No space left on device

Otherwise force the buffer to be fflush()ed and i it will also
report an error.

> 	return EXIT_SUCCESS;
> 
> report_failure:
> 	perror(__func__);
from perror(3):
 errno is undefined after a successful library call

so this may or may not return what you expect.

re,
 wh
> 	return errno;
> }
> 
> 
> I got the following result.
> 
> elfring@Sonne:~/Projekte/selftests> gcc-7 putc_into_full_file1.c && ./a.out; echo $?
> 0
> 
> 
> Does such a simple test example need further software development considerations?
> 
> Regards,
> Markus
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-12-03 21:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-03 20:46 selftests: Testing a write attempt into a full file? SF Markus Elfring
2017-12-03 21:59 ` walter harms

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).