summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnuradio-runtime/lib/local_sighandler.cc11
-rw-r--r--gnuradio-runtime/lib/vmcircbuf_mmap_shm_open.cc27
-rw-r--r--gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc24
3 files changed, 27 insertions, 35 deletions
diff --git a/gnuradio-runtime/lib/local_sighandler.cc b/gnuradio-runtime/lib/local_sighandler.cc
index ffeaa9068b..7f96b2460d 100644
--- a/gnuradio-runtime/lib/local_sighandler.cc
+++ b/gnuradio-runtime/lib/local_sighandler.cc
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <string.h>
#include <stdexcept>
+#include <boost/format.hpp>
namespace gr {
@@ -70,7 +71,7 @@ void local_sighandler::throw_signal(int signum) { throw signal(signum); }
std::string signal::name() const
{
- char tmp[128];
+ std::string tmp;
switch (signum()) {
#ifdef SIGHUP
@@ -167,18 +168,14 @@ std::string signal::name() const
SIGNAME(SIGSYS);
#endif
default:
-#if defined(HAVE_SNPRINTF)
#if defined(SIGRTMIN) && defined(SIGRTMAX)
if (signum() >= SIGRTMIN && signum() <= SIGRTMAX) {
- snprintf(tmp, sizeof(tmp), "SIGRTMIN + %d", signum());
+ tmp = str(boost::format("SIGRTMIN + %d") % signum());
return tmp;
}
#endif
- snprintf(tmp, sizeof(tmp), "SIGNAL %d", signum());
+ tmp = str(boost::format("SIGNAL %d") % signum());
return tmp;
-#else
- return "Unknown signal";
-#endif
}
}
diff --git a/gnuradio-runtime/lib/vmcircbuf_mmap_shm_open.cc b/gnuradio-runtime/lib/vmcircbuf_mmap_shm_open.cc
index 94f0a26f11..7d63dc08d1 100644
--- a/gnuradio-runtime/lib/vmcircbuf_mmap_shm_open.cc
+++ b/gnuradio-runtime/lib/vmcircbuf_mmap_shm_open.cc
@@ -39,6 +39,7 @@
#include <gnuradio/sys_paths.h>
#include <errno.h>
#include <stdio.h>
+#include <boost/format.hpp>
namespace gr {
@@ -58,7 +59,7 @@ vmcircbuf_mmap_shm_open::vmcircbuf_mmap_shm_open(int size) : gr::vmcircbuf(size)
}
int shm_fd = -1;
- char seg_name[1024];
+ std::string seg_name;
static bool portable_format = true;
// open a new named shared memory segment
@@ -67,23 +68,17 @@ vmcircbuf_mmap_shm_open::vmcircbuf_mmap_shm_open(int size) : gr::vmcircbuf(size)
// This is the POSIX recommended "portable format".
// Of course the "portable format" doesn't work on some systems...
-
- snprintf(
- seg_name, sizeof(seg_name), "/gnuradio-%d-%d", getpid(), s_seg_counter);
+ seg_name = str(boost::format("/gnuradio-%d-%d") % getpid() % s_seg_counter);
} else {
// Where the "portable format" doesn't work, we try building
// a full filesystem pathname pointing into a suitable temporary directory.
- snprintf(seg_name,
- sizeof(seg_name),
- "%s/gnuradio-%d-%d",
- gr::tmp_path(),
- getpid(),
- s_seg_counter);
+ seg_name = str(boost::format("%s/gnuradio-%d-%d") %
+ gr::tmp_path() % getpid() % s_seg_counter);
}
- shm_fd = shm_open(seg_name, O_RDWR | O_CREAT | O_EXCL, 0600);
+ shm_fd = shm_open(seg_name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600);
if (shm_fd == -1 && errno == EACCES && portable_format) {
portable_format = false;
continue; // try again using "non-portable format"
@@ -96,10 +91,10 @@ vmcircbuf_mmap_shm_open::vmcircbuf_mmap_shm_open(int size) : gr::vmcircbuf(size)
EEXIST) // Named segment already exists (shouldn't happen). Try again
continue;
- char msg[1024];
- snprintf(
- msg, sizeof(msg), "gr::vmcircbuf_mmap_shm_open: shm_open [%s]", seg_name);
- perror(msg);
+ static std::string msg =
+ str(boost::format("gr::vmcircbuf_mmap_shm_open: shm_open [%s]") %
+ seg_name);
+ perror(msg.c_str());
throw std::runtime_error("gr::vmcircbuf_mmap_shm_open");
}
break;
@@ -156,7 +151,7 @@ vmcircbuf_mmap_shm_open::vmcircbuf_mmap_shm_open(int size) : gr::vmcircbuf(size)
close(shm_fd); // fd no longer needed. The mapping is retained.
- if (shm_unlink(seg_name) == -1) { // unlink the seg_name.
+ if (shm_unlink(seg_name.c_str()) == -1) { // unlink the seg_name.
perror("gr::vmcircbuf_mmap_shm_open: shm_unlink");
throw std::runtime_error("gr::vmcircbuf_mmap_shm_open");
}
diff --git a/gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc b/gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc
index ec5f320ab1..f6c1777013 100644
--- a/gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc
+++ b/gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc
@@ -41,6 +41,7 @@
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
+#include <boost/format.hpp>
namespace gr {
@@ -58,34 +59,33 @@ vmcircbuf_mmap_tmpfile::vmcircbuf_mmap_tmpfile(int size) : gr::vmcircbuf(size)
}
int seg_fd = -1;
- char seg_name[1024];
+ std::string seg_name;
static int s_seg_counter = 0;
// open a temporary file that we'll map in a bit later
while (1) {
- snprintf(seg_name,
- sizeof(seg_name),
- "%s/gnuradio-%d-%d-XXXXXX",
- gr::tmp_path(),
- getpid(),
- s_seg_counter);
+ seg_name = str(boost::format(
+ "%s/gnuradio-%d-%d-XXXXXX") %
+ gr::tmp_path() %
+ getpid() %
+ s_seg_counter);
s_seg_counter++;
- seg_fd = open(seg_name, O_RDWR | O_CREAT | O_EXCL, 0600);
+ seg_fd = open(seg_name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600);
if (seg_fd == -1) {
if (errno == EEXIST) // File already exists (shouldn't happen). Try again
continue;
- char msg[1024];
- snprintf(msg, sizeof(msg), "gr::vmcircbuf_mmap_tmpfile: open [%s]", seg_name);
- perror(msg);
+ static std::string msg =
+ str(boost::format("gr::vmcircbuf_mmap_tmpfile: open [%s]") % seg_name);
+ perror(msg.c_str());
throw std::runtime_error("gr::vmcircbuf_mmap_tmpfile");
}
break;
}
- if (unlink(seg_name) == -1) {
+ if (unlink(seg_name.c_str()) == -1) {
perror("gr::vmcircbuf_mmap_tmpfile: unlink");
throw std::runtime_error("gr::vmcircbuf_mmap_tmpfile");
}