<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Intermittent problem with BAD FILE NUMBER errno 9 in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614227#M104516</link>
    <description>Hi David,&lt;BR /&gt;&lt;BR /&gt;according to the posting above you may have a look at this "well known" procedure.&lt;BR /&gt;Maybe this is helpful in this case&lt;BR /&gt;________________________________&lt;BR /&gt;&lt;BR /&gt;int writen (int fd,char * ptr, int nbytes)&lt;BR /&gt;{&lt;BR /&gt;int nleft,nwritten;&lt;BR /&gt;&lt;BR /&gt;   nleft=nbytes;&lt;BR /&gt;   while (nleft &amp;gt; 0)&lt;BR /&gt;   {  nwritten=write(fd,ptr,nleft);&lt;BR /&gt;      if (nwritten &amp;lt;= 0)&lt;BR /&gt;         return (nwritten); /* error or EOF */&lt;BR /&gt;      nleft-=nwritten;&lt;BR /&gt;      ptr+=nwritten;&lt;BR /&gt;   }&lt;BR /&gt;   return (nbytes-nleft);&lt;BR /&gt;}</description>
    <pubDate>Wed, 31 Aug 2005 07:35:56 GMT</pubDate>
    <dc:creator>Torsten.</dc:creator>
    <dc:date>2005-08-31T07:35:56Z</dc:date>
    <item>
      <title>Intermittent problem with BAD FILE NUMBER errno 9</title>
      <link>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614219#M104508</link>
      <description>What type of conditions can cause an errno 9, "BAD FILE NUMBER" to occur when you try to write (that's a man 2 write) to a file that you created with the open call with a status of O_APPEND and a mode of 0666.&lt;BR /&gt;</description>
      <pubDate>Mon, 29 Aug 2005 14:24:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614219#M104508</guid>
      <dc:creator>David DiBiase</dc:creator>
      <dc:date>2005-08-29T14:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: Intermittent problem with BAD FILE NUMBER errno 9</title>
      <link>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614220#M104509</link>
      <description>Hi David:&lt;BR /&gt;&lt;BR /&gt;Well. errno=9 is EBADF and that will be returned for an invalid file descriptor; viz. The 'fildes' argument to the write() is not a valid file descriptor open for writing.&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Mon, 29 Aug 2005 14:33:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614220#M104509</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2005-08-29T14:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: Intermittent problem with BAD FILE NUMBER errno 9</title>
      <link>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614221#M104510</link>
      <description>9  EBADF  Bad file number&lt;BR /&gt;     Either a file descriptor refers to no open file, or a read (resp.  write)&lt;BR /&gt;     request is made to a file that is open only for writing (resp. reading).&lt;BR /&gt;&lt;BR /&gt;If the file is open is it growing beyond your ulimit? Just a guess.</description>
      <pubDate>Mon, 29 Aug 2005 14:40:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614221#M104510</guid>
      <dc:creator>Marvin Strong</dc:creator>
      <dc:date>2005-08-29T14:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: Intermittent problem with BAD FILE NUMBER errno 9</title>
      <link>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614222#M104511</link>
      <description>You did check that the open() call returned a valid file descriptor before using it in the write() call, didn't you?</description>
      <pubDate>Tue, 30 Aug 2005 04:30:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614222#M104511</guid>
      <dc:creator>Stephen Keane</dc:creator>
      <dc:date>2005-08-30T04:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: Intermittent problem with BAD FILE NUMBER errno 9</title>
      <link>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614223#M104512</link>
      <description>All your responses have given me lots of ideas - thanks.  Below is the function i am using.  In test - works fine.  My problem is intermittent failures in production:&lt;BR /&gt;&lt;BR /&gt;Here's the partial&lt;BR /&gt;code: Please note that error_file is declared an extern in the main program and is set to a 1.&lt;BR /&gt;===============================================================&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STRING.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include &lt;UNISTD.H&gt;&lt;BR /&gt;#include &lt;FCNTL.H&gt;&lt;BR /&gt;#include &lt;ERRNO.H&gt;&lt;BR /&gt;&lt;BR /&gt;extern int debug;&lt;BR /&gt;char ErrorFile[70];&lt;BR /&gt;extern char *pgm_name;&lt;BR /&gt;int error_file;&lt;BR /&gt;&lt;BR /&gt;void&lt;BR /&gt;error_proc(const char *in_mess)&lt;BR /&gt;{&lt;BR /&gt; int mess_sz;&lt;BR /&gt; int err_fd;&lt;BR /&gt; static int the_top = 1;&lt;BR /&gt;&lt;BR /&gt; if (debug)&lt;BR /&gt;  (void)fprintf(stderr, "%s: in_mess = %s\n", pgm_name, in_mess);&lt;BR /&gt; if (error_file == 1)&lt;BR /&gt; {&lt;BR /&gt;  mess_sz = strlen(in_mess);&lt;BR /&gt;  if (the_top)&lt;BR /&gt;  {&lt;BR /&gt;   if ((err_fd = open(ErrorFile,  O_WRONLY | O_CREAT, 0666)) &amp;lt; 0)&lt;BR /&gt;   {&lt;BR /&gt;    (void)fprintf(stderr, "%s: Error in opening the Error File %s errno = %d\n", pgm_name, ErrorFile, errno);&lt;BR /&gt;    return;&lt;BR /&gt;   }&lt;BR /&gt;   the_top = 0;&lt;BR /&gt;  }&lt;BR /&gt;  else&lt;BR /&gt;  {&lt;BR /&gt;   if ((err_fd = open(ErrorFile,  O_APPEND, 0666)) &amp;lt; 0)&lt;BR /&gt;   {&lt;BR /&gt;    (void)fprintf(stderr, "%s: Error in opening the Error File %s errno = %d\n", pgm_name, ErrorFile, errno);&lt;BR /&gt;    return;&lt;BR /&gt;   }&lt;BR /&gt;  }&lt;BR /&gt;  if (write(err_fd, in_mess, mess_sz) != mess_sz)&lt;BR /&gt;  {&lt;BR /&gt;   (void)fprintf(stderr, "%s: Error in writing to the Error File %s errno = %d\n", pgm_name, ErrorFile, errno);&lt;BR /&gt;   (void)close(err_fd);&lt;BR /&gt;   return;&lt;BR /&gt;  }&lt;BR /&gt;  (void)close(err_fd);&lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt;  (void)fprintf(stderr, "%s: %s\n", pgm_name, in_mess);&lt;BR /&gt; return;&lt;BR /&gt;}&lt;BR /&gt;&lt;/ERRNO.H&gt;&lt;/FCNTL.H&gt;&lt;/UNISTD.H&gt;&lt;/STDLIB.H&gt;&lt;/STRING.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Tue, 30 Aug 2005 09:50:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614223#M104512</guid>
      <dc:creator>David DiBiase</dc:creator>
      <dc:date>2005-08-30T09:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Intermittent problem with BAD FILE NUMBER errno 9</title>
      <link>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614224#M104513</link>
      <description>Are you sure that the write is failing?  You seem to be checking for a return write value not equal to the size of the max buffer size:&lt;BR /&gt;&lt;BR /&gt; if (write(err_fd, in_mess, mess_sz) != mess_sz)&lt;BR /&gt;&lt;BR /&gt;and could it be returning a value greater than -1 but less than mess_sz, like mess_sz -1?&lt;BR /&gt;  Can you change the test to be != -1 and then print errno?  I think that the value of errno is undefined unless the write returns a -1 to signify failure.  If the write is successful, you shouldn't be checking errno.....</description>
      <pubDate>Tue, 30 Aug 2005 12:31:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614224#M104513</guid>
      <dc:creator>susan gregory_1</dc:creator>
      <dc:date>2005-08-30T12:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Intermittent problem with BAD FILE NUMBER errno 9</title>
      <link>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614225#M104514</link>
      <description>Hi David,&lt;BR /&gt;&lt;BR /&gt;for my own private programming I use perror instead of reading errno. &lt;BR /&gt;&lt;BR /&gt;e.g.:&lt;BR /&gt;&lt;BR /&gt;if ((sf=open(argv[1],O_RDONLY)) == -1)&lt;BR /&gt;  {&lt;BR /&gt;      perror("open ");&lt;BR /&gt;   return EXIT_FAILURE;&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;prints the systems error message.&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Aug 2005 13:44:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614225#M104514</guid>
      <dc:creator>Torsten.</dc:creator>
      <dc:date>2005-08-30T13:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: Intermittent problem with BAD FILE NUMBER errno 9</title>
      <link>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614226#M104515</link>
      <description>You should ideally check for three conditions when doing a write.&lt;BR /&gt;&lt;BR /&gt;1) All the characters you asked it to write were written in one go. write() will return the number of characters you asked it to write.&lt;BR /&gt;&lt;BR /&gt;2) Some (but not all) of the characters you asked it to write were written. i.e. a partial write. this can happen if the write() was interrupted by say a signal. It isn't an error, but you haven't written all the data, you must write the remaining data in subsequent write() operation(s). write() will return the actial number of characters written, which will be less than what you asked it to write.&lt;BR /&gt;&lt;BR /&gt;3) An error occurred. write() will return -1 and set errno to indicate the error.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 31 Aug 2005 03:15:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614226#M104515</guid>
      <dc:creator>Stephen Keane</dc:creator>
      <dc:date>2005-08-31T03:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: Intermittent problem with BAD FILE NUMBER errno 9</title>
      <link>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614227#M104516</link>
      <description>Hi David,&lt;BR /&gt;&lt;BR /&gt;according to the posting above you may have a look at this "well known" procedure.&lt;BR /&gt;Maybe this is helpful in this case&lt;BR /&gt;________________________________&lt;BR /&gt;&lt;BR /&gt;int writen (int fd,char * ptr, int nbytes)&lt;BR /&gt;{&lt;BR /&gt;int nleft,nwritten;&lt;BR /&gt;&lt;BR /&gt;   nleft=nbytes;&lt;BR /&gt;   while (nleft &amp;gt; 0)&lt;BR /&gt;   {  nwritten=write(fd,ptr,nleft);&lt;BR /&gt;      if (nwritten &amp;lt;= 0)&lt;BR /&gt;         return (nwritten); /* error or EOF */&lt;BR /&gt;      nleft-=nwritten;&lt;BR /&gt;      ptr+=nwritten;&lt;BR /&gt;   }&lt;BR /&gt;   return (nbytes-nleft);&lt;BR /&gt;}</description>
      <pubDate>Wed, 31 Aug 2005 07:35:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/intermittent-problem-with-bad-file-number-errno-9/m-p/3614227#M104516</guid>
      <dc:creator>Torsten.</dc:creator>
      <dc:date>2005-08-31T07:35:56Z</dc:date>
    </item>
  </channel>
</rss>

