[Frugalware-git] fwsetup-ng: add C++ utility source

James Buren ryuo at frugalware.org
Sun Aug 19 05:43:11 CEST 2012


Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=1fa41f4e4870cd6fb2df809a87133a13aaa06415

commit 1fa41f4e4870cd6fb2df809a87133a13aaa06415
Author: James Buren <ryuo at frugalware.org>
Date:   Sat Aug 18 22:43:00 2012 -0500

add C++ utility source

diff --git a/Utility.cc b/Utility.cc
new file mode 100644
index 0000000..a0fd4c4
--- /dev/null
+++ b/Utility.cc
@@ -0,0 +1,32 @@
+#include <fcntl.h>
+#include <unistd.h>
+#include "Utility.hh"
+
+#define LOGFILE "fwsetup.log"
+
+pid_t execute(const string &cmd)
+{
+  pid_t pid = -1;
+
+  pid = fork();
+
+  if(pid == 0)
+  {
+    int fd = open(LOGFILE,O_WRONLY|O_APPEND|O_CREAT,0644);
+
+    if(fd == -1)
+      _exit(200);
+
+    dup2(fd,STDOUT_FILENO);
+
+    dup2(fd,STDERR_FILENO);
+
+    close(fd);
+
+    execl("/bin/sh","/bin/sh","-c",cmd.c_str(),(void *) 0);
+
+    _exit(250);
+  }
+
+  return pid;
+}
diff --git a/Utility.hh b/Utility.hh
new file mode 100644
index 0000000..12bf460
--- /dev/null
+++ b/Utility.hh
@@ -0,0 +1,8 @@
+#pragma once
+
+#include <sys/types.h>
+#include <string>
+
+using std::string;
+
+pid_t execute(const string &cmd);


More information about the Frugalware-git mailing list