mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-28 21:02:38 +00:00
Use "using namespace std;" and remove all std::'s
I'm doing this because otherwise i'll will forget to add all those std::'s and will lose a LOT of time finding the problems. If you don't agree, undo this patch... ...but i hope you won't :)
This commit is contained in:
parent
63133c19d6
commit
41e80b9833
@ -259,7 +259,7 @@ int compare(const char *expr)
|
|||||||
|
|
||||||
int check_if_match(struct text_object *obj)
|
int check_if_match(struct text_object *obj)
|
||||||
{
|
{
|
||||||
std::unique_ptr<char []> expression(new char[max_user_text]);
|
unique_ptr<char []> expression(new char[max_user_text]);
|
||||||
int val;
|
int val;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ void update_audacious(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(info.audacious.p_timed_thread->mutex());
|
lock_guard<mutex> lock(info.audacious.p_timed_thread->mutex());
|
||||||
memcpy(&info.audacious.items, audacious_items, sizeof(audacious_items));
|
memcpy(&info.audacious.items, audacious_items, sizeof(audacious_items));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,8 +88,8 @@ int create_audacious_thread(void)
|
|||||||
{
|
{
|
||||||
if (!info.audacious.p_timed_thread) {
|
if (!info.audacious.p_timed_thread) {
|
||||||
info.audacious.p_timed_thread =
|
info.audacious.p_timed_thread =
|
||||||
timed_thread::create(std::bind(audacious_thread_func,
|
timed_thread::create(bind(audacious_thread_func,
|
||||||
std::placeholders::_1), info.music_player_interval *
|
placeholders::_1), info.music_player_interval *
|
||||||
1000000);
|
1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ void audacious_thread_func(thread_handle &handle)
|
|||||||
} while (0);
|
} while (0);
|
||||||
{
|
{
|
||||||
/* Deliver the refreshed items array to audacious_items. */
|
/* Deliver the refreshed items array to audacious_items. */
|
||||||
std::lock_guard<std::mutex> lock(handle.mutex());
|
lock_guard<mutex> lock(handle.mutex());
|
||||||
memcpy(&audacious_items, items, sizeof(items));
|
memcpy(&audacious_items, items, sizeof(items));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ void ccurl_fetch_data(thread_handle &handle, ccurl_location_ptr &curloc)
|
|||||||
long http_status_code;
|
long http_status_code;
|
||||||
|
|
||||||
if(curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status_code) == CURLE_OK && http_status_code == 200) {
|
if(curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status_code) == CURLE_OK && http_status_code == 200) {
|
||||||
std::lock_guard<std::mutex> lock(handle.mutex());
|
lock_guard<mutex> lock(handle.mutex());
|
||||||
curloc->process_function(curloc->result, chunk.memory);
|
curloc->process_function(curloc->result, chunk.memory);
|
||||||
} else {
|
} else {
|
||||||
NORM_ERR("curl: no data from server");
|
NORM_ERR("curl: no data from server");
|
||||||
@ -142,8 +142,8 @@ void ccurl_init_thread(ccurl_location_ptr curloc, int interval)
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
assert(curloc->result);
|
assert(curloc->result);
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
curloc->p_timed_thread = timed_thread::create(std::bind(ccurl_thread,
|
curloc->p_timed_thread = timed_thread::create(bind(ccurl_thread,
|
||||||
std::placeholders::_1, curloc), interval * 1000000);
|
placeholders::_1, curloc), interval * 1000000);
|
||||||
|
|
||||||
if (!curloc->p_timed_thread) {
|
if (!curloc->p_timed_thread) {
|
||||||
NORM_ERR("curl thread: error creating timed thread");
|
NORM_ERR("curl thread: error creating timed thread");
|
||||||
@ -194,8 +194,8 @@ void ccurl_process_info(char *p, int p_max_size, char *uri, int interval)
|
|||||||
if (!curloc->p_timed_thread) {
|
if (!curloc->p_timed_thread) {
|
||||||
curloc->result = (char*)malloc(max_user_text);
|
curloc->result = (char*)malloc(max_user_text);
|
||||||
memset(curloc->result, 0, max_user_text);
|
memset(curloc->result, 0, max_user_text);
|
||||||
curloc->process_function = std::bind(ccurl_parse_data,
|
curloc->process_function = bind(ccurl_parse_data,
|
||||||
std::placeholders::_1, std::placeholders::_2);
|
placeholders::_1, placeholders::_2);
|
||||||
ccurl_init_thread(curloc, interval);
|
ccurl_init_thread(curloc, interval);
|
||||||
if (!curloc->p_timed_thread) {
|
if (!curloc->p_timed_thread) {
|
||||||
NORM_ERR("error setting up curl thread");
|
NORM_ERR("error setting up curl thread");
|
||||||
@ -203,7 +203,7 @@ void ccurl_process_info(char *p, int p_max_size, char *uri, int interval)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(curloc->p_timed_thread->mutex());
|
lock_guard<mutex> lock(curloc->p_timed_thread->mutex());
|
||||||
strncpy(p, curloc->result, p_max_size);
|
strncpy(p, curloc->result, p_max_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,11 +43,11 @@ struct ccurl_location_t {
|
|||||||
/* function to call when data is ready to be processed, the first argument
|
/* function to call when data is ready to be processed, the first argument
|
||||||
* will be the result pointer, and the second argument is an internal
|
* will be the result pointer, and the second argument is an internal
|
||||||
* buffer that shouldn't be mangled */
|
* buffer that shouldn't be mangled */
|
||||||
std::function<void(char *, const char *)> process_function;
|
function<void(char *, const char *)> process_function;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<ccurl_location_t> ccurl_location_ptr;
|
typedef shared_ptr<ccurl_location_t> ccurl_location_ptr;
|
||||||
typedef std::list<ccurl_location_ptr> ccurl_location_list;
|
typedef list<ccurl_location_ptr> ccurl_location_list;
|
||||||
|
|
||||||
/* find an existing location for the uri specified */
|
/* find an existing location for the uri specified */
|
||||||
ccurl_location_ptr ccurl_find_location(ccurl_location_list &locations, char *uri);
|
ccurl_location_ptr ccurl_find_location(ccurl_location_list &locations, char *uri);
|
||||||
|
@ -96,7 +96,7 @@ void parse_combine_arg(struct text_object *obj, const char *arg, void *free_at_c
|
|||||||
void print_combine(struct text_object *obj, char *p, int p_max_size)
|
void print_combine(struct text_object *obj, char *p, int p_max_size)
|
||||||
{
|
{
|
||||||
struct combine_data *cd = (struct combine_data *)obj->data.opaque;
|
struct combine_data *cd = (struct combine_data *)obj->data.opaque;
|
||||||
std::vector<std::vector<char>> buf;
|
vector<vector<char>> buf;
|
||||||
buf.resize(2);
|
buf.resize(2);
|
||||||
buf[0].resize(max_user_text);
|
buf[0].resize(max_user_text);
|
||||||
buf[1].resize(max_user_text);
|
buf[1].resize(max_user_text);
|
||||||
|
@ -638,7 +638,7 @@ void print_evaluate(struct text_object *obj, char *p, int p_max_size)
|
|||||||
|
|
||||||
int if_empty_iftest(struct text_object *obj)
|
int if_empty_iftest(struct text_object *obj)
|
||||||
{
|
{
|
||||||
std::vector<char> buf(max_user_text);
|
vector<char> buf(max_user_text);
|
||||||
int result = 1;
|
int result = 1;
|
||||||
|
|
||||||
generate_text_internal(&(buf[0]), max_user_text, *obj->sub);
|
generate_text_internal(&(buf[0]), max_user_text, *obj->sub);
|
||||||
@ -769,7 +769,7 @@ void print_battery_short(struct text_object *obj, char *p, int p_max_size)
|
|||||||
void print_blink(struct text_object *obj, char *p, int p_max_size)
|
void print_blink(struct text_object *obj, char *p, int p_max_size)
|
||||||
{
|
{
|
||||||
//blinking like this can look a bit ugly if the chars in the font don't have the same width
|
//blinking like this can look a bit ugly if the chars in the font don't have the same width
|
||||||
std::vector<char> buf(max_user_text);
|
vector<char> buf(max_user_text);
|
||||||
static int visible = 1;
|
static int visible = 1;
|
||||||
static int last_len = 0;
|
static int last_len = 0;
|
||||||
int i;
|
int i;
|
||||||
@ -788,7 +788,7 @@ void print_blink(struct text_object *obj, char *p, int p_max_size)
|
|||||||
|
|
||||||
void print_include(struct text_object *obj, char *p, int p_max_size)
|
void print_include(struct text_object *obj, char *p, int p_max_size)
|
||||||
{
|
{
|
||||||
std::vector<char> buf(max_user_text);
|
vector<char> buf(max_user_text);
|
||||||
|
|
||||||
if (!obj->sub)
|
if (!obj->sub)
|
||||||
return;
|
return;
|
||||||
@ -799,7 +799,7 @@ void print_include(struct text_object *obj, char *p, int p_max_size)
|
|||||||
|
|
||||||
void print_to_bytes(struct text_object *obj, char *p, int p_max_size)
|
void print_to_bytes(struct text_object *obj, char *p, int p_max_size)
|
||||||
{
|
{
|
||||||
std::vector<char> buf(max_user_text);
|
vector<char> buf(max_user_text);
|
||||||
long long bytes;
|
long long bytes;
|
||||||
char unit[16]; // 16 because we can also have long names (like mega-bytes)
|
char unit[16]; // 16 because we can also have long names (like mega-bytes)
|
||||||
|
|
||||||
|
@ -31,6 +31,8 @@
|
|||||||
#ifndef _conky_h_
|
#ifndef _conky_h_
|
||||||
#define _conky_h_
|
#define _conky_h_
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
#include <config.h> /* defines */
|
#include <config.h> /* defines */
|
||||||
#include "common.h" /* at least for struct dns_data */
|
#include "common.h" /* at least for struct dns_data */
|
||||||
#include <sys/utsname.h> /* struct uname_s */
|
#include <sys/utsname.h> /* struct uname_s */
|
||||||
|
@ -58,7 +58,7 @@ void clear_diskio_stats(void)
|
|||||||
struct diskio_stat *prepare_diskio_stat(const char *s)
|
struct diskio_stat *prepare_diskio_stat(const char *s)
|
||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
std::vector<char> stat_name(text_buffer_size), device_name(text_buffer_size);
|
vector<char> stat_name(text_buffer_size), device_name(text_buffer_size);
|
||||||
struct diskio_stat *cur = &stats;
|
struct diskio_stat *cur = &stats;
|
||||||
|
|
||||||
if (!s)
|
if (!s)
|
||||||
|
@ -162,7 +162,7 @@ static inline void read_exec(const char *data, char *buf, const int size)
|
|||||||
|
|
||||||
length = fread(buf, 1, size, fp);
|
length = fread(buf, 1, size, fp);
|
||||||
pclose(fp);
|
pclose(fp);
|
||||||
buf[std::min(length, size-1)] = '\0';
|
buf[min(length, size-1)] = '\0';
|
||||||
if (length > 0 && buf[length - 1] == '\n') {
|
if (length > 0 && buf[length - 1] == '\n') {
|
||||||
buf[length - 1] = '\0';
|
buf[length - 1] = '\0';
|
||||||
}
|
}
|
||||||
@ -203,7 +203,7 @@ static void threaded_exec(thread_handle &handle, struct text_object *obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(handle.mutex());
|
lock_guard<mutex> lock(handle.mutex());
|
||||||
free_and_zero(ed->buffer);
|
free_and_zero(ed->buffer);
|
||||||
ed->buffer = buff;
|
ed->buffer = buff;
|
||||||
}
|
}
|
||||||
@ -323,13 +323,13 @@ void print_execi(struct text_object *obj, char *p, int p_max_size)
|
|||||||
* note that we don't register this thread with the
|
* note that we don't register this thread with the
|
||||||
* timed_thread list, because we destroy it manually
|
* timed_thread list, because we destroy it manually
|
||||||
*/
|
*/
|
||||||
ed->p_timed_thread = timed_thread::create(std::bind(threaded_exec, std::placeholders::_1, obj), ed->interval * 1000000, false);
|
ed->p_timed_thread = timed_thread::create(bind(threaded_exec, placeholders::_1, obj), ed->interval * 1000000, false);
|
||||||
if (!ed->p_timed_thread) {
|
if (!ed->p_timed_thread) {
|
||||||
NORM_ERR("Error creating texeci timed thread");
|
NORM_ERR("Error creating texeci timed thread");
|
||||||
}
|
}
|
||||||
fillbuffer = false;
|
fillbuffer = false;
|
||||||
} else {
|
} else {
|
||||||
std::lock_guard<std::mutex> lock(ed->p_timed_thread->mutex());
|
lock_guard<mutex> lock(ed->p_timed_thread->mutex());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (time_to_update(ed)) {
|
if (time_to_update(ed)) {
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "conky.h"
|
||||||
#include "libtcp-portmon.h"
|
#include "libtcp-portmon.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@ -75,8 +76,8 @@ namespace {
|
|||||||
bool operator==(const tcp_connection_t &a, const tcp_connection_t &b)
|
bool operator==(const tcp_connection_t &a, const tcp_connection_t &b)
|
||||||
{
|
{
|
||||||
return a.local_port == b.local_port && a.remote_port == b.remote_port &&
|
return a.local_port == b.local_port && a.remote_port == b.remote_port &&
|
||||||
! std::memcmp(&a.local_addr, &b.local_addr, sizeof(a.local_addr)) &&
|
! memcmp(&a.local_addr, &b.local_addr, sizeof(a.local_addr)) &&
|
||||||
! std::memcmp(&a.remote_addr.s6_addr, &b.remote_addr, sizeof(a.remote_addr));
|
! memcmp(&a.remote_addr.s6_addr, &b.remote_addr, sizeof(a.remote_addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
@ -85,10 +86,10 @@ namespace {
|
|||||||
* The second parameter provides the mechanism for removing connections if
|
* The second parameter provides the mechanism for removing connections if
|
||||||
* they are not seen again in subsequent update cycles.
|
* they are not seen again in subsequent update cycles.
|
||||||
* ------------------------------------------------------------------------ */
|
* ------------------------------------------------------------------------ */
|
||||||
typedef std::unordered_map<tcp_connection_t, int, tcp_connection_hash> connection_hash_t;
|
typedef unordered_map<tcp_connection_t, int, tcp_connection_hash> connection_hash_t;
|
||||||
|
|
||||||
/* start and end of port monitor range. Set start=end to monitor a single port */
|
/* start and end of port monitor range. Set start=end to monitor a single port */
|
||||||
typedef std::pair<in_port_t, in_port_t> port_range_t;
|
typedef pair<in_port_t, in_port_t> port_range_t;
|
||||||
|
|
||||||
/* hash function for port ranges */
|
/* hash function for port ranges */
|
||||||
struct port_range_hash {
|
struct port_range_hash {
|
||||||
@ -98,7 +99,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::unordered_map<port_range_t,
|
typedef unordered_map<port_range_t,
|
||||||
tcp_port_monitor_t,
|
tcp_port_monitor_t,
|
||||||
port_range_hash> monitor_hash_t;
|
port_range_hash> monitor_hash_t;
|
||||||
|
|
||||||
@ -112,7 +113,7 @@ struct _tcp_port_monitor_t {
|
|||||||
connection_hash_t hash;
|
connection_hash_t hash;
|
||||||
/* array of connection pointers for O(1) peeking
|
/* array of connection pointers for O(1) peeking
|
||||||
* these point into the hash table*/
|
* these point into the hash table*/
|
||||||
std::vector<const tcp_connection_t *> p_peek;
|
vector<const tcp_connection_t *> p_peek;
|
||||||
|
|
||||||
_tcp_port_monitor_t(int max_connections)
|
_tcp_port_monitor_t(int max_connections)
|
||||||
: hash(), p_peek(max_connections, static_cast<const tcp_connection_t *>(NULL))
|
: hash(), p_peek(max_connections, static_cast<const tcp_connection_t *>(NULL))
|
||||||
@ -132,7 +133,7 @@ struct _tcp_port_monitor_t {
|
|||||||
* done in O(1) time instead of O(n) time for each peek. */
|
* done in O(1) time instead of O(n) time for each peek. */
|
||||||
|
|
||||||
/* zero out the peek array */
|
/* zero out the peek array */
|
||||||
std::fill(p_peek.begin(), p_peek.end(), static_cast<tcp_connection_t *>(NULL));
|
fill(p_peek.begin(), p_peek.end(), static_cast<tcp_connection_t *>(NULL));
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (connection_hash_t::iterator j = hash.begin(); j != hash.end(); ++j, ++i ) {
|
for (connection_hash_t::iterator j = hash.begin(); j != hash.end(); ++j, ++i ) {
|
||||||
@ -275,7 +276,7 @@ namespace {
|
|||||||
/* checks whether the address is a IPv4-mapped IPv6 address */
|
/* checks whether the address is a IPv4-mapped IPv6 address */
|
||||||
bool is_4on6(const struct in6_addr *addr)
|
bool is_4on6(const struct in6_addr *addr)
|
||||||
{
|
{
|
||||||
return ! std::memcmp(&addr->s6_addr, prefix_4on6, sizeof(prefix_4on6));
|
return ! memcmp(&addr->s6_addr, prefix_4on6, sizeof(prefix_4on6));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -285,15 +286,15 @@ namespace {
|
|||||||
union sockaddr_in46 sa;
|
union sockaddr_in46 sa;
|
||||||
socklen_t slen;
|
socklen_t slen;
|
||||||
|
|
||||||
std::memset(&sa, 0, sizeof(sa));
|
memset(&sa, 0, sizeof(sa));
|
||||||
|
|
||||||
if(is_4on6(addr)) {
|
if(is_4on6(addr)) {
|
||||||
sa.sa4.sin_family = AF_INET;
|
sa.sa4.sin_family = AF_INET;
|
||||||
std::memcpy(&sa.sa4.sin_addr.s_addr, &addr->s6_addr[12], 4);
|
memcpy(&sa.sa4.sin_addr.s_addr, &addr->s6_addr[12], 4);
|
||||||
slen = sizeof(sa.sa4);
|
slen = sizeof(sa.sa4);
|
||||||
} else {
|
} else {
|
||||||
sa.sa6.sin6_family = AF_INET6;
|
sa.sa6.sin6_family = AF_INET6;
|
||||||
std::memcpy(&sa.sa6.sin6_addr, addr, sizeof(struct in6_addr));
|
memcpy(&sa.sa6.sin6_addr, addr, sizeof(struct in6_addr));
|
||||||
slen = sizeof(sa.sa6);
|
slen = sizeof(sa.sa6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,48 +306,48 @@ namespace {
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if(std::strlen(p_buffer) < 32) { //IPv4 address
|
if(strlen(p_buffer) < 32) { //IPv4 address
|
||||||
i = sizeof(prefix_4on6);
|
i = sizeof(prefix_4on6);
|
||||||
std::memcpy(addr->s6_addr, prefix_4on6, i);
|
memcpy(addr->s6_addr, prefix_4on6, i);
|
||||||
} else {
|
} else {
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( ; i < sizeof(addr->s6_addr); i+=4, p_buffer+=8) {
|
for( ; i < sizeof(addr->s6_addr); i+=4, p_buffer+=8) {
|
||||||
std::sscanf(p_buffer, "%8x", (unsigned *)&addr->s6_addr[i]);
|
sscanf(p_buffer, "%8x", (unsigned *)&addr->s6_addr[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* adds connections from file to the collection */
|
/* adds connections from file to the collection */
|
||||||
void process_file(tcp_port_monitor_collection_t *p_collection, const char *file)
|
void process_file(tcp_port_monitor_collection_t *p_collection, const char *file)
|
||||||
{
|
{
|
||||||
std::FILE *fp;
|
FILE *fp;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
char local_addr[40];
|
char local_addr[40];
|
||||||
char remote_addr[40];
|
char remote_addr[40];
|
||||||
tcp_connection_t conn;
|
tcp_connection_t conn;
|
||||||
unsigned long inode, uid, state;
|
unsigned long inode, uid, state;
|
||||||
|
|
||||||
if ((fp = std::fopen(file, "r")) == NULL) {
|
if ((fp = fopen(file, "r")) == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ignore field name line */
|
/* ignore field name line */
|
||||||
if(std::fgets(buf, 255, fp) == NULL) {
|
if(fgets(buf, 255, fp) == NULL) {
|
||||||
std::fclose(fp);
|
fclose(fp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read all tcp connections */
|
/* read all tcp connections */
|
||||||
while (std::fgets(buf, sizeof(buf), fp) != NULL) {
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
||||||
|
|
||||||
if (std::sscanf(buf,
|
if (sscanf(buf,
|
||||||
"%*d: %39[0-9a-fA-F]:%hx %39[0-9a-fA-F]:%hx %lx %*x:%*x %*x:%*x %*x %lu %*d %lu",
|
"%*d: %39[0-9a-fA-F]:%hx %39[0-9a-fA-F]:%hx %lx %*x:%*x %*x:%*x %*x %lu %*d %lu",
|
||||||
local_addr, &conn.local_port,
|
local_addr, &conn.local_port,
|
||||||
remote_addr, &conn.remote_port,
|
remote_addr, &conn.remote_port,
|
||||||
(unsigned long *) &state, (unsigned long *) &uid,
|
(unsigned long *) &state, (unsigned long *) &uid,
|
||||||
(unsigned long *) &inode) != 7) {
|
(unsigned long *) &inode) != 7) {
|
||||||
std::fprintf(stderr, "%s: bad file format\n", file);
|
fprintf(stderr, "%s: bad file format\n", file);
|
||||||
}
|
}
|
||||||
/** TCP_ESTABLISHED equals 1, but is not (always??) included **/
|
/** TCP_ESTABLISHED equals 1, but is not (always??) included **/
|
||||||
//if ((inode == 0) || (state != TCP_ESTABLISHED)) {
|
//if ((inode == 0) || (state != TCP_ESTABLISHED)) {
|
||||||
@ -362,7 +363,7 @@ namespace {
|
|||||||
&show_connection_to_tcp_port_monitor, (void *) &conn);
|
&show_connection_to_tcp_port_monitor, (void *) &conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,8 +390,8 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::memset(p_buffer, 0, buffer_size);
|
memset(p_buffer, 0, buffer_size);
|
||||||
std::memset(&sa, 0, sizeof(sa));
|
memset(&sa, 0, sizeof(sa));
|
||||||
|
|
||||||
sa.sin_family = AF_INET;
|
sa.sin_family = AF_INET;
|
||||||
|
|
||||||
@ -404,7 +405,7 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
|
|||||||
|
|
||||||
case COUNT:
|
case COUNT:
|
||||||
|
|
||||||
std::snprintf(p_buffer, buffer_size, "%u", unsigned(p_monitor->hash.size()));
|
snprintf(p_buffer, buffer_size, "%u", unsigned(p_monitor->hash.size()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REMOTEIP:
|
case REMOTEIP:
|
||||||
@ -419,7 +420,7 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
|
|||||||
|
|
||||||
case REMOTEPORT:
|
case REMOTEPORT:
|
||||||
|
|
||||||
std::snprintf(p_buffer, buffer_size, "%d",
|
snprintf(p_buffer, buffer_size, "%d",
|
||||||
p_monitor->p_peek[connection_index]->remote_port);
|
p_monitor->p_peek[connection_index]->remote_port);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -441,7 +442,7 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
|
|||||||
|
|
||||||
case LOCALPORT:
|
case LOCALPORT:
|
||||||
|
|
||||||
std::snprintf(p_buffer, buffer_size, "%d",
|
snprintf(p_buffer, buffer_size, "%d",
|
||||||
p_monitor->p_peek[connection_index]->local_port);
|
p_monitor->p_peek[connection_index]->local_port);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
26
src/mail.cc
26
src/mail.cc
@ -616,7 +616,7 @@ int imap_check_status(char *recvbuf, struct mail_s *mail, thread_handle &handle)
|
|||||||
NORM_ERR("Error parsing IMAP response: %s", recvbuf);
|
NORM_ERR("Error parsing IMAP response: %s", recvbuf);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
std::lock_guard<std::mutex> lock(handle.mutex());
|
lock_guard<mutex> lock(handle.mutex());
|
||||||
sscanf(reply, "MESSAGES %lu UNSEEN %lu", &mail->messages,
|
sscanf(reply, "MESSAGES %lu UNSEEN %lu", &mail->messages,
|
||||||
&mail->unseen);
|
&mail->unseen);
|
||||||
}
|
}
|
||||||
@ -635,12 +635,12 @@ void imap_unseen_command(struct mail_s *mail, unsigned long old_unseen, unsigned
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void ensure_mail_thread(struct mail_s *mail,
|
static void ensure_mail_thread(struct mail_s *mail,
|
||||||
const std::function<void(thread_handle &, struct mail_s *mail)> &func, const char *text)
|
const function<void(thread_handle &, struct mail_s *mail)> &func, const char *text)
|
||||||
{
|
{
|
||||||
if (mail->p_timed_thread)
|
if (mail->p_timed_thread)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mail->p_timed_thread = timed_thread::create(std::bind(func, std::placeholders::_1, mail), mail->interval * 1000000);
|
mail->p_timed_thread = timed_thread::create(bind(func, placeholders::_1, mail), mail->interval * 1000000);
|
||||||
if (!mail->p_timed_thread) {
|
if (!mail->p_timed_thread) {
|
||||||
NORM_ERR("Error creating %s timed thread", text);
|
NORM_ERR("Error creating %s timed thread", text);
|
||||||
}
|
}
|
||||||
@ -832,7 +832,7 @@ static void imap_thread(thread_handle &handle, struct mail_s *mail)
|
|||||||
buf--;
|
buf--;
|
||||||
}
|
}
|
||||||
if (sscanf(buf, "* %lu EXISTS\r\n", &messages) == 1) {
|
if (sscanf(buf, "* %lu EXISTS\r\n", &messages) == 1) {
|
||||||
std::lock_guard<std::mutex> lock(handle.mutex());
|
lock_guard<mutex> lock(handle.mutex());
|
||||||
if (mail->messages != messages) {
|
if (mail->messages != messages) {
|
||||||
force_check = 1;
|
force_check = 1;
|
||||||
mail->messages = messages;
|
mail->messages = messages;
|
||||||
@ -947,10 +947,10 @@ void print_imap_unseen(struct text_object *obj, char *p, int p_max_size)
|
|||||||
if (!mail)
|
if (!mail)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ensure_mail_thread(mail, std::bind(imap_thread, std::placeholders::_1, std::placeholders::_2), "imap");
|
ensure_mail_thread(mail, bind(imap_thread, placeholders::_1, placeholders::_2), "imap");
|
||||||
|
|
||||||
if (mail && mail->p_timed_thread) {
|
if (mail && mail->p_timed_thread) {
|
||||||
std::lock_guard<std::mutex> lock(mail->p_timed_thread->mutex());
|
lock_guard<mutex> lock(mail->p_timed_thread->mutex());
|
||||||
snprintf(p, p_max_size, "%lu", mail->unseen);
|
snprintf(p, p_max_size, "%lu", mail->unseen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -962,10 +962,10 @@ void print_imap_messages(struct text_object *obj, char *p, int p_max_size)
|
|||||||
if (!mail)
|
if (!mail)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ensure_mail_thread(mail, std::bind(imap_thread, std::placeholders::_1, std::placeholders::_2), "imap");
|
ensure_mail_thread(mail, bind(imap_thread, placeholders::_1, placeholders::_2), "imap");
|
||||||
|
|
||||||
if (mail && mail->p_timed_thread) {
|
if (mail && mail->p_timed_thread) {
|
||||||
std::lock_guard<std::mutex> lock(mail->p_timed_thread->mutex());
|
lock_guard<mutex> lock(mail->p_timed_thread->mutex());
|
||||||
snprintf(p, p_max_size, "%lu", mail->messages);
|
snprintf(p, p_max_size, "%lu", mail->messages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1115,7 +1115,7 @@ static void pop3_thread(thread_handle &handle, struct mail_s *mail)
|
|||||||
fail++;
|
fail++;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
std::lock_guard<std::mutex> lock(handle.mutex());
|
lock_guard<mutex> lock(handle.mutex());
|
||||||
sscanf(reply, "%lu %lu", &mail->unseen, &mail->used);
|
sscanf(reply, "%lu %lu", &mail->unseen, &mail->used);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1154,10 +1154,10 @@ void print_pop3_unseen(struct text_object *obj, char *p, int p_max_size)
|
|||||||
if (!mail)
|
if (!mail)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ensure_mail_thread(mail, std::bind(pop3_thread, std::placeholders::_1, std::placeholders::_2), "pop3");
|
ensure_mail_thread(mail, bind(pop3_thread, placeholders::_1, placeholders::_2), "pop3");
|
||||||
|
|
||||||
if (mail && mail->p_timed_thread) {
|
if (mail && mail->p_timed_thread) {
|
||||||
std::lock_guard<std::mutex> lock(mail->p_timed_thread->mutex());
|
lock_guard<mutex> lock(mail->p_timed_thread->mutex());
|
||||||
snprintf(p, p_max_size, "%lu", mail->unseen);
|
snprintf(p, p_max_size, "%lu", mail->unseen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1169,10 +1169,10 @@ void print_pop3_used(struct text_object *obj, char *p, int p_max_size)
|
|||||||
if (!mail)
|
if (!mail)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ensure_mail_thread(mail, std::bind(pop3_thread, std::placeholders::_1, std::placeholders::_2), "pop3");
|
ensure_mail_thread(mail, bind(pop3_thread, placeholders::_1, placeholders::_2), "pop3");
|
||||||
|
|
||||||
if (mail && mail->p_timed_thread) {
|
if (mail && mail->p_timed_thread) {
|
||||||
std::lock_guard<std::mutex> lock(mail->p_timed_thread->mutex());
|
lock_guard<mutex> lock(mail->p_timed_thread->mutex());
|
||||||
snprintf(p, p_max_size, "%.1f",
|
snprintf(p, p_max_size, "%.1f",
|
||||||
mail->used / 1024.0 / 1024.0);
|
mail->used / 1024.0 / 1024.0);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ static void mbox_scan(char *args, char *output, size_t max_len)
|
|||||||
{
|
{
|
||||||
int i, u, flag;
|
int i, u, flag;
|
||||||
int force_rescan = 0;
|
int force_rescan = 0;
|
||||||
std::unique_ptr<char []> buf_(new char[text_buffer_size]);
|
unique_ptr<char []> buf_(new char[text_buffer_size]);
|
||||||
char *buf = buf_.get();
|
char *buf = buf_.get();
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
struct ring_list *curr = 0, *prev = 0, *startlist = 0;
|
struct ring_list *curr = 0, *prev = 0, *startlist = 0;
|
||||||
|
@ -116,7 +116,7 @@ static void update_moc_loop(thread_handle &handle)
|
|||||||
{
|
{
|
||||||
while (1) {
|
while (1) {
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(handle.mutex());
|
lock_guard<mutex> lock(handle.mutex());
|
||||||
update_infos();
|
update_infos();
|
||||||
}
|
}
|
||||||
if (handle.test(0)) {
|
if (handle.test(0)) {
|
||||||
@ -131,7 +131,7 @@ static int run_moc_thread(double interval)
|
|||||||
if (moc_thread)
|
if (moc_thread)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
moc_thread = timed_thread::create(std::bind(update_moc_loop, std::placeholders::_1), interval);
|
moc_thread = timed_thread::create(bind(update_moc_loop, placeholders::_1), interval);
|
||||||
if (!moc_thread) {
|
if (!moc_thread) {
|
||||||
NORM_ERR("Failed to create MOC timed thread");
|
NORM_ERR("Failed to create MOC timed thread");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -136,7 +136,7 @@ void update_mpd(void)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
interval = info.music_player_interval * 1000000;
|
interval = info.music_player_interval * 1000000;
|
||||||
thread = timed_thread::create(std::bind(update_mpd_thread, std::placeholders::_1), interval);
|
thread = timed_thread::create(bind(update_mpd_thread, placeholders::_1), interval);
|
||||||
if (!thread) {
|
if (!thread) {
|
||||||
NORM_ERR("Failed to create MPD timed thread");
|
NORM_ERR("Failed to create MPD timed thread");
|
||||||
return;
|
return;
|
||||||
@ -171,7 +171,7 @@ bool mpd_process(thread_handle &handle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(handle.mutex());
|
lock_guard<mutex> lock(handle.mutex());
|
||||||
|
|
||||||
if (conn->error || conn == NULL) {
|
if (conn->error || conn == NULL) {
|
||||||
NORM_ERR("MPD error: %s\n", conn->errorStr);
|
NORM_ERR("MPD error: %s\n", conn->errorStr);
|
||||||
|
70
src/proc.cc
70
src/proc.cc
@ -60,7 +60,7 @@ char* readfile(char* filename, int* total_read, char showerror) {
|
|||||||
|
|
||||||
void pid_readlink(char *file, char *p, int p_max_size)
|
void pid_readlink(char *file, char *p, int p_max_size)
|
||||||
{
|
{
|
||||||
std::unique_ptr<char []> buf(new char[p_max_size]);
|
unique_ptr<char []> buf(new char[p_max_size]);
|
||||||
|
|
||||||
memset(buf.get(), 0, p_max_size);
|
memset(buf.get(), 0, p_max_size);
|
||||||
if(readlink(file, buf.get(), p_max_size) >= 0) {
|
if(readlink(file, buf.get(), p_max_size) >= 0) {
|
||||||
@ -106,7 +106,7 @@ int inlist(struct ll_string* front, char* string) {
|
|||||||
|
|
||||||
void print_pid_chroot(struct text_object *obj, char *p, int p_max_size) {
|
void print_pid_chroot(struct text_object *obj, char *p, int p_max_size) {
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> buf(new char[max_user_text]);
|
unique_ptr<char []> buf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(buf.get(), max_user_text, *obj->sub);
|
generate_text_internal(buf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/root", buf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/root", buf.get());
|
||||||
@ -118,7 +118,7 @@ void print_pid_cmdline(struct text_object *obj, char *p, int p_max_size)
|
|||||||
char* buf;
|
char* buf;
|
||||||
int i, bytes_read;
|
int i, bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
|
|
||||||
@ -141,10 +141,10 @@ void print_pid_cmdline(struct text_object *obj, char *p, int p_max_size)
|
|||||||
|
|
||||||
void print_pid_cwd(struct text_object *obj, char *p, int p_max_size)
|
void print_pid_cwd(struct text_object *obj, char *p, int p_max_size)
|
||||||
{
|
{
|
||||||
std::unique_ptr<char []> buf(new char[p_max_size]);
|
unique_ptr<char []> buf(new char[p_max_size]);
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/cwd", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/cwd", objbuf.get());
|
||||||
@ -162,7 +162,7 @@ void print_pid_environ(struct text_object *obj, char *p, int p_max_size)
|
|||||||
int i, total_read;
|
int i, total_read;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
char *buf, *var=strdup(obj->data.s);;
|
char *buf, *var=strdup(obj->data.s);;
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
@ -195,7 +195,7 @@ void print_pid_environ_list(struct text_object *obj, char *p, int p_max_size)
|
|||||||
int bytes_read, total_read;
|
int bytes_read, total_read;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/environ", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/environ", objbuf.get());
|
||||||
@ -217,7 +217,7 @@ void print_pid_environ_list(struct text_object *obj, char *p, int p_max_size)
|
|||||||
|
|
||||||
void print_pid_exe(struct text_object *obj, char *p, int p_max_size) {
|
void print_pid_exe(struct text_object *obj, char *p, int p_max_size) {
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/exe", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/exe", objbuf.get());
|
||||||
@ -229,7 +229,7 @@ void print_pid_nice(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
int bytes_read;
|
int bytes_read;
|
||||||
long int nice_value;
|
long int nice_value;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
|
|
||||||
@ -249,11 +249,11 @@ void print_pid_nice(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
void print_pid_openfiles(struct text_object *obj, char *p, int p_max_size) {
|
void print_pid_openfiles(struct text_object *obj, char *p, int p_max_size) {
|
||||||
DIR* dir;
|
DIR* dir;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
std::unique_ptr<char []> buf(new char[p_max_size]);
|
unique_ptr<char []> buf(new char[p_max_size]);
|
||||||
int length, totallength = 0;
|
int length, totallength = 0;
|
||||||
struct ll_string* files_front = NULL;
|
struct ll_string* files_front = NULL;
|
||||||
struct ll_string* files_back = NULL;
|
struct ll_string* files_back = NULL;
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ void print_pid_parent(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
char *begin, *end, *buf = NULL;
|
char *begin, *end, *buf = NULL;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
||||||
@ -315,7 +315,7 @@ void print_pid_priority(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
int bytes_read;
|
int bytes_read;
|
||||||
long int priority;
|
long int priority;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
|
|
||||||
@ -338,7 +338,7 @@ void print_pid_state(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
char *begin, *end, *buf = NULL;
|
char *begin, *end, *buf = NULL;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
||||||
@ -364,7 +364,7 @@ void print_pid_state_short(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
char *begin, *buf = NULL;
|
char *begin, *buf = NULL;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
|
|
||||||
@ -384,7 +384,7 @@ void print_pid_state_short(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
|
|
||||||
void print_pid_stderr(struct text_object *obj, char *p, int p_max_size) {
|
void print_pid_stderr(struct text_object *obj, char *p, int p_max_size) {
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
|
|
||||||
@ -393,7 +393,7 @@ void print_pid_stderr(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void print_pid_stdin(struct text_object *obj, char *p, int p_max_size) {
|
void print_pid_stdin(struct text_object *obj, char *p, int p_max_size) {
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
@ -404,7 +404,7 @@ void print_pid_stdin(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
|
|
||||||
void print_pid_stdout(struct text_object *obj, char *p, int p_max_size) {
|
void print_pid_stdout(struct text_object *obj, char *p, int p_max_size) {
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
|
|
||||||
@ -414,7 +414,7 @@ void print_pid_stdout(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
|
|
||||||
void scan_cmdline_to_pid_arg(struct text_object *obj, const char *arg, void* free_at_crash) {
|
void scan_cmdline_to_pid_arg(struct text_object *obj, const char *arg, void* free_at_crash) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
/* FIXME */
|
/* FIXME */
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
@ -472,7 +472,7 @@ void print_pid_threads(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
char *begin, *end, *buf = NULL;
|
char *begin, *end, *buf = NULL;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
||||||
@ -499,7 +499,7 @@ void print_pid_thread_list(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
int totallength = 0;
|
int totallength = 0;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/task", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/task", objbuf.get());
|
||||||
@ -524,7 +524,7 @@ void print_pid_time_kernelmode(struct text_object *obj, char *p, int p_max_size)
|
|||||||
int bytes_read;
|
int bytes_read;
|
||||||
unsigned long int umtime;
|
unsigned long int umtime;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
|
|
||||||
@ -546,7 +546,7 @@ void print_pid_time_usermode(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
int bytes_read;
|
int bytes_read;
|
||||||
unsigned long int kmtime;
|
unsigned long int kmtime;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
|
|
||||||
@ -568,7 +568,7 @@ void print_pid_time(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
int bytes_read;
|
int bytes_read;
|
||||||
unsigned long int umtime, kmtime;
|
unsigned long int umtime, kmtime;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
|
|
||||||
@ -591,7 +591,7 @@ void print_pid_uid(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
char *begin, *end, *buf = NULL;
|
char *begin, *end, *buf = NULL;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
||||||
@ -618,7 +618,7 @@ void print_pid_euid(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
char *begin, *end, *buf = NULL;
|
char *begin, *end, *buf = NULL;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
||||||
@ -646,7 +646,7 @@ void print_pid_suid(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
char *begin, *end, *buf = NULL;
|
char *begin, *end, *buf = NULL;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
||||||
@ -675,7 +675,7 @@ void print_pid_fsuid(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
char *begin, *end, *buf = NULL;
|
char *begin, *end, *buf = NULL;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
||||||
@ -706,7 +706,7 @@ void print_pid_gid(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
char *begin, *end, *buf = NULL;
|
char *begin, *end, *buf = NULL;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
||||||
@ -733,7 +733,7 @@ void print_pid_egid(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
char *begin, *end, *buf = NULL;
|
char *begin, *end, *buf = NULL;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
||||||
@ -761,7 +761,7 @@ void print_pid_sgid(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
char *begin, *end, *buf = NULL;
|
char *begin, *end, *buf = NULL;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
||||||
@ -790,7 +790,7 @@ void print_pid_fsgid(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
char *begin, *end, *buf = NULL;
|
char *begin, *end, *buf = NULL;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
||||||
@ -819,7 +819,7 @@ void internal_print_pid_vm(struct text_object *obj, char *p, int p_max_size, con
|
|||||||
char *begin, *end, *buf = NULL;
|
char *begin, *end, *buf = NULL;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
|
||||||
@ -890,7 +890,7 @@ void print_pid_read(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
char *begin, *end, *buf = NULL;
|
char *begin, *end, *buf = NULL;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/io", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/io", objbuf.get());
|
||||||
@ -917,7 +917,7 @@ void print_pid_write(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
char *begin, *end, *buf = NULL;
|
char *begin, *end, *buf = NULL;
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
char pathbuf[64];
|
char pathbuf[64];
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
snprintf(pathbuf, 64, PROCDIR "/%s/io", objbuf.get());
|
snprintf(pathbuf, 64, PROCDIR "/%s/io", objbuf.get());
|
||||||
|
@ -61,15 +61,15 @@ static void rss_process_info(char *p, int p_max_size, char *uri, char *action, i
|
|||||||
if (!curloc->p_timed_thread) {
|
if (!curloc->p_timed_thread) {
|
||||||
curloc->result = (char*)malloc(sizeof(PRSS));
|
curloc->result = (char*)malloc(sizeof(PRSS));
|
||||||
memset(curloc->result, 0, sizeof(PRSS));
|
memset(curloc->result, 0, sizeof(PRSS));
|
||||||
curloc->process_function = std::bind(prss_parse_data,
|
curloc->process_function = bind(prss_parse_data,
|
||||||
std::placeholders::_1, std::placeholders::_2);
|
placeholders::_1, placeholders::_2);
|
||||||
ccurl_init_thread(curloc, interval);
|
ccurl_init_thread(curloc, interval);
|
||||||
if (!curloc->p_timed_thread) {
|
if (!curloc->p_timed_thread) {
|
||||||
NORM_ERR("error setting up RSS thread");
|
NORM_ERR("error setting up RSS thread");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(curloc->p_timed_thread->mutex());
|
lock_guard<mutex> lock(curloc->p_timed_thread->mutex());
|
||||||
data = (PRSS*)curloc->result;
|
data = (PRSS*)curloc->result;
|
||||||
|
|
||||||
if (data == NULL || data->item_count < 1) {
|
if (data == NULL || data->item_count < 1) {
|
||||||
|
@ -109,7 +109,7 @@ void print_scroll(struct text_object *obj, char *p, int p_max_size)
|
|||||||
struct scroll_data *sd = (struct scroll_data *)obj->data.opaque;
|
struct scroll_data *sd = (struct scroll_data *)obj->data.opaque;
|
||||||
unsigned int j, colorchanges = 0, frontcolorchanges = 0, visibcolorchanges = 0, strend;
|
unsigned int j, colorchanges = 0, frontcolorchanges = 0, visibcolorchanges = 0, strend;
|
||||||
char *pwithcolors;
|
char *pwithcolors;
|
||||||
std::vector<char> buf(max_user_text);
|
vector<char> buf(max_user_text);
|
||||||
|
|
||||||
if (!sd)
|
if (!sd)
|
||||||
return;
|
return;
|
||||||
|
@ -358,7 +358,7 @@ static void graph_append(struct special_t *graph, double f, char showaslog)
|
|||||||
graph->graph[0] = f; /* add new data */
|
graph->graph[0] = f; /* add new data */
|
||||||
|
|
||||||
if(graph->scaled) {
|
if(graph->scaled) {
|
||||||
graph->scale = *std::max_element(graph->graph + 0, graph->graph + graph->graph_width);
|
graph->scale = *max_element(graph->graph + 0, graph->graph + graph->graph_width);
|
||||||
if(graph->scale < 1e-47) {
|
if(graph->scale < 1e-47) {
|
||||||
/* avoid NaN's when the graph is all-zero (e.g. before the first update)
|
/* avoid NaN's when the graph is all-zero (e.g. before the first update)
|
||||||
* there is nothing magical about 1e-47 here */
|
* there is nothing magical about 1e-47 here */
|
||||||
|
@ -41,25 +41,25 @@
|
|||||||
|
|
||||||
/* Abstraction layer for timed threads */
|
/* Abstraction layer for timed threads */
|
||||||
|
|
||||||
typedef struct std::chrono::system_clock clk;
|
typedef struct chrono::system_clock clk;
|
||||||
|
|
||||||
/* private */
|
/* private */
|
||||||
struct _timed_thread {
|
struct _timed_thread {
|
||||||
std::auto_ptr<std::thread> thread; /* thread itself */
|
auto_ptr<thread> the_thread; /* thread itself */
|
||||||
std::mutex cs_mutex; /* critical section mutex */
|
mutex cs_mutex; /* critical section mutex */
|
||||||
std::mutex runnable_mutex; /* runnable section mutex */
|
mutex runnable_mutex; /* runnable section mutex */
|
||||||
std::condition_variable runnable_cond; /* signalled to stop the thread */
|
condition_variable runnable_cond; /* signalled to stop the thread */
|
||||||
clk::time_point last_time; /* last time interval */
|
clk::time_point last_time; /* last time interval */
|
||||||
int pipefd[2];
|
int pipefd[2];
|
||||||
int die;
|
int die;
|
||||||
_timed_thread() : die(0) {}
|
_timed_thread() : die(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::list<timed_thread_ptr> thread_list_t;
|
typedef list<timed_thread_ptr> thread_list_t;
|
||||||
thread_list_t thread_list;
|
thread_list_t thread_list;
|
||||||
|
|
||||||
/* create a timed thread (object creation only) */
|
/* create a timed thread (object creation only) */
|
||||||
timed_thread::timed_thread(const std::function<void(thread_handle &)> start_routine, unsigned
|
timed_thread::timed_thread(const function<void(thread_handle &)> start_routine, unsigned
|
||||||
int interval_usecs) :
|
int interval_usecs) :
|
||||||
p_timed_thread(new _timed_thread), p_thread_handle(this),
|
p_timed_thread(new _timed_thread), p_thread_handle(this),
|
||||||
interval_usecs(interval_usecs), running(false)
|
interval_usecs(interval_usecs), running(false)
|
||||||
@ -71,7 +71,7 @@ timed_thread::timed_thread(const std::function<void(thread_handle &)> start_rout
|
|||||||
|
|
||||||
/* create thread pipe (used to tell threads to die) */
|
/* create thread pipe (used to tell threads to die) */
|
||||||
if (pipe(p_timed_thread->pipefd)) {
|
if (pipe(p_timed_thread->pipefd)) {
|
||||||
throw std::runtime_error("couldn't create pipe");
|
throw runtime_error("couldn't create pipe");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set initialize to current time */
|
/* set initialize to current time */
|
||||||
@ -81,11 +81,11 @@ timed_thread::timed_thread(const std::function<void(thread_handle &)> start_rout
|
|||||||
p_timed_thread->interval_time.tv_sec,
|
p_timed_thread->interval_time.tv_sec,
|
||||||
p_timed_thread->interval_time.tv_nsec); */
|
p_timed_thread->interval_time.tv_nsec); */
|
||||||
|
|
||||||
p_timed_thread->thread = std::auto_ptr<std::thread>(
|
p_timed_thread->the_thread = auto_ptr<thread>(
|
||||||
new std::thread(start_routine, p_thread_handle)
|
new thread(start_routine, p_thread_handle)
|
||||||
);
|
);
|
||||||
|
|
||||||
DBGP("created thread %ld", (long)p_timed_thread->thread.get());
|
DBGP("created thread %ld", (long)p_timed_thread->the_thread.get());
|
||||||
|
|
||||||
running = true;
|
running = true;
|
||||||
}
|
}
|
||||||
@ -93,13 +93,13 @@ timed_thread::timed_thread(const std::function<void(thread_handle &)> start_rout
|
|||||||
/* destroy a timed thread. */
|
/* destroy a timed thread. */
|
||||||
void timed_thread::destroy(bool deregister_this)
|
void timed_thread::destroy(bool deregister_this)
|
||||||
{
|
{
|
||||||
DBGP("destroying thread %ld", (long)p_timed_thread->thread.get());
|
DBGP("destroying thread %ld", (long)p_timed_thread->the_thread.get());
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
assert(running && p_timed_thread->thread->joinable());
|
assert(running && p_timed_thread->the_thread->joinable());
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
{
|
{
|
||||||
/* signal thread to stop */
|
/* signal thread to stop */
|
||||||
std::lock_guard<std::mutex> l(p_timed_thread->runnable_mutex);
|
lock_guard<std::mutex> l(p_timed_thread->runnable_mutex);
|
||||||
p_timed_thread->runnable_cond.notify_one();
|
p_timed_thread->runnable_cond.notify_one();
|
||||||
p_timed_thread->die = 1;
|
p_timed_thread->die = 1;
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ void timed_thread::destroy(bool deregister_this)
|
|||||||
perror("write()");
|
perror("write()");
|
||||||
|
|
||||||
/* join the terminating thread */
|
/* join the terminating thread */
|
||||||
p_timed_thread->thread->join();
|
p_timed_thread->the_thread->join();
|
||||||
|
|
||||||
close(p_timed_thread->pipefd[0]);
|
close(p_timed_thread->pipefd[0]);
|
||||||
close(p_timed_thread->pipefd[1]);
|
close(p_timed_thread->pipefd[1]);
|
||||||
@ -137,7 +137,7 @@ void timed_thread::unlock(void)
|
|||||||
p_timed_thread->cs_mutex.unlock();
|
p_timed_thread->cs_mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::mutex &timed_thread::mutex()
|
mutex &timed_thread::mutex()
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
assert(running);
|
assert(running);
|
||||||
@ -176,7 +176,7 @@ int timed_thread::test(int override_wait_time)
|
|||||||
|
|
||||||
/* acquire runnable_cond mutex */
|
/* acquire runnable_cond mutex */
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(p_timed_thread->runnable_mutex);
|
unique_lock<std::mutex> lock(p_timed_thread->runnable_mutex);
|
||||||
|
|
||||||
if (p_timed_thread->die) {
|
if (p_timed_thread->die) {
|
||||||
/* if we were kindly asked to die, then die */
|
/* if we were kindly asked to die, then die */
|
||||||
@ -250,7 +250,7 @@ int thread_handle::test(int override_wait_time) {
|
|||||||
return thread->test(override_wait_time);
|
return thread->test(override_wait_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::mutex &thread_handle::mutex()
|
mutex &thread_handle::mutex()
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
assert(thread->running);
|
assert(thread->running);
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#ifndef _TIMED_THREAD_H_
|
#ifndef _TIMED_THREAD_H_
|
||||||
#define _TIMED_THREAD_H_
|
#define _TIMED_THREAD_H_
|
||||||
|
|
||||||
|
#include "conky.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -36,7 +37,7 @@ const unsigned int MINIMUM_INTERVAL_USECS = 10000;
|
|||||||
typedef struct _timed_thread _timed_thread;
|
typedef struct _timed_thread _timed_thread;
|
||||||
|
|
||||||
class timed_thread;
|
class timed_thread;
|
||||||
typedef std::shared_ptr<timed_thread> timed_thread_ptr;
|
typedef shared_ptr<timed_thread> timed_thread_ptr;
|
||||||
|
|
||||||
namespace std { class mutex; }
|
namespace std { class mutex; }
|
||||||
|
|
||||||
@ -59,9 +60,9 @@ class thread_handle {
|
|||||||
class timed_thread {
|
class timed_thread {
|
||||||
public:
|
public:
|
||||||
/* create a timed thread (object creation only) */
|
/* create a timed thread (object creation only) */
|
||||||
static timed_thread_ptr create(const std::function<void(thread_handle &)> start_routine, const unsigned int
|
static timed_thread_ptr create(const function<void(thread_handle &)> start_routine, const unsigned int
|
||||||
interval_usecs, bool register_for_destruction = true) {
|
interval_usecs, bool register_for_destruction = true) {
|
||||||
timed_thread_ptr ptr(new timed_thread(std::cref(start_routine), interval_usecs));
|
timed_thread_ptr ptr(new timed_thread(cref(start_routine), interval_usecs));
|
||||||
if (register_for_destruction) {
|
if (register_for_destruction) {
|
||||||
register_(ptr);
|
register_(ptr);
|
||||||
}
|
}
|
||||||
@ -92,7 +93,7 @@ class timed_thread {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/* create a timed thread (object creation only) */
|
/* create a timed thread (object creation only) */
|
||||||
timed_thread(const std::function<void(thread_handle &)> start_routine, unsigned int
|
timed_thread(const function<void(thread_handle &)> start_routine, unsigned int
|
||||||
interval_usecs);
|
interval_usecs);
|
||||||
|
|
||||||
/* waits required interval (unless override_wait_time is non-zero) for
|
/* waits required interval (unless override_wait_time is non-zero) for
|
||||||
@ -110,7 +111,7 @@ class timed_thread {
|
|||||||
static void deregister(const timed_thread *timed_thread);
|
static void deregister(const timed_thread *timed_thread);
|
||||||
|
|
||||||
/* private internal data */
|
/* private internal data */
|
||||||
std::auto_ptr<_timed_thread> p_timed_thread;
|
auto_ptr<_timed_thread> p_timed_thread;
|
||||||
thread_handle p_thread_handle;
|
thread_handle p_thread_handle;
|
||||||
unsigned int interval_usecs;
|
unsigned int interval_usecs;
|
||||||
bool running;
|
bool running;
|
||||||
|
@ -317,7 +317,7 @@ static void do_format_time(struct text_object *obj, char *p, unsigned int p_max_
|
|||||||
|
|
||||||
void print_format_time(struct text_object *obj, char *p, int p_max_size)
|
void print_format_time(struct text_object *obj, char *p, int p_max_size)
|
||||||
{
|
{
|
||||||
std::unique_ptr<char []> buf(new char[max_user_text]);
|
unique_ptr<char []> buf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(buf.get(), max_user_text, *obj->sub);
|
generate_text_internal(buf.get(), max_user_text, *obj->sub);
|
||||||
obj->data.s = buf.get();
|
obj->data.s = buf.get();
|
||||||
|
@ -39,7 +39,7 @@ void print_uid_name(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
char* firstinvalid;
|
char* firstinvalid;
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ void print_gid_name(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
struct group *grp;
|
struct group *grp;
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
char* firstinvalid;
|
char* firstinvalid;
|
||||||
std::unique_ptr<char []> objbuf(new char[max_user_text]);
|
unique_ptr<char []> objbuf(new char[max_user_text]);
|
||||||
|
|
||||||
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
|
||||||
|
|
||||||
|
@ -717,15 +717,15 @@ static void weather_forecast_process_info(char *p, int p_max_size, char *uri, un
|
|||||||
if (!curloc->p_timed_thread) {
|
if (!curloc->p_timed_thread) {
|
||||||
curloc->result = (char*)malloc(sizeof(PWEATHER_FORECAST));
|
curloc->result = (char*)malloc(sizeof(PWEATHER_FORECAST));
|
||||||
memset(curloc->result, 0, sizeof(PWEATHER_FORECAST));
|
memset(curloc->result, 0, sizeof(PWEATHER_FORECAST));
|
||||||
curloc->process_function = std::bind(parse_weather_forecast,
|
curloc->process_function = bind(parse_weather_forecast,
|
||||||
std::placeholders::_1, std::placeholders::_2);
|
placeholders::_1, placeholders::_2);
|
||||||
ccurl_init_thread(curloc, interval);
|
ccurl_init_thread(curloc, interval);
|
||||||
if (!curloc->p_timed_thread) {
|
if (!curloc->p_timed_thread) {
|
||||||
NORM_ERR("error setting up weather_forecast thread");
|
NORM_ERR("error setting up weather_forecast thread");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(curloc->p_timed_thread->mutex());
|
lock_guard<mutex> lock(curloc->p_timed_thread->mutex());
|
||||||
data = (PWEATHER_FORECAST*)curloc->result;
|
data = (PWEATHER_FORECAST*)curloc->result;
|
||||||
if (strcmp(data_type, "hi") == EQUAL) {
|
if (strcmp(data_type, "hi") == EQUAL) {
|
||||||
temp_print(p, p_max_size, data->hi[day], TEMP_CELSIUS);
|
temp_print(p, p_max_size, data->hi[day], TEMP_CELSIUS);
|
||||||
@ -768,15 +768,15 @@ static void weather_process_info(char *p, int p_max_size, char *uri, char *data_
|
|||||||
if (!curloc->p_timed_thread) {
|
if (!curloc->p_timed_thread) {
|
||||||
curloc->result = (char*)malloc(sizeof(PWEATHER));
|
curloc->result = (char*)malloc(sizeof(PWEATHER));
|
||||||
memset(curloc->result, 0, sizeof(PWEATHER));
|
memset(curloc->result, 0, sizeof(PWEATHER));
|
||||||
curloc->process_function = std::bind(parse_weather,
|
curloc->process_function = bind(parse_weather,
|
||||||
std::placeholders::_1, std::placeholders::_2);
|
placeholders::_1, placeholders::_2);
|
||||||
ccurl_init_thread(curloc, interval);
|
ccurl_init_thread(curloc, interval);
|
||||||
if (!curloc->p_timed_thread) {
|
if (!curloc->p_timed_thread) {
|
||||||
NORM_ERR("error setting up weather thread");
|
NORM_ERR("error setting up weather thread");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(curloc->p_timed_thread->mutex());
|
lock_guard<mutex> lock(curloc->p_timed_thread->mutex());
|
||||||
data = (PWEATHER*)curloc->result;
|
data = (PWEATHER*)curloc->result;
|
||||||
if (strcmp(data_type, "last_update") == EQUAL) {
|
if (strcmp(data_type, "last_update") == EQUAL) {
|
||||||
strncpy(p, data->lastupd, p_max_size);
|
strncpy(p, data->lastupd, p_max_size);
|
||||||
@ -832,8 +832,8 @@ static void weather_process_info(char *p, int p_max_size, char *uri, char *data_
|
|||||||
#ifdef BUILD_WEATHER_XOAP
|
#ifdef BUILD_WEATHER_XOAP
|
||||||
/* xoap suffix for weather from weather.com */
|
/* xoap suffix for weather from weather.com */
|
||||||
namespace {
|
namespace {
|
||||||
std::string xoap_cc;
|
string xoap_cc;
|
||||||
std::string xoap_df;
|
string xoap_df;
|
||||||
}
|
}
|
||||||
#endif /* BUILD_WEATHER_XOAP */
|
#endif /* BUILD_WEATHER_XOAP */
|
||||||
|
|
||||||
@ -888,11 +888,11 @@ void load_xoap_keys(void)
|
|||||||
fp = fopen(xoap, "r");
|
fp = fopen(xoap, "r");
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
if (fscanf(fp, "%10s %16s", par, key) == 2) {
|
if (fscanf(fp, "%10s %16s", par, key) == 2) {
|
||||||
xoap_cc = std::string("?cc=*&link=xoap&prod=xoap&par=")
|
xoap_cc = string("?cc=*&link=xoap&prod=xoap&par=")
|
||||||
+ par + "&key=" + key + "&unit=m";
|
+ par + "&key=" + key + "&unit=m";
|
||||||
|
|
||||||
/* TODO: Use FORECAST_DAYS instead of 5 */
|
/* TODO: Use FORECAST_DAYS instead of 5 */
|
||||||
xoap_df = std::string("?dayf=5&link=xoap&prod=xoap&par=")
|
xoap_df = string("?dayf=5&link=xoap&prod=xoap&par=")
|
||||||
+ par + "&key=" + key + "&unit=m";
|
+ par + "&key=" + key + "&unit=m";
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
Loading…
Reference in New Issue
Block a user