Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fun.git;a=commitdiff;h=8e981b4c879f475d5562e64c1e062812c0247ff9
commit 8e981b4c879f475d5562e64c1e062812c0247ff9 Author: Priyank <[EMAIL PROTECTED]> Date: Fri Nov 2 18:42:19 2007 +0530 renamed updnotifierd to fund diff --git a/Makefile.am b/Makefile.am index 0b8e3df..007992d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ SUBDIRS = src dbusdir = $(DBUS_SYS_DIR) -dbus_DATA = updnotifierd.conf +dbus_DATA = fund.conf EXTRA_DIST = $(dbus_DATA) diff --git a/configure.ac b/configure.ac index a5ed71c..dba106d 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ ENV_CFLAGS=$CFLAGS AC_PREREQ(2.59) AC_INIT([updnotifierd], 0.1, [EMAIL PROTECTED], updnotifierd) -AC_CONFIG_SRCDIR([src/updnotifierd.c]) +AC_CONFIG_SRCDIR([src/fund.c]) AC_LANG(C) AM_CONFIG_HEADER(config.h) AC_CANONICAL_SYSTEM diff --git a/fund.conf b/fund.conf new file mode 100644 index 0000000..1bfeb25 --- /dev/null +++ b/fund.conf @@ -0,0 +1,20 @@ +<!DOCTYPE busconfig PUBLIC + "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> +<busconfig> + <policy user="root"> + <allow own="org.frugalware.UpdNotifier"/> + <allow send_destination="org.frugalware.UpdNotifier"/> + <allow send_interface="org.frugalware.UpdNotifier"/> + </policy> + <policy group="users"> + <allow own="org.frugalware.UpdNotifier"/> + <allow send_destination="org.frugalware.UpdNotifier"/> + <allow send_interface="org.frugalware.UpdNotifier"/> + </policy> + <policy context="default"> + <deny own="org.frugalware.UpdNotifier"/> + <deny send_destination="org.frugalware.UpdNotifier"/> + <deny send_interface="org.frugalware.UpdNotifier"/> + </policy> +</busconfig> diff --git a/src/Makefile.am b/src/Makefile.am index 1caffbc..078dcf3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,10 +3,10 @@ INCLUDES = @UPDNOTIFIERD_CFLAGS@ \ -DPREFIX=\"$(prefix)\" \ -fPIC -sbin_PROGRAMS = updnotifierd +sbin_PROGRAMS = fund bin_PROGRAMS = fun -updnotifierd_SOURCES = updnotifierd.c +fund_SOURCES = fund.c fun_SOURCES = eggtrayicon.c \ sexy-tooltip.c \ fun-tooltip.c \ @@ -14,15 +14,15 @@ fun_SOURCES = eggtrayicon.c \ fun-dbus.c \ fun.c -updnotifierd_LDADD= @UPDNOTIFIERD_LIBS@ -lpacman -lfwutil +fund_LDADD= @UPDNOTIFIERD_LIBS@ -lpacman -lfwutil fun_LDADD= @FUN_LIBS@ @UPDNOTIFIERD_LIBS@ -BUILT_SOURCES = updnotifierd-dbus-glue.h +BUILT_SOURCES = fund-dbus-glue.h -updnotifierd-dbus-glue.h: updnotifierd.xml - @DBUSBINDINGTOOL@ --mode=glib-server --prefix=updnotifierd \ - $(srcdir)/updnotifierd.xml > updnotifierd-dbus-glue.h +fund-dbus-glue.h: fund.xml + @DBUSBINDINGTOOL@ --mode=glib-server --prefix=fund \ + $(srcdir)/fund.xml > fund-dbus-glue.h -EXTRA_DIST = updnotifierd.xml +EXTRA_DIST = fund.xml DISTCLEANFILES = \ - updnotifierd-dbus-glue.h + fund-dbus-glue.h diff --git a/src/fund.c b/src/fund.c new file mode 100644 index 0000000..dd61487 --- /dev/null +++ b/src/fund.c @@ -0,0 +1,238 @@ +/* + * updatenotifierd.c for updatenotifier + * + * Copyright (C) 2007 by Priyank Gosalia <[EMAIL PROTECTED]> + * Portions of this code are borrowed fron netconfigd + * netconfigd is Copyright (C) 2007 Alex Smith <[EMAIL PROTECTED]> + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> +#include <dbus/dbus-glib-bindings.h> +#include <libfwutil.h> +#include <dirent.h> +#include <config.h> +#include <syslog.h> +#include <pacman.h> +#include "updnotifierd.h" +#include "updnotifierd-dbus-glue.h" + +typedef void* netbuf; +static PM_DB *sync_db = NULL; +static PM_DB *local_db = NULL; + +G_DEFINE_TYPE(UpdNotifier, updnotifierd, G_TYPE_OBJECT); + +void updnotifierd_class_init(UpdNotifierClass *class) { + // Nothing here +} + +void updnotifierd_init(UpdNotifier *server) { + GError *error = NULL; + DBusGProxy *driver_proxy; + int request_ret; + + // Init the DBus connection + server->connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); + if (server->connection == NULL) { + g_warning("Unable to connect to dbus: %s", error->message); + g_error_free(error); + return; + } + + dbus_g_object_type_install_info(updnotifierd_get_type(), &dbus_glib_updnotifierd_object_info); + + // Register DBUS path + dbus_g_connection_register_g_object(server->connection, "/org/frugalware/UpdNotifier", G_OBJECT(server)); + + // Register the service name, the constant here are defined in dbus-glib-bindings.h + driver_proxy = dbus_g_proxy_new_for_name(server->connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); + + if (!org_freedesktop_DBus_request_name (driver_proxy, "org.frugalware.UpdNotifier", 0, &request_ret, &error)) { + g_warning("Unable to register service: %s", error->message); + g_error_free(error); + } + + g_object_unref(driver_proxy); +} + +static void +_log_cb (unsigned short level, char *msg) { + g_print ("%s\n", msg); + + return; +} + +static gboolean +_updatenotifierd_init_pacman () { + /* initialize the pacman-g2 library */ + if (pacman_initialize ("/") == -1) + return FALSE; + + /* register the main repo */ + /* FIXME: Later add support for custom repos */ + sync_db = pacman_db_register ("frugalware-current"); + local_db = pacman_db_register ("local"); + + if (sync_db == NULL) + return FALSE; + if (local_db == NULL) + return FALSE; + + /* parse the pacman-g2 config */ + pacman_parse_config ("/etc/pacman.conf", NULL, ""); + pacman_set_option (PM_OPT_LOGMASK, (long)-1); + pacman_set_option (PM_OPT_LOGCB, (long)_log_cb); + + return TRUE; +} + +GList* _updnotifierd_update_database (void) { + PM_LIST *packages = NULL; + GList *ret = NULL; + int retval = 0; + + /* update the pacman database */ + retval = pacman_db_update (0, sync_db); + + /* something went wrong */ + if (retval== -1) { + printf ("%s\n", pacman_strerror(pm_errno)); + return ret; + } + + if (pacman_trans_init(PM_TRANS_TYPE_SYNC, 0, NULL, NULL, NULL) == -1) { + gchar *errorstr = g_strdup_printf ("Failed to init transaction (%s)\n", pacman_strerror(pm_errno)); + g_print (errorstr); + g_free (errorstr); + return ret; + } + else { + if (pacman_trans_sysupgrade() == -1) { + g_print (pacman_strerror(pm_errno)); + } + else { + packages = pacman_trans_getinfo (PM_TRANS_PACKAGES); + if (packages == NULL) { + g_print ("No new updates are available\n"); + } + else { + PM_LIST *i = NULL; + + for (i=pacman_list_first(packages);i!=NULL;i=pacman_list_next(i)) { + PM_SYNCPKG *spkg = pacman_list_getdata (i); + PM_PKG *pkg = pacman_sync_getinfo (spkg, PM_SYNC_PKG); + ret = g_list_append (ret, g_strdup((char*)pacman_pkg_getinfo(pkg,PM_PKG_NAME))); + } + } + pacman_trans_release (); + } + } + + return ret; +} + +gboolean updnotifier_update_database(UpdNotifier *obj, gchar **packages, GError **error) { + GList *list = NULL; + if ((list = _updnotifierd_update_database())==NULL) { + *packages = NULL; + return FALSE; + } + else { + GString *tmp = g_string_new (""); + for (list; list!=NULL;list=g_list_next(list)) { + tmp = g_string_append (tmp, list->data); + tmp = g_string_append (tmp, " "); + } + *packages = g_strdup (tmp->str); + return TRUE; + } +} + +gboolean updnotifier_test_service(UpdNotifier *obj, gint *ret, GError **error) { + *ret = 1; + return TRUE; +} + +void usage() { + printf("Fund v" VERSION "\n"); + printf(" --help Display this help text\n"); + printf(" --daemon Fork into the background\n"); +} + +int main (int argc, char *argv[]) { + GMainLoop *main_loop; + UpdNotifier *server; + int i = 1; + int daemonize = 0; + + // Parse command line options + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "--daemon")) + daemonize = 1; + else if (!strcmp(argv[i], "--help")) { + usage(); + return 0; + } else { + usage(); + return 1; + } + } + + if (getuid() != 0) { + printf("Must run as root!\n"); + exit(1); + } + + // Daemonize if wanted + if (daemonize) { + switch (fork()) { + case 0: + break; + case -1: + printf("Can't fork: %s\n", strerror(errno)); + exit(1); + break; + default: + exit(0); + } + + fclose(stdin); + fclose(stdout); + fclose(stderr); + } + + // Connect to syslog + openlog("updnotifierd", LOG_PID, LOG_DAEMON); + + syslog(LOG_INFO, "Fund v" VERSION " started..."); + + g_type_init(); + + server = g_object_new(updnotifierd_get_type(), NULL); + + _updatenotifierd_init_pacman (); + main_loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(main_loop); + + return 0; +} + diff --git a/src/fund.h b/src/fund.h new file mode 100644 index 0000000..dee4fde --- /dev/null +++ b/src/fund.h @@ -0,0 +1,43 @@ +/*************************************************************************** + * netconfigd.h + * Author(s): Alex Smith <[EMAIL PROTECTED]> + * Copyright (C) 2007 Frugalware Developer Team + ****************************************************************************/ + +/* + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef _UPDNOTIFIERD_H +#define _UPDNOTIFIERD_H + +typedef struct +{ + GObject parent; + DBusGConnection *connection; +} UpdNotifier; + +typedef struct +{ + GObjectClass parent_class; +} UpdNotifierClass; + +static void updnotifierd_init(UpdNotifier *server); +static void updnotifierd_class_init(UpdNotifierClass *class); + +gboolean updnotifier_update_database(UpdNotifier *obj, gchar **packages, GError **error); +gboolean updnotifier_test_service(UpdNotifier *obj, gint *ret, GError **error); + +#endif diff --git a/src/fund.xml b/src/fund.xml new file mode 100644 index 0000000..305d636 --- /dev/null +++ b/src/fund.xml @@ -0,0 +1,13 @@ +<node name="/org/frugalware/UpdNotifier"> + <interface name="org.frugalware.UpdNotifier"> + <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="updnotifier"/> + <method name="PerformUpdate"> + <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="updnotifier_update_database"/> + <arg type="s" name="packages" direction="out" /> + </method> + <method name="TestService"> + <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="updnotifier_test_service"/> + <arg type="i" name="ret" direction="out" /> + </method> + </interface> +</node> diff --git a/src/updnotifierd.c b/src/updnotifierd.c deleted file mode 100644 index dd61487..0000000 --- a/src/updnotifierd.c +++ /dev/null @@ -1,238 +0,0 @@ -/* - * updatenotifierd.c for updatenotifier - * - * Copyright (C) 2007 by Priyank Gosalia <[EMAIL PROTECTED]> - * Portions of this code are borrowed fron netconfigd - * netconfigd is Copyright (C) 2007 Alex Smith <[EMAIL PROTECTED]> - * - * This program 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 2 of the License, or - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <glib.h> -#include <dbus/dbus-glib-bindings.h> -#include <libfwutil.h> -#include <dirent.h> -#include <config.h> -#include <syslog.h> -#include <pacman.h> -#include "updnotifierd.h" -#include "updnotifierd-dbus-glue.h" - -typedef void* netbuf; -static PM_DB *sync_db = NULL; -static PM_DB *local_db = NULL; - -G_DEFINE_TYPE(UpdNotifier, updnotifierd, G_TYPE_OBJECT); - -void updnotifierd_class_init(UpdNotifierClass *class) { - // Nothing here -} - -void updnotifierd_init(UpdNotifier *server) { - GError *error = NULL; - DBusGProxy *driver_proxy; - int request_ret; - - // Init the DBus connection - server->connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); - if (server->connection == NULL) { - g_warning("Unable to connect to dbus: %s", error->message); - g_error_free(error); - return; - } - - dbus_g_object_type_install_info(updnotifierd_get_type(), &dbus_glib_updnotifierd_object_info); - - // Register DBUS path - dbus_g_connection_register_g_object(server->connection, "/org/frugalware/UpdNotifier", G_OBJECT(server)); - - // Register the service name, the constant here are defined in dbus-glib-bindings.h - driver_proxy = dbus_g_proxy_new_for_name(server->connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); - - if (!org_freedesktop_DBus_request_name (driver_proxy, "org.frugalware.UpdNotifier", 0, &request_ret, &error)) { - g_warning("Unable to register service: %s", error->message); - g_error_free(error); - } - - g_object_unref(driver_proxy); -} - -static void -_log_cb (unsigned short level, char *msg) { - g_print ("%s\n", msg); - - return; -} - -static gboolean -_updatenotifierd_init_pacman () { - /* initialize the pacman-g2 library */ - if (pacman_initialize ("/") == -1) - return FALSE; - - /* register the main repo */ - /* FIXME: Later add support for custom repos */ - sync_db = pacman_db_register ("frugalware-current"); - local_db = pacman_db_register ("local"); - - if (sync_db == NULL) - return FALSE; - if (local_db == NULL) - return FALSE; - - /* parse the pacman-g2 config */ - pacman_parse_config ("/etc/pacman.conf", NULL, ""); - pacman_set_option (PM_OPT_LOGMASK, (long)-1); - pacman_set_option (PM_OPT_LOGCB, (long)_log_cb); - - return TRUE; -} - -GList* _updnotifierd_update_database (void) { - PM_LIST *packages = NULL; - GList *ret = NULL; - int retval = 0; - - /* update the pacman database */ - retval = pacman_db_update (0, sync_db); - - /* something went wrong */ - if (retval== -1) { - printf ("%s\n", pacman_strerror(pm_errno)); - return ret; - } - - if (pacman_trans_init(PM_TRANS_TYPE_SYNC, 0, NULL, NULL, NULL) == -1) { - gchar *errorstr = g_strdup_printf ("Failed to init transaction (%s)\n", pacman_strerror(pm_errno)); - g_print (errorstr); - g_free (errorstr); - return ret; - } - else { - if (pacman_trans_sysupgrade() == -1) { - g_print (pacman_strerror(pm_errno)); - } - else { - packages = pacman_trans_getinfo (PM_TRANS_PACKAGES); - if (packages == NULL) { - g_print ("No new updates are available\n"); - } - else { - PM_LIST *i = NULL; - - for (i=pacman_list_first(packages);i!=NULL;i=pacman_list_next(i)) { - PM_SYNCPKG *spkg = pacman_list_getdata (i); - PM_PKG *pkg = pacman_sync_getinfo (spkg, PM_SYNC_PKG); - ret = g_list_append (ret, g_strdup((char*)pacman_pkg_getinfo(pkg,PM_PKG_NAME))); - } - } - pacman_trans_release (); - } - } - - return ret; -} - -gboolean updnotifier_update_database(UpdNotifier *obj, gchar **packages, GError **error) { - GList *list = NULL; - if ((list = _updnotifierd_update_database())==NULL) { - *packages = NULL; - return FALSE; - } - else { - GString *tmp = g_string_new (""); - for (list; list!=NULL;list=g_list_next(list)) { - tmp = g_string_append (tmp, list->data); - tmp = g_string_append (tmp, " "); - } - *packages = g_strdup (tmp->str); - return TRUE; - } -} - -gboolean updnotifier_test_service(UpdNotifier *obj, gint *ret, GError **error) { - *ret = 1; - return TRUE; -} - -void usage() { - printf("Fund v" VERSION "\n"); - printf(" --help Display this help text\n"); - printf(" --daemon Fork into the background\n"); -} - -int main (int argc, char *argv[]) { - GMainLoop *main_loop; - UpdNotifier *server; - int i = 1; - int daemonize = 0; - - // Parse command line options - for (i = 1; i < argc; i++) { - if (!strcmp(argv[i], "--daemon")) - daemonize = 1; - else if (!strcmp(argv[i], "--help")) { - usage(); - return 0; - } else { - usage(); - return 1; - } - } - - if (getuid() != 0) { - printf("Must run as root!\n"); - exit(1); - } - - // Daemonize if wanted - if (daemonize) { - switch (fork()) { - case 0: - break; - case -1: - printf("Can't fork: %s\n", strerror(errno)); - exit(1); - break; - default: - exit(0); - } - - fclose(stdin); - fclose(stdout); - fclose(stderr); - } - - // Connect to syslog - openlog("updnotifierd", LOG_PID, LOG_DAEMON); - - syslog(LOG_INFO, "Fund v" VERSION " started..."); - - g_type_init(); - - server = g_object_new(updnotifierd_get_type(), NULL); - - _updatenotifierd_init_pacman (); - main_loop = g_main_loop_new(NULL, FALSE); - g_main_loop_run(main_loop); - - return 0; -} - diff --git a/src/updnotifierd.h b/src/updnotifierd.h deleted file mode 100644 index dee4fde..0000000 --- a/src/updnotifierd.h +++ /dev/null @@ -1,43 +0,0 @@ -/*************************************************************************** - * netconfigd.h - * Author(s): Alex Smith <[EMAIL PROTECTED]> - * Copyright (C) 2007 Frugalware Developer Team - ****************************************************************************/ - -/* - * This program 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 2 of the License, or - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef _UPDNOTIFIERD_H -#define _UPDNOTIFIERD_H - -typedef struct -{ - GObject parent; - DBusGConnection *connection; -} UpdNotifier; - -typedef struct -{ - GObjectClass parent_class; -} UpdNotifierClass; - -static void updnotifierd_init(UpdNotifier *server); -static void updnotifierd_class_init(UpdNotifierClass *class); - -gboolean updnotifier_update_database(UpdNotifier *obj, gchar **packages, GError **error); -gboolean updnotifier_test_service(UpdNotifier *obj, gint *ret, GError **error); - -#endif diff --git a/src/updnotifierd.xml b/src/updnotifierd.xml deleted file mode 100644 index 305d636..0000000 --- a/src/updnotifierd.xml +++ /dev/null @@ -1,13 +0,0 @@ -<node name="/org/frugalware/UpdNotifier"> - <interface name="org.frugalware.UpdNotifier"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="updnotifier"/> - <method name="PerformUpdate"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="updnotifier_update_database"/> - <arg type="s" name="packages" direction="out" /> - </method> - <method name="TestService"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="updnotifier_test_service"/> - <arg type="i" name="ret" direction="out" /> - </method> - </interface> -</node> diff --git a/updnotifierd.conf b/updnotifierd.conf deleted file mode 100644 index 1bfeb25..0000000 --- a/updnotifierd.conf +++ /dev/null @@ -1,20 +0,0 @@ -<!DOCTYPE busconfig PUBLIC - "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" - "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> -<busconfig> - <policy user="root"> - <allow own="org.frugalware.UpdNotifier"/> - <allow send_destination="org.frugalware.UpdNotifier"/> - <allow send_interface="org.frugalware.UpdNotifier"/> - </policy> - <policy group="users"> - <allow own="org.frugalware.UpdNotifier"/> - <allow send_destination="org.frugalware.UpdNotifier"/> - <allow send_interface="org.frugalware.UpdNotifier"/> - </policy> - <policy context="default"> - <deny own="org.frugalware.UpdNotifier"/> - <deny send_destination="org.frugalware.UpdNotifier"/> - <deny send_interface="org.frugalware.UpdNotifier"/> - </policy> -</busconfig> _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
