2016-07-22 28 views
1

從kernel.org聯的,在所述的http://man7.org/linux/man-pages/man2/epoll_ctl.2.html手冊頁,聲明epoll_ctl過程如下:可能`epoll_ctl`修改傳遞給它的`epoll_event`結構?

int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); 

可以明顯看出,所述event參數被聲明爲指向struct epoll_event

這個問題的意義在於,在類型聲明之前沒有const,因此,至少「在紙上」,該過程看起來被允許修改傳遞的結構的內容。

它是一種遺漏或是它是如此的程序設計,我們不得不假設通過的結構可以在程序中修改嗎?

我知道這裏的聲明是毫不含糊的,但是有沒有人注意到這是一個遺漏?

我也看過relevant source code in kernel 4.6 tree,我沒有看到很多證據表明該程序甚至打算修改結構,所以在那裏。

回答

0

沒關係,找到一個寧可conclusive answer on the linux kernel mailing list。對於後人,這裏引用達維德Libenzi,首席或獨着的epoll

From: Davide Libenzi <davidel <at> xmailserver.org> 
Subject: Re: epoll_ctl and const correctness 
Newsgroups: gmane.linux.kernel 
Date: 2009-03-25 16:23:21 GMT (7 years, 17 weeks, 1 day, 9 hours and 4 minutes ago) 

On Wed, 25 Mar 2009, nicolas sitbon wrote: 

> Currently, the prototype of epoll_ctl is : 
> 
> int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); 
> 
> I searched in the man of epoll_ctl and google, and it seems that the 
> structure pointed to by event isn't modify, valgrind confirms this 
> behaviour, so am I wrong? or the good prototype is 
> 
> int epoll_ctl(int epfd, int op, int fd, struct epoll_event const *event); 

According to the current ctl operations, yes. But doing that would prevent 
other non-const operations to be added later on. 

- Davide

外賣是,儘管事實上的行爲不修改結構,接口省略const改性劑,由於其他控制操作可能會在未來通過相同的系統調用添加,這需要可能修改的結構,如event參數指出的那樣。

我應該先打到linux內核郵件列表,對另一個可能的冗餘信息道歉。