@@ -237,15 +237,15 @@ static int expand_files(struct files_struct *files, unsigned int nr)
237
237
return expanded ;
238
238
}
239
239
240
- static inline void __set_close_on_exec (unsigned int fd , struct fdtable * fdt )
240
+ static inline void __set_close_on_exec (unsigned int fd , struct fdtable * fdt ,
241
+ bool set )
241
242
{
242
- __set_bit (fd , fdt -> close_on_exec );
243
- }
244
-
245
- static inline void __clear_close_on_exec (unsigned int fd , struct fdtable * fdt )
246
- {
247
- if (test_bit (fd , fdt -> close_on_exec ))
248
- __clear_bit (fd , fdt -> close_on_exec );
243
+ if (set ) {
244
+ __set_bit (fd , fdt -> close_on_exec );
245
+ } else {
246
+ if (test_bit (fd , fdt -> close_on_exec ))
247
+ __clear_bit (fd , fdt -> close_on_exec );
248
+ }
249
249
}
250
250
251
251
static inline void __set_open_fd (unsigned int fd , struct fdtable * fdt )
@@ -518,10 +518,7 @@ static int alloc_fd(unsigned start, unsigned end, unsigned flags)
518
518
files -> next_fd = fd + 1 ;
519
519
520
520
__set_open_fd (fd , fdt );
521
- if (flags & O_CLOEXEC )
522
- __set_close_on_exec (fd , fdt );
523
- else
524
- __clear_close_on_exec (fd , fdt );
521
+ __set_close_on_exec (fd , fdt , flags & O_CLOEXEC );
525
522
error = fd ;
526
523
527
524
out :
@@ -1147,13 +1144,8 @@ void __f_unlock_pos(struct file *f)
1147
1144
void set_close_on_exec (unsigned int fd , int flag )
1148
1145
{
1149
1146
struct files_struct * files = current -> files ;
1150
- struct fdtable * fdt ;
1151
1147
spin_lock (& files -> file_lock );
1152
- fdt = files_fdtable (files );
1153
- if (flag )
1154
- __set_close_on_exec (fd , fdt );
1155
- else
1156
- __clear_close_on_exec (fd , fdt );
1148
+ __set_close_on_exec (fd , files_fdtable (files ), flag );
1157
1149
spin_unlock (& files -> file_lock );
1158
1150
}
1159
1151
@@ -1195,10 +1187,7 @@ __releases(&files->file_lock)
1195
1187
get_file (file );
1196
1188
rcu_assign_pointer (fdt -> fd [fd ], file );
1197
1189
__set_open_fd (fd , fdt );
1198
- if (flags & O_CLOEXEC )
1199
- __set_close_on_exec (fd , fdt );
1200
- else
1201
- __clear_close_on_exec (fd , fdt );
1190
+ __set_close_on_exec (fd , fdt , flags & O_CLOEXEC );
1202
1191
spin_unlock (& files -> file_lock );
1203
1192
1204
1193
if (tofree )
0 commit comments