Slide 15
Slide 15 text
https://github.com/kazeburo/no_excl_open
int open(const char *pathname, int flags, ...)
{
static int (*func_open)(const char *, int, mode_t);
va_list ap;
mode_t mode;
int fd;
if (!func_open)
func_open = dlsym (RTLD_NEXT, "open");
va_start(ap, flags);
mode = va_arg(ap, int);
va_end(ap);
// O_RDWR and ! O_TRUNC
if ( (flags & O_CREAT) != 0 && (flags & O_RDWR) != 0 && (flags & O_TRUNC) == 0 ) {
flags = flags & ~O_EXCL; // ͜͜ͰO_EXCLΛআڈ
}
fd = func_open(pathname, flags, mode);
return fd;
}