aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid <dbphillipsnz@gmail.com>2014-06-04 19:54:12 +1200
committerDavid <dbphillipsnz@gmail.com>2014-06-06 20:31:40 +1200
commit38f928b2f33ec527490899e580e5ee1327a327e9 (patch)
tree8e7d50f2d5a50e20e8f384241afe782ea94653a3
parent4634e137f7c1ab4a06ae6b6e808510159be55000 (diff)
downloadparamano-38f928b2f33ec527490899e580e5ee1327a327e9.tar.xz
Moved away from manual setting of sudo-ness
-rw-r--r--Makefile38
-rw-r--r--bat_tray.c1
-rw-r--r--common.c2
-rw-r--r--common.h20
-rw-r--r--config_file.c2
-rw-r--r--debug.h34
-rw-r--r--defaults.c2
-rw-r--r--defaults.h1
-rw-r--r--getcore.c2
-rw-r--r--getcore.h2
-rw-r--r--getfreq.c1
-rw-r--r--getgov.c1
-rw-r--r--reload.c2
-rw-r--r--tray.c1
-rw-r--r--trayfreq.c11
-rw-r--r--trayfreq.conf.src5
-rw-r--r--trayfreq_set.c2
-rw-r--r--trayfreq_set_interface.c12
18 files changed, 51 insertions, 88 deletions
diff --git a/Makefile b/Makefile
index eae2be7..d539b47 100644
--- a/Makefile
+++ b/Makefile
@@ -1,15 +1,24 @@
# Tabsize: 4
+# Build utils
MAKE = make
CC = gcc
+
+# Directories
PREFIX=/usr
BINDIR=$(PREFIX)/bin
+SYSCONFDIR=/etc
SHAREDIR=$(PREFIX)/share
-LOCALEDIR=$(SHAREDIR)/locale/
+LOCALEDIR=$(SHAREDIR)/locale
-SUDO=/usr/bin/sudo
+# External program/support programs
+SUDO=$(BINDIR)/sudo
TRAYFREQ_SET=$(BINDIR)/trayfreq-set
-TRAYFREQ_CONF=/etc/trayfreq.conf
+
+# Misc
+TRAYFREQ_CONF=$(SYSCONFDIR)/trayfreq.conf
+ROOT_UID=0
+
ifdef DEBUG
EXTRA_CFLAGS+=-DDEBUG
@@ -20,14 +29,14 @@ EXTRA_CFLAGS+= -DPREFIX=\"$(PREFIX)\" \
-DSUDO=\"$(SUDO)\" \
-DTRAYFREQ_SET=\"$(TRAYFREQ_SET)\" \
-DLOCALEDIR=\"$(LOCALEDIR)\" \
- -DSHAREDIR=\"$(SHAREDIR)\"
+ -DSHAREDIR=\"$(SHAREDIR)\" \
+ -DROOT_UID=$(ROOT_UID)
DEPS = bat_tray.h \
bool.h \
common.h \
config_file.h \
- debug.h \
defaults.h \
getcore.h \
getfreq.h \
@@ -37,7 +46,6 @@ DEPS = bat_tray.h \
tray.h \
trayfreq_set_interface.h
-
trayfreq_CFLAGS = -I/usr/include/gtk-2.0 \
-I/usr/lib/gtk-2.0/include \
-I/usr/include/pango-1.0 \
@@ -53,28 +61,11 @@ trayfreq_LDFLAGS = -lgtk-3 \
-lgobject-2.0 \
-lglib-2.0
-trayfreq_SOURCES = freq_tray/getcore.c \
- freq_tray/getfreq.c \
- freq_tray/getgov.c \
- tray.c \
- trayfreq.c \
- trayfreq_set/trayfreq_set_interface.c \
- config_file.c \
- defaults.c \
- bat_tray/bat_tray.c \
- common.c \
- reload.c
-
trayfreq_set_CFLAGS = -Wall \
-D_=gettext
trayfreq_set_LDFLAGS = -lglib-2.0
-trayfreq_set_SOURCES = trayfreq_set/trayfreq_set.c \
- freq_tray/getfreq.c \
- freq_tray/getcore.c
-
-
########################################################################
# Make entire suite
all: trayfreq trayfreq-set lang trayfreq.conf
@@ -108,7 +99,6 @@ trayfreq-set: \
########################################################################
-
########################################################################
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(trayfreq_CFLAGS) $(EXTRA_CFLAGS)
diff --git a/bat_tray.c b/bat_tray.c
index 1aad51a..a474c8a 100644
--- a/bat_tray.c
+++ b/bat_tray.c
@@ -21,7 +21,6 @@
#include <gtk/gtk.h>
#include <libintl.h>
-#include "debug.h"
#include "common.h"
#include "defaults.h"
diff --git a/common.c b/common.c
index 5ffdd8b..35bfe43 100644
--- a/common.c
+++ b/common.c
@@ -18,8 +18,6 @@
#include "common.h"
-#include "debug.h" /* debug() */
-
#include <stdio.h> /* fopen, fgets, printf */
#include <stdlib.h> /* atoi */
#include <string.h> /* lots of functions */
diff --git a/common.h b/common.h
index dfec86b..613541d 100644
--- a/common.h
+++ b/common.h
@@ -25,4 +25,24 @@ int get_int_value_from_file(const char* filename);
int get_int(const char* string);
bool file_has_line(const char *filename, const char *line);
+#include <stdio.h>
+// <ew> Stringification of line number
+#define STRING2(x) #x
+#define STRING(x) STRING2(x)
+#define STR_LINE STRING(__LINE__)
+// </ew>
+
+
+#ifdef DEBUG
+/*
+ Make debug macros into empty space if debug mode's not enabled.
+ Otherwise, make debug macro calls into appropriate printf()s
+*/
+ #define debug(...) printf("DEBUG: "__FILE__":"STR_LINE" --- "__VA_ARGS__)
+#else
+ #define debug(...);
+#endif
+
+#define info(...) printf("INFO: "__FILE__":"STR_LINE" --- "__VA_ARGS__)
+
#endif
diff --git a/config_file.c b/config_file.c
index 784956b..169b82a 100644
--- a/config_file.c
+++ b/config_file.c
@@ -17,7 +17,7 @@
************************************************************************/
#include "config_file.h"
-#include "debug.h"
+#include "common.h"
gboolean config_open(struct config_file* config_file)
{
diff --git a/debug.h b/debug.h
deleted file mode 100644
index 571d271..0000000
--- a/debug.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/************************************************************************
- * This file is part of trayfreq-archlinux. *
- * *
- * trayfreq-archlinux is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU General Public License as *
- * published by the Free Software Foundation; either version 3 of the *
- * License, or (at your option) any later version. *
- * *
- * trayfreq-archlinux is distributed in the hope that it will be useful,*
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with trayfreq-archlinux. If not, see *
- * <http://www.gnu.org/licenses/>. *
- ************************************************************************/
-
-/*
- This file makes debug macros into empty space if debug mode's not enabled.
- Otherwise it will make debug macro calls into appropriate printf()s
-*/
-
-#ifdef DEBUG
- #include <stdio.h>
- // <ew> Stringification of line number
- #define STRING2(x) #x
- #define STRING(x) STRING2(x)
- #define STR_LINE STRING(__LINE__)
- // </ew>
- #define debug(...) printf("DEBUG: "__FILE__":"STR_LINE" --- "__VA_ARGS__)
-#else
- #define debug(...);
-#endif
diff --git a/defaults.c b/defaults.c
index 79a9566..e3afa9a 100644
--- a/defaults.c
+++ b/defaults.c
@@ -26,7 +26,6 @@ char* _DEFAULT_PROG;
char* _DEFAULT_BAT_GOV;
char* _DEFAULT_AC_GOV;
bool _DEFAULT_SHOW_BATTERY = TRUE;
-bool _DEFAULT_USE_SUDO = FALSE;
char _DEFAULT_THEME[2048]; // to do : make dynamic with malloc
void defaults_init()
@@ -37,6 +36,5 @@ void defaults_init()
_DEFAULT_BAT_GOV = NULL;
_DEFAULT_AC_GOV = NULL;
_DEFAULT_SHOW_BATTERY = TRUE;
- _DEFAULT_USE_SUDO = FALSE;
sprintf (_DEFAULT_THEME, SHAREDIR"/trayfreq/themes/default");
}
diff --git a/defaults.h b/defaults.h
index dbd8822..bf5f5d9 100644
--- a/defaults.h
+++ b/defaults.h
@@ -28,7 +28,6 @@ char* _DEFAULT_PROG;
char* _DEFAULT_BAT_GOV;
char* _DEFAULT_AC_GOV;
bool _DEFAULT_SHOW_BATTERY;
-bool _DEFAULT_USE_SUDO;
char _DEFAULT_THEME[2048];
diff --git a/getcore.c b/getcore.c
index fc92e4c..39abb1c 100644
--- a/getcore.c
+++ b/getcore.c
@@ -18,6 +18,8 @@
#include "getcore.h"
+#include "common.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
diff --git a/getcore.h b/getcore.h
index 67d2f41..fc1fc8d 100644
--- a/getcore.h
+++ b/getcore.h
@@ -19,8 +19,6 @@
#ifndef GETCORE_H
#define GETCORE_H
-#include "debug.h"
-
void gc_init();
int gc_number();
diff --git a/getfreq.c b/getfreq.c
index 8984ecb..afd8fd7 100644
--- a/getfreq.c
+++ b/getfreq.c
@@ -18,6 +18,7 @@
#include "getfreq.h"
#include "getcore.h"
+#include "common.h"
#include <stdio.h>
#include <stdlib.h>
diff --git a/getgov.c b/getgov.c
index 181ad41..882b281 100644
--- a/getgov.c
+++ b/getgov.c
@@ -19,6 +19,7 @@
#include "string.h"
#include "getgov.h"
#include "getcore.h"
+#include "common.h"
#include <stdio.h>
#include <stdlib.h>
diff --git a/reload.c b/reload.c
index 16ee29a..1288fe4 100644
--- a/reload.c
+++ b/reload.c
@@ -21,7 +21,7 @@
#include "tray.h"
#include "trayfreq.h"
#include "defaults.h"
-#include "debug.h"
+#include "common.h"
#include <stdio.h>
void reload_config()
diff --git a/tray.c b/tray.c
index 3143464..dc10478 100644
--- a/tray.c
+++ b/tray.c
@@ -24,6 +24,7 @@
#include "trayfreq_set_interface.h"
#include "bat_tray.h"
#include "defaults.h"
+#include "common.h"
#include <glib.h>
#include <gtk/gtk.h>
diff --git a/trayfreq.c b/trayfreq.c
index 3e63cd5..8213e06 100644
--- a/trayfreq.c
+++ b/trayfreq.c
@@ -26,10 +26,11 @@
#include "config_file.h"
#include "reload.h"
#include "defaults.h"
-#include "debug.h"
+#include "common.h"
#include <gtk/gtk.h>
#include <stdlib.h>
+#include <unistd.h>
#include <stdio.h>
#include <libintl.h>
#include <locale.h>
@@ -127,11 +128,7 @@ void config_init()
if (temp)
_DEFAULT_SHOW_BATTERY = ( temp[0] == '1' );
- temp = config_get_key(&config, "extra", "sudo");
- if (temp)
- {
- _DEFAULT_USE_SUDO = ( temp[0] == '1' );
- }
+ info("Running as UID %d and GID %d\n", getuid(), getgid());
temp = config_get_key(&config, "extra", "theme");
if (temp && strlen(temp) < sizeof(_DEFAULT_THEME) )
@@ -141,8 +138,6 @@ void config_init()
debug("Using theme %s\n",_DEFAULT_THEME);
- debug("%s sudo\n",_DEFAULT_USE_SUDO? "Using" : "Not using");
-
g_free(config.file_name);
config_close(&config);
}
diff --git a/trayfreq.conf.src b/trayfreq.conf.src
index 753bcb4..a661a6a 100644
--- a/trayfreq.conf.src
+++ b/trayfreq.conf.src
@@ -32,11 +32,6 @@
[extra]
-## Uncomment to make trayfreq run trayfreq-set through sudo.
-## Useful if your WM doesn't run trayfreq as root, but you'll have to give the user
-## trayfreq is run as passwordless sudo access to `trayfreq-set`
-# sudo=1
-
## If you're arty, you can put together your own theme and point trayfreq to it
# theme=SHAREDIR/trayfreq/themes/some-theme/
diff --git a/trayfreq_set.c b/trayfreq_set.c
index 8f2ad72..02b0eef 100644
--- a/trayfreq_set.c
+++ b/trayfreq_set.c
@@ -26,7 +26,7 @@
#include "getfreq.h"
#include "getcore.h"
-#include "debug.h"
+#include "common.h"
#define FILE_PATH_STRING_SIZE 100
diff --git a/trayfreq_set_interface.c b/trayfreq_set_interface.c
index d16c160..a2e20c8 100644
--- a/trayfreq_set_interface.c
+++ b/trayfreq_set_interface.c
@@ -18,33 +18,33 @@
#include "trayfreq_set_interface.h"
-#include "debug.h"
-#include "defaults.h"
+#include "common.h"
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
void si_gov(char* gov, int core)
{
char cmd[256];
- if (_DEFAULT_USE_SUDO)
+ if (getuid() != ROOT_UID)
{
sprintf(cmd, SUDO" "TRAYFREQ_SET" -g %s -c %i",gov,core);
} else {
sprintf(cmd, TRAYFREQ_SET" -g %s -c %i",gov,core);
}
- debug("Running '%s'\n",cmd);
+ info("Running '%s'\n",cmd);
system(cmd);
}
void si_freq(int freq, int core)
{
char cmd[256];
- if (_DEFAULT_USE_SUDO)
+ if (getuid() != ROOT_UID)
{
sprintf(cmd, SUDO" "TRAYFREQ_SET" -f %i -c %i",freq,core);
} else {
sprintf(cmd, TRAYFREQ_SET" -f %i -c %i",freq,core);
}
- debug("Running '%s'\n",cmd);
+ info("Running '%s'\n",cmd);
system(cmd);
}