{
ZIP_TYPE ret = ZT_NONE;
- int fd = open( file.asString().c_str(), O_RDONLY );
+ int fd = open( file.asString().c_str(), O_RDONLY|O_CLOEXEC );
if ( fd != -1 ) {
const int magicSize = 3;
{
NO_REPOSITORY_THROW( Exception( "Can't add solvables to norepo." ) );
- AutoDispose<FILE*> file( ::fopen( file_r.c_str(), "r" ), ::fclose );
+ AutoDispose<FILE*> file( ::fopen( file_r.c_str(), "re" ), ::fclose );
if ( file == NULL )
{
file.resetDispose();
std::string command( file_r.extension() == ".gz" ? "zcat " : "cat " );
command += file_r.asString();
- AutoDispose<FILE*> file( ::popen( command.c_str(), "r" ), ::pclose );
+ AutoDispose<FILE*> file( ::popen( command.c_str(), "re" ), ::pclose );
if ( file == NULL )
{
file.resetDispose();
return;
}
- int tmpFd = ::mkstemp( buf );
+ int tmpFd = ::mkostemp( buf, O_CLOEXEC );
if ( tmpFd != -1 )
{
// success; create _impl
// we expect gzdopen to handle errors of ::open
if ( mode_r == std::ios_base::in )
{
- _fd = ::open( name_r, O_RDONLY );
+ _fd = ::open( name_r, O_RDONLY | O_CLOEXEC );
_file = gzdopen( _fd, "rb" );
}
else if ( mode_r == std::ios_base::out )
{
- _fd = ::open( name_r, O_WRONLY|O_CREAT, 0666 );
+ _fd = ::open( name_r, O_WRONLY|O_CREAT|O_CLOEXEC, 0666 );
_file = gzdopen( _fd, "wb" );
}
// else: not supported
{
unsigned int seed;
init = true;
- int fd = open("/dev/urandom", O_RDONLY);
+ int fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC);
if (fd < 0 || ::read(fd, &seed, sizeof(seed)) != sizeof(seed))
{
// No /dev/urandom... try something else.
//
bool MediaCD::openTray( const std::string & device_r )
{
- int fd = ::open( device_r.c_str(), O_RDONLY|O_NONBLOCK );
+ int fd = ::open( device_r.c_str(), O_RDONLY|O_NONBLOCK|O_CLOEXEC );
int res = -1;
if ( fd != -1)
//
bool MediaCD::closeTray( const std::string & device_r )
{
- int fd = ::open( device_r.c_str(), O_RDONLY|O_NONBLOCK );
+ int fd = ::open( device_r.c_str(), O_RDONLY|O_NONBLOCK|O_CLOEXEC );
if ( fd == -1 ) {
WAR << "Unable to open '" << device_r << "' (" << ::strerror( errno ) << ")" << endl;
return false;
ZYPP_THROW(MediaSystemException(url, "out of memory for temp file name"));
}
- int tmp_fd = ::mkstemp( buf );
+ int tmp_fd = ::mkostemp( buf, O_CLOEXEC );
if( tmp_fd == -1)
{
free( buf);
destNew = buf;
free( buf);
- FILE *file = ::fdopen( tmp_fd, "w" );
+ FILE *file = ::fdopen( tmp_fd, "we" );
if ( !file ) {
::close( tmp_fd);
filesystem::unlink( destNew );
struct addrinfo *ai, aihints;
memset(&aihints, 0, sizeof(aihints));
aihints.ai_family = PF_UNSPEC;
- int tstsock = socket(PF_INET6, SOCK_DGRAM, 0);
+ int tstsock = socket(PF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (tstsock == -1)
aihints.ai_family = PF_INET;
else
{
char buf[256], *p;
int fd, l;
- if ((fd = open(file.asString().c_str(), O_RDONLY)) == -1)
+ if ((fd = open(file.asString().c_str(), O_RDONLY|O_CLOEXEC)) == -1)
return false;
while ((l = read(fd, buf, sizeof(buf) - 1)) == -1 && errno == EINTR)
;
ZYPP_THROW(MediaSystemException(url, "out of memory for temp file name"));
}
- int tmp_fd = ::mkstemp( buf );
+ int tmp_fd = ::mkostemp( buf, O_CLOEXEC );
if( tmp_fd == -1)
{
free( buf);
destNew = buf;
free( buf);
- FILE *file = ::fdopen( tmp_fd, "w" );
+ FILE *file = ::fdopen( tmp_fd, "we" );
if ( !file ) {
::close( tmp_fd);
filesystem::unlink( destNew );
MediaBlockList bl = mlp.getBlockList();
vector<Url> urls = mlp.getUrls();
DBG << bl << endl;
- file = fopen(destNew.c_str(), "w+");
+ file = fopen(destNew.c_str(), "w+e");
if (!file)
ZYPP_THROW(MediaWriteException(destNew));
if (PathInfo(target).isExist())
filesystem::unlink(destNew);
ZYPP_RETHROW(ex);
}
- file = fopen(destNew.c_str(), "w+");
+ file = fopen(destNew.c_str(), "w+e");
if (!file)
ZYPP_THROW(MediaWriteException(destNew));
MediaCurl::doGetFileCopyFile(filename, dest, file, report, options | OPTION_NO_REPORT_START);
{
DBG << "Reading mount table from '" << *t << "'" << std::endl;
}
- FILE *fp = setmntent(t->c_str(), "r");
+ FILE *fp = setmntent(t->c_str(), "re");
if( fp)
{
char buf[PATH_MAX * 4];
return 0;
}
snprintf(path, sizeof(path), "%s/%s", dir, file);
- if ((fd = open(path, O_RDONLY)) == -1)
+ if ((fd = open(path, O_RDONLY|O_CLOEXEC)) == -1)
return 0;
len = read(fd, modalias, sizeof(modalias) - 1);
if (len < 0)