[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: icecream
From: Stephan Kulow <coolo () kde ! org>
Date: 2009-03-02 9:47:26
Message-ID: 1235987246.794676.17078.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 934044 by coolo:
more fixes from Michal Schmidt:
- don't leak file descriptor to create-env
- don't use the shell to call simple commands
M +37 -26 daemon/environment.cpp
M +6 -0 services/comm.cpp
--- trunk/icecream/daemon/environment.cpp #934043:934044
@@ -142,40 +142,48 @@
closedir( envdir );
}
-bool cleanup_cache( const string &basedir )
+/* Returns true if the child exited with success */
+static bool exec_and_wait( const char *const argv[] )
{
- flush_debug();
pid_t pid = fork();
- if ( pid )
- {
- int status = 0;
+ if ( pid == -1 ) {
+ log_perror("fork");
+ return false;
+ }
+ if ( pid ) {
+ // parent
+ int status;
while ( waitpid( pid, &status, 0 ) < 0 && errno == EINTR )
;
+ return WIFEXITED(status) && WEXITSTATUS(status) == 0;
+ }
+ // child
+ _exit(execv(argv[0], const_cast<char *const *>(argv)));
+}
- if ( mkdir( basedir.c_str(), 0755 ) && errno != EEXIST ) {
- if ( errno == EPERM )
- log_error() << "permission denied on mkdir " << basedir << endl;
- else
- log_perror( "mkdir in cleanup_cache() failed" );
- return false;
- }
- chown( basedir.c_str(), 0, 0 );
- chmod( basedir.c_str(), 0755 );
+bool cleanup_cache( const string &basedir )
+{
+ flush_debug();
- return WIFEXITED(status);
- }
- // else
- char **argv;
- argv = new char*[5];
- argv[0] = strdup( "/bin/rm" );
- argv[1] = strdup( "-rf" );
- argv[2] = strdup( "--" );
// make sure it ends with '/' to not fall into symlink traps
string bdir = basedir + '/';
- argv[3] = strdup( bdir.c_str() );
- argv[4] = NULL;
+ const char *const argv[] = {
+ "/bin/rm", "-rf", "--", bdir.c_str(), NULL
+ };
- _exit(execv(argv[0], argv));
+ bool ret = exec_and_wait( argv );
+
+ if ( mkdir( basedir.c_str(), 0755 ) && errno != EEXIST ) {
+ if ( errno == EPERM )
+ log_error() << "permission denied on mkdir " << basedir << endl;
+ else
+ log_perror( "mkdir in cleanup_cache() failed" );
+ return false;
+ }
+ chown( basedir.c_str(), 0, 0 );
+ chmod( basedir.c_str(), 0755 );
+
+ return ret;
}
Environments available_environmnents(const string &basedir)
@@ -259,7 +267,10 @@
_exit(1);
}
- if ( system( BINDIR "/icecc --build-native" ) ) {
+ const char *const argv[] = {
+ BINDIR "/icecc", "--build-native", NULL
+ };
+ if ( !exec_and_wait( argv ) ) {
log_error() << BINDIR "/icecc --build-native failed\n";
_exit(1);
}
--- trunk/icecream/services/comm.cpp #934043:934044
@@ -987,6 +987,12 @@
return -1;
}
+ if (fcntl (ask_fd, F_SETFD, FD_CLOEXEC) < 0)
+ {
+ log_perror("open_send_broadcast fcntl");
+ close (ask_fd);
+ return -1;
+ }
int optval = 1;
if (setsockopt (ask_fd, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) < 0)
{
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic