mcabber/mcabber/utils.c
changeset 2135 361603828d9e
parent 2134 fc7a758ebbde
child 2168 87244845fd9c
equal deleted inserted replaced
2134:fc7a758ebbde 2135:361603828d9e
   185   int err;
   185   int err;
   186   char *v;
   186   char *v;
   187 
   187 
   188   fp = fopen(FName, "a");
   188   fp = fopen(FName, "a");
   189   if (!fp) {
   189   if (!fp) {
   190     scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot open tracelog file: %s!",
   190     scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot open tracelog file: %s",
   191                  strerror(errno));
   191                  strerror(errno));
   192     return FALSE;
   192     return FALSE;
   193   }
   193   }
   194 
   194 
   195   err = fstat(fileno(fp), &buf);
   195   err = fstat(fileno(fp), &buf);
   196   if (err || buf.st_uid != geteuid()) {
   196   if (err || buf.st_uid != geteuid()) {
   197     fclose(fp);
   197     fclose(fp);
   198     if (err)
   198     if (err)
   199       scr_LogPrint(LPRINT_NORMAL, "ERROR: cannot stat the tracelog file: %s!",
   199       scr_LogPrint(LPRINT_NORMAL, "ERROR: cannot stat the tracelog file: %s",
   200                    strerror(errno));
   200                    strerror(errno));
   201     else
   201     else
   202       scr_LogPrint(LPRINT_NORMAL, "ERROR: tracelog file does not belong to you!");
   202       scr_LogPrint(LPRINT_NORMAL, "ERROR: tracelog file does not belong to you!");
   203     return FALSE;
   203     return FALSE;
   204   }
   204   }
   205   fchmod(fileno(fp), S_IRUSR|S_IWUSR);
   205 
       
   206   if (fchmod(fileno(fp), S_IRUSR|S_IWUSR)) {
       
   207     scr_LogPrint(LPRINT_NORMAL, "WARNING: Cannot set tracelog file permissions: %s",
       
   208                  strerror(errno));
       
   209   }
   206 
   210 
   207   v = mcabber_version();
   211   v = mcabber_version();
   208   fprintf(fp, "New trace log started.  MCabber version %s\n"
   212   fprintf(fp, "New trace log started.  MCabber version %s\n"
   209               "----------------------\n", v);
   213               "----------------------\n", v);
   210   g_free(v);
   214   g_free(v);
   266     if (!fp) {
   270     if (!fp) {
   267       scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot open tracelog file: %s.",
   271       scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot open tracelog file: %s.",
   268                    strerror(errno));
   272                    strerror(errno));
   269       return;
   273       return;
   270     }
   274     }
       
   275 
       
   276     // Check file permissions again (it could be a new file)
       
   277     fchmod(fileno(fp), S_IRUSR|S_IWUSR);
       
   278 
   271     if (fputs(data, fp) == EOF)
   279     if (fputs(data, fp) == EOF)
   272       scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot write to tracelog file.");
   280       scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot write to tracelog file.");
   273     fclose(fp);
   281     fclose(fp);
   274   }
   282   }
   275 }
   283 }