Minor bug fix for shell scripts like kill_tera.sh, launch_tera.sh and teracli#1280
Minor bug fix for shell scripts like kill_tera.sh, launch_tera.sh and teracli#1280lpstudy wants to merge 3 commits intobaidu:masterfrom
kill_tera.sh, launch_tera.sh and teracli#1280Conversation
1. add readline download link to avoid compile error 2. run the shell with CURRENT_DIRECTORY, to avoid the error like `bin/kill_tera.sh` 3. add GetProcessDir function to get the exe directory, so that we can run `teracli` in any directory, rather than only work by `./teracli`.
| } | ||
| return buf; | ||
| } | ||
|
|
| return dirname(buf); | ||
| } | ||
| } | ||
|
|
| } | ||
|
|
||
| std::string exedir = GetProcessDir(); | ||
| if (!confpath.empty() && IsExist(confpath)){ |
There was a problem hiding this comment.
tera.flag里面会配置logdir,路径不对的话,会导致日志不能输出,可以增加一下判断
| return -1; | ||
| } | ||
| } | ||
|
|
| cd - | ||
| touch "${FLAG_DIR}/readline_${READLINE_VERSION}" | ||
| fi | ||
|
|
There was a problem hiding this comment.
如果系统已经预装了readline,就不需要下载此tar包重新编译了
There was a problem hiding this comment.
已经增加了判断,我的是centos7.2的系统,但是并没有安装readline库。需要手动安装,其他预装库都正常,我认为其他人也会有相似的情况。
| INS_URL=http://gitlab.baidu.com/baidups/third/raw/master/ins-${INS_VERSION}.tar.gz | ||
| NOSE_URL=http://gitlab.baidu.com/baidups/third/raw/master/nose-${NOSE_VERSION}.tar.gz | ||
| READLINE_URL=http://git.savannah.gnu.org/cgit/readline.git/snapshot/readline-${READLINE_VERSION}.tar.gz | ||
| else |
| #include <sys/types.h> | ||
| #include <unistd.h> | ||
| #include <libgen.h> | ||
|
|
There was a problem hiding this comment.
感谢评论,原来我并没有关注过头文件的包含顺序问题,去调查了一下顺序:OS SDK .h , C标准库、C++标准库、其它库的头文件、自己工程的头文件。于是按照这个顺序重新组织了一下,如下:
#include "common/file/file_path.h"
#include <dirent.h>
#include <grp.h>
#include <libgen.h>
#include <pwd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gflags/gflags.h>
#include "common/base/string_ext.h"
| return ""; | ||
| } else{ | ||
| return dirname(buf); | ||
| } |
There was a problem hiding this comment.
dirname返回一个char*,是否需要释放;如果不用释放,是否是线程安全的?
There was a problem hiding this comment.
不需要释放,线程安全的。dirname可能返回内部的static alloc的内存,也可能返回buf的内存。buf本身是局部变量,可以确保线程安全,dirname本身是线程安全函数。
There was a problem hiding this comment.
如果是内部的静态分配,为什么是线程安全的
src/common/file/file_path.cc
Outdated
|
|
||
| std::string GetProcessDir(){ | ||
| char buf[1024]; | ||
| ssize_t count = readlink("/proc/self/exe", buf, 1024); |
see the comments for the details.
| LOG(ERROR) << "wrong log directory: "<<FLAGS_log_dir; | ||
| return -1; | ||
| } | ||
|
|
There was a problem hiding this comment.
可以报warning,不应该直接new client失败;
(#1279)
build.conf.templateandbuild.sh.bin/kill_tera.sh.teracliin any directory, rather than only work by./teracli.