Diff

Differences From Artifact [fcb400b744]:

To Artifact [b4d256af0b]:


   182    182   
   183    183   	return(fd);
   184    184   }
   185    185   
   186    186   /* Log a message */
   187    187   //#define FILED_DONT_LOG
   188    188   #ifdef FILED_DONT_LOG
   189         -#  define filed_logging_thread_init() 0
          189  +#  define filed_logging_thread_init(x) 0
   190    190   #  define filed_log_msg_debug(x, ...) /**/
   191    191   #  define filed_log_msg(x) /**/
   192    192   #else
   193    193   #ifdef FILED_DEBUG
   194    194   #  define filed_log_msg_debug(x, ...) { fprintf(stderr, x, __VA_ARGS__); fprintf(stderr, "\n"); fflush(stderr); }
   195    195   #else
   196    196   #  define filed_log_msg_debug(x, ...) /**/
................................................................................
   221    221   
   222    222   			prev = curr;
   223    223   		}
   224    224   
   225    225   		curr = prev;
   226    226   		while (curr) {
   227    227   			fprintf(fp, "%s THREAD=%llu\n", curr->buffer, (unsigned long long) curr->thread);
          228  +			fflush(fp);
   228    229   
   229    230   			prev = curr;
   230    231   			curr = curr->_prev;
   231    232   
   232    233   			free(prev);
   233    234   		}
   234    235   	}
   235    236   
   236    237   	return(NULL);
   237    238   }
   238    239   
   239         -static int filed_logging_thread_init(const char *logfile) {
          240  +static int filed_logging_thread_init(FILE *logfp) {
   240    241   	struct filed_logging_thread_args *args;
   241    242   	pthread_t thread_id;
   242         -	FILE *logfp;
   243         -
   244         -	if (strcmp(logfile, "-") == 0) {
   245         -		logfp = stdout;
   246         -	} else {
   247         -		logfp = fopen(logfile, "a+");
   248         -		if (logfp == NULL) {
   249         -			return(1);
   250         -		}
   251         -	}
   252    243   
   253    244   	args = malloc(sizeof(*args));
   254    245   	args->fp = logfp;
   255    246   
   256    247   	filed_log_msg_list = NULL;
   257    248   
   258    249   	pthread_mutex_init(&filed_log_msg_list_mutex, NULL);
................................................................................
  1002    993   	return(0);
  1003    994   }
  1004    995   
  1005    996   /* Run process */
  1006    997   int main(int argc, char **argv) {
  1007    998   	struct option options[10];
  1008    999   	const char *bind_addr = BIND_ADDR, *newroot = NULL, *log_file = LOG_FILE;
         1000  +	FILE *log_fp;
  1009   1001   	uid_t user = 0;
  1010   1002   	int port = PORT, thread_count = THREAD_COUNT;
  1011   1003   	int cache_size = CACHE_SIZE;
  1012   1004   	int init_ret, chroot_ret, setuid_ret, lookup_ret, chdir_ret;
  1013   1005   	int setuid_enabled = 0, daemon_enabled = 0;
  1014   1006   	int ch;
  1015   1007   	int fd;
................................................................................
  1064   1056   				return(1);
  1065   1057   			case 'h':
  1066   1058   				filed_print_help(stdout, 1, NULL);
  1067   1059   
  1068   1060   				return(0);
  1069   1061   		}
  1070   1062   	}
         1063  +
         1064  +	/* Open log file */
         1065  +	if (strcmp(log_file, "-") == 0) {
         1066  +		log_fp = stdout;
         1067  +	} else {
         1068  +		log_fp = fopen(log_file, "a+");
         1069  +		if (log_fp == NULL) {
         1070  +			perror("fopen");
         1071  +
         1072  +			return(4);
         1073  +		}
         1074  +	}
  1071   1075   
  1072   1076   	/* Create listening socket */
  1073   1077   	fd = filed_listen(bind_addr, port);
  1074   1078   	if (fd < 0) {
  1075   1079   		perror("filed_listen");
  1076   1080   
  1077   1081   		return(1);
................................................................................
  1114   1118   	if (init_ret != 0) {
  1115   1119   		perror("filed_init");
  1116   1120   
  1117   1121   		return(3);
  1118   1122   	}
  1119   1123   
  1120   1124   	/* Create logging thread */
  1121         -	init_ret = filed_logging_thread_init(log_file);
         1125  +	init_ret = filed_logging_thread_init(log_fp);
  1122   1126   	if (init_ret != 0) {
  1123   1127   		perror("filed_logging_thread_init");
  1124   1128   
  1125   1129   		return(4);
  1126   1130   	}
  1127   1131   
  1128   1132   	/* Create worker threads */