On 28/10/2010, at 9:29 AM, john skaller wrote: > > well, that's interesting. I do: > > int sout = open("mystdout.log",O_CREAT | O_WRONLY | O_TRUNC); > int serr = open("mystderr.log",O_CREAT | O_WRONLY | O_TRUNC); > close(0); close(1); close(2); > dup2(sout,1); > dup2(serr,2); > while(1){ > FILE *f= fopen("log.log","w"); > fprintf(f,"Daemon running\n"); > fclose(f); > printf("[stdout]Daemon running pid=%d\n",getpid()); > fprintf(stderr,"[stderr]Daemon running pid=%d\n",getpid()); > sleep(5); > } > > and all the output goes into mystdout.log, mystderr.log is > empty. what did I do wrong here?
Well, thanks to the bad documentation (see the man page to the open() function, doesn't even *mention* the permissions argument, not even the OpenGroup page does .. despite giving examples using it): Now I do: int sout = open("mystdout.log",O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); int serr = open("mystderr.log",O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); and the C output works. Maybe I got confused. I moved the close() calls to after the open calls to ensure 0,1,2 stayed open long enough to ensure sout and serr didn't get numbers 0,1, or 2 so I could dup2 onto them. I should also open 0 onto /dev/null I guess to prevent some other open() call using the wrong value (fd 0 will be unused so must be assigned by the next open() call, I better use it in case I try to read from it and get a different file .. kind of messy). -- john skaller skal...@users.sourceforge.net ------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language