mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-17 18:45:10 +00:00
Merge branch 'master' into lua-config
Conflicts: src/conky.cc
This commit is contained in:
commit
70d53b770f
@ -99,31 +99,23 @@ double get_time(void)
|
|||||||
return tv.tv_sec + (tv.tv_usec / 1000000.0);
|
return tv.tv_sec + (tv.tv_usec / 1000000.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Converts '~/...' paths to '/home/blah/...' assumes that 'dest' is at least
|
/* Converts '~/...' paths to '/home/blah/...'
|
||||||
* DEFAULT_TEXT_BUFFER_SIZE. It's similar to variable_substitute, except only
|
* It's similar to variable_substitute, except only cheques for $HOME and ~/ in path */
|
||||||
* cheques for $HOME and ~/ in path */
|
std::string to_real_path(const std::string &source)
|
||||||
void to_real_path(char *dest, const char *source)
|
|
||||||
{
|
{
|
||||||
char tmp[DEFAULT_TEXT_BUFFER_SIZE];
|
const char *homedir = getenv("HOME");
|
||||||
if (sscanf(source, "~/%s", tmp) || sscanf(source, "$HOME/%s", tmp)) {
|
if(source.find("~/") == 0)
|
||||||
char *homedir = getenv("HOME");
|
return homedir + source.substr(1);
|
||||||
if (homedir) {
|
else if(source.find("$HOME/") == 0)
|
||||||
snprintf(dest, DEFAULT_TEXT_BUFFER_SIZE, "%s/%s", homedir, tmp);
|
return homedir + source.substr(5);
|
||||||
} else {
|
else
|
||||||
NORM_ERR("$HOME environment variable doesn't exist");
|
return source;
|
||||||
strncpy(dest, source, DEFAULT_TEXT_BUFFER_SIZE);
|
|
||||||
}
|
|
||||||
} else if (dest != source) { //see changelog 2009-06-29 if you doubt that this check is necessary
|
|
||||||
strncpy(dest, source, DEFAULT_TEXT_BUFFER_SIZE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int open_fifo(const char *file, int *reported)
|
int open_fifo(const char *file, int *reported)
|
||||||
{
|
{
|
||||||
char path[DEFAULT_TEXT_BUFFER_SIZE];
|
|
||||||
int fd = 0;
|
int fd = 0;
|
||||||
|
|
||||||
to_real_path(path, file);
|
|
||||||
fd = open(file, O_RDONLY | O_NONBLOCK);
|
fd = open(file, O_RDONLY | O_NONBLOCK);
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
@ -141,10 +133,8 @@ int open_fifo(const char *file, int *reported)
|
|||||||
|
|
||||||
FILE *open_file(const char *file, int *reported)
|
FILE *open_file(const char *file, int *reported)
|
||||||
{
|
{
|
||||||
char path[DEFAULT_TEXT_BUFFER_SIZE];
|
|
||||||
FILE *fp = 0;
|
FILE *fp = 0;
|
||||||
|
|
||||||
to_real_path(path, file);
|
|
||||||
fp = fopen(file, "r");
|
fp = fopen(file, "r");
|
||||||
|
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
@ -282,7 +272,7 @@ struct update_cb {
|
|||||||
|
|
||||||
static struct update_cb update_cb_head;
|
static struct update_cb update_cb_head;
|
||||||
|
|
||||||
static void *run_update_callback(void *) __attribute__((noreturn));
|
static void *run_update_callback(void *);
|
||||||
|
|
||||||
static int threading_started = 0;
|
static int threading_started = 0;
|
||||||
|
|
||||||
@ -373,13 +363,13 @@ static void *run_update_callback(void *data)
|
|||||||
{
|
{
|
||||||
struct update_cb *ucb = static_cast<struct update_cb *>(data);
|
struct update_cb *ucb = static_cast<struct update_cb *>(data);
|
||||||
|
|
||||||
if (!ucb || !ucb->func) pthread_exit(NULL);
|
if (!ucb || !ucb->func) return(NULL);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (sem_wait(&ucb->start_wait)) pthread_exit(NULL);
|
if (sem_wait(&ucb->start_wait)) return(NULL);
|
||||||
if (ucb->running == 0) pthread_exit(NULL);
|
if (ucb->running == 0) return(NULL);
|
||||||
(*ucb->func)();
|
(*ucb->func)();
|
||||||
if (sem_post(&ucb->end_wait)) pthread_exit(NULL);
|
if (sem_post(&ucb->end_wait)) return(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include "text_object.h"
|
#include "text_object.h"
|
||||||
@ -60,10 +61,9 @@ struct process *get_first_process(void);
|
|||||||
void get_cpu_count(void);
|
void get_cpu_count(void);
|
||||||
double get_time(void);
|
double get_time(void);
|
||||||
|
|
||||||
/* Converts '~/...' paths to '/home/blah/...' assumes that 'dest' is at least
|
/* Converts '~/...' paths to '/home/blah/...'
|
||||||
* DEFAULT_TEXT_BUFFER_SIZE. It's similar to variable_substitute, except only
|
* It's similar to variable_substitute, except only cheques for $HOME and ~/ in path */
|
||||||
* cheques for $HOME and ~/ in path */
|
std::string to_real_path(const std::string &source);
|
||||||
void to_real_path(char *dest, const char *source);
|
|
||||||
FILE *open_file(const char *file, int *reported);
|
FILE *open_file(const char *file, int *reported);
|
||||||
int open_fifo(const char *file, int *reported);
|
int open_fifo(const char *file, int *reported);
|
||||||
void variable_substitute(const char *s, char *dest, unsigned int n);
|
void variable_substitute(const char *s, char *dest, unsigned int n);
|
||||||
|
53
src/conky.cc
53
src/conky.cc
@ -318,7 +318,7 @@ static char *disp = NULL;
|
|||||||
struct information info;
|
struct information info;
|
||||||
|
|
||||||
/* path to config file */
|
/* path to config file */
|
||||||
char *current_config;
|
std::string current_config;
|
||||||
|
|
||||||
/* set to 1 if you want all text to be in uppercase */
|
/* set to 1 if you want all text to be in uppercase */
|
||||||
static unsigned int stuff_in_uppercase;
|
static unsigned int stuff_in_uppercase;
|
||||||
@ -2264,12 +2264,14 @@ static void main_loop(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_SYS_INOTIFY_H
|
#ifdef HAVE_SYS_INOTIFY_H
|
||||||
if (!disable_auto_reload && inotify_fd != -1 && inotify_config_wd == -1 && current_config != 0) {
|
if (!disable_auto_reload && inotify_fd != -1
|
||||||
|
&& inotify_config_wd == -1 && !current_config.empty()) {
|
||||||
inotify_config_wd = inotify_add_watch(inotify_fd,
|
inotify_config_wd = inotify_add_watch(inotify_fd,
|
||||||
current_config,
|
current_config.c_str(),
|
||||||
IN_MODIFY);
|
IN_MODIFY);
|
||||||
}
|
}
|
||||||
if (!disable_auto_reload && inotify_fd != -1 && inotify_config_wd != -1 && current_config != 0) {
|
if (!disable_auto_reload && inotify_fd != -1
|
||||||
|
&& inotify_config_wd != -1 && !current_config.empty()) {
|
||||||
int len = 0, idx = 0;
|
int len = 0, idx = 0;
|
||||||
fd_set descriptors;
|
fd_set descriptors;
|
||||||
struct timeval time_to_wait;
|
struct timeval time_to_wait;
|
||||||
@ -2287,13 +2289,13 @@ static void main_loop(void)
|
|||||||
struct inotify_event *ev = (struct inotify_event *) &inotify_buff[idx];
|
struct inotify_event *ev = (struct inotify_event *) &inotify_buff[idx];
|
||||||
if (ev->wd == inotify_config_wd && (ev->mask & IN_MODIFY || ev->mask & IN_IGNORED)) {
|
if (ev->wd == inotify_config_wd && (ev->mask & IN_MODIFY || ev->mask & IN_IGNORED)) {
|
||||||
/* current_config should be reloaded */
|
/* current_config should be reloaded */
|
||||||
NORM_ERR("'%s' modified, reloading...", current_config);
|
NORM_ERR("'%s' modified, reloading...", current_config.c_str());
|
||||||
reload_config();
|
reload_config();
|
||||||
if (ev->mask & IN_IGNORED) {
|
if (ev->mask & IN_IGNORED) {
|
||||||
/* for some reason we get IN_IGNORED here
|
/* for some reason we get IN_IGNORED here
|
||||||
* sometimes, so we need to re-add the watch */
|
* sometimes, so we need to re-add the watch */
|
||||||
inotify_config_wd = inotify_add_watch(inotify_fd,
|
inotify_config_wd = inotify_add_watch(inotify_fd,
|
||||||
current_config,
|
current_config.c_str(),
|
||||||
IN_MODIFY);
|
IN_MODIFY);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -2337,10 +2339,8 @@ void initialisation(int argc, char** argv);
|
|||||||
/* reload the config file */
|
/* reload the config file */
|
||||||
static void reload_config(void)
|
static void reload_config(void)
|
||||||
{
|
{
|
||||||
char *current_config_copy = strdup(current_config);
|
|
||||||
clean_up(NULL, NULL);
|
clean_up(NULL, NULL);
|
||||||
sleep(1); /* slight pause */
|
sleep(1); /* slight pause */
|
||||||
current_config = current_config_copy;
|
|
||||||
initialisation(argc_copy, argv_copy);
|
initialisation(argc_copy, argv_copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2404,7 +2404,6 @@ void clean_up(void *memtofree1, void* memtofree2)
|
|||||||
free_and_zero(tmpstring2);
|
free_and_zero(tmpstring2);
|
||||||
free_and_zero(text_buffer);
|
free_and_zero(text_buffer);
|
||||||
free_and_zero(global_text);
|
free_and_zero(global_text);
|
||||||
free_and_zero(current_config);
|
|
||||||
|
|
||||||
#ifdef BUILD_PORT_MONITORS
|
#ifdef BUILD_PORT_MONITORS
|
||||||
tcp_portmon_clear();
|
tcp_portmon_clear();
|
||||||
@ -3734,40 +3733,39 @@ static const struct option longopts[] = {
|
|||||||
|
|
||||||
void set_current_config() {
|
void set_current_config() {
|
||||||
/* check if specified config file is valid */
|
/* check if specified config file is valid */
|
||||||
if (current_config) {
|
if (not current_config.empty()) {
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
if (stat(current_config, &sb) ||
|
if (stat(current_config.c_str(), &sb) ||
|
||||||
(!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
|
(!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
|
||||||
NORM_ERR("invalid configuration file '%s'\n", current_config);
|
NORM_ERR("invalid configuration file '%s'\n", current_config.c_str());
|
||||||
free_and_zero(current_config);
|
current_config.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
|
/* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
|
||||||
|
|
||||||
if (!current_config) {
|
if (current_config.empty()) {
|
||||||
/* load default config file */
|
/* load default config file */
|
||||||
char buf[DEFAULT_TEXT_BUFFER_SIZE];
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
/* Try to use personal config file first */
|
/* Try to use personal config file first */
|
||||||
to_real_path(buf, CONFIG_FILE);
|
std::string buf = to_real_path(CONFIG_FILE);
|
||||||
if (buf[0] && (fp = fopen(buf, "r"))) {
|
if (!buf.empty() && (fp = fopen(buf.c_str(), "r"))) {
|
||||||
current_config = strndup(buf, max_user_text);
|
current_config = buf;
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to use system config file if personal config not readable */
|
/* Try to use system config file if personal config not readable */
|
||||||
if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
|
if (current_config.empty() && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
|
||||||
current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
|
current_config = SYSTEM_CONFIG_FILE;
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No readable config found */
|
/* No readable config found */
|
||||||
if (!current_config) {
|
if (current_config.empty()) {
|
||||||
#define NOCFGFILEFOUND "no readable personal or system-wide config file found"
|
#define NOCFGFILEFOUND "no readable personal or system-wide config file found"
|
||||||
#ifdef BUILD_BUILTIN_CONFIG
|
#ifdef BUILD_BUILTIN_CONFIG
|
||||||
current_config = strdup("==builtin==");
|
current_config = "==builtin==";
|
||||||
NORM_ERR(NOCFGFILEFOUND
|
NORM_ERR(NOCFGFILEFOUND
|
||||||
", using builtin default");
|
", using builtin default");
|
||||||
#else
|
#else
|
||||||
@ -3800,8 +3798,8 @@ void initialisation(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
if(for_scripts == false) {
|
if(for_scripts == false) {
|
||||||
set_current_config();
|
set_current_config();
|
||||||
load_config_file(current_config);
|
load_config_file(current_config.c_str());
|
||||||
currentconffile = conftree_add(currentconffile, current_config);
|
currentconffile = conftree_add(currentconffile, current_config.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* init specials array */
|
/* init specials array */
|
||||||
@ -3907,7 +3905,7 @@ void initialisation(int argc, char **argv) {
|
|||||||
#ifdef BUILD_X11
|
#ifdef BUILD_X11
|
||||||
/* load font */
|
/* load font */
|
||||||
if (out_to_x.get(*state)) {
|
if (out_to_x.get(*state)) {
|
||||||
load_config_file_x11(current_config);
|
load_config_file_x11(current_config.c_str());
|
||||||
}
|
}
|
||||||
#endif /* BUILD_X11 */
|
#endif /* BUILD_X11 */
|
||||||
|
|
||||||
@ -4002,7 +4000,6 @@ int main(int argc, char **argv)
|
|||||||
argv_copy = argv;
|
argv_copy = argv;
|
||||||
g_signal_pending = 0;
|
g_signal_pending = 0;
|
||||||
max_user_text = MAX_USER_TEXT_DEFAULT;
|
max_user_text = MAX_USER_TEXT_DEFAULT;
|
||||||
current_config = 0;
|
|
||||||
memset(&info, 0, sizeof(info));
|
memset(&info, 0, sizeof(info));
|
||||||
free_templates();
|
free_templates();
|
||||||
clear_net_stats();
|
clear_net_stats();
|
||||||
@ -4036,8 +4033,7 @@ int main(int argc, char **argv)
|
|||||||
case 'V':
|
case 'V':
|
||||||
print_version(); /* doesn't return */
|
print_version(); /* doesn't return */
|
||||||
case 'c':
|
case 'c':
|
||||||
free_and_zero(current_config);
|
current_config = optarg;
|
||||||
current_config = strndup(optarg, max_user_text);
|
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
if (!freopen("/dev/null", "w", stderr))
|
if (!freopen("/dev/null", "w", stderr))
|
||||||
@ -4129,7 +4125,6 @@ int main(int argc, char **argv)
|
|||||||
std::cerr << "caught exception: " << e.what() << std::endl;
|
std::cerr << "caught exception: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
free(current_config);
|
|
||||||
return 0;
|
return 0;
|
||||||
//////////// XXX ////////////////////////////////
|
//////////// XXX ////////////////////////////////
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ void human_readable(long long, char *, int);
|
|||||||
extern unsigned int max_user_text;
|
extern unsigned int max_user_text;
|
||||||
|
|
||||||
/* path to config file */
|
/* path to config file */
|
||||||
extern char *current_config;
|
extern std::string current_config;
|
||||||
|
|
||||||
#define TO_STDOUT 2
|
#define TO_STDOUT 2
|
||||||
#define TO_STDERR 4
|
#define TO_STDERR 4
|
||||||
|
@ -129,7 +129,9 @@ void cimlib_add_image(const char *args)
|
|||||||
free(cur);
|
free(cur);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
to_real_path(cur->name, cur->name);
|
strncpy(cur->name, to_real_path(cur->name).c_str(), 1024);
|
||||||
|
cur->name[1023] = 0;
|
||||||
|
//
|
||||||
// now we check for optional args
|
// now we check for optional args
|
||||||
tmp = strstr(args, "-p ");
|
tmp = strstr(args, "-p ");
|
||||||
if (tmp) {
|
if (tmp) {
|
||||||
|
@ -120,7 +120,7 @@ void llua_init(void)
|
|||||||
lua_pushstring(lua_L, BUILD_ARCH);
|
lua_pushstring(lua_L, BUILD_ARCH);
|
||||||
lua_setglobal(lua_L, "conky_build_arch");
|
lua_setglobal(lua_L, "conky_build_arch");
|
||||||
|
|
||||||
lua_pushstring(lua_L, current_config);
|
lua_pushstring(lua_L, current_config.c_str());
|
||||||
lua_setglobal(lua_L, "conky_config");
|
lua_setglobal(lua_L, "conky_config");
|
||||||
|
|
||||||
lua_pushcfunction(lua_L, &llua_conky_parse);
|
lua_pushcfunction(lua_L, &llua_conky_parse);
|
||||||
@ -141,18 +141,17 @@ void llua_init(void)
|
|||||||
void llua_load(const char *script)
|
void llua_load(const char *script)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
char path[DEFAULT_TEXT_BUFFER_SIZE];
|
|
||||||
|
|
||||||
llua_init();
|
llua_init();
|
||||||
|
|
||||||
to_real_path(path, script);
|
std::string path = to_real_path(script);
|
||||||
error = luaL_dofile(lua_L, path);
|
error = luaL_dofile(lua_L, path.c_str());
|
||||||
if (error) {
|
if (error) {
|
||||||
NORM_ERR("llua_load: %s", lua_tostring(lua_L, -1));
|
NORM_ERR("llua_load: %s", lua_tostring(lua_L, -1));
|
||||||
lua_pop(lua_L, 1);
|
lua_pop(lua_L, 1);
|
||||||
#ifdef HAVE_SYS_INOTIFY_H
|
#ifdef HAVE_SYS_INOTIFY_H
|
||||||
} else if (!llua_block_notify && inotify_fd != -1) {
|
} else if (!llua_block_notify && inotify_fd != -1) {
|
||||||
llua_append_notify(path);
|
llua_append_notify(path.c_str());
|
||||||
#endif /* HAVE_SYS_INOTIFY_H */
|
#endif /* HAVE_SYS_INOTIFY_H */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,11 +44,18 @@
|
|||||||
|
|
||||||
struct headtail {
|
struct headtail {
|
||||||
int wantedlines;
|
int wantedlines;
|
||||||
char *logfile;
|
std::string logfile;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
int current_use;
|
int current_use;
|
||||||
int max_uses;
|
int max_uses;
|
||||||
int reported;
|
int reported;
|
||||||
|
|
||||||
|
headtail()
|
||||||
|
: wantedlines(0), buffer(NULL), current_use(0), max_uses(0), reported(0)
|
||||||
|
{}
|
||||||
|
|
||||||
|
~headtail()
|
||||||
|
{ free(buffer); }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void tailstring(char *string, int endofstring, int wantedlines) {
|
static void tailstring(char *string, int endofstring, int wantedlines) {
|
||||||
@ -73,26 +80,21 @@ static void tailstring(char *string, int endofstring, int wantedlines) {
|
|||||||
void free_tailhead(struct text_object *obj)
|
void free_tailhead(struct text_object *obj)
|
||||||
{
|
{
|
||||||
struct headtail *ht = (struct headtail *)obj->data.opaque;
|
struct headtail *ht = (struct headtail *)obj->data.opaque;
|
||||||
if (!ht)
|
obj->data.opaque = NULL;
|
||||||
return;
|
delete ht;
|
||||||
free_and_zero(ht->logfile);
|
|
||||||
free_and_zero(ht->buffer);
|
|
||||||
free_and_zero(obj->data.opaque);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_tailhead(const char* type, const char* arg, struct text_object *obj, void* free_at_crash) {
|
void init_tailhead(const char* type, const char* arg, struct text_object *obj, void* free_at_crash) {
|
||||||
unsigned int args;
|
unsigned int args;
|
||||||
struct headtail *ht;
|
struct headtail *ht = new headtail;
|
||||||
|
|
||||||
ht = (struct headtail *)malloc(sizeof(struct headtail));
|
std::unique_ptr<char []> tmp(new char[DEFAULT_TEXT_BUFFER_SIZE]);
|
||||||
memset(ht, 0, sizeof(struct headtail));
|
memset(tmp.get(), 0, DEFAULT_TEXT_BUFFER_SIZE);
|
||||||
|
|
||||||
ht->logfile = (char*)malloc(DEFAULT_TEXT_BUFFER_SIZE);
|
|
||||||
memset(ht->logfile, 0, DEFAULT_TEXT_BUFFER_SIZE);
|
|
||||||
|
|
||||||
ht->max_uses = DEFAULT_MAX_HEADTAIL_USES;
|
ht->max_uses = DEFAULT_MAX_HEADTAIL_USES;
|
||||||
|
|
||||||
args = sscanf(arg, "%s %d %d", ht->logfile, &ht->wantedlines, &ht->max_uses);
|
// XXX: Buffer overflow ?
|
||||||
|
args = sscanf(arg, "%s %d %d", tmp.get(), &ht->wantedlines, &ht->max_uses);
|
||||||
if (args < 2 || args > 3) {
|
if (args < 2 || args > 3) {
|
||||||
free_tailhead(obj);
|
free_tailhead(obj);
|
||||||
CRIT_ERR(obj, free_at_crash, "%s needs a file as 1st and a number of lines as 2nd argument", type);
|
CRIT_ERR(obj, free_at_crash, "%s needs a file as 1st and a number of lines as 2nd argument", type);
|
||||||
@ -102,7 +104,7 @@ void init_tailhead(const char* type, const char* arg, struct text_object *obj, v
|
|||||||
CRIT_ERR(obj, free_at_crash, "invalid arg for %s, next_check must be larger than 0", type);
|
CRIT_ERR(obj, free_at_crash, "invalid arg for %s, next_check must be larger than 0", type);
|
||||||
}
|
}
|
||||||
if (ht->wantedlines > 0 && ht->wantedlines <= MAX_HEADTAIL_LINES) {
|
if (ht->wantedlines > 0 && ht->wantedlines <= MAX_HEADTAIL_LINES) {
|
||||||
to_real_path(ht->logfile, ht->logfile);
|
ht->logfile = to_real_path(tmp.get());
|
||||||
ht->buffer = NULL;
|
ht->buffer = NULL;
|
||||||
ht->current_use = 0;
|
ht->current_use = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -131,9 +133,9 @@ static void print_tailhead(const char* type, struct text_object *obj, char *p, i
|
|||||||
strcpy(p, ht->buffer);
|
strcpy(p, ht->buffer);
|
||||||
ht->current_use++;
|
ht->current_use++;
|
||||||
}else{ //otherwise find the needed data
|
}else{ //otherwise find the needed data
|
||||||
if(stat(ht->logfile, &st) == 0) {
|
if(stat(ht->logfile.c_str(), &st) == 0) {
|
||||||
if (S_ISFIFO(st.st_mode)) {
|
if (S_ISFIFO(st.st_mode)) {
|
||||||
fd = open_fifo(ht->logfile, &ht->reported);
|
fd = open_fifo(ht->logfile.c_str(), &ht->reported);
|
||||||
if(fd != -1) {
|
if(fd != -1) {
|
||||||
if(strcmp(type, "head") == 0) {
|
if(strcmp(type, "head") == 0) {
|
||||||
for(i = 0; linescounted < ht->wantedlines; i++) {
|
for(i = 0; linescounted < ht->wantedlines; i++) {
|
||||||
@ -153,7 +155,7 @@ static void print_tailhead(const char* type, struct text_object *obj, char *p, i
|
|||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
} else {
|
} else {
|
||||||
fp = open_file(ht->logfile, &ht->reported);
|
fp = open_file(ht->logfile.c_str(), &ht->reported);
|
||||||
if(fp != NULL) {
|
if(fp != NULL) {
|
||||||
if(strcmp(type, "head") == 0) {
|
if(strcmp(type, "head") == 0) {
|
||||||
for(i = 0; i < ht->wantedlines; i++) {
|
for(i = 0; i < ht->wantedlines; i++) {
|
||||||
@ -173,7 +175,7 @@ static void print_tailhead(const char* type, struct text_object *obj, char *p, i
|
|||||||
}
|
}
|
||||||
ht->buffer = strdup(p);
|
ht->buffer = strdup(p);
|
||||||
} else {
|
} else {
|
||||||
CRIT_ERR(NULL, NULL, "$%s can't find information about %s", type, ht->logfile);
|
CRIT_ERR(NULL, NULL, "$%s can't find information about %s", type, ht->logfile.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -882,10 +882,9 @@ void load_xoap_keys(void)
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *par = (char *) malloc(11 * sizeof(char));
|
char *par = (char *) malloc(11 * sizeof(char));
|
||||||
char *key = (char *) malloc(17 * sizeof(char));
|
char *key = (char *) malloc(17 * sizeof(char));
|
||||||
char *xoap = (char *) malloc(64 * sizeof(char));
|
|
||||||
|
|
||||||
to_real_path(xoap, XOAP_FILE);
|
std::string xoap = to_real_path(XOAP_FILE);
|
||||||
fp = fopen(xoap, "r");
|
fp = fopen(xoap.c_str(), "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 = std::string("?cc=*&link=xoap&prod=xoap&par=")
|
||||||
@ -899,7 +898,6 @@ void load_xoap_keys(void)
|
|||||||
}
|
}
|
||||||
free(par);
|
free(par);
|
||||||
free(key);
|
free(key);
|
||||||
free(xoap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void scan_weather_forecast_arg(struct text_object *obj, const char *arg, void *free_at_crash)
|
void scan_weather_forecast_arg(struct text_object *obj, const char *arg, void *free_at_crash)
|
||||||
|
Loading…
Reference in New Issue
Block a user