Note that there are some explanatory texts on larger screens.

plurals
  1. POPermission denied when trying to write into log file
    primarykey
    data
    text
    <p>I have a problem writing into a log file in my C/C++ prog. Here's an example of the code where the problem occurs </p> <pre><code>EnterCriticalSection(&amp;critical); printf("\nWaiting for a connection on TCP port %d (nbr of current threads = %d)...\n", pServer-&gt;TCPServerPort, (*pServer-&gt;lChildInfo)); AddLog("Waiting for a connection on TCP port %d (nbr of current threads = %d)...", pServer-&gt;TCPServerPort, (*pServer-&gt;lChildInfo)); LeaveCriticalSection(&amp;critical); // creating variables to be passed to the thread struct*ThreadData = (struct*) malloc(sizeof(struct)); ThreadData-&gt;csock = (int*)malloc(sizeof(int)); memcpy(&amp;ThreadData-&gt;pServer,&amp;pServer,sizeof(pServer)); if((*ThreadData-&gt;csock = accept( pServer-&gt;ListenSocket, (SOCKADDR*)&amp;sadr, &amp;addr_size))!= INVALID_SOCKET ){ ThreadData-&gt;dwIP = sadr.sin_addr.s_addr; ThreadData-&gt;wPort = sadr.sin_port; printf("Received connection from %s:%d \n",inet_ntoa(sadr.sin_addr), ntohs(sadr.sin_port)); AddLog("Received connection from %s:%d ",inet_ntoa(sadr.sin_addr), ntohs(sadr.sin_port)); </code></pre> <p>AddLog is the function i wrote in order to write into the file : </p> <pre><code>FILE *fichier = NULL; va_list ap; va_start(ap, log); //fichier = fopen("log.log","a"); fichier = _fsopen("log.log", "a", SH_DENYNO); if (fichier == NULL) printf("Error log: %d (%s)\n", errno, strerror(errno)); else { fprintf(fichier,":"); vfprintf(fichier, log, ap); fprintf(fichier,"\n"); va_end(ap); fclose(fichier); } </code></pre> <p>What I can't really explain is that the first AddLog ("Waiting for...." and all the ones before..) are correctly written into the file. But when i try a connection, the logs coming then (received connection from...) are not written into the file and i always get the error 13 "Permission denied". I used chmod 777 into the file, i also tried _fsopen function and i still get this error once i enter into the thread. If someone have any idea it would be reaaally helpful. Thanks to all</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload