简体   繁体   中英

May `epoll_ctl` modify the `epoll_event` structure passed to it?

The Linux kernel manpages declare the epoll_ctl procedure as follows:

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

As evident, the event parameter is declared as a pointer to the epoll_event struct .

The significance of this in the context of this question is that there is no const ahead of the pointer type declaration, and thus, the procedure appears to be permitted to modify the contents of the passed structure.

Is this an omission of sorts, or is it so that the procedure is made like that by design and we have to assume that the passed structure may indeed be modified inside the procedure?

I understand that the declaration is unambiguous here, but has anyone observed this to be an omission?

I have also taken a look at the relevant source code in kernel 4.6 tree , and I don't see much evidence that the procedure even intends to modify the structure, so there.

Found a rather conclusive answer on the linux kernel mailing list . Quoting Davide Libenzi here, chief or sole author of epoll :

 From: Davide Libenzi <davidel <at> xmailserver.org> \nSubject: Re: epoll_ctl and const correctness \nNewsgroups: gmane.linux.kernel \nDate: 2009-03-25 16:23:21 GMT (7 years, 17 weeks, 1 day, 9 hours and 4 minutes ago) \n\nOn Wed, 25 Mar 2009, nicolas sitbon wrote: \n\n> Currently, the prototype of epoll_ctl is : \n>  \n> int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); \n>  \n> I searched in the man of epoll_ctl and google, and it seems that the \n> structure pointed to by event isn't modify, valgrind confirms this \n> behaviour, so am I wrong?  or the good prototype is \n>  \n> int epoll_ctl(int epfd, int op, int fd, struct epoll_event const *event); \n\nAccording to the current ctl operations, yes.  But doing that would prevent  \nother non-const operations to be added later on. \n\n- Davide  

The takeaway is that even though de-facto behavior is not to modify the structure, the interface omits const modifier because other control operations may be added in the future through the same system call, which necessitate potentially modifiable structure as pointed at by event argument.

I should have hit the linux kernel mailing list first, apologies for another perhaps redundant information on SO. Leaving the question and this answer for posterity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM