Changeset 14335
- Timestamp:
- Sep 21, 2014, 6:03:13 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/daemon/daemon.c
r14320 r14335 62 62 #define SPEED_T_STR "TB/s" 63 63 64 #define LOGFILE_MODE_STR "a+"65 66 64 static bool paused = false; 67 65 static bool seenHUP = false; 68 66 static const char *logfileName = NULL; 69 static FILE *logfile = NULL;67 static tr_sys_file_t logfile = TR_BAD_SYS_FILE; 70 68 static tr_session * mySession = NULL; 71 69 static tr_quark key_pidfile = 0; … … 145 143 } 146 144 145 static bool 146 reopen_log_file (const char *filename) 147 { 148 tr_error * error = NULL; 149 const tr_sys_file_t old_log_file = logfile; 150 const tr_sys_file_t new_log_file = tr_sys_file_open (filename, 151 TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE | TR_SYS_FILE_APPEND, 152 0666, &error); 153 154 if (new_log_file == TR_BAD_SYS_FILE) 155 { 156 fprintf (stderr, "Couldn't (re)open log file \"%s\": %s\n", filename, error->message); 157 tr_error_free (error); 158 return false; 159 } 160 161 logfile = new_log_file; 162 163 if (old_log_file != TR_BAD_SYS_FILE) 164 tr_sys_file_close (old_log_file, NULL); 165 166 return true; 167 } 168 147 169 static void 148 170 gotsig (int sig) … … 163 185 164 186 /* reopen the logfile to allow for log rotation */ 165 if (logfileName) { 166 logfile = freopen (logfileName, LOGFILE_MODE_STR, logfile); 167 if (!logfile) 168 fprintf (stderr, "Couldn't reopen \"%s\": %s\n", logfileName, tr_strerror (errno)); 187 if (logfileName != NULL) 188 { 189 reopen_log_file (logfileName); 169 190 } 170 191 … … 307 328 308 329 static void 309 printMessage ( FILE *logfile, int level, const char * name, const char * message, const char * file, int line)310 { 311 if (logfile != NULL)330 printMessage (tr_sys_file_t logfile, int level, const char * name, const char * message, const char * file, int line) 331 { 332 if (logfile != TR_BAD_SYS_FILE) 312 333 { 313 334 char timestr[64]; 314 335 tr_logGetTimeStr (timestr, sizeof (timestr)); 315 336 if (name) 316 fprintf (logfile, "[%s] %s %s (%s:%d)\n", timestr, name, message, file, line); 337 tr_sys_file_write_fmt (logfile, "[%s] %s %s (%s:%d)" TR_NATIVE_EOL_STR, 338 NULL, timestr, name, message, file, line); 317 339 else 318 fprintf (logfile, "[%s] %s (%s:%d)\n", timestr, message, file, line); 340 tr_sys_file_write_fmt (logfile, "[%s] %s (%s:%d)" TR_NATIVE_EOL_STR, 341 NULL, timestr, message, file, line); 319 342 } 320 343 #ifdef HAVE_SYSLOG … … 339 362 340 363 static void 341 pumpLogMessages ( FILE *logfile)364 pumpLogMessages (tr_sys_file_t logfile) 342 365 { 343 366 const tr_log_message * l; … … 347 370 printMessage (logfile, l->level, l->name, l->message, l->file, l->line); 348 371 349 if (logfile != NULL)350 fflush (logfile);372 if (logfile != TR_BAD_SYS_FILE) 373 tr_sys_file_flush (logfile, NULL); 351 374 352 375 tr_logFreeQueue (list); … … 440 463 case 'd': dumpSettings = true; 441 464 break; 442 case 'e': logfile = fopen (optarg, LOGFILE_MODE_STR); 443 if (logfile) 465 case 'e': if (reopen_log_file (optarg)) 444 466 logfileName = optarg; 445 else446 fprintf (stderr, "Couldn't open \"%s\": %s\n", optarg, tr_strerror (errno));447 467 break; 448 468 case 'f': foreground = true; … … 519 539 } 520 540 521 if (foreground && !logfile)522 logfile = stderr;541 if (foreground && logfile == TR_BAD_SYS_FILE) 542 logfile = tr_sys_file_get_std (TR_STD_SYS_FILE_ERR, NULL); 523 543 524 544 if (!loaded) … … 569 589 if (pid_filename && *pid_filename) 570 590 { 571 FILE * fp = fopen (pid_filename, "w+"); 572 if (fp != NULL) 591 tr_error * error = NULL; 592 tr_sys_file_t fp = tr_sys_file_open (pid_filename, 593 TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE | TR_SYS_FILE_TRUNCATE, 594 0666, &error); 595 if (fp != TR_BAD_SYS_FILE) 573 596 { 574 fprintf (fp, "%d", (int)getpid ());575 fclose (fp);597 tr_sys_file_write_fmt (fp, "%d", NULL, (int)getpid ()); 598 tr_sys_file_close (fp, NULL); 576 599 tr_logAddInfo ("Saved pidfile \"%s\"", pid_filename); 577 600 pidfile_created = true; 578 601 } 579 602 else 580 tr_logAddError ("Unable to save pidfile \"%s\": %s", pid_filename, tr_strerror (errno)); 603 { 604 tr_logAddError ("Unable to save pidfile \"%s\": %s", pid_filename, error->message); 605 tr_error_free (error); 606 } 581 607 } 582 608 -
trunk/libtransmission/platform-quota.c
r14316 r14335 30 30 #ifdef HAVE_GETMNTENT 31 31 #ifdef __sun 32 #include <sys/types.h>33 #include <sys/stat.h>34 32 #include <fcntl.h> 35 33 #include <stdio.h> … … 367 365 #ifdef _WIN32 368 366 369 uint64_t freeBytesAvailable = 0; 370 return GetDiskFreeSpaceEx (path, &freeBytesAvailable, NULL, NULL) 371 ? (int64_t)freeBytesAvailable 372 : -1; 367 int64_t ret = -1; 368 wchar_t * wide_path; 369 370 wide_path = tr_win32_utf8_to_native (path, -1); 371 372 if (wide_path != NULL) 373 { 374 ULARGE_INTEGER freeBytesAvailable; 375 if (GetDiskFreeSpaceExW (wide_path, &freeBytesAvailable, NULL, NULL)) 376 ret = freeBytesAvailable.QuadPart; 377 378 tr_free (wide_path); 379 } 380 381 return ret; 373 382 374 383 #elif defined(HAVE_STATVFS) -
trunk/libtransmission/platform.c
r14331 r14335 14 14 15 15 #include <assert.h> 16 #include <stdio.h>17 16 #include <stdlib.h> 18 17 #include <string.h> 19 #include <unistd.h> /* getuid(), close() */ 18 #include <unistd.h> /* getuid() */ 19 20 #ifdef __HAIKU__ 21 #include <limits.h> /* PATH_MAX */ 22 #endif 20 23 21 24 #ifdef _WIN32 … … 44 47 #include "platform.h" 45 48 #include "session.h" 49 #include "utils.h" 46 50 47 51 /*** … … 224 228 #endif 225 229 230 #ifdef _WIN32 231 232 char * 233 win32_get_special_folder (int folder_id) 234 { 235 wchar_t path[MAX_PATH]; /* SHGetFolderPath () requires MAX_PATH */ 236 *path = L'\0'; 237 SHGetFolderPathW (NULL, folder_id, NULL, 0, path); 238 return tr_win32_native_to_utf8 (path, -1); 239 } 240 241 #endif 242 226 243 static const char * 227 244 getHomeDir (void) … … 236 253 { 237 254 #ifdef _WIN32 238 char appdata[MAX_PATH]; /* SHGetFolderPath () requires MAX_PATH */ 239 *appdata = '\0'; 240 SHGetFolderPath (NULL, CSIDL_PERSONAL, NULL, 0, appdata); 241 home = tr_strdup (appdata); 255 home = win32_get_special_folder (CSIDL_PERSONAL); 242 256 #else 243 257 struct passwd * pw = getpwuid (getuid ()); … … 316 330 s = tr_buildPath (getHomeDir (), "Library", "Application Support", appname, NULL); 317 331 #elif defined (_WIN32) 318 char appdata[TR_PATH_MAX]; /* SHGetFolderPath () requires MAX_PATH */ 319 SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, appdata); 332 char * appdata = win32_get_special_folder (CSIDL_APPDATA); 320 333 s = tr_buildPath (appdata, appname, NULL); 334 tr_free (appdata); 321 335 #elif defined (__HAIKU__) 322 char buf[ TR_PATH_MAX];336 char buf[PATH_MAX]; 323 337 find_directory (B_USER_SETTINGS_DIRECTORY, -1, true, buf, sizeof (buf)); 324 338 s = tr_buildPath (buf, appname, NULL); … … 397 411 ***/ 398 412 399 static int413 static bool 400 414 isWebClientDir (const char * path) 401 415 { … … 460 474 #elif defined (_WIN32) 461 475 462 /* SHGetFolderPath explicitly requires MAX_PATH length */463 char dir[MAX_PATH];464 465 476 /* Generally, Web interface should be stored in a Web subdir of 466 477 * calling executable dir. */ … … 468 479 if (s == NULL) /* check personal AppData/Transmission/Web */ 469 480 { 470 SHGetFolderPath (NULL, CSIDL_COMMON_APPDATA, NULL, 0, dir);481 char * dir = win32_get_special_folder (CSIDL_COMMON_APPDATA); 471 482 s = tr_buildPath (dir, "Transmission", "Web", NULL); 483 tr_free (dir); 472 484 if (!isWebClientDir (s)) 473 485 { … … 479 491 if (s == NULL) /* check personal AppData */ 480 492 { 481 SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, dir);493 char * dir = win32_get_special_folder (CSIDL_APPDATA); 482 494 s = tr_buildPath (dir, "Transmission", "Web", NULL); 495 tr_free (dir); 483 496 if (!isWebClientDir (s)) 484 497 { … … 490 503 if (s == NULL) /* check calling module place */ 491 504 { 492 char * tmp; 493 GetModuleFileName (GetModuleHandle (NULL), dir, sizeof (dir)); 494 tmp = tr_sys_path_dirname (dir, NULL); 495 s = tr_buildPath (tmp, "Web", NULL); 496 tr_free (tmp); 505 wchar_t wide_module_path[MAX_PATH]; 506 char * module_path; 507 char * dir; 508 GetModuleFileNameW (NULL, wide_module_path, 509 sizeof (wide_module_path) / sizeof (*wide_module_path)); 510 module_path = tr_win32_native_to_utf8 (wide_module_path, -1); 511 dir = tr_sys_path_dirname (module_path, NULL); 512 tr_free (module_path); 513 s = tr_buildPath (dir, "Web", NULL); 514 tr_free (dir); 497 515 if (!isWebClientDir (s)) 498 516 {
Note: See TracChangeset
for help on using the changeset viewer.