LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 976|回复: 1

vsftpd在日志中不支持中文(utf-8)的原因

[复制链接]
发表于 2006-9-27 23:22:20 | 显示全部楼层 |阅读模式
针对FC4中自带的vsftpd_2.0.3-1
在源码中,发现写日志处理是这样的:

logging.c: Line146-165

  1. static void
  2. vsf_log_do_log_to_file(int fd, struct mystr* p_str)
  3. {
  4.   if (!tunable_no_log_lock)
  5.   {
  6.     int retval = vsf_sysutil_lock_file(fd);
  7.     if (vsf_sysutil_retval_is_error(retval))
  8.     {
  9.       return;
  10.     }
  11.   }
  12.   str_replace_unprintable(p_str, '?');
  13.   str_append_char(p_str, '\n');
  14.   /* Ignore write failure; maybe the disk filled etc. */
  15.   (void) str_write_loop(p_str, fd);
  16.   if (!tunable_no_log_lock)
  17.   {
  18.     vsf_sysutil_unlock_file(fd);
  19.   }
  20. }
复制代码


str.c: Line652-663

  1. void
  2. str_replace_unprintable(struct mystr* p_str, char new_char)
  3. {
  4.   unsigned int i;
  5.   for (i=0; i < p_str->len; i++)
  6.   {
  7.     if (!vsf_sysutil_isprint(p_str->p_buf[i]))
  8.     {
  9.       p_str->p_buf[i] = new_char;
  10.     }
  11.   }
  12. }
复制代码


sysutil.c: Line881-901

  1. int
  2. vsf_sysutil_isprint(int the_char)
  3. {
  4.   /* From Solar - we know better than some libc's! Don't let any potential
  5.    * control chars through
  6.    */
  7.   unsigned char uc = (unsigned char) the_char;
  8.   if (uc <= 31)
  9.   {
  10.     return 0;
  11.   }
  12.   if (uc == 177)
  13.   {
  14.     return 0;
  15.   }
  16.   if (uc >= 128 && uc <= 159)
  17.   {
  18.     return 0;
  19.   }
  20.   return isprint(the_char);
  21. }
复制代码

这样的结果就是在日志中的中文会变成"?"。他的解释是Don't let any potential control chars through.
不过,vsftpd在通过syslog写系统日志时,不会这样处理。(具体信息请man vsftpd.conf)
所以,写入系统日志时的中文是存在的。
发表于 2006-10-12 13:55:54 | 显示全部楼层
@_@
去问那个作者呗,也许作者只是懒得实现更多
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表