diff options
| -rw-r--r-- | Makefile | 38 | ||||
| -rw-r--r-- | bat_tray.c | 1 | ||||
| -rw-r--r-- | common.c | 2 | ||||
| -rw-r--r-- | common.h | 20 | ||||
| -rw-r--r-- | config_file.c | 2 | ||||
| -rw-r--r-- | debug.h | 34 | ||||
| -rw-r--r-- | defaults.c | 2 | ||||
| -rw-r--r-- | defaults.h | 1 | ||||
| -rw-r--r-- | getcore.c | 2 | ||||
| -rw-r--r-- | getcore.h | 2 | ||||
| -rw-r--r-- | getfreq.c | 1 | ||||
| -rw-r--r-- | getgov.c | 1 | ||||
| -rw-r--r-- | reload.c | 2 | ||||
| -rw-r--r-- | tray.c | 1 | ||||
| -rw-r--r-- | trayfreq.c | 11 | ||||
| -rw-r--r-- | trayfreq.conf.src | 5 | ||||
| -rw-r--r-- | trayfreq_set.c | 2 | ||||
| -rw-r--r-- | trayfreq_set_interface.c | 12 | 
18 files changed, 51 insertions, 88 deletions
@@ -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) @@ -21,7 +21,6 @@  #include <gtk/gtk.h>  #include <libintl.h> -#include "debug.h"  #include "common.h"  #include "defaults.h" @@ -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 */ @@ -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 @@ -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");  } @@ -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]; @@ -18,6 +18,8 @@  #include "getcore.h" +#include "common.h" +  #include <stdio.h>  #include <stdlib.h>  #include <glib.h> @@ -19,8 +19,6 @@  #ifndef GETCORE_H  #define GETCORE_H -#include "debug.h" -  void gc_init();  int  gc_number(); @@ -18,6 +18,7 @@  #include "getfreq.h"  #include "getcore.h" +#include "common.h"  #include <stdio.h>  #include <stdlib.h> @@ -19,6 +19,7 @@  #include "string.h"  #include "getgov.h"  #include "getcore.h" +#include "common.h"  #include <stdio.h>  #include <stdlib.h> @@ -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() @@ -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> @@ -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);  }  | 
