grop:bugfix: When running grop as root, save config file in directory '/root/.config/grop' (it was saved in the ordinary user home dir)

git-svn-id: https://svn.code.sf.net/p/porg/code/trunk@160 8854956c-c02d-4db9-8198-7e99b8e08f37
This commit is contained in:
davidrr 2015-08-22 19:12:46 +00:00
parent 086356a608
commit 1128ea70ee
5 changed files with 48 additions and 8 deletions

View File

@ -9,6 +9,11 @@ SVN
Tomoaki Nishiyama).
+ Allow lowercase'd variables in porgrc (like 'include').
Changes in grop:
+ Bugfix: When running grop as root, save config file in directory
'/root/.config/grop' (it was saved in the ordinary user home dir).
Version 0.8 (13 April 2015)
---------------------------

View File

@ -69,6 +69,9 @@ AC_ARG_ENABLE([grop],
[enable_grop=$enableval], [enable_grop=yes])
AM_CONDITIONAL([ENABLE_GROP], [test "$enable_grop" = yes])
test -d /run && PIDFILEDIR="/run" || PIDFILEDIR="/var/run"
AC_DEFINE_UNQUOTED([PIDFILEDIR], ["$PIDFILEDIR"], [pid file directory])
#================
# Check programs

View File

@ -12,8 +12,10 @@
#include "mainwindow.h"
#include "util.h"
#include <gtkmm/main.h>
#include <fstream>
static void show_error(std::string msg, bool gtk_started);
static void create_pid_file();
int main(int argc, char* argv[])
@ -24,9 +26,15 @@ int main(int argc, char* argv[])
{
Grop::Opt::init();
Gtk::Main kit(argc, argv, Grop::Opt::context());
gtk_started = true;
if (!geteuid())
create_pid_file();
Grop::DB::init();
Grop::MainWindow window;
kit.run(window);
}
@ -39,6 +47,8 @@ int main(int argc, char* argv[])
{
show_error(x.what(), gtk_started);
}
remove(PIDFILEDIR "/grop.pid");
}
@ -50,3 +60,25 @@ void show_error(std::string msg, bool gtk_started)
std::cerr << "grop: " << msg << '\n';
}
//
// create temp file carrying PID for later retrieval
//
void create_pid_file()
{
/*
std::string pidfile(PIDFILEDIR "/grop.pid");
if (!access(pidfile.c_str(), W_OK))
throw Porg::Error("Grop is already running");
Porg::FileStream<std::ofstream> os(pidfile);
if (!(os << getpid())) {
throw Porg::Error(std::string("Error writing to PID file '")
+ pidfile + "'", errno);
}
*/
}

View File

@ -31,9 +31,14 @@ Opt::Opt()
:
Porg::BaseOpt(),
Glib::KeyFile(),
m_rcdir(Glib::get_user_config_dir() + "/grop"),
m_groprc(m_rcdir + "/groprc")
m_groprc()
{
string dir(Glib::get_home_dir() + "/.config");
mkdir(dir.c_str(), 0700);
dir += "/grop";
mkdir(dir.c_str(), 0700);
m_groprc = dir + "/groprc";
read_config_file();
set_command_line_options();
s_initialized = true;
@ -49,12 +54,8 @@ Opt::~Opt()
set_integer("gui", "ypos", s_ypos);
set_boolean_list("gui", "columns", s_columns);
mkdir(m_rcdir.c_str(), 0700);
std::ofstream os(m_groprc.c_str());
if (os)
os << to_data();
else
if (!(os << to_data()))
g_warning("Cannot open file '%s' for writing", m_groprc.c_str());
}

View File

@ -45,7 +45,6 @@ class Opt : public Porg::BaseOpt, public Glib::KeyFile
void read_config_file();
void set_command_line_options();
std::string m_rcdir;
std::string m_groprc;
static bool s_hour;