Skip to content
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

Open
wants to merge 88 commits into
base: code-review
Choose a base branch
from
Open

for code review #3

wants to merge 88 commits into from

Conversation

hurley25
Copy link
Collaborator

for code review

etc/file.conf Outdated
port:8888
addr:132.232.63.90
path:/phpstudy/www/git/deepin-file-control/tests
#path请使用绝对路径
Copy link
Collaborator Author

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`
Copy link
Collaborator Author

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];
Copy link
Collaborator Author

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,...)
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

正式的产品代码里,不能随意这样输出的,尤其是hook模块,什么都不要输出

//这个网卡这得改!!!
//这个网卡这得改!!!
//这个网卡这得改!!!
const char *etho = "wlp2s0";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

放配置里



//flag = 1是知道size,flag = 0是不知道size,是读取\r\n的
int recv_n(int fd,char *buffer,int flag,int _size)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数好像没看到哪里有调用

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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

send_buffer 肯定不会返回 NULL 吗?

}
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"));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"It is a secret" 这种常量用宏或者配置定义来做,万一复制的时候前面比前面多一个空格不就异常了

req.setFilesize(req.filesize() - readable);
req.setState(req.state() | Request::RECVING);
}
while (1) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C++的话其实写 while (true) 好看

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants