-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
for code review #3
base: code-review
Are you sure you want to change the base?
Conversation
etc/file.conf
Outdated
port:8888 | ||
addr:132.232.63.90 | ||
path:/phpstudy/www/git/deepin-file-control/tests | ||
#path请使用绝对路径 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一行配置的注释一般是写在配置上面的
mk.sh
Outdated
|
||
`gcc -fPIC -shared -o tests/hook.so src/hook.c -ldl` | ||
`g++ -o tests/cli src/cli_main.cpp -lpthread -ldl` | ||
`g++ -o tests/ser src/ser_main.cpp -lpthread -ldl` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还是要有写Makefile的习惯,觉得Makefile难写可以学学cmake之类
src/hook.c
Outdated
static CLOSE old_close = NULL; | ||
|
||
//记录绝对路径 | ||
char real_path[100]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
路径比100长会发生什么事?
#include <linux/limits.h>
char real_path[PATH_MAX];
src/hook.c
Outdated
void get_msg_id(); | ||
void send_queue_pathname(int *pflag,int mtype); | ||
|
||
int open(const char *pathname,int flags,...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码格式不对的就不特意标注了,用格式化工具批量处理吧
src/hook.c
Outdated
{ | ||
//首先建立消息队列 | ||
get_msg_id(); | ||
printf("劫持成功,文件名:%s\n",pathname); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
正式的产品代码里,不能随意这样输出的,尤其是hook模块,什么都不要输出
version2/src/cli/sendn.hpp
Outdated
//这个网卡这得改!!! | ||
//这个网卡这得改!!! | ||
//这个网卡这得改!!! | ||
const char *etho = "wlp2s0"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
放配置里
version2/src/cli/sendn.hpp
Outdated
|
||
|
||
//flag = 1是知道size,flag = 0是不知道size,是读取\r\n的 | ||
int recv_n(int fd,char *buffer,int flag,int _size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数好像没看到哪里有调用
version2/src/cli/sendn.hpp
Outdated
bzero(&buf_stat,sizeof(buf_stat)); | ||
fstat(file_fd,&buf_stat); | ||
|
||
char *send_buffer = (char*)mmap(NULL,buf_stat.st_size,PROT_READ | PROT_WRITE, MAP_SHARED,file_fd, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
send_buffer 肯定不会返回 NULL 吗?
version2/src/cli/sendn.hpp
Outdated
} | ||
munmap(send_buffer,buf_stat.st_size); | ||
ftruncate(file_fd,strlen("It is a secret")); | ||
write(file_fd,"It is a secret",strlen("It is a secret")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"It is a secret" 这种常量用宏或者配置定义来做,万一复制的时候前面比前面多一个空格不就异常了
version2/src/server/Coder.cc
Outdated
req.setFilesize(req.filesize() - readable); | ||
req.setState(req.state() | Request::RECVING); | ||
} | ||
while (1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C++的话其实写 while (true) 好看
for code review