]> git.cworth.org Git - apitrace/blobdiff - common/os_posix.cpp
Merge branch 'trace-threads'
[apitrace] / common / os_posix.cpp
index 586ad84ed5ced202736957d3c28b645bdc16f9af..65c5404e3c0e64dd92c2184143474e05fe815b10 100644 (file)
@@ -31,7 +31,7 @@
 
 #include <unistd.h>
 #include <sys/time.h>
-#include <pthread.h>
+#include <sys/wait.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <signal.h>
 #endif
 
 #include "os.hpp"
-#include "os_path.hpp"
+#include "os_string.hpp"
 
 
 namespace os {
 
 
-static pthread_mutex_t 
-mutex = PTHREAD_MUTEX_INITIALIZER;
-
-
-void
-acquireMutex(void)
-{
-    pthread_mutex_lock(&mutex);
-}
-
-
-void
-releaseMutex(void)
-{
-    pthread_mutex_unlock(&mutex);
-}
-
-
-Path
+String
 getProcessName(void)
 {
-    Path path;
+    String path;
     size_t size = PATH_MAX;
     char *buf = path.buf(size);
 
@@ -112,10 +94,10 @@ getProcessName(void)
     return path;
 }
 
-Path
+String
 getCurrentDir(void)
 {
-    Path path;
+    String path;
     size_t size = PATH_MAX;
     char *buf = path.buf(size);
 
@@ -127,7 +109,7 @@ getCurrentDir(void)
 }
 
 bool
-Path::exists(void) const
+String::exists(void) const
 {
     struct stat st;
     int err;
@@ -143,6 +125,26 @@ Path::exists(void) const
     return true;
 }
 
+int execute(char * const * args)
+{
+    pid_t pid = fork();
+    if (pid == 0) {
+        // child
+        execvp(args[0], args);
+        fprintf(stderr, "error: failed to execute %s\n", args[0]);
+        exit(-1);
+    } else {
+        // parent
+        if (pid == -1) {
+            fprintf(stderr, "error: failed to fork\n");
+            return -1;
+        }
+        int status = -1;
+        waitpid(pid, &status, 0);
+        return status;
+    }
+}
+
 void
 log(const char *format, ...)
 {