423758b30c
cupsAdminSetServerSettings() or cupsPutFile())
151 lines
5.0 KiB
Diff
151 lines
5.0 KiB
Diff
--- 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>
|