rpms/cups-pk-helper/devel cph_reconnect.patch, NONE, 1.1 cups-pk-helper.spec, 1.3, 1.4
Marek Kašík
mkasik at fedoraproject.org
Fri Feb 13 11:37:46 UTC 2009
Author: mkasik
Update of /cvs/pkgs/rpms/cups-pk-helper/devel
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv32017
Modified Files:
cups-pk-helper.spec
Added Files:
cph_reconnect.patch
Log Message:
* Fri Feb 13 2009 Marek Kasik <mkasik at redhat.com> 0.0.3-4
- Add ability to reconnect to CUPS server after its reload
(caused by cupsAdminSetServerSettings() or cupsPutFile())
cph_reconnect.patch:
--- NEW FILE cph_reconnect.patch ---
--- src/cups.c 2009-02-13 11:55:38.000000000 +0100
+++ src/cups.c 2009-02-13 11:57:39.000000000 +0100
@@ -45,6 +45,9 @@
#include "cups.h"
+#define MAX_RECONNECT_ATTEMPTS 100
+#define RECONNECT_DELAY 100000
+
/*
getPrinters
getDests
@@ -114,6 +117,7 @@ struct CphCupsPrivate
http_t *connection;
ipp_status_t last_status;
char *internal_status;
+ gboolean reconnecting;
};
static GObject *cph_cups_constructor (GType type,
@@ -172,6 +176,31 @@ cph_cups_init (CphCups *cups)
cups->priv->connection = NULL;
cups->priv->last_status = IPP_OK;
cups->priv->internal_status = NULL;
+ cups->priv->reconnecting = FALSE;
+}
+
+gboolean
+cph_cups_reconnect (CphCups *cups)
+{
+ gint return_value = -1;
+ gint i;
+
+ cups->priv->reconnecting = TRUE;
+
+ for (i = 0; i < MAX_RECONNECT_ATTEMPTS; i++) {
+ return_value = httpReconnect (cups->priv->connection);
+ if (return_value == 0) {
+ break;
+ }
+ g_usleep (RECONNECT_DELAY);
+ }
+
+ cups->priv->reconnecting = FALSE;
+
+ if (return_value == 0)
+ return TRUE;
+ else
+ return FALSE;
}
static void
@@ -848,6 +877,10 @@ cph_cups_file_get (CphCups *cups,
const char *resource,
const char *filename)
{
+ struct stat file_stat;
+ uid_t uid = 0;
+ gid_t gid = 0;
+
g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
if (!_cph_cups_is_resource_valid (cups, resource))
@@ -855,12 +888,31 @@ cph_cups_file_get (CphCups *cups,
if (!_cph_cups_is_filename_valid (cups, filename))
return FALSE;
+ stat (filename, &file_stat);
+ uid = file_stat.st_uid;
+ gid = file_stat.st_gid;
+
/* reset the internal status: we'll use the cups status */
_cph_cups_set_internal_status (cups, NULL);
-
cups->priv->last_status = cupsGetFile (cups->priv->connection,
resource, filename);
+ if (cups->priv->last_status != HTTP_OK) {
+ int fd;
+
+ if (cph_cups_reconnect (cups)) {
+
+ /* if cupsGetFile fail then filename is erased */
+ fd = open (filename, O_CREAT, S_IRUSR | S_IWUSR);
+ close (fd);
+ chown (filename, uid, gid);
+
+ _cph_cups_set_internal_status (cups, NULL);
+ cups->priv->last_status = cupsGetFile (cups->priv->connection,
+ resource, filename);
+ }
+ }
+
return cups->priv->last_status == HTTP_OK;
}
@@ -882,6 +934,9 @@ cph_cups_file_put (CphCups *cups,
cups->priv->last_status = cupsPutFile (cups->priv->connection,
resource, filename);
+ /* CUPS is being restarted, so we need to reconnect */
+ cph_cups_reconnect (cups);
+
return (cups->priv->last_status == HTTP_OK ||
cups->priv->last_status == HTTP_CREATED);
}
@@ -1613,6 +1668,9 @@ cph_cups_server_set_settings (CphCups
retval = cupsAdminSetServerSettings (cups->priv->connection,
num_settings, cups_settings);
+ /* CUPS is being restarted, so we need to reconnect */
+ cph_cups_reconnect (cups);
+
cupsFreeOptions (num_settings, cups_settings);
if (retval == 0) {
--- src/cups-pk-helper-mechanism.c 2009-02-13 11:55:38.000000000 +0100
+++ src/cups-pk-helper-mechanism.c 2009-02-13 11:55:52.000000000 +0100
@@ -60,7 +60,8 @@
static gboolean
do_exit (gpointer user_data)
{
- g_object_unref (CPH_MECHANISM (user_data));
+ if (user_data != NULL)
+ g_object_unref (CPH_MECHANISM (user_data));
exit (0);
@@ -540,10 +541,6 @@ cph_mechanism_file_put (CphMechanism
ret = cph_cups_file_put (mechanism->priv->cups, resource, filename);
_cph_mechanism_return_error (mechanism, context, !ret);
- /* TODO: this is a workaround for bnc#447422
- * https://bugzilla.novell.com/show_bug.cgi?id=447422 */
- do_exit (NULL);
-
return TRUE;
}
--- src/org.opensuse.cupspkhelper.mechanism.policy.in 2009-02-13 11:55:38.000000000 +0100
+++ src/org.opensuse.cupspkhelper.mechanism.policy.in 2009-02-13 11:55:52.000000000 +0100
@@ -114,7 +114,7 @@
</action>
<action id="org.opensuse.cupspkhelper.mechanism.job-set-hold-until-another-owner">
- <_description>Set hold-until time of a job owned by another</_description>
+ <_description>Set hold-until time of a job owned by another user</_description>
<_message>Privileges are required to set hold-until time of a job owned by another user.</_message>
<defaults>
<allow_inactive>no</allow_inactive>
Index: cups-pk-helper.spec
===================================================================
RCS file: /cvs/pkgs/rpms/cups-pk-helper/devel/cups-pk-helper.spec,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- cups-pk-helper.spec 28 Jan 2009 12:08:29 -0000 1.3
+++ cups-pk-helper.spec 13 Feb 2009 11:37:16 -0000 1.4
@@ -1,6 +1,6 @@
Name: cups-pk-helper
Version: 0.0.3
-Release: 3%{?dist}
+Release: 4%{?dist}
Summary: A helper that makes system-config-printer use PolicyKit
Group: System Environment/Base
@@ -11,6 +11,7 @@
Patch0: dependencies.patch
Patch1: pk_order.patch
Patch2: pk_jobs.patch
+Patch3: cph_reconnect.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
@@ -36,6 +37,7 @@
%patch0 -p0 -b .dependencies
%patch1 -p0 -b .pk-order
%patch2 -p0 -b .pk-jobs
+%patch3 -p0 -b .cph-reconnect
%build
%configure
@@ -62,6 +64,10 @@
%changelog
+* Fri Feb 13 2009 Marek Kasik <mkasik at redhat.com> 0.0.3-4
+- Add ability to reconnect to CUPS server after its reload
+ (caused by cupsAdminSetServerSettings() or cupsPutFile())
+
* Tue Jan 28 2009 Marek Kasik <mkasik at redhat.com> 0.0.3-3
- Add functions for handling jobs (JobRestart, JobCancel, JobSetHoldUntil)
More information about the fedora-extras-commits
mailing list